Debian Codegraph @

clang/test/CIR/CodeGen/struct.cpp

raw
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
2 // RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
3 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll
4 // RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s
5 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
6 // RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s
7
8 struct IncompleteS;
9 IncompleteS *p;
10
11 // CIR: cir.global external @p = #cir.ptr<null> : !cir.ptr<!rec_IncompleteS>
12 // LLVM: @p = global ptr null
13 // OGCG: @p = global ptr null, align 8
14
15 struct CompleteS {
16 int a;
17 char b;
18 };
19
20 CompleteS cs;
21
22 // CIR: cir.global external @cs = #cir.zero : !rec_CompleteS
23 // LLVM-DAG: @cs = global %struct.CompleteS zeroinitializer
24 // OGCG-DAG: @cs = global %struct.CompleteS zeroinitializer, align 4
25
26 void f(void) {
27 IncompleteS *p;
28 }
29
30 // CIR: cir.func{{.*}} @_Z1fv()
31 // CIR-NEXT: cir.alloca !cir.ptr<!rec_IncompleteS>, !cir.ptr<!cir.ptr<!rec_IncompleteS>>, ["p"]
32 // CIR-NEXT: cir.return
33
34 // LLVM: define{{.*}} void @_Z1fv()
35 // LLVM-NEXT: %[[P:.*]] = alloca ptr, i64 1, align 8
36 // LLVM-NEXT: ret void
37
38 // OGCG: define{{.*}} void @_Z1fv()
39 // OGCG-NEXT: entry:
40 // OGCG-NEXT: %[[P:.*]] = alloca ptr, align 8
41 // OGCG-NEXT: ret void
42
43 char f2(CompleteS &s) {
44 return s.b;
45 }
46
47 // CIR: cir.func{{.*}} @_Z2f2R9CompleteS(%[[ARG_S:.*]]: !cir.ptr<!rec_CompleteS>{{.*}})
48 // CIR: %[[S_ADDR:.*]] = cir.alloca !cir.ptr<!rec_CompleteS>, !cir.ptr<!cir.ptr<!rec_CompleteS>>, ["s", init, const]
49 // CIR: cir.store %[[ARG_S]], %[[S_ADDR]]
50 // CIR: %[[S_REF:.*]] = cir.load{{.*}} %[[S_ADDR]]
51 // CIR: %[[S_ADDR2:.*]] = cir.get_member %[[S_REF]][1] {name = "b"}
52 // CIR: %[[S_B:.*]] = cir.load{{.*}} %[[S_ADDR2]]
53
54 // LLVM: define{{.*}} i8 @_Z2f2R9CompleteS(ptr %[[ARG_S:.*]])
55 // LLVM: %[[S_ADDR:.*]] = alloca ptr
56 // LLVM: store ptr %[[ARG_S]], ptr %[[S_ADDR]]
57 // LLVM: %[[S_REF:.*]] = load ptr, ptr %[[S_ADDR]], align 8
58 // LLVM: %[[S_ADDR2:.*]] = getelementptr %struct.CompleteS, ptr %[[S_REF]], i32 0, i32 1
59 // LLVM: %[[S_B:.*]] = load i8, ptr %[[S_ADDR2]]
60
61 // OGCG: define{{.*}} i8 @_Z2f2R9CompleteS(ptr{{.*}} %[[ARG_S:.*]])
62 // OGCG: entry:
63 // OGCG: %[[S_ADDR:.*]] = alloca ptr
64 // OGCG: store ptr %[[ARG_S]], ptr %[[S_ADDR]]
65 // OGCG: %[[S_REF:.*]] = load ptr, ptr %[[S_ADDR]]
66 // OGCG: %[[S_ADDR2:.*]] = getelementptr inbounds nuw %struct.CompleteS, ptr %[[S_REF]], i32 0, i32 1
67 // OGCG: %[[S_B:.*]] = load i8, ptr %[[S_ADDR2]]
68
69 struct Inner {
70 int n;
71 };
72
73 struct Outer {
74 Inner i;
75 };
76
77 void f3() {
78 Outer o;
79 o.i.n;
80 }
81
82 // CIR: cir.func{{.*}} @_Z2f3v()
83 // CIR: %[[O:.*]] = cir.alloca !rec_Outer, !cir.ptr<!rec_Outer>, ["o"]
84 // CIR: %[[O_I:.*]] = cir.get_member %[[O]][0] {name = "i"}
85 // CIR: %[[O_I_N:.*]] = cir.get_member %[[O_I]][0] {name = "n"}
86
87 // LLVM: define{{.*}} void @_Z2f3v()
88 // LLVM: %[[O:.*]] = alloca %struct.Outer, i64 1, align 4
89 // LLVM: %[[O_I:.*]] = getelementptr %struct.Outer, ptr %[[O]], i32 0, i32 0
90 // LLVM: %[[O_I_N:.*]] = getelementptr %struct.Inner, ptr %[[O_I]], i32 0, i32 0
91
92 // OGCG: define{{.*}} void @_Z2f3v()
93 // OGCG: %[[O:.*]] = alloca %struct.Outer, align 4
94 // OGCG: %[[O_I:.*]] = getelementptr inbounds nuw %struct.Outer, ptr %[[O]], i32 0, i32 0
95 // OGCG: %[[O_I_N:.*]] = getelementptr inbounds nuw %struct.Inner, ptr %[[O_I]], i32 0, i32 0
96
97 void paren_expr() {
98 struct Point {
99 int x;
100 int y;
101 };
102
103 Point a = (Point{});
104 Point b = (a);
105 }
106
107 // CIR: cir.func{{.*}} @_Z10paren_exprv()
108 // CIR: %[[A_ADDR:.*]] = cir.alloca !rec_Point, !cir.ptr<!rec_Point>, ["a", init]
109 // CIR: %[[B_ADDR:.*]] = cir.alloca !rec_Point, !cir.ptr<!rec_Point>, ["b", init]
110 // CIR: %[[CONST:.*]] = cir.const #cir.zero : !rec_Point
111 // CIR: cir.store{{.*}} %[[CONST]], %[[A_ADDR]] : !rec_Point, !cir.ptr<!rec_Point>
112 // CIR: cir.copy %[[A_ADDR]] to %[[B_ADDR]] : !cir.ptr<!rec_Point>
113
114 // LLVM: define{{.*}} void @_Z10paren_exprv()
115 // LLVM: %[[A_ADDR:.*]] = alloca %struct.Point, i64 1, align 4
116 // LLVM: %[[B_ADDR:.*]] = alloca %struct.Point, i64 1, align 4
117 // LLVM: store %struct.Point zeroinitializer, ptr %[[A_ADDR]], align 4
118 // LLVM: call void @llvm.memcpy.p0.p0.i32(ptr %[[B_ADDR]], ptr %[[A_ADDR]], i32 8, i1 false)
119
120 // OGCG: define{{.*}} void @_Z10paren_exprv()
121 // OGCG: %[[A_ADDR:.*]] = alloca %struct.Point, align 4
122 // OGCG: %[[B_ADDR:.*]] = alloca %struct.Point, align 4
123 // OGCG: call void @llvm.memset.p0.i64(ptr align 4 %[[A_ADDR]], i8 0, i64 8, i1 false)
124 // OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[B_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false)
125
126 void choose_expr() {
127 CompleteS a;
128 CompleteS b;
129 CompleteS c = __builtin_choose_expr(true, a, b);
130 }
131
132 // CIR: cir.func{{.*}} @_Z11choose_exprv()
133 // CIR: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a"]
134 // CIR: %[[B_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["b"]
135 // CIR: %[[C_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["c", init]
136 // CIR: cir.copy %[[A_ADDR]] to %[[C_ADDR]] : !cir.ptr<!rec_CompleteS>
137
138 // LLVM: define{{.*}} void @_Z11choose_exprv()
139 // LLVM: %[[A_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
140 // LLVM: %[[B_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
141 // LLVM: %[[C_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
142 // LLVM: call void @llvm.memcpy.p0.p0.i32(ptr %[[C_ADDR]], ptr %[[A_ADDR]], i32 8, i1 false)
143
144 // OGCG: define{{.*}} void @_Z11choose_exprv()
145 // OGCG: %[[A_ADDR:.*]] = alloca %struct.CompleteS, align 4
146 // OGCG: %[[B_ADDR:.*]] = alloca %struct.CompleteS, align 4
147 // OGCG: %[[C_ADDR:.*]] = alloca %struct.CompleteS, align 4
148 // OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[C_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false)
149
150 void generic_selection() {
151 CompleteS a;
152 CompleteS b;
153 int c;
154 CompleteS d = _Generic(c, int : a, default: b);
155 }
156
157 // CIR: cir.func{{.*}} @_Z17generic_selectionv()
158 // CIR: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a"]
159 // CIR: %[[B_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["b"]
160 // CIR: %[[C_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["c"]
161 // CIR: %[[D_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["d", init]
162 // CIR: cir.copy %[[A_ADDR]] to %[[D_ADDR]] : !cir.ptr<!rec_CompleteS>
163
164 // LLVM: define{{.*}} void @_Z17generic_selectionv()
165 // LLVM: %1 = alloca %struct.CompleteS, i64 1, align 4
166 // LLVM: %2 = alloca %struct.CompleteS, i64 1, align 4
167 // LLVM: %3 = alloca i32, i64 1, align 4
168 // LLVM: %4 = alloca %struct.CompleteS, i64 1, align 4
169 // LLVM: call void @llvm.memcpy.p0.p0.i32(ptr %4, ptr %1, i32 8, i1 false)
170
171 // OGCG: define{{.*}} void @_Z17generic_selectionv()
172 // OGCG: %[[A_ADDR:.*]] = alloca %struct.CompleteS, align 4
173 // OGCG: %[[B_ADDR:.*]] = alloca %struct.CompleteS, align 4
174 // OGCG: %[[C_ADDR:.*]] = alloca i32, align 4
175 // OGCG: %[[D_ADDR:.*]] = alloca %struct.CompleteS, align 4
176 // OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[D_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false)
177
178 void designated_init_update_expr() {
179 CompleteS a;
180
181 struct Container {
182 CompleteS c;
183 } b = {a, .c.a = 1};
184 }
185
186 // CIR: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a"]
187 // CIR: %[[B_ADDR:.*]] = cir.alloca !rec_Container, !cir.ptr<!rec_Container>, ["b", init]
188 // CIR: %[[C_ADDR:.*]] = cir.get_member %[[B_ADDR]][0] {name = "c"} : !cir.ptr<!rec_Container> -> !cir.ptr<!rec_CompleteS>
189 // CIR: cir.copy %[[A_ADDR]] to %[[C_ADDR]] : !cir.ptr<!rec_CompleteS>
190 // CIR: %[[ELEM_0_PTR:.*]] = cir.get_member %[[C_ADDR]][0] {name = "a"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s32i>
191 // CIR: %[[CONST_1:.*]] = cir.const #cir.int<1> : !s32i
192 // CIR: cir.store{{.*}} %[[CONST_1]], %[[ELEM_0_PTR]] : !s32i, !cir.ptr<!s32i>
193 // CIR: %[[ELEM_1_PTR:.*]] = cir.get_member %[[C_ADDR]][1] {name = "b"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s8i>
194
195 // LLVM: %[[A_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
196 // LLVM: %[[B_ADDR:.*]] = alloca %struct.Container, i64 1, align 4
197 // LLVM: %[[C_ADDR:.*]] = getelementptr %struct.Container, ptr %[[B_ADDR]], i32 0, i32 0
198 // LLVM: call void @llvm.memcpy.p0.p0.i32(ptr %[[C_ADDR]], ptr %[[A_ADDR]], i32 8, i1 false)
199 // LLVM: %[[ELEM_0_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[C_ADDR]], i32 0, i32 0
200 // LLVM: store i32 1, ptr %[[ELEM_0_PTR]], align 4
201 // LLVM: %[[ELEM_1_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[C_ADDR]], i32 0, i32 1
202
203 // OGCG: %[[A_ADDR:.*]] = alloca %struct.CompleteS, align 4
204 // OGCG: %[[B_ADDR:.*]] = alloca %struct.Container, align 4
205 // OGCG: %[[C_ADDR:.*]] = getelementptr inbounds nuw %struct.Container, ptr %[[B_ADDR]], i32 0, i32 0
206 // OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[C_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false)
207 // OGCG: %[[ELEM_0_PTR:.*]] = getelementptr inbounds nuw %struct.CompleteS, ptr %[[C_ADDR]], i32 0, i32 0
208 // OGCG: store i32 1, ptr %[[ELEM_0_PTR]], align 4
209 // OGCG: %[[ELEM_1_PTR:.*]] = getelementptr inbounds nuw %struct.CompleteS, ptr %[[C_ADDR]], i32 0, i32 1
210
211 void atomic_init() {
212 _Atomic CompleteS a;
213 __c11_atomic_init(&a, {});
214 }
215
216 // CIR: cir.func{{.*}} @_Z11atomic_initv()
217 // CIR: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a"]
218 // CIR: %[[ELEM_0_PTR:.*]] = cir.get_member %[[A_ADDR]][0] {name = "a"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s32i>
219 // CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s32i
220 // CIR: cir.store{{.*}} %[[CONST_0]], %[[ELEM_0_PTR]] : !s32i, !cir.ptr<!s32i>
221 // CIR: %[[ELEM_1_PTR:.*]] = cir.get_member %[[A_ADDR]][1] {name = "b"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s8i>
222 // CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s8i
223 // CIR: cir.store{{.*}} %[[CONST_0]], %[[ELEM_1_PTR]] : !s8i, !cir.ptr<!s8i>
224
225 // LLVM: define{{.*}} void @_Z11atomic_initv()
226 // LLVM: %[[A_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 8
227 // LLVM: %[[ELEM_0_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[A_ADDR]], i32 0, i32 0
228 // LLVM: store i32 0, ptr %[[ELEM_0_PTR]], align 8
229 // LLVM: %[[ELEM_1_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[A_ADDR]], i32 0, i32 1
230 // LLVM: store i8 0, ptr %[[ELEM_1_PTR]], align 4
231
232 // OGCG: define{{.*}} void @_Z11atomic_initv()
233 // OGCG: %[[A_ADDR:.*]] = alloca %struct.CompleteS, align 8
234 // OGCG: %[[ELEM_0_PTR:.*]] = getelementptr inbounds nuw %struct.CompleteS, ptr %[[A_ADDR]], i32 0, i32 0
235 // OGCG: store i32 0, ptr %[[ELEM_0_PTR]], align 8
236 // OGCG: %[[ELEM_1_PTR:.*]] = getelementptr inbounds nuw %struct.CompleteS, ptr %[[A_ADDR]], i32 0, i32 1
237 // OGCG: store i8 0, ptr %[[ELEM_1_PTR]], align 4
238
239 void unary_extension() {
240 CompleteS a = __extension__ CompleteS();
241 }
242
243 // CIR: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a", init]
244 // CIR: %[[ZERO_INIT:.*]] = cir.const #cir.zero : !rec_CompleteS
245 // CIR: cir.store{{.*}} %[[ZERO_INIT]], %[[A_ADDR]] : !rec_CompleteS, !cir.ptr<!rec_CompleteS>
246
247 // LLVM: %[[A_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
248 // LLVM: store %struct.CompleteS zeroinitializer, ptr %[[A_ADDR]], align 4
249
250 // OGCG: %[[A_ADDR:.*]] = alloca %struct.CompleteS, align 4
251 // OGCG: call void @llvm.memset.p0.i64(ptr align 4 %[[A_ADDR]], i8 0, i64 8, i1 false)
252
253 void bin_comma() {
254 CompleteS a = (CompleteS(), CompleteS());
255 }
256
257 // CIR: cir.func{{.*}} @_Z9bin_commav()
258 // CIR: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a", init]
259 // CIR: %[[CONST:.*]] = cir.const #cir.zero : !rec_CompleteS
260 // CIR: cir.store{{.*}} %[[CONST]], %[[A_ADDR]] : !rec_CompleteS, !cir.ptr<!rec_CompleteS>
261
262 // LLVM: define{{.*}} void @_Z9bin_commav()
263 // LLVM: %[[A_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
264 // LLVM: store %struct.CompleteS zeroinitializer, ptr %[[A_ADDR]], align 4
265
266 // OGCG: define{{.*}} void @_Z9bin_commav()
267 // OGCG: %[[A_ADDR:.*]] = alloca %struct.CompleteS, align 4
268 // OGCG: call void @llvm.memset.p0.i64(ptr align 4 %[[A_ADDR]], i8 0, i64 8, i1 false)
269
270 void compound_literal_expr() { CompleteS a = (CompleteS){}; }
271
272 // CIR: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a", init]
273 // CIR: %[[CONST:.*]] = cir.const #cir.zero : !rec_CompleteS
274 // CIR: cir.store{{.*}} %[[CONST]], %[[A_ADDR]] : !rec_CompleteS, !cir.ptr<!rec_CompleteS>
275
276 // TODO(cir): zero-initialize the padding
277
278 // LLVM: %[[A_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
279 // LLVM: store %struct.CompleteS zeroinitializer, ptr %[[A_ADDR]], align 4
280
281 // OGCG: %[[A_ADDR:.*]] = alloca %struct.CompleteS, align 4
282 // OGCG: call void @llvm.memset.p0.i64(ptr align 4 %[[A_ADDR]], i8 0, i64 8, i1 false)
283
284 struct StructWithConstMember {
285 int a : 1;
286 };
287
288 void struct_with_const_member_expr() {
289 int a = (StructWithConstMember){}.a;
290 }
291
292 // CIR: %[[A_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["a", init]
293 // CIR: %[[RESULT:.*]] = cir.scope {
294 // CIR: %[[REF_ADDR:.*]] = cir.alloca !rec_StructWithConstMember, !cir.ptr<!rec_StructWithConstMember>, ["ref.tmp0"]
295 // CIR: %[[ELEM_0_PTR:.*]] = cir.get_member %[[REF_ADDR]][0] {name = "a"} : !cir.ptr<!rec_StructWithConstMember> -> !cir.ptr<!u8i>
296 // CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s32i
297 // CIR: %[[SET_BF:.*]] = cir.set_bitfield{{.*}} (#bfi_a, %[[ELEM_0_PTR]] : !cir.ptr<!u8i>, %[[CONST_0]] : !s32i) -> !s32i
298 // CIR: %[[CONST_0:.*]] = cir.const #cir.int<0> : !s32i
299 // CIR: cir.yield %[[CONST_0]] : !s32i
300 // CIR: } : !s32i
301 // CIR: cir.store{{.*}} %[[RESULT]], %[[A_ADDR]] : !s32i, !cir.ptr<!s32i>
302
303 // TODO(cir): zero-initialize the padding
304
305 // LLVM: %[[REF_ADDR:.*]] = alloca %struct.StructWithConstMember, i64 1, align 4
306 // LLVM: %[[A_ADDR:.*]] = alloca i32, i64 1, align 4
307 // LLVM: br label %[[BF_LABEL:.*]]
308 // LLVM: [[BF_LABEL]]:
309 // LLVM: %[[ELEM_0_PTR:.*]] = getelementptr %struct.StructWithConstMember, ptr %[[REF_ADDR]], i32 0, i32 0
310 // LLVM: %[[TMP_REF:.*]] = load i8, ptr %[[ELEM_0_PTR]], align 4
311 // LLVM: %[[BF_CLEAR:.*]] = and i8 %[[TMP_REF]], -2
312 // LLVM: %[[BF_SET:.*]] = or i8 %[[BF_CLEAR]], 0
313 // LLVM: store i8 %[[BF_SET]], ptr %[[ELEM_0_PTR]], align 4
314 // LLVM: br label %[[RESULT_LABEL:.*]]
315 // LLVM: [[RESULT_LABEL]]:
316 // LLVM: %[[RESULT:.*]] = phi i32 [ 0, %[[BF_LABEL]] ]
317 // LLVM: store i32 %[[RESULT]], ptr %[[A_ADDR]], align 4
318
319 // OGCG: %[[A_ADDR:.*]] = alloca i32, align 4
320 // OGCG: %[[REF_ADDR:.*]] = alloca %struct.StructWithConstMember, align 4
321 // OGCG: %[[TMP_REF:.*]] = load i8, ptr %[[REF_ADDR]], align 4
322 // OGCG: %[[BF_CLEAR:.*]] = and i8 %[[TMP_REF]], -2
323 // OGCG: %[[BF_SET:.*]] = or i8 %[[BF_CLEAR]], 0
324 // OGCG: store i8 %[[BF_SET]], ptr %[[REF_ADDR]], align 4
325 // OGCG: store i32 0, ptr %[[A_ADDR]], align 4
326
327 void function_arg_with_default_value(CompleteS a = {1, 2}) {}
328
329 // CIR: %[[ARG_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a", init]
330 // CIR: cir.store %{{.*}}, %[[ARG_ADDR]] : !rec_CompleteS, !cir.ptr<!rec_CompleteS>
331
332 // LLVM: %[[ARG_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
333 // LLVM: store %struct.CompleteS %{{.*}}, ptr %[[ARG_ADDR]], align 4
334
335 // OGCG: %[[ARG_ADDR:.*]] = alloca %struct.CompleteS, align 4
336 // OGCG: store i64 %{{.*}}, ptr %[[ARG_ADDR]], align 4
337
338 void calling_function_with_default_values() {
339 function_arg_with_default_value();
340 }
341
342 // CIR: %[[AGG_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["agg.tmp0"]
343 // CIR: %[[ELEM_0_PTR:.*]] = cir.get_member %[[AGG_ADDR]][0] {name = "a"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s32i>
344 // CIR: %[[CONST_1:.*]] = cir.const #cir.int<1> : !s32i
345 // CIR: cir.store{{.*}} %[[CONST_1]], %[[ELEM_0_PTR]] : !s32i, !cir.ptr<!s32i>
346 // CIR: %[[ELEM_1_PTR:.*]] = cir.get_member %[[AGG_ADDR]][1] {name = "b"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s8i>
347 // CIR: %[[CONST_2:.*]] = cir.const #cir.int<2> : !s8i
348 // CIR: cir.store{{.*}} %[[CONST_2]], %[[ELEM_1_PTR]] : !s8i, !cir.ptr<!s8i>
349 // CIR: %[[TMP_AGG:.*]] = cir.load{{.*}} %[[AGG_ADDR]] : !cir.ptr<!rec_CompleteS>, !rec_CompleteS
350 // CIR: cir.call @_Z31function_arg_with_default_value9CompleteS(%[[TMP_AGG]]) : (!rec_CompleteS) -> ()
351
352 // TODO(CIR): the difference between the CIR LLVM and OGCG is because the lack of calling convention lowering,
353
354 // LLVM: %[[AGG_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
355 // LLVM: %[[ELEM_0_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[AGG_ADDR]], i32 0, i32 0
356 // LLVM: store i32 1, ptr %[[ELEM_0_PTR]], align 4
357 // LLVM: %[[ELEM_1_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[AGG_ADDR]], i32 0, i32 1
358 // LLVM: store i8 2, ptr %[[ELEM_1_PTR]], align 4
359 // LLVM: %[[TMP_AGG:.*]] = load %struct.CompleteS, ptr %[[AGG_ADDR]], align 4
360 // LLVM: call void @_Z31function_arg_with_default_value9CompleteS(%struct.CompleteS %[[TMP_AGG]])
361
362 // OGCG: %[[AGG_ADDR:.*]] = alloca %struct.CompleteS, align 4
363 // OGCG: %[[ELEM_0_PTR:.*]] = getelementptr inbounds nuw %struct.CompleteS, ptr %[[AGG_ADDR]], i32 0, i32 0
364 // OGCG: store i32 1, ptr %[[ELEM_0_PTR]], align 4
365 // OGCG: %[[ELEM_1_PTR:.*]] = getelementptr inbounds nuw %struct.CompleteS, ptr %[[AGG_ADDR]], i32 0, i32 1
366 // OGCG: store i8 2, ptr %[[ELEM_1_PTR]], align 4
367 // OGCG: %[[TMP_AGG:.*]] = load i64, ptr %[[AGG_ADDR]], align 4
368 // OGCG: call void @_Z31function_arg_with_default_value9CompleteS(i64 %[[TMP_AGG]])