(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
pr56997-1.c
       1  /* Test volatile access to unaligned field.  */
       2  /* { dg-do run } */
       3  /* { dg-options "-fstrict-volatile-bitfields" } */
       4  
       5  extern void abort (void);
       6  
       7  #define test_type unsigned short
       8  #define MAGIC (unsigned short)0x102u
       9  
      10  typedef struct s{
      11   unsigned char Prefix;
      12   test_type Type;
      13  }__attribute((__packed__)) ss;
      14  
      15  volatile ss v;
      16  ss g;
      17  
      18  void __attribute__((noinline))
      19  foo (test_type u)
      20  {
      21    v.Type = u;
      22  }
      23  
      24  test_type __attribute__((noinline))
      25  bar (void)
      26  {
      27    return v.Type;
      28  }
      29  
      30  int main()
      31  {
      32    test_type temp;
      33    foo(MAGIC);
      34    __builtin_memcpy(&g, (void *)&v, sizeof(g));
      35    if (g.Type != MAGIC)
      36      abort ();
      37  
      38    g.Type = MAGIC;
      39    __builtin_memcpy((void *)&v, &g, sizeof(v));
      40    temp = bar();
      41    if (temp != MAGIC)
      42      abort ();
      43    return 0;
      44  }