1 /* { dg-do run } */
2 /* { dg-require-effective-target int32plus } */
3 
4 #include <cstdint>
5 
6 typedef struct
7 {
8   uint16_t  x ;
9   uint16_t  y ;
10   uint64_t  z ;
11 } __attribute__((packed, aligned(1))) TestMsgType;
12 
13 struct Payload
14 {
15   uint16_t header_info[2];
16   TestMsgType _pref;
PackPayload17   void Pack(uint8_t *buffer)
18     {
19       __builtin_memcpy(buffer, &_pref, sizeof(_pref));
20     }
UnPackPayload21   void UnPack(uint8_t *buffer)
22     {
23       __builtin_memcpy(&_pref, buffer, sizeof(_pref));
24     }
25 };
26 
27 
28 struct Msg
29 {
30   Payload _payload;
PackMsg31   void Pack(uint8_t *buffer)
32     {
33       _payload.Pack(buffer);
34     }
35 
UnPackMsg36   void UnPack(uint8_t *buffer)
37     {
38       _payload.UnPack(buffer);
39     }
40 };
41 
main()42 int main()
43 {
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;
55 }
56