| 1 |
// { dg-do compile { target { c++20 && { ilp32 || lp64 } } } } |
| 2 |
|
| 3 |
struct A { signed char a, b, c, d, e, f; }; |
| 4 |
struct B {}; |
| 5 |
struct C { B a, b; short c; B d; }; |
| 6 |
struct D { int a : 4, b : 24, c : 4; }; |
| 7 |
struct E { B a, b; short c; }; |
| 8 |
struct F { B a; signed char b, c; B d; }; |
| 9 |
|
| 10 |
constexpr bool |
| 11 |
f1 () |
| 12 |
{ |
| 13 |
A a; |
| 14 |
a.c = 23; a.d = 42; |
| 15 |
C b = __builtin_bit_cast (C, a); // OK |
| 16 |
return false; |
| 17 |
} |
| 18 |
|
| 19 |
constexpr bool |
| 20 |
f2 () |
| 21 |
{ |
| 22 |
A a; |
| 23 |
a.a = 1; a.b = 2; a.c = 3; a.e = 4; a.f = 5; |
| 24 |
C b = __builtin_bit_cast (C, a); // { dg-error "'__builtin_bit_cast' accessing uninitialized byte at offset 3" "" { target { ! default_packed } } } |
| 25 |
return false; |
| 26 |
} |
| 27 |
|
| 28 |
constexpr bool |
| 29 |
f3 () |
| 30 |
{ |
| 31 |
D a; |
| 32 |
a.b = 1; |
| 33 |
F b = __builtin_bit_cast (F, a); // OK |
| 34 |
return false; |
| 35 |
} |
| 36 |
|
| 37 |
constexpr bool |
| 38 |
f4 () |
| 39 |
{ |
| 40 |
D a; |
| 41 |
a.b = 1; a.c = 2; |
| 42 |
E b = __builtin_bit_cast (E, a); // OK |
| 43 |
return false; |
| 44 |
} |
| 45 |
|
| 46 |
constexpr bool |
| 47 |
f5 () |
| 48 |
{ |
| 49 |
D a; |
| 50 |
a.b = 1; |
| 51 |
E b = __builtin_bit_cast (E, a); // { dg-error "'__builtin_bit_cast' accessing uninitialized byte at offset 3" "" { target { ! default_packed } } } |
| 52 |
return false; |
| 53 |
} |
| 54 |
|
| 55 |
constexpr bool |
| 56 |
f6 () |
| 57 |
{ |
| 58 |
D a; |
| 59 |
a.c = 1; |
| 60 |
E b = __builtin_bit_cast (E, a); // { dg-error "'__builtin_bit_cast' accessing uninitialized byte at offset 2" "" { target { ! default_packed } } } |
| 61 |
return false; |
| 62 |
} |
| 63 |
|
| 64 |
constexpr bool a = f1 (); |
| 65 |
constexpr bool b = f2 (); |
| 66 |
constexpr bool c = f3 (); |
| 67 |
constexpr bool d = f4 (); |
| 68 |
constexpr bool e = f5 (); |
| 69 |
constexpr bool f = f6 (); |