| 1 |
// { dg-do run } |
| 2 |
// { dg-additional-options "-std=c++17 -Wno-psabi -w" } |
| 3 |
|
| 4 |
struct verify |
| 5 |
{ |
| 6 |
const bool m_failed = false; |
| 7 |
|
| 8 |
[[gnu::noinline]] void print_hex(const void* x, int n) const |
| 9 |
{ |
| 10 |
const auto* bytes = static_cast<const unsigned char*>(x); |
| 11 |
for (int i = 0; i < n; ++i) |
| 12 |
__builtin_printf((i && i % 4 == 0) ? "'%02x" : "%02x", bytes[i]); |
| 13 |
__builtin_printf("\n"); |
| 14 |
} |
| 15 |
|
| 16 |
template <typename... Ts> |
| 17 |
verify(bool ok, const Ts&... extra_info) : m_failed(!ok) |
| 18 |
{ |
| 19 |
if (m_failed) |
| 20 |
(print_hex(&extra_info, sizeof(extra_info)), ...); |
| 21 |
} |
| 22 |
|
| 23 |
~verify() |
| 24 |
{ |
| 25 |
if (m_failed) |
| 26 |
__builtin_abort(); |
| 27 |
} |
| 28 |
}; |
| 29 |
|
| 30 |
using K [[gnu::vector_size(16)]] = int; |
| 31 |
|
| 32 |
int |
| 33 |
main() |
| 34 |
{ |
| 35 |
int count = 1; |
| 36 |
asm("" : "+m"(count)); |
| 37 |
verify(count == 1, 0, "", 0); |
| 38 |
|
| 39 |
{ |
| 40 |
struct SW |
| 41 |
{ |
| 42 |
K d; |
| 43 |
}; |
| 44 |
struct |
| 45 |
{ |
| 46 |
SW d; |
| 47 |
} xx; |
| 48 |
SW& x = xx.d; |
| 49 |
x = SW(); // [0, 0, 0, 0] |
| 50 |
for (int i = 3; i >= 2; --i) |
| 51 |
{ |
| 52 |
x.d[i] = -1; // [0, 0, 0, -1] ... |
| 53 |
int a = [](K y) { |
| 54 |
for (int j = 0; j < 4; ++j) |
| 55 |
if (y[j] != 0) |
| 56 |
return j; |
| 57 |
return -1; |
| 58 |
}(x.d); |
| 59 |
verify(a == i, 0, 0, 0, 0, i, x); |
| 60 |
} |
| 61 |
} |
| 62 |
} |