[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGenCoroutines / coro-dest-slot.cpp
blobd794c74cd52d61afaeda0a4d30b2cc8b7fa6694d
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -emit-llvm %s -o - -disable-llvm-passes | FileCheck %s
3 #include "Inputs/coroutine.h"
5 using namespace std;
7 struct coro {
8 struct promise_type {
9 coro get_return_object();
10 suspend_always initial_suspend();
11 suspend_never final_suspend() noexcept;
12 void return_void();
13 static void unhandled_exception();
17 extern "C" coro f(int) { co_return; }
18 // Verify that cleanup.dest.slot is eliminated in a coroutine.
19 // CHECK-LABEL: f(
20 // CHECK: %[[INIT_SUSPEND:.+]] = call i8 @llvm.coro.suspend(
21 // CHECK-NEXT: switch i8 %[[INIT_SUSPEND]], label
22 // CHECK-NEXT: i8 0, label %[[INIT_READY:.+]]
23 // CHECK-NEXT: i8 1, label %[[INIT_CLEANUP:.+]]
24 // CHECK-NEXT: ]
25 // CHECK: %[[CLEANUP_DEST0:.+]] = phi i32 [ 0, %[[INIT_READY]] ], [ 2, %[[INIT_CLEANUP]] ]
27 // CHECK: %[[FINAL_SUSPEND:.+]] = call i8 @llvm.coro.suspend(
28 // CHECK-NEXT: switch i8 %{{.*}}, label %coro.ret [
29 // CHECK-NEXT: i8 0, label %[[FINAL_READY:.+]]
30 // CHECK-NEXT: i8 1, label %[[FINAL_CLEANUP:.+]]
31 // CHECK-NEXT: ]
33 // CHECK: call void @_ZNSt13suspend_never12await_resumeEv(
34 // CHECK: %[[CLEANUP_DEST1:.+]] = phi i32 [ 0, %[[FINAL_READY]] ], [ 2, %[[FINAL_CLEANUP]] ]
35 // CHECK: %[[CLEANUP_DEST2:.+]] = phi i32 [ %[[CLEANUP_DEST0]], %{{.+}} ], [ %[[CLEANUP_DEST1]], %{{.+}} ], [ 0, %{{.+}} ]
36 // CHECK: call ptr @llvm.coro.free(
37 // CHECK: switch i32 %[[CLEANUP_DEST2]], label %{{.+}} [
38 // CHECK-NEXT: i32 0
39 // CHECK-NEXT: i32 2
40 // CHECK-NEXT: ]