coro-unhandled-exception.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -triple=x86_64-pc-windows-msvc18.0.0 -emit-llvm %s -o - -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s
  2. // RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck --check-prefix=CHECK-LPAD %s
  3. #include "Inputs/coroutine.h"
  4. namespace coro = std::experimental::coroutines_v1;
  5. namespace std {
  6. using exception_ptr = int;
  7. exception_ptr current_exception();
  8. }
  9. struct coro_t {
  10. struct promise_type {
  11. coro_t get_return_object() {
  12. coro::coroutine_handle<promise_type>{};
  13. return {};
  14. }
  15. coro::suspend_never initial_suspend() { return {}; }
  16. coro::suspend_never final_suspend() { return {}; }
  17. void return_void(){}
  18. void unhandled_exception() noexcept;
  19. };
  20. };
  21. struct Cleanup { ~Cleanup(); };
  22. void may_throw();
  23. coro_t f() {
  24. Cleanup x;
  25. may_throw();
  26. co_return;
  27. }
  28. // CHECK: @"?f@@YA?AUcoro_t@@XZ"(
  29. // CHECK: invoke void @"?may_throw@@YAXXZ"()
  30. // CHECK: to label %{{.+}} unwind label %[[EHCLEANUP:.+]]
  31. // CHECK: [[EHCLEANUP]]:
  32. // CHECK: %[[INNERPAD:.+]] = cleanuppad within none []
  33. // CHECK: call void @"??1Cleanup@@QEAA@XZ"(
  34. // CHECK: cleanupret from %[[INNERPAD]] unwind label %[[CATCHSW:.+]]
  35. // CHECK: [[CATCHSW]]:
  36. // CHECK: %[[CATCHSWTOK:.+]] = catchswitch within none [label %[[CATCH:.+]]] unwind label
  37. // CHECK: [[CATCH]]:
  38. // CHECK: %[[CATCHTOK:.+]] = catchpad within [[CATCHSWTOK:.+]]
  39. // CHECK: call void @"?unhandled_exception@promise_type@coro_t@@QEAAXXZ"
  40. // CHECK: catchret from %[[CATCHTOK]] to label %[[CATCHRETDEST:.+]]
  41. // CHECK: [[CATCHRETDEST]]:
  42. // CHECK-NEXT: br label %[[TRYCONT:.+]]
  43. // CHECK: [[TRYCONT]]:
  44. // CHECK-NEXT: br label %[[RESUMECONT:.+]]
  45. // CHECK: [[RESUMECONT]]:
  46. // CHECK-NEXT: br label %[[COROFIN:.+]]
  47. // CHECK: [[COROFIN]]:
  48. // CHECK-NEXT: invoke void @"?final_suspend@promise_type@coro_t@@QEAA?AUsuspend_never@coroutines_v1@experimental@std@@XZ"(
  49. // CHECK-LPAD: @_Z1fv(
  50. // CHECK-LPAD: invoke void @_Z9may_throwv()
  51. // CHECK-LPAD: to label %[[CONT:.+]] unwind label %[[CLEANUP:.+]]
  52. // CHECK-LPAD: [[CLEANUP]]:
  53. // CHECK-LPAD: call void @_ZN7CleanupD1Ev(%struct.Cleanup* %x) #2
  54. // CHECK-LPAD: br label %[[CATCH:.+]]
  55. // CHECK-LPAD: [[CATCH]]:
  56. // CHECK-LPAD: call i8* @__cxa_begin_catch
  57. // CHECK-LPAD: call void @_ZN6coro_t12promise_type19unhandled_exceptionEv(%"struct.coro_t::promise_type"* %__promise) #2
  58. // CHECK-LPAD: invoke void @__cxa_end_catch()
  59. // CHECK-LPAD-NEXT: to label %[[CATCHRETDEST:.+]] unwind label
  60. // CHECK-LPAD: [[CATCHRETDEST]]:
  61. // CHECK-LPAD-NEXT: br label %[[TRYCONT:.+]]
  62. // CHECK-LPAD: [[TRYCONT]]:
  63. // CHECK-LPAD: br label %[[RESUMECONT:.+]]
  64. // CHECK-LPAD: [[RESUMECONT]]:
  65. // CHECK-LPAD-NEXT: br label %[[COROFIN:.+]]
  66. // CHECK-LPAD: [[COROFIN]]:
  67. // CHECK-LPAD-NEXT: invoke void @_ZN6coro_t12promise_type13final_suspendEv(