llvm-project/clang/test/CodeGenCXX/override-layout-packed-base.cpp
Akira Hatanaka adaf62ced2 [Sema] Reject array element types whose sizes aren't a multiple of their
alignments

In the following code, the first element is aligned on a 16-byte
boundary, but the remaining elements aren't:

```
typedef char int8_a16 __attribute__((aligned(16)));
int8_a16 array[4];
```

Currently clang doesn't reject the code, but it should since it can
cause crashes at runtime. This patch also fixes assertion failures in
CodeGen caused by the changes in https://reviews.llvm.org/D123649.

Differential Revision: https://reviews.llvm.org/D133711
2022-09-21 09:15:03 -07:00

41 lines
713 B
C++

// RUN: %clang_cc1 -triple i686-windows-msvc -w -fdump-record-layouts-simple -foverride-record-layout=%S/Inputs/override-layout-packed-base.layout %s | FileCheck %s
//#pragma pack(push, 1)
// CHECK: Type: class B<0>
// CHECK: Size:40
// CHECK: FieldOffsets: [0, 32]
// CHECK: Type: class B<1>
// CHECK: Size:40
// CHECK: FieldOffsets: [0, 32]
template<int I>
class B {
int _b1;
char _b2;
};
// CHECK: Type: class C
// CHECK: Size:88
// CHECK: FieldOffsets: [80]
class C : B<0>, B<1> {
char _c;
};
// CHECK: Type: class D
// CHECK: Size:120
// CHECK: FieldOffsets: [32]
class D : virtual B<0>, virtual B<1> {
char _d;
};
//#pragma pack(pop)
void use_structs() {
C cs;
D ds;
}