xref: /llvm-project/clang/test/CodeGenCXX/unwind-inline-asm.cpp (revision 8ec9fd483949ca3b23053effcac226dcc56e7a95)
1*8ec9fd48Scynecx // RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm -DUNWIND -fcxx-exceptions -fexceptions -o - %s | FileCheck -check-prefixes CHECK,CHECK-UNWIND %s
2*8ec9fd48Scynecx // RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm -fcxx-exceptions -fexceptions -o - %s | FileCheck -check-prefixes CHECK,CHECK-NO-UNWIND %s
3*8ec9fd48Scynecx 
4*8ec9fd48Scynecx extern "C" void printf(const char *fmt, ...);
5*8ec9fd48Scynecx 
6*8ec9fd48Scynecx struct DropBomb {
7*8ec9fd48Scynecx   bool defused = false;
8*8ec9fd48Scynecx 
~DropBombDropBomb9*8ec9fd48Scynecx   ~DropBomb() {
10*8ec9fd48Scynecx     if (defused) {
11*8ec9fd48Scynecx       return;
12*8ec9fd48Scynecx     }
13*8ec9fd48Scynecx     printf("Boom!\n");
14*8ec9fd48Scynecx   }
15*8ec9fd48Scynecx };
16*8ec9fd48Scynecx 
trap()17*8ec9fd48Scynecx extern "C" void trap() {
18*8ec9fd48Scynecx   throw "Trap";
19*8ec9fd48Scynecx }
20*8ec9fd48Scynecx 
21*8ec9fd48Scynecx // CHECK: define dso_local void @test()
test()22*8ec9fd48Scynecx extern "C" void test() {
23*8ec9fd48Scynecx   DropBomb bomb;
24*8ec9fd48Scynecx // CHECK-UNWIND: invoke void asm sideeffect unwind "call trap"
25*8ec9fd48Scynecx // CHECK-NO-UNWIND: call void asm sideeffect "call trap"
26*8ec9fd48Scynecx #ifdef UNWIND
27*8ec9fd48Scynecx   asm volatile("call trap" ::
28*8ec9fd48Scynecx                    : "unwind");
29*8ec9fd48Scynecx #else
30*8ec9fd48Scynecx   asm volatile("call trap" ::
31*8ec9fd48Scynecx                    :);
32*8ec9fd48Scynecx #endif
33*8ec9fd48Scynecx   bomb.defused = true;
34*8ec9fd48Scynecx }
35