1 | // Make sure we can throw exceptions from work items executed via |
2 | // BindIoCompletionCallback. |
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 | |
10 | void ThrowAndCatch(); |
11 | |
12 | __declspec(noinline) |
13 | void Throw() { |
14 | fprintf(stderr, format: "Throw\n" ); |
15 | // CHECK: Throw |
16 | throw 1; |
17 | } |
18 | |
19 | void ThrowAndCatch() { |
20 | int local; |
21 | try { |
22 | Throw(); |
23 | } catch(...) { |
24 | fprintf(stderr, format: "Catch\n" ); |
25 | // CHECK: Catch |
26 | } |
27 | } |
28 | |
29 | char buffer[65536]; |
30 | HANDLE done; |
31 | OVERLAPPED ov; |
32 | |
33 | void CALLBACK completion_callback(DWORD error, DWORD bytesRead, |
34 | LPOVERLAPPED pov) { |
35 | ThrowAndCatch(); |
36 | SetEvent(done); |
37 | } |
38 | |
39 | int main(int argc, char **argv) { |
40 | done = CreateEvent(0, false, false, "job is done" ); |
41 | if (!done) |
42 | return 1; |
43 | HANDLE file = CreateFile( |
44 | argv[0], GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, |
45 | OPEN_EXISTING, |
46 | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, |
47 | NULL); |
48 | if (!file) |
49 | return 2; |
50 | if (!BindIoCompletionCallback(file, completion_callback, 0)) |
51 | return 3; |
52 | |
53 | if (!ReadFile(file, buffer, sizeof(buffer), NULL, &ov) && |
54 | GetLastError() != ERROR_IO_PENDING) |
55 | return 4; |
56 | |
57 | if (WAIT_OBJECT_0 != WaitForSingleObject(done, 10 * 1000)) |
58 | return 5; |
59 | fprintf(stderr, format: "Done!\n" ); |
60 | // CHECK: Done! |
61 | } |
62 | |