brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · ef7e458 Raw
62 lines · cpp
1// Make sure we can throw exceptions from work items executed via2// BindIoCompletionCallback.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 29char buffer[65536];30HANDLE done;31OVERLAPPED ov;32 33void CALLBACK completion_callback(DWORD error, DWORD bytesRead,34                                  LPOVERLAPPED pov) {35  ThrowAndCatch();36  SetEvent(done);37}38 39int 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, "Done!\n");60// CHECK: Done!61}62