52 lines · cpp
1// Make sure we can throw exceptions from work items executed via2// QueueUserWorkItem.3//4// RUN: %clangxx_asan %s -o %t.exe5// RUN: %run %t.exe 2>&1 | FileCheck %s6 7#include <windows.h>8#include <stdio.h>9 10void ThrowAndCatch();11 12__declspec(noinline)13void Throw() {14 fprintf(stderr, "Throw\n");15// CHECK: Throw16 throw 1;17}18 19void ThrowAndCatch() {20 int local;21 try {22 Throw();23 } catch(...) {24 fprintf(stderr, "Catch\n");25// CHECK: Catch26 }27}28 29HANDLE done;30 31DWORD CALLBACK work_item(LPVOID) {32 ThrowAndCatch();33 SetEvent(done);34 return 0;35}36 37int main(int argc, char **argv) {38 done = CreateEvent(0, false, false, "job is done");39 if (!done)40 return 1;41 QueueUserWorkItem(&work_item, nullptr, 0);42 unsigned wait_result = WaitForSingleObject(done, 10 * 1000);43 if (wait_result == WAIT_ABANDONED)44 fprintf(stderr, "Timed out\n");45 if (wait_result != WAIT_OBJECT_0) {46 fprintf(stderr, "Wait for work item failed\n");47 return 2;48 }49 fprintf(stderr, "Done!\n");50// CHECK: Done!51}52