OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gcc.dg/] [struct-ret-3.c] - Blame information for rev 689

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 689 jeremybenn
/* PR middle-end/31309 */
2
/* Origin: Peeter Joot <peeterj@ca.ibm.com> */
3
 
4
/* { dg-do run { target *-*-linux* } } */
5
 
6
#include <sys/mman.h>
7
#include <string.h>
8
#include <stdio.h>
9
#include <errno.h>
10
#include <unistd.h>
11
 
12
#if defined(STACK_SIZE) && (STACK_SIZE < 128*1024)
13
 #define CHUNK_SIZE 4096
14
#else
15
 #define CHUNK_SIZE 16384
16
#endif
17
 
18
unsigned long ossAlignX(unsigned long i, unsigned long X)
19
{
20
   return ((i + (X - 1)) & ~(unsigned long) (X - 1));
21
}
22
 
23
struct STRUCT_6_BYTES
24
{
25
   unsigned char slot[sizeof(unsigned short)];
26
   unsigned char page[sizeof(unsigned int)];
27
};
28
 
29
struct SQLU_DICT_INFO_0
30
{
31
   void *pBlah;
32
   char bSomeFlag1;
33
   char bSomeFlag2;
34
   struct STRUCT_6_BYTES dRID;
35
};
36
 
37
struct SQLU_DATAPART_0
38
{
39
   struct SQLU_DICT_INFO_0 *pDictRidderInfo;
40
};
41
 
42
struct XXX
43
{
44
   struct SQLU_DATAPART_0 *m_pDatapart;
45
};
46
 
47
struct STRUCT_6_BYTES INIT_6_BYTES_ZERO()
48
{
49
   struct STRUCT_6_BYTES ridOut = {{0,0}, {0,0,0,0}};
50
   return ridOut;
51
}
52
 
53
void Initialize(struct XXX *this, int iIndex)
54
{
55
   struct SQLU_DICT_INFO_0 *pDictRidderInfo
56
     = this->m_pDatapart[iIndex].pDictRidderInfo;
57
   pDictRidderInfo->bSomeFlag1 = 0;
58
   pDictRidderInfo->bSomeFlag2 = 0;
59
   pDictRidderInfo->dRID = INIT_6_BYTES_ZERO();
60
}
61
 
62
int main(void)
63
{
64
   int rc;
65
 
66
   struct stuff
67
   {
68
      char c0[CHUNK_SIZE-sizeof(struct XXX)];
69
      struct XXX o;
70
      char c1[CHUNK_SIZE*2-sizeof(struct SQLU_DATAPART_0)];
71
      struct SQLU_DATAPART_0 dp;
72
      char c2[CHUNK_SIZE*2-sizeof(struct SQLU_DICT_INFO_0)];
73
      struct SQLU_DICT_INFO_0 di;
74
      char c3[CHUNK_SIZE];
75
   };
76
 
77
   char buf[sizeof(struct stuff)+CHUNK_SIZE];
78
   struct stuff *u
79
     = (struct stuff *)ossAlignX((unsigned long)&buf[0], CHUNK_SIZE);
80
 
81
   /* This test assumes system memory page
82
      size of CHUNK_SIZE bytes or less.  */
83
   if (sysconf(_SC_PAGESIZE) > CHUNK_SIZE)
84
     return 0;
85
 
86
   memset(u, 1, sizeof(struct stuff));
87
   u->c1[0] = '\xAA';
88
   u->c2[0] = '\xBB';
89
   u->c3[0] = '\xCC';
90
 
91
   rc = mprotect(u->c1, CHUNK_SIZE, PROT_NONE);
92
   if (rc == -1)
93
      printf("mprotect:c1: %d: %d(%s)\n", rc, errno, strerror(errno));
94
 
95
   rc = mprotect(u->c2, CHUNK_SIZE, PROT_NONE);
96
   if (rc == -1)
97
      printf("mprotect:c2: %d: %d(%s)\n", rc, errno, strerror(errno));
98
 
99
   rc = mprotect(u->c3, CHUNK_SIZE, PROT_NONE);
100
   if (rc == -1)
101
      printf("mprotect:c3: %d: %d(%s)\n", rc, errno, strerror(errno));
102
 
103
   u->o.m_pDatapart = &u->dp;
104
   u->dp.pDictRidderInfo = &u->di;
105
   Initialize(&u->o, 0);
106
 
107
   mprotect(u->c1, CHUNK_SIZE, PROT_READ|PROT_WRITE);
108
   mprotect(u->c2, CHUNK_SIZE, PROT_READ|PROT_WRITE);
109
   mprotect(u->c3, CHUNK_SIZE, PROT_READ|PROT_WRITE);
110
 
111
   return 0;
112
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.