xref: /aosp_15_r20/external/llvm/test/CodeGen/X86/seh-except-finally.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker; Test case based on this source:
4*9880d681SAndroid Build Coastguard Worker; int puts(const char*);
5*9880d681SAndroid Build Coastguard Worker; __declspec(noinline) void crash() {
6*9880d681SAndroid Build Coastguard Worker;   *(volatile int*)0 = 42;
7*9880d681SAndroid Build Coastguard Worker; }
8*9880d681SAndroid Build Coastguard Worker; int filt();
9*9880d681SAndroid Build Coastguard Worker; void use_both() {
10*9880d681SAndroid Build Coastguard Worker;   __try {
11*9880d681SAndroid Build Coastguard Worker;     __try {
12*9880d681SAndroid Build Coastguard Worker;       crash();
13*9880d681SAndroid Build Coastguard Worker;     } __finally {
14*9880d681SAndroid Build Coastguard Worker;       puts("__finally");
15*9880d681SAndroid Build Coastguard Worker;     }
16*9880d681SAndroid Build Coastguard Worker;   } __except (filt()) {
17*9880d681SAndroid Build Coastguard Worker;     puts("__except");
18*9880d681SAndroid Build Coastguard Worker;   }
19*9880d681SAndroid Build Coastguard Worker; }
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
22*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-pc-windows-msvc"
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Worker$"\01??_C@_09KJEHOMHG@__finally?$AA@" = comdat any
25*9880d681SAndroid Build Coastguard Worker
26*9880d681SAndroid Build Coastguard Worker$"\01??_C@_08MLCMLGHM@__except?$AA@" = comdat any
27*9880d681SAndroid Build Coastguard Worker
28*9880d681SAndroid Build Coastguard Worker@"\01??_C@_09KJEHOMHG@__finally?$AA@" = linkonce_odr unnamed_addr constant [10 x i8] c"__finally\00", comdat, align 1
29*9880d681SAndroid Build Coastguard Worker@"\01??_C@_08MLCMLGHM@__except?$AA@" = linkonce_odr unnamed_addr constant [9 x i8] c"__except\00", comdat, align 1
30*9880d681SAndroid Build Coastguard Worker
31*9880d681SAndroid Build Coastguard Workerdeclare void @crash()
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard Workerdeclare i32 @filt()
34*9880d681SAndroid Build Coastguard Worker
35*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind uwtable
36*9880d681SAndroid Build Coastguard Workerdefine void @use_both() #1 personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
37*9880d681SAndroid Build Coastguard Workerentry:
38*9880d681SAndroid Build Coastguard Worker  %exn.slot = alloca i8*
39*9880d681SAndroid Build Coastguard Worker  %ehselector.slot = alloca i32
40*9880d681SAndroid Build Coastguard Worker  invoke void @crash() #5
41*9880d681SAndroid Build Coastguard Worker          to label %invoke.cont unwind label %__finally
42*9880d681SAndroid Build Coastguard Worker
43*9880d681SAndroid Build Coastguard Workerinvoke.cont:                                      ; preds = %entry
44*9880d681SAndroid Build Coastguard Worker  %0 = call i8* @llvm.localaddress()
45*9880d681SAndroid Build Coastguard Worker  invoke void @"\01?fin$0@0@use_both@@"(i1 zeroext false, i8* %0) #5
46*9880d681SAndroid Build Coastguard Worker          to label %invoke.cont2 unwind label %catch.dispatch
47*9880d681SAndroid Build Coastguard Worker
48*9880d681SAndroid Build Coastguard Workerinvoke.cont2:                                     ; preds = %invoke.cont
49*9880d681SAndroid Build Coastguard Worker  br label %__try.cont
50*9880d681SAndroid Build Coastguard Worker
51*9880d681SAndroid Build Coastguard Worker__finally:                                             ; preds = %entry
52*9880d681SAndroid Build Coastguard Worker  %cleanuppad = cleanuppad within none []
53*9880d681SAndroid Build Coastguard Worker  %locals = call i8* @llvm.localaddress()
54*9880d681SAndroid Build Coastguard Worker  invoke void @"\01?fin$0@0@use_both@@"(i1 zeroext true, i8* %locals) #5 [ "funclet"(token %cleanuppad) ]
55*9880d681SAndroid Build Coastguard Worker          to label %invoke.cont3 unwind label %catch.dispatch
56*9880d681SAndroid Build Coastguard Worker
57*9880d681SAndroid Build Coastguard Workerinvoke.cont3:                                     ; preds = %__finally
58*9880d681SAndroid Build Coastguard Worker  cleanupret from %cleanuppad unwind label %catch.dispatch
59*9880d681SAndroid Build Coastguard Worker
60*9880d681SAndroid Build Coastguard Workercatch.dispatch:                                   ; preds = %invoke.cont3, %lpad1
61*9880d681SAndroid Build Coastguard Worker  %cs1 = catchswitch within none [label %__except] unwind to caller
62*9880d681SAndroid Build Coastguard Worker
63*9880d681SAndroid Build Coastguard Worker__except:                                         ; preds = %catch.dispatch
64*9880d681SAndroid Build Coastguard Worker  %catchpad = catchpad within %cs1 [i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@use_both@@" to i8*)]
65*9880d681SAndroid Build Coastguard Worker  %call = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @"\01??_C@_08MLCMLGHM@__except?$AA@", i32 0, i32 0)) [ "funclet"(token %catchpad) ]
66*9880d681SAndroid Build Coastguard Worker  catchret from %catchpad to label %__try.cont
67*9880d681SAndroid Build Coastguard Worker
68*9880d681SAndroid Build Coastguard Worker__try.cont:                                       ; preds = %__except, %invoke.cont2
69*9880d681SAndroid Build Coastguard Worker  ret void
70*9880d681SAndroid Build Coastguard Worker}
71*9880d681SAndroid Build Coastguard Worker
72*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: use_both:
73*9880d681SAndroid Build Coastguard Worker; CHECK: .Ltmp0
74*9880d681SAndroid Build Coastguard Worker; CHECK: callq crash
75*9880d681SAndroid Build Coastguard Worker; CHECK: .Ltmp1
76*9880d681SAndroid Build Coastguard Worker; CHECK: .Ltmp4
77*9880d681SAndroid Build Coastguard Worker; CHECK: callq "?fin$0@0@use_both@@"
78*9880d681SAndroid Build Coastguard Worker; CHECK: .Ltmp5
79*9880d681SAndroid Build Coastguard Worker; CHECK: retq
80*9880d681SAndroid Build Coastguard Worker;
81*9880d681SAndroid Build Coastguard Worker; CHECK: .seh_handlerdata
82*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .Luse_both$parent_frame_offset
83*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .long (.Llsda_end0-.Llsda_begin0)/16
84*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .Llsda_begin0:
85*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .long .Ltmp0@IMGREL+1
86*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .long .Ltmp1@IMGREL+1
87*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .long "?dtor$2@?0?use_both@4HA"@IMGREL
88*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .long 0
89*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .long .Ltmp0@IMGREL+1
90*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .long .Ltmp1@IMGREL+1
91*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .long "?filt$0@0@use_both@@"@IMGREL
92*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .long .LBB0_{{[0-9]+}}@IMGREL
93*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .long .Ltmp4@IMGREL+1
94*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .long .Ltmp5@IMGREL+1
95*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .long "?filt$0@0@use_both@@"@IMGREL
96*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .long .LBB0_{{[0-9]+}}@IMGREL
97*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: .Llsda_end0:
98*9880d681SAndroid Build Coastguard Worker
99*9880d681SAndroid Build Coastguard Worker; Function Attrs: noinline nounwind
100*9880d681SAndroid Build Coastguard Workerdefine internal i32 @"\01?filt$0@0@use_both@@"(i8* %exception_pointers, i8* %frame_pointer) #2 {
101*9880d681SAndroid Build Coastguard Workerentry:
102*9880d681SAndroid Build Coastguard Worker  %frame_pointer.addr = alloca i8*, align 8
103*9880d681SAndroid Build Coastguard Worker  %exception_pointers.addr = alloca i8*, align 8
104*9880d681SAndroid Build Coastguard Worker  %exn.slot = alloca i8*
105*9880d681SAndroid Build Coastguard Worker  store i8* %frame_pointer, i8** %frame_pointer.addr, align 8
106*9880d681SAndroid Build Coastguard Worker  store i8* %exception_pointers, i8** %exception_pointers.addr, align 8
107*9880d681SAndroid Build Coastguard Worker  %0 = load i8*, i8** %exception_pointers.addr
108*9880d681SAndroid Build Coastguard Worker  %1 = bitcast i8* %0 to { i32*, i8* }*
109*9880d681SAndroid Build Coastguard Worker  %2 = getelementptr inbounds { i32*, i8* }, { i32*, i8* }* %1, i32 0, i32 0
110*9880d681SAndroid Build Coastguard Worker  %3 = load i32*, i32** %2
111*9880d681SAndroid Build Coastguard Worker  %4 = load i32, i32* %3
112*9880d681SAndroid Build Coastguard Worker  %5 = zext i32 %4 to i64
113*9880d681SAndroid Build Coastguard Worker  %6 = inttoptr i64 %5 to i8*
114*9880d681SAndroid Build Coastguard Worker  store i8* %6, i8** %exn.slot
115*9880d681SAndroid Build Coastguard Worker  %call = call i32 @filt()
116*9880d681SAndroid Build Coastguard Worker  ret i32 %call
117*9880d681SAndroid Build Coastguard Worker}
118*9880d681SAndroid Build Coastguard Worker
119*9880d681SAndroid Build Coastguard Workerdefine internal void @"\01?fin$0@0@use_both@@"(i1 zeroext %abnormal_termination, i8* %frame_pointer) #3 {
120*9880d681SAndroid Build Coastguard Workerentry:
121*9880d681SAndroid Build Coastguard Worker  %frame_pointer.addr = alloca i8*, align 8
122*9880d681SAndroid Build Coastguard Worker  %abnormal_termination.addr = alloca i8, align 1
123*9880d681SAndroid Build Coastguard Worker  store i8* %frame_pointer, i8** %frame_pointer.addr, align 8
124*9880d681SAndroid Build Coastguard Worker  %frombool = zext i1 %abnormal_termination to i8
125*9880d681SAndroid Build Coastguard Worker  store i8 %frombool, i8* %abnormal_termination.addr, align 1
126*9880d681SAndroid Build Coastguard Worker  %call = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @"\01??_C@_09KJEHOMHG@__finally?$AA@", i32 0, i32 0))
127*9880d681SAndroid Build Coastguard Worker  ret void
128*9880d681SAndroid Build Coastguard Worker}
129*9880d681SAndroid Build Coastguard Worker
130*9880d681SAndroid Build Coastguard Workerdeclare i32 @puts(i8*) #3
131*9880d681SAndroid Build Coastguard Worker
132*9880d681SAndroid Build Coastguard Workerdeclare i32 @__C_specific_handler(...)
133*9880d681SAndroid Build Coastguard Worker
134*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind readnone
135*9880d681SAndroid Build Coastguard Workerdeclare i8* @llvm.localaddress() #4
136*9880d681SAndroid Build Coastguard Worker
137*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind readnone
138*9880d681SAndroid Build Coastguard Workerdeclare i32 @llvm.eh.typeid.for(i8*) #4
139*9880d681SAndroid Build Coastguard Worker
140*9880d681SAndroid Build Coastguard Workerattributes #0 = { noinline nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
141*9880d681SAndroid Build Coastguard Workerattributes #1 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
142*9880d681SAndroid Build Coastguard Workerattributes #2 = { noinline nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
143*9880d681SAndroid Build Coastguard Workerattributes #3 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
144*9880d681SAndroid Build Coastguard Workerattributes #4 = { nounwind readnone }
145*9880d681SAndroid Build Coastguard Workerattributes #5 = { noinline }
146*9880d681SAndroid Build Coastguard Workerattributes #6 = { nounwind }
147