| 1 |
// RUN: %clang_cc1 -fno-rtti -triple x86_64-pc-win32 -fms-extensions -fdump-record-layouts -fsyntax-only %s 2>/dev/null \ |
| 2 |
// RUN: | FileCheck %s -check-prefix CHECK |
| 3 |
|
| 4 |
// Before PR45420, we would only find the alignment on this record. Afterwards, |
| 5 |
// we can see the alignment on the typedef through the array type. |
| 6 |
// FIXME: What about other type sugar, like _Atomic? This would only matter in a |
| 7 |
// packed struct context. |
| 8 |
struct __declspec(align(16)) AlignedStruct { int x; }; |
| 9 |
struct Struct2 { |
| 10 |
char c[16]; |
| 11 |
}; |
| 12 |
typedef struct Struct2 __declspec(align(16)) AlignedStruct2; |
| 13 |
|
| 14 |
#define CHECK_SIZE(X, Align) \ |
| 15 |
_Static_assert(__alignof(struct X) == Align, "should be aligned"); |
| 16 |
|
| 17 |
#pragma pack(push, 2) |
| 18 |
|
| 19 |
struct A { |
| 20 |
struct AlignedStruct a[1]; |
| 21 |
}; |
| 22 |
CHECK_SIZE(A, 16); |
| 23 |
|
| 24 |
struct B { |
| 25 |
char b; |
| 26 |
AlignedStruct2 a[1]; |
| 27 |
}; |
| 28 |
CHECK_SIZE(B, 16); |
| 29 |
|
| 30 |
struct C { |
| 31 |
char b; |
| 32 |
AlignedStruct2 a[]; |
| 33 |
}; |
| 34 |
CHECK_SIZE(C, 16); |
| 35 |
|
| 36 |
// CHECK: *** Dumping AST Record Layout |
| 37 |
// CHECK-NEXT: 0 | struct AlignedStruct |
| 38 |
// CHECK-NEXT: 0 | int x |
| 39 |
// CHECK-NEXT: | [sizeof=16, align=16] |
| 40 |
// CHECK: *** Dumping AST Record Layout |
| 41 |
// CHECK-NEXT: 0 | struct A |
| 42 |
// CHECK-NEXT: 0 | struct AlignedStruct[1] a |
| 43 |
// CHECK-NEXT: | [sizeof=16, align=16] |
| 44 |
// CHECK: *** Dumping AST Record Layout |
| 45 |
// CHECK-NEXT: 0 | struct Struct2 |
| 46 |
// CHECK-NEXT: 0 | char[16] c |
| 47 |
// CHECK-NEXT: | [sizeof=16, align=1] |
| 48 |
// CHECK: *** Dumping AST Record Layout |
| 49 |
// CHECK-NEXT: 0 | struct B |
| 50 |
// CHECK-NEXT: 0 | char b |
| 51 |
// CHECK-NEXT: 16 | AlignedStruct2[1] a |
| 52 |
// CHECK-NEXT: | [sizeof=32, align=16] |
| 53 |
// CHECK: *** Dumping AST Record Layout |
| 54 |
// CHECK-NEXT: 0 | struct C |
| 55 |
// CHECK-NEXT: 0 | char b |
| 56 |
// CHECK-NEXT: 16 | AlignedStruct2[] a |
| 57 |
// CHECK-NEXT: | [sizeof=16, align=16] |
| 58 |
|
| 59 |
#pragma pack(pop) |
| 60 |
|