1; RUN: llc < %s | FileCheck %s 2 3; Based on the source: 4; extern "C" int puts(const char *); 5; extern "C" int printf(const char *, ...); 6; extern "C" int do_div(int a, int b) { return a / b; } 7; extern "C" int filt(); 8; int main() { 9; __try { 10; __try { 11; do_div(1, 0); 12; } __except (1) { 13; __try { 14; do_div(1, 0); 15; } __finally { 16; puts("finally"); 17; } 18; } 19; } __except (filt()) { 20; puts("caught"); 21; } 22; return 0; 23; } 24 25; ModuleID = 't.cpp' 26target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" 27target triple = "x86_64-pc-windows-msvc" 28 29$"\01??_C@_07MKBLAIAL@finally?$AA@" = comdat any 30 31$"\01??_C@_06IBDBCMGJ@caught?$AA@" = comdat any 32 33@"\01??_C@_07MKBLAIAL@finally?$AA@" = linkonce_odr unnamed_addr constant [8 x i8] c"finally\00", comdat, align 1 34@"\01??_C@_06IBDBCMGJ@caught?$AA@" = linkonce_odr unnamed_addr constant [7 x i8] c"caught\00", comdat, align 1 35 36; Function Attrs: nounwind readnone 37define i32 @do_div(i32 %a, i32 %b) #0 { 38entry: 39 %div = sdiv i32 %a, %b 40 ret i32 %div 41} 42 43define i32 @main() #1 personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) { 44entry: 45 %call = invoke i32 @do_div(i32 1, i32 0) #4 46 to label %__try.cont.12 unwind label %catch.dispatch 47 48__except.2: ; preds = %__except 49 %call4 = invoke i32 @do_div(i32 1, i32 0) #4 50 to label %invoke.cont.3 unwind label %ehcleanup 51 52invoke.cont.3: ; preds = %__except.2 53 invoke fastcc void @"\01?fin$0@0@main@@"() #4 54 to label %__try.cont.12 unwind label %catch.dispatch.7 55 56__except.9: ; preds = %__except.ret 57 %call11 = tail call i32 @puts(i8* nonnull getelementptr inbounds ([7 x i8], [7 x i8]* @"\01??_C@_06IBDBCMGJ@caught?$AA@", i64 0, i64 0)) 58 br label %__try.cont.12 59 60__try.cont.12: ; preds = %invoke.cont.3, %entry, %__except.9 61 ret i32 0 62 63catch.dispatch: ; preds = %entry 64 %cs1 = catchswitch within none [label %__except] unwind label %catch.dispatch.7 65 66__except: ; preds = %catch.dispatch 67 %cp1 = catchpad within %cs1 [i8* null] 68 catchret from %cp1 to label %__except.2 69 70ehcleanup: ; preds = %__except.2 71 %cp2 = cleanuppad within none [] 72 invoke fastcc void @"\01?fin$0@0@main@@"() #4 [ "funclet"(token %cp2) ] 73 to label %invoke.cont.6 unwind label %catch.dispatch.7 74 75invoke.cont.6: ; preds = %ehcleanup 76 cleanupret from %cp2 unwind label %catch.dispatch.7 77 78catch.dispatch.7: 79 %cs2 = catchswitch within none [label %__except.ret] unwind to caller 80 81__except.ret: ; preds = %catch.dispatch.7 82 %cp3 = catchpad within %cs2 [i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@main@@" to i8*)] 83 catchret from %cp3 to label %__except.9 84} 85 86; CHECK: main: # @main 87; CHECK: .seh_proc main 88; CHECK: .seh_handler __C_specific_handler, @unwind, @except 89; CHECK: pushq %rbp 90; CHECK: .seh_pushreg %rbp 91; CHECK: subq $32, %rsp 92; CHECK: .seh_stackalloc 32 93; CHECK: leaq 32(%rsp), %rbp 94; CHECK: .seh_setframe %rbp, 32 95; CHECK: .seh_endprologue 96; CHECK: .Ltmp0: 97; CHECK: movl $1, %ecx 98; CHECK: xorl %edx, %edx 99; CHECK: callq do_div 100; CHECK: .Ltmp1: 101; CHECK: .LBB1_[[epilogue:[0-9]+]]: # %__try.cont.12 102; CHECK: xorl %eax, %eax 103; CHECK: addq $32, %rsp 104; CHECK: popq %rbp 105; CHECK: retq 106; CHECK: .LBB1_[[except1bb:[0-9]+]]: # %__except 107; CHECK: .Ltmp2: 108; CHECK: movl $1, %ecx 109; CHECK: xorl %edx, %edx 110; CHECK: callq do_div 111; CHECK: .Ltmp3: 112; CHECK: callq "?fin$0@0@main@@" 113; CHECK: jmp .LBB1_[[epilogue]] 114; CHECK: .LBB1_[[except2bb:[0-9]+]]: # %__except.ret 115; CHECK: leaq "??_C@_06IBDBCMGJ@caught?$AA@"(%rip), %rcx 116; CHECK: callq puts 117; CHECK: jmp .LBB1_[[epilogue]] 118 119; CHECK: .seh_handlerdata 120; CHECK-NEXT: .set .Lmain$parent_frame_offset, 32 121; CHECK-NEXT: .long (.Llsda_end0-.Llsda_begin0)/16 122; CHECK-NEXT: .Llsda_begin0: 123; CHECK-NEXT: .long .Ltmp0@IMGREL+1 124; CHECK-NEXT: .long .Ltmp1@IMGREL+1 125; CHECK-NEXT: .long 1 126; CHECK-NEXT: .long .LBB1_[[except1bb]]@IMGREL 127; CHECK-NEXT: .long .Ltmp0@IMGREL+1 128; CHECK-NEXT: .long .Ltmp1@IMGREL+1 129; CHECK-NEXT: .long "?filt$0@0@main@@"@IMGREL 130; CHECK-NEXT: .long .LBB1_[[except2bb]]@IMGREL 131; CHECK-NEXT: .long .Ltmp2@IMGREL+1 132; CHECK-NEXT: .long .Ltmp3@IMGREL+1 133; CHECK-NEXT: .long "?dtor$[[finbb:[0-9]+]]@?0?main@4HA"@IMGREL 134; CHECK-NEXT: .long 0 135; CHECK-NEXT: .long .Ltmp2@IMGREL+1 136; CHECK-NEXT: .long .Ltmp3@IMGREL+1 137; CHECK-NEXT: .long "?filt$0@0@main@@"@IMGREL 138; CHECK-NEXT: .long .LBB1_3@IMGREL 139; CHECK-NEXT: .long .Ltmp6@IMGREL+1 140; CHECK-NEXT: .long .Ltmp7@IMGREL+1 141; CHECK-NEXT: .long "?filt$0@0@main@@"@IMGREL 142; CHECK-NEXT: .long .LBB1_3@IMGREL 143; CHECK-NEXT: .Llsda_end0: 144 145; CHECK: .text 146; CHECK: .seh_endproc 147 148; CHECK: "?dtor$[[finbb]]@?0?main@4HA": 149; CHECK: .seh_proc "?dtor$[[finbb]]@?0?main@4HA" 150; CHECK-NOT: .seh_handler 151; CHECK: .LBB1_[[finbb]]: # %ehcleanup 152; CHECK: movq %rdx, 16(%rsp) 153; CHECK: pushq %rbp 154; CHECK: .seh_pushreg %rbp 155; CHECK: subq $32, %rsp 156; CHECK: .seh_stackalloc 32 157; CHECK: leaq 32(%rdx), %rbp 158; CHECK: .seh_endprologue 159; CHECK: callq "?fin$0@0@main@@" 160; CHECK: nop 161; CHECK: addq $32, %rsp 162; CHECK: popq %rbp 163; CHECK: retq 164; CHECK: .seh_handlerdata 165; CHECK: .seh_endproc 166 167define internal i32 @"\01?filt$0@0@main@@"(i8* nocapture readnone %exception_pointers, i8* nocapture readnone %frame_pointer) #1 { 168entry: 169 %call = tail call i32 @filt() 170 ret i32 %call 171} 172 173; CHECK: "?filt$0@0@main@@": # @"\01?filt$0@0@main@@" 174; CHECK: jmp filt # TAILCALL 175 176declare i32 @filt() #1 177 178declare i32 @__C_specific_handler(...) 179 180; Function Attrs: noinline nounwind 181define internal fastcc void @"\01?fin$0@0@main@@"() #2 { 182entry: 183 %call = tail call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @"\01??_C@_07MKBLAIAL@finally?$AA@", i64 0, i64 0)) #5 184 ret void 185} 186 187; Function Attrs: nounwind 188declare i32 @puts(i8* nocapture readonly) #3 189 190attributes #0 = { nounwind readnone "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } 191attributes #1 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } 192attributes #2 = { noinline nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } 193attributes #3 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } 194attributes #4 = { noinline } 195attributes #5 = { nounwind } 196