Skip to content

Commit 4a2d639

Browse files
committed
Add test case
1 parent 473fd89 commit 4a2d639

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

Diff for: clang/test/CIR/CodeGen/struct-align.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir --check-prefix=CIR %s
3+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll
4+
// RUN: FileCheck --input-file=%t.ll --check-prefix=LLVM %s
5+
6+
struct Foo {
7+
short a;
8+
short b;
9+
short c;
10+
short d;
11+
long e; // Make the struct 8-byte aligned
12+
};
13+
14+
void test(Foo *ptr) {
15+
ptr->a = 1; // align 8
16+
ptr->b = 2; // align 2
17+
ptr->c = 3; // align 4
18+
ptr->d = 4; // align 2
19+
}
20+
21+
// CIR-LABEL: _Z4testP3Foo
22+
// LLVM-LABEL: _Z4testP3Foo
23+
24+
// CIR: [[PTR:%.*]] = cir.load {{%.*}} : !cir.ptr<!cir.ptr<!ty_Foo>>, !cir.ptr<!ty_Foo>
25+
// CIR: [[PTRA:%.*]] = cir.get_member [[PTR]][0] {name = "a"} : !cir.ptr<!ty_Foo> -> !cir.ptr<!s16i>
26+
// CIR: cir.store align(8) {{%.*}}, [[PTRA]] : !s16i, !cir.ptr<!s16i>
27+
// CIR: [[PTR:%.*]] = cir.load {{%.*}} : !cir.ptr<!cir.ptr<!ty_Foo>>, !cir.ptr<!ty_Foo>
28+
// CIR: [[PTRB:%.*]] = cir.get_member [[PTR]][1] {name = "b"} : !cir.ptr<!ty_Foo> -> !cir.ptr<!s16i>
29+
// CIR: cir.store align(2) {{%.*}}, [[PTRB]] : !s16i, !cir.ptr<!s16i>
30+
// CIR: [[PTR:%.*]] = cir.load {{%.*}} : !cir.ptr<!cir.ptr<!ty_Foo>>, !cir.ptr<!ty_Foo>
31+
// CIR: [[PTRC:%.*]] = cir.get_member [[PTR]][2] {name = "c"} : !cir.ptr<!ty_Foo> -> !cir.ptr<!s16i>
32+
// CIR: cir.store align(4) {{%.*}}, [[PTRC]] : !s16i, !cir.ptr<!s16i>
33+
// CIR: [[PTR:%.*]] = cir.load {{%.*}} : !cir.ptr<!cir.ptr<!ty_Foo>>, !cir.ptr<!ty_Foo>
34+
// CIR: [[PTRD:%.*]] = cir.get_member [[PTR]][3] {name = "d"} : !cir.ptr<!ty_Foo> -> !cir.ptr<!s16i>
35+
// CIR: cir.store align(2) {{%.*}}, [[PTRD]] : !s16i, !cir.ptr<!s16i>
36+
37+
// FIXME: miss inbounds and nuw attribute
38+
// LLVM: [[PTR:%.*]] = load ptr, ptr {{%.*}}, align 8
39+
// LLVM: [[PTRA:%.*]] = getelementptr %struct.Foo, ptr [[PTR]], i32 0, i32 0
40+
// LLVM: store i16 1, ptr [[PTRA]], align 8
41+
// LLVM: [[PTR:%.*]] = load ptr, ptr {{%.*}}, align 8
42+
// LLVM: [[PTRB:%.*]] = getelementptr %struct.Foo, ptr [[PTR]], i32 0, i32 1
43+
// LLVM: store i16 2, ptr [[PTRB]], align 2
44+
// LLVM: [[PTR:%.*]] = load ptr, ptr {{%.*}}, align 8
45+
// LLVM: [[PTRC:%.*]] = getelementptr %struct.Foo, ptr [[PTR]], i32 0, i32 2
46+
// LLVM: store i16 3, ptr [[PTRC]], align 4
47+
// LLVM: [[PTR:%.*]] = load ptr, ptr {{%.*}}, align 8
48+
// LLVM: [[PTRD:%.*]] = getelementptr %struct.Foo, ptr [[PTR]], i32 0, i32 3
49+
// LLVM: store i16 4, ptr [[PTRD]], align 2

0 commit comments

Comments
 (0)