| 1 |
/* Test support of scalar_storage_order pragma */ |
| 2 |
|
| 3 |
/* { dg-do run } */ |
| 4 |
/* { dg-require-effective-target int32plus } */ |
| 5 |
|
| 6 |
#pragma scalar_storage_order /* { dg-warning "missing .big-endian., .little-endian., or .default." } */ |
| 7 |
|
| 8 |
#pragma scalar_storage_order big-endian |
| 9 |
|
| 10 |
struct S1 |
| 11 |
{ |
| 12 |
int i; |
| 13 |
}; |
| 14 |
|
| 15 |
struct __attribute__((scalar_storage_order("little-endian"))) S2 |
| 16 |
{ |
| 17 |
int i; |
| 18 |
}; |
| 19 |
|
| 20 |
#pragma scalar_storage_order little-endian |
| 21 |
|
| 22 |
struct S3 |
| 23 |
{ |
| 24 |
int i; |
| 25 |
}; |
| 26 |
|
| 27 |
struct __attribute__((scalar_storage_order("big-endian"))) S4 |
| 28 |
{ |
| 29 |
int i; |
| 30 |
}; |
| 31 |
|
| 32 |
#pragma scalar_storage_order default |
| 33 |
|
| 34 |
struct S5 |
| 35 |
{ |
| 36 |
int i; |
| 37 |
}; |
| 38 |
|
| 39 |
#pragma scalar_storage_order other /* { dg-warning "expected .big-endian., .little-endian., or .default." } */ |
| 40 |
|
| 41 |
struct S1 my_s1 = { 0x12345678 }; |
| 42 |
struct S2 my_s2 = { 0x12345678 }; |
| 43 |
struct S3 my_s3 = { 0x12345678 }; |
| 44 |
struct S4 my_s4 = { 0x12345678 }; |
| 45 |
struct S5 my_s5 = { 0x12345678 }; |
| 46 |
|
| 47 |
unsigned char big_endian_pattern[4] = { 0x12, 0x34, 0x56, 0x78 }; |
| 48 |
unsigned char little_endian_pattern[4] = { 0x78, 0x56, 0x34, 0x12 }; |
| 49 |
|
| 50 |
int main (void) |
| 51 |
{ |
| 52 |
if (__builtin_memcmp (&my_s1, &big_endian_pattern, 4) != 0) |
| 53 |
__builtin_abort (); |
| 54 |
|
| 55 |
if (__builtin_memcmp (&my_s2, &little_endian_pattern, 4) != 0) |
| 56 |
__builtin_abort (); |
| 57 |
|
| 58 |
if (__builtin_memcmp (&my_s3, &little_endian_pattern, 4) != 0) |
| 59 |
__builtin_abort (); |
| 60 |
|
| 61 |
if (__builtin_memcmp (&my_s4, &big_endian_pattern, 4) != 0) |
| 62 |
__builtin_abort (); |
| 63 |
|
| 64 |
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
| 65 |
if (__builtin_memcmp (&my_s5, &little_endian_pattern, 4) != 0) |
| 66 |
__builtin_abort (); |
| 67 |
#else |
| 68 |
if (__builtin_memcmp (&my_s5, &big_endian_pattern, 4) != 0) |
| 69 |
__builtin_abort (); |
| 70 |
#endif |
| 71 |
|
| 72 |
return 0; |
| 73 |
} |