xref: /llvm-project/clang/test/CodeGenCXX/debug-info-struct-align.cpp (revision 66df6141659375e738d9b9b74bf79b2317576042)
1 //  Test for debug info related to DW_AT_alignment attribute in the struct type.
2 // RUN: %clang_cc1 -dwarf-version=5 -debug-info-kind=standalone -emit-llvm %s -o - | FileCheck %s
3 
4 // CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "MyType", {{.*}}, align: 32
5 // CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "MyType1", {{.*}}, align: 8
6 // CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "MyType2", {{.*}}, align: 8
7 
8 struct MyType {
9   int m;
10 } __attribute__((aligned(1)));
11 MyType mt;
12 
13 static_assert(alignof(MyType) == 4, "alignof MyType is wrong");
14 
15 struct MyType1 {
16   int m;
17 } __attribute__((packed, aligned(1)));
18 MyType1 mt1;
19 
20 static_assert(alignof(MyType1) == 1, "alignof MyType1 is wrong");
21 
22 struct MyType2 {
23   __attribute__((packed)) int m;
24 } __attribute__((aligned(1)));
25 MyType2 mt2;
26 
27 static_assert(alignof(MyType2) == 1, "alignof MyType2 is wrong");
28 
29 #pragma pack(1)
30 struct MyType3 {
31   int m;
32 };
33 MyType3 mt3;
34 
35 static_assert(alignof(MyType3) == 1, "alignof MyType3 is wrong");
36