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