1 // RUN: %clang_cc1 -std=c++11 -fblocks -fms-extensions %s -triple=x86_64-windows-msvc -emit-llvm \
2 // RUN:         -o - -mconstructor-aliases -fcxx-exceptions -fexceptions | \
3 // RUN:         FileCheck %s --check-prefix=CHECK --check-prefix=CXXEH
4 
5 extern "C" int basic_filter(int v, ...);
6 extern "C" void might_crash();
7 
test_freefunc(int p1)8 extern "C" void test_freefunc(int p1) {
9   int l1 = 13;
10   static int s1 = 42;
11   __try {
12     might_crash();
13   } __except(basic_filter(p1, l1, s1)) {
14   }
15 }
16 
17 // CHECK-LABEL: define void @test_freefunc(i32 %p1)
18 // CHECK: @llvm.frameescape(i32* %[[p1_ptr:[^, ]*]], i32* %[[l1_ptr:[^, ]*]])
19 // CHECK: store i32 %p1, i32* %[[p1_ptr]], align 4
20 // CHECK: store i32 13, i32* %[[l1_ptr]], align 4
21 // CHECK: invoke void @might_crash()
22 
23 // CHECK-LABEL: define internal i32 @"\01?filt$0@0@test_freefunc@@"(i8* %exception_pointers, i8* %frame_pointer)
24 // CHECK: %[[p1_i8:[^ ]*]] = call i8* @llvm.framerecover(i8* bitcast (void (i32)* @test_freefunc to i8*), i8* %frame_pointer, i32 0)
25 // CHECK: %[[p1_ptr:[^ ]*]] = bitcast i8* %[[p1_i8]] to i32*
26 // CHECK: %[[l1_i8:[^ ]*]] = call i8* @llvm.framerecover(i8* bitcast (void (i32)* @test_freefunc to i8*), i8* %frame_pointer, i32 1)
27 // CHECK: %[[l1_ptr:[^ ]*]] = bitcast i8* %[[l1_i8]] to i32*
28 // CHECK: %[[s1:[^ ]*]] = load i32, i32* @"\01?s1@?1??test_freefunc@@9@4HA", align 4
29 // CHECK: %[[l1:[^ ]*]] = load i32, i32* %[[l1_ptr]]
30 // CHECK: %[[p1:[^ ]*]] = load i32, i32* %[[p1_ptr]]
31 // CHECK: call i32 (i32, ...) @basic_filter(i32 %[[p1]], i32 %[[l1]], i32 %[[s1]])
32 
33 struct S {
34   int m1;
35   void test_method(void);
36 };
37 
test_method()38 void S::test_method() {
39   int l1 = 13;
40   __try {
41     might_crash();
42   } __except(basic_filter(l1)) {
43     // FIXME: Test capturing 'this' and 'm1'.
44   }
45 }
46 
47 // CHECK-LABEL: define void @"\01?test_method@S@@QEAAXXZ"(%struct.S* %this)
48 // CHECK: @llvm.frameescape(i32* %[[l1_addr:[^, ]*]])
49 // CHECK: store i32 13, i32* %[[l1_addr]], align 4
50 // CHECK: invoke void @might_crash()
51 
52 // CHECK-LABEL: define internal i32 @"\01?filt$0@0@test_method@S@@"(i8* %exception_pointers, i8* %frame_pointer)
53 // CHECK: %[[l1_i8:[^ ]*]] = call i8* @llvm.framerecover(i8* bitcast (void (%struct.S*)* @"\01?test_method@S@@QEAAXXZ" to i8*), i8* %frame_pointer, i32 0)
54 // CHECK: %[[l1_ptr:[^ ]*]] = bitcast i8* %[[l1_i8]] to i32*
55 // CHECK: %[[l1:[^ ]*]] = load i32, i32* %[[l1_ptr]]
56 // CHECK: call i32 (i32, ...) @basic_filter(i32 %[[l1]])
57 
test_lambda()58 void test_lambda() {
59   int l1 = 13;
60   auto lambda = [&]() {
61     int l2 = 42;
62     __try {
63       might_crash();
64     } __except(basic_filter(l2)) {
65       // FIXME: Test 'l1' when we can capture the lambda's 'this' decl.
66     }
67   };
68   lambda();
69 }
70 
71 // CHECK-LABEL: define internal void @"\01??R<lambda_0>@?test_lambda@@YAXXZ@QEBAXXZ"(%class.anon* %this)
72 // CHECK: @llvm.frameescape(i32* %[[l2_addr:[^, ]*]])
73 // CHECK: store i32 42, i32* %[[l2_addr]], align 4
74 // CHECK: invoke void @might_crash()
75 
76 // CHECK-LABEL: define internal i32 @"\01?filt$0@0@?R<lambda_0>@?test_lambda@@YAXXZ@"(i8* %exception_pointers, i8* %frame_pointer)
77 // CHECK: %[[l2_i8:[^ ]*]] = call i8* @llvm.framerecover(i8* bitcast (void (%class.anon*)* @"\01??R<lambda_0>@?test_lambda@@YAXXZ@QEBAXXZ" to i8*), i8* %frame_pointer, i32 0)
78 // CHECK: %[[l2_ptr:[^ ]*]] = bitcast i8* %[[l2_i8]] to i32*
79 // CHECK: %[[l2:[^ ]*]] = load i32, i32* %[[l2_ptr]]
80 // CHECK: call i32 (i32, ...) @basic_filter(i32 %[[l2]])
81