1// Make sure we can throw exceptions from work items executed via
2// QueueUserWorkItem.
3//
4// RUN: %clangxx_asan %s -o %t.exe
5// RUN: %run %t.exe 2>&1 | FileCheck %s
6
7#include <windows.h>
8#include <stdio.h>
9
10void ThrowAndCatch();
11
12__declspec(noinline)
13void Throw() {
14 fprintf(stderr, format: "Throw\n");
15// CHECK: Throw
16 throw 1;
17}
18
19void ThrowAndCatch() {
20 int local;
21 try {
22 Throw();
23 } catch(...) {
24 fprintf(stderr, format: "Catch\n");
25// CHECK: Catch
26 }
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, format: "Timed out\n");
45 if (wait_result != WAIT_OBJECT_0) {
46 fprintf(stderr, format: "Wait for work item failed\n");
47 return 2;
48 }
49 fprintf(stderr, format: "Done!\n");
50// CHECK: Done!
51}
52

source code of compiler-rt/test/asan/TestCases/Windows/queue_user_work_item.cpp