coro-eh-cleanup.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // RUN: %clang_cc1 -std=c++1z -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++1z -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. namespace std::experimental {
  4. template <typename R, typename... T> struct coroutine_traits {
  5. using promise_type = typename R::promise_type;
  6. };
  7. template <class Promise = void> struct coroutine_handle;
  8. template <> struct coroutine_handle<void> {
  9. static coroutine_handle from_address(void *) noexcept;
  10. coroutine_handle() = default;
  11. template <class PromiseType>
  12. coroutine_handle(coroutine_handle<PromiseType>) noexcept;
  13. };
  14. template <class Promise> struct coroutine_handle: coroutine_handle<void> {
  15. coroutine_handle() = default;
  16. static coroutine_handle from_address(void *) noexcept;
  17. };
  18. }
  19. struct suspend_always {
  20. bool await_ready() noexcept;
  21. void await_suspend(std::experimental::coroutine_handle<>) noexcept;
  22. void await_resume() noexcept;
  23. };
  24. struct coro_t {
  25. struct promise_type {
  26. coro_t get_return_object() noexcept;
  27. suspend_always initial_suspend() noexcept;
  28. suspend_always final_suspend() noexcept;
  29. void return_void() noexcept;
  30. void unhandled_exception() noexcept;
  31. };
  32. };
  33. struct Cleanup { ~Cleanup(); };
  34. void may_throw();
  35. coro_t f() {
  36. Cleanup x;
  37. may_throw();
  38. co_return;
  39. }
  40. // CHECK: @"?f@@YA?AUcoro_t@@XZ"(
  41. // CHECK: invoke void @"?may_throw@@YAXXZ"()
  42. // CHECK: to label %[[CONT:.+]] unwind label %[[EHCLEANUP:.+]]
  43. // CHECK: [[EHCLEANUP]]:
  44. // CHECK: %[[INNERPAD:.+]] = cleanuppad within none []
  45. // CHECK: call void @"??1Cleanup@@QEAA@XZ"(
  46. // CHECK: cleanupret from %{{.+}} unwind label %[[CATCHDISPATCH:.+]]
  47. // CHECK: [[CATCHDISPATCH]]:
  48. // CHECK: catchswitch within none [label %[[CATCHPAD:.+]]] unwind label %[[COROENDBB:.+]]
  49. // CHECK: [[CATCHPAD]]:
  50. // CHECK: call void @"?unhandled_exception@promise_type@coro_t@@QEAAXXZ"
  51. // CHECK: [[COROENDBB]]:
  52. // CHECK-NEXT: %[[CLPAD:.+]] = cleanuppad within none
  53. // CHECK-NEXT: call i1 @llvm.coro.end(i8* null, i1 true) [ "funclet"(token %[[CLPAD]]) ]
  54. // CHECK-NEXT: cleanupret from %[[CLPAD]] unwind label
  55. // CHECK-LPAD: @_Z1fv(
  56. // CHECK-LPAD: invoke void @_Z9may_throwv()
  57. // CHECK-LPAD: to label %[[CONT:.+]] unwind label %[[EHCLEANUP:.+]]
  58. // CHECK-LPAD: [[EHCLEANUP]]:
  59. // CHECK-LPAD: landingpad { i8*, i32 }
  60. // CHECK-LPAD: catch
  61. // CHECK-LPAD: call void @_ZN7CleanupD1Ev(
  62. // CHECK-LPAD: call i8* @__cxa_begin_catch
  63. // CHECK-LPAD: call void @_ZN6coro_t12promise_type19unhandled_exceptionEv
  64. // CHECK-LPAD: invoke void @__cxa_end_catch()
  65. // CHECK-LPAD: to label %{{.+}} unwind label %[[UNWINDBB:.+]]
  66. // CHECK-LPAD: [[UNWINDBB]]:
  67. // CHECK-LPAD: %[[I1RESUME:.+]] = call i1 @llvm.coro.end(i8* null, i1 true)
  68. // CHECK-LPAD: br i1 %[[I1RESUME]], label %[[EHRESUME:.+]], label
  69. // CHECK-LPAD: [[EHRESUME]]:
  70. // CHECK-LPAD-NEXT: %[[exn:.+]] = load i8*, i8** %exn.slot, align 8
  71. // CHECK-LPAD-NEXT: %[[sel:.+]] = load i32, i32* %ehselector.slot, align 4
  72. // CHECK-LPAD-NEXT: %[[val1:.+]] = insertvalue { i8*, i32 } undef, i8* %[[exn]], 0
  73. // CHECK-LPAD-NEXT: %[[val2:.+]] = insertvalue { i8*, i32 } %[[val1]], i32 %[[sel]], 1
  74. // CHECK-LPAD-NEXT: resume { i8*, i32 } %[[val2]]