aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gcc.dg/pr56997-3.c
blob: 3754b108ac660cd581c47756aa657fa5a84ec8d5 (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
/* Test volatile access to unaligned field.  */
/* { dg-do run } */
/* { dg-options "-fstrict-volatile-bitfields" } */

extern void abort (void);

#define test_type unsigned long long
#define MAGIC 0x102030405060708ull

typedef struct s{
 unsigned char Prefix;
 test_type Type;
}__attribute((__packed__)) ss;

volatile ss v;
ss g;

void __attribute__((noinline))
foo (test_type u)
{
  v.Type = u;
}

test_type __attribute__((noinline))
bar (void)
{
  return v.Type;
}

int main()
{
  test_type temp;
  foo(MAGIC);
  __builtin_memcpy(&g, (void *)&v, sizeof(g));
  if (g.Type != MAGIC)
    abort ();

  g.Type = MAGIC;
  __builtin_memcpy((void *)&v, &g, sizeof(v));
  temp = bar();
  if (temp != MAGIC)
    abort ();
  return 0;
}