1 // RUN: %clang_cc1 -fblocks -emit-llvm %s -o %t
2 // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK1
3 // RUN: FileCheck %s -input-file=%t -check-prefix=CHECK2
11 void test_nest_captured_stmt(int param
, int size
, int param_arr
[size
]) {
14 // CHECK1: %struct.anon{{.*}} = type { ptr, ptr, [[SIZE_TYPE:i.+]], ptr, ptr, [[SIZE_TYPE]], [[SIZE_TYPE]], ptr }
15 // CHECK1: %struct.anon{{.*}} = type { ptr, ptr, ptr, ptr, [[SIZE_TYPE]], ptr, ptr, [[SIZE_TYPE]], [[SIZE_TYPE]], ptr }
16 // CHECK1: [[T:%struct.anon.*]] = type { ptr, ptr, ptr, ptr, ptr, [[SIZE_TYPE]], ptr, ptr, [[SIZE_TYPE]], [[SIZE_TYPE]], ptr }
17 #pragma clang __debug captured
21 #pragma clang __debug captured
24 #pragma clang __debug captured
30 param_arr
[size
- 1] = 2;
33 // CHECK1: define internal {{.*}}void @__captured_stmt.2(ptr
34 // CHECK1: [[PARAM_ARR_SIZE_REF:%.+]] = getelementptr inbounds nuw [[T]], ptr {{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 5
35 // CHECK1: [[PARAM_ARR_SIZE:%.+]] = load [[SIZE_TYPE]], ptr [[PARAM_ARR_SIZE_REF]]
36 // CHECK1: [[ARR_SIZE1_REF:%.+]] = getelementptr inbounds nuw [[T]], ptr {{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 8
37 // CHECK1: [[ARR_SIZE1:%.+]] = load [[SIZE_TYPE]], ptr [[ARR_SIZE1_REF]]
38 // CHECK1: [[ARR_SIZE2_REF:%.+]] = getelementptr inbounds nuw [[T]], ptr {{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 9
39 // CHECK1: [[ARR_SIZE2:%.+]] = load [[SIZE_TYPE]], ptr [[ARR_SIZE2_REF]]
41 // CHECK1: getelementptr inbounds nuw [[T]], ptr {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 2
42 // CHECK1-NEXT: load ptr, ptr
43 // CHECK1-NEXT: getelementptr inbounds nuw %struct.A, ptr
44 // CHECK1-NEXT: store i{{.+}} 1
46 // CHECK1: getelementptr inbounds nuw [[T]], ptr {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 1
47 // CHECK1-NEXT: load ptr, ptr
48 // CHECK1-NEXT: store i{{[0-9]+}} 1
50 // CHECK1: getelementptr inbounds nuw [[T]], ptr {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 0
51 // CHECK1-NEXT: load ptr, ptr
52 // CHECK1-NEXT: store i{{[0-9]+}} 1
54 // CHECK1: getelementptr inbounds nuw [[T]], ptr {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 4
55 // CHECK1-NEXT: load ptr, ptr
56 // CHECK1-NEXT: load i{{[0-9]+}}, ptr
57 // CHECK1-NEXT: getelementptr inbounds nuw [[T]], ptr {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 3
58 // CHECK1-NEXT: load ptr, ptr
59 // CHECK1-NEXT: load ptr, ptr
60 // CHECK1-NEXT: store i{{[0-9]+}}
62 // CHECK1: getelementptr inbounds nuw [[T]], ptr {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 2
63 // CHECK1-NEXT: load ptr, ptr
64 // CHECK1-NEXT: getelementptr inbounds nuw %struct.A, ptr
65 // CHECK1-NEXT: store float
67 // CHECK1: getelementptr inbounds nuw [[T]], ptr {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 2
68 // CHECK1-NEXT: load ptr, ptr
69 // CHECK1-NEXT: getelementptr inbounds nuw %struct.A, ptr
70 // CHECK1-NEXT: store i8 99
72 // CHECK1-DAG: [[SIZE_ADDR_REF:%.*]] = getelementptr inbounds nuw [[T]], ptr {{.*}}, i{{.+}} 0, i{{.+}} 7
73 // CHECK1-DAG: [[SIZE_ADDR:%.*]] = load ptr, ptr [[SIZE_ADDR_REF]]
74 // CHECK1-DAG: [[SIZE:%.*]] = load i{{.+}}, ptr [[SIZE_ADDR]]
75 // CHECK1-DAG: [[PARAM_ARR_IDX:%.*]] = sub nsw i{{.+}} [[SIZE]], 1
76 // CHECK1-DAG: [[PARAM_ARR_ADDR_REF:%.*]] = getelementptr inbounds nuw [[T]], ptr {{.*}}, i{{.+}} 0, i{{.+}} 6
77 // CHECK1-DAG: [[PARAM_ARR_ADDR:%.*]] = load ptr, ptr [[PARAM_ARR_ADDR_REF]]
78 // CHECK1-DAG: [[PARAM_ARR:%.*]] = load ptr, ptr [[PARAM_ARR_ADDR]]
79 // CHECK1-DAG: [[PARAM_ARR_SIZE_MINUS_1_ADDR:%.*]] = getelementptr inbounds i{{.+}}, ptr [[PARAM_ARR]], i{{.*}}
80 // CHECK1: store i{{.+}} 2, ptr [[PARAM_ARR_SIZE_MINUS_1_ADDR]]
82 // CHECK1-DAG: [[Z_ADDR_REF:%.*]] = getelementptr inbounds nuw [[T]], ptr {{.*}}, i{{.+}} 0, i{{.+}} 2
83 // CHECK1-DAG: [[Z_ADDR:%.*]] = load ptr, ptr [[Z_ADDR_REF]]
84 // CHECK1-DAG: [[Z_A_ADDR:%.*]] = getelementptr inbounds nuw %struct.A, ptr [[Z_ADDR]], i{{.+}} 0, i{{.+}} 0
85 // CHECK1-DAG: [[ARR_IDX_2:%.*]] = load i{{.+}}, ptr [[Z_A_ADDR]]
86 // CHECK1-DAG: [[ARR_ADDR_REF:%.*]] = getelementptr inbounds nuw [[T]], ptr {{.*}}, i{{.+}} 0, i{{.+}} 10
87 // CHECK1-DAG: [[ARR_ADDR:%.*]] = load ptr, ptr [[ARR_ADDR_REF]]
88 // CHECK1-DAG: [[ARR_IDX_1:%.*]] = mul {{.*}} 10
89 // CHECK1-DAG: [[ARR_10_ADDR:%.*]] = getelementptr inbounds i{{.+}}, ptr [[ARR_ADDR]], i{{.*}} [[ARR_IDX_1]]
90 // CHECK1-DAG: [[ARR_10_Z_A_ADDR:%.*]] = getelementptr inbounds i{{.+}}, ptr [[ARR_10_ADDR]], i{{.*}}
91 // CHECK1: store i{{.+}} 12, ptr [[ARR_10_Z_A_ADDR]]
97 void test_nest_block(void) {
103 #pragma clang __debug captured
109 // CHECK2: define internal {{.*}}void @{{.*}}test_nest_block_block_invoke
111 // CHECK2: [[Z:%[0-9a-z_]*]] = alloca i{{[0-9]+}},
112 // CHECK2: alloca %struct.anon{{.*}}
114 // CHECK2: store i{{[0-9]+}}
115 // CHECK2: store ptr [[Z]]
117 // CHECK2: getelementptr inbounds nuw %struct.anon
118 // CHECK2-NEXT: getelementptr inbounds
119 // CHECK2-NEXT: store ptr
121 // CHECK2: call void @__captured_stmt
124 #pragma clang __debug captured
136 // CHECK2: alloca %struct.__block_byref_b
137 // CHECK2-NEXT: [[C:%[0-9a-z_]*]] = alloca i{{[0-9]+}}
138 // CHECK2-NEXT: alloca %struct.__block_byref_d
142 // CHECK2: [[CapA:%[0-9a-z_.]*]] = getelementptr inbounds {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 7
144 // CHECK2: getelementptr inbounds nuw %struct.anon{{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 0
145 // CHECK2: load ptr, ptr
146 // CHECK2: load i{{[0-9]+}}, ptr
147 // CHECK2: store i{{[0-9]+}} {{.*}}, ptr [[CapA]]
149 // CHECK2: [[CapC:%[0-9a-z_.]*]] = getelementptr inbounds {{.*}}, i{{[0-9]+}} 0, i{{[0-9]+}} 8
150 // CHECK2-NEXT: [[Val:%[0-9a-z_]*]] = load i{{[0-9]+}}, ptr [[C]]
151 // CHECK2-NEXT: store i{{[0-9]+}} [[Val]], ptr [[CapC]]