| 1 |
// RUN: %clang_cc1 -triple x86_64-windows-msvc -fsyntax-only -verify -Wpadded %s |
| 2 |
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify -Wpadded %s |
| 3 |
|
| 4 |
struct __attribute__((ms_struct)) BitfieldStruct { // expected-warning {{padding size of 'BitfieldStruct' with 3 bytes to alignment boundary}} |
| 5 |
char c : 1; |
| 6 |
int : 0; // expected-warning {{padding struct 'BitfieldStruct' with 31 bits to align anonymous bit-field}} |
| 7 |
char i; |
| 8 |
}; |
| 9 |
|
| 10 |
struct __attribute__((ms_struct)) SevenBitfieldStruct { // expected-warning {{padding size of 'SevenBitfieldStruct' with 3 bytes to alignment boundary}} |
| 11 |
char c : 7; |
| 12 |
int : 0; // expected-warning {{padding struct 'SevenBitfieldStruct' with 25 bits to align anonymous bit-field}} |
| 13 |
char i; |
| 14 |
}; |
| 15 |
|
| 16 |
struct __attribute__((ms_struct)) SameUnitSizeBitfield { |
| 17 |
char c : 7; |
| 18 |
char : 1; // Same unit size attributes fall in the same unit + they fill the unit -> no padding |
| 19 |
char i; |
| 20 |
}; |
| 21 |
|
| 22 |
struct __attribute__((ms_struct)) DifferentUnitSizeBitfield { // expected-warning {{padding size of 'DifferentUnitSizeBitfield' with 3 bytes to alignment boundary}} |
| 23 |
char c : 7; |
| 24 |
int : 1; // expected-warning {{padding struct 'DifferentUnitSizeBitfield' with 25 bits to align anonymous bit-field}} |
| 25 |
char i; // expected-warning {{padding struct 'DifferentUnitSizeBitfield' with 31 bits to align 'i'}} |
| 26 |
}; |
| 27 |
|
| 28 |
struct __attribute__((ms_struct)) BitfieldBigPadding { // expected-warning {{padding size of 'BitfieldBigPadding' with 63 bits to alignment boundary}} |
| 29 |
long long x; |
| 30 |
char a : 1; |
| 31 |
long long b : 1; // expected-warning {{padding struct 'BitfieldBigPadding' with 63 bits to align 'b'}} |
| 32 |
}; |
| 33 |
|
| 34 |
struct __attribute__((ms_struct)) SameUnitSizeMultiple { // expected-warning {{padding size of 'SameUnitSizeMultiple' with 2 bits to alignment boundary}} |
| 35 |
char c : 1; |
| 36 |
char cc : 2; |
| 37 |
char ccc : 3; |
| 38 |
}; |
| 39 |
|
| 40 |
int main() { |
| 41 |
BitfieldStruct b; |
| 42 |
SevenBitfieldStruct s; |
| 43 |
SameUnitSizeBitfield su; |
| 44 |
DifferentUnitSizeBitfield du; |
| 45 |
BitfieldBigPadding bbp; |
| 46 |
SameUnitSizeMultiple susm; |
| 47 |
} |