| 1 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux -DSANITIZER_ENABLED -fsanitize=address -fsanitize-address-field-padding=1 %s |
| 2 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux %s |
| 3 |
|
| 4 |
struct S { |
| 5 |
~S() {} |
| 6 |
virtual void foo() {} |
| 7 |
|
| 8 |
int buffer[1]; |
| 9 |
int other_field = 0; |
| 10 |
}; |
| 11 |
|
| 12 |
union U { |
| 13 |
S s; |
| 14 |
}; |
| 15 |
|
| 16 |
struct Derived : S {}; |
| 17 |
|
| 18 |
static_assert(!__is_trivially_copyable(S)); |
| 19 |
#ifdef SANITIZER_ENABLED |
| 20 |
// Don't allow memcpy when the struct has poisoned padding bits. |
| 21 |
// The sanitizer adds posion padding bits to struct S. |
| 22 |
static_assert(sizeof(S) > 16); |
| 23 |
static_assert(!__is_bitwise_cloneable(S)); |
| 24 |
static_assert(sizeof(U) == sizeof(S)); // no padding bit for U. |
| 25 |
static_assert(!__is_bitwise_cloneable(U)); |
| 26 |
static_assert(!__is_bitwise_cloneable(S[2])); |
| 27 |
static_assert(!__is_bitwise_cloneable(Derived)); |
| 28 |
#else |
| 29 |
static_assert(sizeof(S) == 16); |
| 30 |
static_assert(__is_bitwise_cloneable(S)); |
| 31 |
static_assert(__is_bitwise_cloneable(U)); |
| 32 |
static_assert(__is_bitwise_cloneable(S[2])); |
| 33 |
static_assert(__is_bitwise_cloneable(Derived)); |
| 34 |
#endif |