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