llvm-project
113 строк · 3.1 Кб
1// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
2// RUN: -fsyntax-only -fxl-pragma-pack -x c %s | \
3// RUN: FileCheck --check-prefixes=CHECK,32BIT %s
4
5// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -fdump-record-layouts \
6// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
7// RUN: FileCheck --check-prefixes=CHECK,32BIT %s
8
9// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
10// RUN: -fsyntax-only -fxl-pragma-pack -x c %s | \
11// RUN: FileCheck --check-prefixes=CHECK,64BIT %s
12
13// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -fdump-record-layouts \
14// RUN: -fsyntax-only -fxl-pragma-pack -x c++ %s | \
15// RUN: FileCheck --check-prefixes=CHECK,64BIT %s
16
17struct A {
18int a1 : 30;
19int a2 : 30;
20int a3 : 4;
21};
22
23int a = sizeof(struct A);
24
25// CHECK: *** Dumping AST Record Layout
26// CHECK-NEXT: 0 | struct A
27// CHECK-NEXT: 0:0-29 | int a1
28// CHECK-NEXT: 4:0-29 | int a2
29// CHECK-NEXT: 8:0-3 | int a3
30// CHECK-NEXT: sizeof=12, {{(dsize=12, )?}}align=4, preferredalign=4
31
32#pragma align(packed)
33struct AlignPacked {
34int a1 : 30;
35int a2 : 30;
36int a3 : 4;
37};
38#pragma align(reset)
39
40int b = sizeof(struct AlignPacked);
41
42// CHECK: *** Dumping AST Record Layout
43// CHECK-NEXT: 0 | struct AlignPacked
44// CHECK-NEXT: 0:0-29 | int a1
45// CHECK-NEXT: 3:6-35 | int a2
46// CHECK-NEXT: 7:4-7 | int a3
47// CHECK-NEXT: sizeof=8, {{(dsize=8, )?}}align=1, preferredalign=1
48
49#pragma pack(1)
50struct Pack1 {
51int a1 : 30;
52int a2 : 30;
53int a3 : 4;
54};
55#pragma pack(pop)
56
57int c = sizeof(struct Pack1);
58
59// CHECK: *** Dumping AST Record Layout
60// CHECK-NEXT: 0 | struct Pack1
61// CHECK-NEXT: 0:0-29 | int a1
62// CHECK-NEXT: 3:6-35 | int a2
63// CHECK-NEXT: 7:4-7 | int a3
64// CHECK-NEXT: sizeof=8, {{(dsize=8, )?}}align=1, preferredalign=1
65
66#pragma pack(2)
67struct Pack2 {
68int a1 : 30;
69int a2 : 30;
70int a3 : 4;
71};
72#pragma pack(pop)
73
74int d = sizeof(struct Pack2);
75
76// CHECK: *** Dumping AST Record Layout
77// CHECK-NEXT: 0 | struct Pack2
78// CHECK-NEXT: 0:0-29 | int a1
79// CHECK-NEXT: 3:6-35 | int a2
80// CHECK-NEXT: 7:4-7 | int a3
81// CHECK-NEXT: sizeof=8, {{(dsize=8, )?}}align=2, preferredalign=2
82//
83struct __attribute__((packed)) PackedAttr {
84char f1;
85int : 0;
86short : 3;
87char f4 : 2;
88};
89
90int e = sizeof(struct PackedAttr);
91// CHECK: *** Dumping AST Record Layout
92// CHECK-NEXT: 0 | struct PackedAttr
93// CHECK-NEXT: 0 | char f1
94// CHECK-NEXT: 4:- | int
95// CHECK-NEXT: 4:0-2 | short
96// CHECK-NEXT: 4:3-4 | char f4
97// CHECK-NEXT: sizeof=5, {{(dsize=5, )?}}align=1, preferredalign=1
98
99#pragma pack(2)
100struct __attribute__((packed)) PackedAttrAndPragma {
101char f1;
102long long : 0;
103};
104#pragma pack(pop)
105
106int f = sizeof(struct PackedAttrAndPragma);
107// CHECK: *** Dumping AST Record Layout
108// CHECK-NEXT: 0 | struct PackedAttrAndPragma
109// CHECK-NEXT: 0 | char f1
110// 32BIT-NEXT: 4:- | long long
111// 32BIT-NEXT: sizeof=4, {{(dsize=4, )?}}align=1, preferredalign=1
112// 64BIT-NEXT: 8:- | long long
113// 64BIT-NEXT: sizeof=8, {{(dsize=8, )?}}align=1, preferredalign=1
114