Update concepts branch to revision 131834
[official-gcc.git] / gcc / testsuite / gcc.dg / struct-ret-3.c
blob4a603cbe681f12fceb156becc9e5e4c6f60d1ee8
1 /* PR middle-end/31309 */
2 /* Origin: Peeter Joot <peeterj@ca.ibm.com> */
4 /* { dg-do run { target *-*-linux* } } */
6 #include <sys/mman.h>
7 #include <string.h>
8 #include <stdio.h>
9 #include <errno.h>
11 unsigned long ossAlignX(unsigned long i, unsigned long X)
13 return ((i + (X - 1)) & ~(unsigned long) (X - 1));
16 struct STRUCT_6_BYTES
18 unsigned char slot[sizeof(unsigned short)];
19 unsigned char page[sizeof(unsigned int)];
22 struct SQLU_DICT_INFO_0
24 void *pBlah;
25 char bSomeFlag1;
26 char bSomeFlag2;
27 struct STRUCT_6_BYTES dRID;
30 struct SQLU_DATAPART_0
32 struct SQLU_DICT_INFO_0 *pDictRidderInfo;
35 struct XXX
37 struct SQLU_DATAPART_0 *m_pDatapart;
40 struct STRUCT_6_BYTES INIT_6_BYTES_ZERO()
42 struct STRUCT_6_BYTES ridOut = {{0,0}, {0,0,0,0}};
43 return ridOut;
46 void Initialize(struct XXX *this, int iIndex)
48 struct SQLU_DICT_INFO_0 *pDictRidderInfo
49 = this->m_pDatapart[iIndex].pDictRidderInfo;
50 pDictRidderInfo->bSomeFlag1 = 0;
51 pDictRidderInfo->bSomeFlag2 = 0;
52 pDictRidderInfo->dRID = INIT_6_BYTES_ZERO();
55 int main(void)
57 int rc;
59 struct stuff
61 char c0[4096-sizeof(struct XXX)];
62 struct XXX o;
63 char c1[4096*2-sizeof(struct SQLU_DATAPART_0)];
64 struct SQLU_DATAPART_0 dp;
65 char c2[4096*2-sizeof(struct SQLU_DICT_INFO_0)];
66 struct SQLU_DICT_INFO_0 di;
67 char c3[4096];
70 char buf[sizeof(struct stuff)+4096];
71 struct stuff *u = (struct stuff *)ossAlignX((unsigned long)&buf[0], 4096);
72 memset(u, 1, sizeof(struct stuff));
73 u->c1[0] = '\xAA';
74 u->c2[0] = '\xBB';
75 u->c3[0] = '\xCC';
77 rc = mprotect(u->c1, 4096, PROT_NONE);
78 if (rc == -1)
79 printf("mprotect:c1: %d: %d(%s)\n", rc, errno, strerror(errno));
81 rc = mprotect(u->c2, 4096, PROT_NONE);
82 if (rc == -1)
83 printf("mprotect:c2: %d: %d(%s)\n", rc, errno, strerror(errno));
85 rc = mprotect(u->c3, 4096, PROT_NONE);
86 if (rc == -1)
87 printf("mprotect:c3: %d: %d(%s)\n", rc, errno, strerror(errno));
89 u->o.m_pDatapart = &u->dp;
90 u->dp.pDictRidderInfo = &u->di;
91 Initialize(&u->o, 0);
93 mprotect(u->c1, 4096, PROT_READ|PROT_WRITE);
94 mprotect(u->c2, 4096, PROT_READ|PROT_WRITE);
95 mprotect(u->c3, 4096, PROT_READ|PROT_WRITE);
97 return 0;