summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/sso-14.c
blob: 7b1590ad03a7bb83bd88c5caf54cd9ab7310e053 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* PR c/100920 */
/* Testcase by George Thopas <george.thopas@gmail.com> */

/* { dg-do compile } */
/* { dg-require-effective-target alloca } */

#include <stddef.h>
#include <stdlib.h>
#include <string.h>

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define REV_ENDIANNESS __attribute__((scalar_storage_order("big-endian")))
#else
#define REV_ENDIANNESS __attribute__((scalar_storage_order("little-endian")))
#endif

struct s_1 {
    int val;
} REV_ENDIANNESS;

typedef struct s_1 t_1;

struct s_2 {
    char val;
} REV_ENDIANNESS;

typedef struct s_2 t_2;

struct s12 {
    t_1 a[1];
    t_2 b[1]; 
} REV_ENDIANNESS;

typedef struct s12 t_s12;

union u12 {
    t_1 a[1];
    t_2 b[1];
} REV_ENDIANNESS;

typedef union u12 t_u12;

int main(void)
{
  t_s12 *msg1 = __builtin_alloca(10);
  t_u12 *msg2 = __builtin_alloca(10);
  int same;

  msg1 = malloc (sizeof (t_s12));
  msg2 = malloc (sizeof (t_s12));

  memset (msg1, 0, sizeof (t_s12));
  memcpy (msg2, msg1, sizeof (t_s12));
  same = memcmp (msg1, msg2, sizeof (t_s12));

  return 0;
}