view gcc/testsuite/gcc.dg/pr56997-1.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
line wrap: on
line source

/* Test volatile access to unaligned field.  */
/* { dg-do run } */
/* { dg-options "-fstrict-volatile-bitfields" } */

extern void abort (void);

#define test_type unsigned short
#define MAGIC (unsigned short)0x102u

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;
}