2018-11-07 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / torture / pr81977.C
bloba8c8ba02b0081167d2368abd4c52896f656a35c5
1 /* { dg-do run } */
2 /* { dg-require-effective-target int32plus } */
4 #include <cstdint>
6 typedef struct
8   uint16_t  x ;
9   uint16_t  y ;
10   uint64_t  z ;
11 } __attribute__((packed, aligned(1))) TestMsgType;
13 struct Payload
15   uint16_t header_info[2];
16   TestMsgType _pref;
17   void Pack(uint8_t *buffer)
18     {
19       __builtin_memcpy(buffer, &_pref, sizeof(_pref));
20     }
21   void UnPack(uint8_t *buffer)
22     {
23       __builtin_memcpy(&_pref, buffer, sizeof(_pref));
24     }
28 struct Msg
30   Payload _payload;
31   void Pack(uint8_t *buffer)
32     {
33       _payload.Pack(buffer);
34     }
36   void UnPack(uint8_t *buffer)
37     {
38       _payload.UnPack(buffer);
39     }
42 int main()
44   uint8_t * buffer = new uint8_t [30];
45   Msg msg;
46   Msg msg1;
47   msg._payload._pref.x             = 0xabcd;
48   msg._payload._pref.y             = 0xa;
49   msg._payload._pref.z             = 0x0001020304051617;
50   msg.Pack(&buffer[0]);
51   msg1.UnPack(&buffer[0]);
52   if (msg1._payload._pref.x != 0xabcd)
53     __builtin_abort ();
54   delete [] buffer;