Debian Codegraph @

gcc/testsuite/gcc.dg/sso-14.c

raw
1 /* PR c/100920 */
2 /* Testcase by George Thopas <[email protected]> */
3
4 /* { dg-do compile } */
5
6 #include <stddef.h>
7 #include <stdlib.h>
8 #include <string.h>
9
10 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
11 #define REV_ENDIANNESS __attribute__((scalar_storage_order("big-endian")))
12 #else
13 #define REV_ENDIANNESS __attribute__((scalar_storage_order("little-endian")))
14 #endif
15
16 struct s_1 {
17 int val;
18 } REV_ENDIANNESS;
19
20 typedef struct s_1 t_1;
21
22 struct s_2 {
23 char val;
24 } REV_ENDIANNESS;
25
26 typedef struct s_2 t_2;
27
28 struct s12 {
29 t_1 a[1];
30 t_2 b[1];
31 } REV_ENDIANNESS;
32
33 typedef struct s12 t_s12;
34
35 union u12 {
36 t_1 a[1];
37 t_2 b[1];
38 } REV_ENDIANNESS;
39
40 typedef union u12 t_u12;
41
42 int main(void)
43 {
44 t_s12 *msg1 = __builtin_alloca(10);
45 t_u12 *msg2 = __builtin_alloca(10);
46 int same;
47
48 msg1 = malloc (sizeof (t_s12));
49 msg2 = malloc (sizeof (t_s12));
50
51 memset (msg1, 0, sizeof (t_s12));
52 memcpy (msg2, msg1, sizeof (t_s12));
53 same = memcmp (msg1, msg2, sizeof (t_s12));
54
55 return 0;
56 }