1 /*
2    pr15262.c from the execute part of the gcc torture tests.
3  */
4 
5 #include <testfwk.h>
6 
7 #ifdef __SDCC
8 #pragma std_c11
9 #pragma disable_warning 85
10 #endif
11 
12 /* PR tree-optimization/20601 */
13 /*extern void abort (void);
14 extern void exit (int);*/
15 
16 struct T
17 {
18   const char *t1;
19   char t2[4096];
20   char **t3;
21 };
22 
23 #if defined (__SDCC) && !defined (__SDCC_mcs51) && !defined (__SDCC_pdk14) && !defined (__SDCC_pdk15) // Lack of memory
24 int a[5];
25 int b;
26 const char **c;
27 int d;
28 const char **e;
29 struct T t;
30 char *f[16];
31 const char *g[] = { "a", "-u", "b", "c" };
32 
33 _Noreturn void
foo(void)34 foo (void)
35 {
36   while (1);
37 }
38 
39 char *
bar(char * x,unsigned int y)40 bar (char *x, unsigned int y)
41 {
42   return 0;
43 }
44 
45 #ifndef __SDCC_pdk14 // Bug #2874
46 static inline char *
baz(char * x,unsigned int y)47 baz (char *x, unsigned int y)
48 {
49   if (sizeof (t.t2) != (unsigned int) -1 && y > sizeof (t.t2))
50     foo ();
51   return bar (x, y);
52 }
53 
54 static inline int
setup1(int x)55 setup1 (int x)
56 {
57   char *p;
58   int rval;
59 
60   if (!baz (t.t2, sizeof (t.t2)))
61     baz (t.t2, sizeof (t.t2));
62 
63   if (x & 0x200)
64     {
65       char **h, **i = e;
66 
67       ++d;
68       e = f;
69       if (t.t1 && *t.t1)
70         e[0] = t.t1;
71       else
72         ASSERT (0);
73 
74       for (h = e + 1; (*h = *i); ++i, ++h)
75         ;
76     }
77   return 1;
78 }
79 
80 static inline int
setup2(void)81 setup2 (void)
82 {
83   int j = 1;
84 
85   e = c + 1;
86   d = b - 1;
87   while (d > 0 && e[0][0] == '-')
88     {
89       if (e[0][1] != '\0' && e[0][2] != '\0')
90         ASSERT (0);
91 
92       switch (e[0][1])
93         {
94         case 'u':
95           if (!e[1])
96             ASSERT (0);
97 
98           t.t3 = &e[1];
99           d--;
100           e++;
101           break;
102         case 'P':
103           j |= 0x1000;
104           break;
105         case '-':
106           d--;
107           e++;
108           if (j == 1)
109             j |= 0x600;
110           return j;
111         }
112       d--;
113       e++;
114     }
115 
116   if (d > 0 && !(j & 1))
117     ASSERT (0);
118 
119   return j;
120 }
121 #endif
122 #endif
123 
124 void
testTortureExecute(void)125 testTortureExecute (void)
126 {
127 #if defined (__SDCC) && !defined (__SDCC_mcs51) && !defined(__SDCC_pdk14) && !defined (__SDCC_pdk15)
128   int x;
129   c = g;
130   b = 4;
131   x = setup2 ();
132   t.t1 = "/bin/sh";
133   setup1 (x);
134   /* PRE shouldn't transform x into the constant 0x601 here, it's not legal.  */
135   if ((x & 0x400) && !a[4])
136     ASSERT (0);
137   return;
138 #endif
139 }
140 
141