summaryrefslogtreecommitdiff
path: root/support/regression/tests/gcc-torture-execute-pr20601-1.c
blob: 125a3e1511b4a3cb4804f173bea2889dc88fdb9d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
   pr15262.c from the execute part of the gcc torture tests.
 */

#include <testfwk.h>

#ifdef __SDCC
#pragma std_c11
#pragma disable_warning 85
#endif

/* PR tree-optimization/20601 */
/*extern void abort (void);
extern void exit (int);*/

struct T
{
  const char *t1;
  char t2[4096];
  char **t3;
};

#if defined (__SDCC) && !defined (__SDCC_mcs51) && !defined (__SDCC_pdk14) && !defined (__SDCC_pdk15) // Lack of memory
int a[5];
int b;
const char **c;
int d;
const char **e;
struct T t;
char *f[16];
const char *g[] = { "a", "-u", "b", "c" };

_Noreturn void
foo (void)
{
  while (1);
}

char *
bar (char *x, unsigned int y)
{
  return 0;
}

#ifndef __SDCC_pdk14 // Bug #2874
static inline char *
baz (char *x, unsigned int y)
{
  if (sizeof (t.t2) != (unsigned int) -1 && y > sizeof (t.t2))
    foo ();
  return bar (x, y);
}

static inline int
setup1 (int x)
{
  char *p;
  int rval;

  if (!baz (t.t2, sizeof (t.t2)))
    baz (t.t2, sizeof (t.t2));

  if (x & 0x200)
    {
      char **h, **i = e;

      ++d;
      e = f;
      if (t.t1 && *t.t1)
        e[0] = t.t1;
      else
        ASSERT (0);

      for (h = e + 1; (*h = *i); ++i, ++h)
        ;
    }
  return 1;
}

static inline int
setup2 (void)
{
  int j = 1;

  e = c + 1;
  d = b - 1;
  while (d > 0 && e[0][0] == '-')
    {
      if (e[0][1] != '\0' && e[0][2] != '\0')
        ASSERT (0);

      switch (e[0][1])
        {
        case 'u':
          if (!e[1])
            ASSERT (0);

          t.t3 = &e[1];
          d--;
          e++;
          break;
        case 'P':
          j |= 0x1000;
          break;
        case '-':
          d--;
          e++;
          if (j == 1)
            j |= 0x600;
          return j;
        }
      d--;
      e++;
    }

  if (d > 0 && !(j & 1))
    ASSERT (0);

  return j;
}
#endif
#endif

void
testTortureExecute (void)
{
#if defined (__SDCC) && !defined (__SDCC_mcs51) && !defined(__SDCC_pdk14) && !defined (__SDCC_pdk15)
  int x;
  c = g;
  b = 4;
  x = setup2 ();
  t.t1 = "/bin/sh";
  setup1 (x);
  /* PRE shouldn't transform x into the constant 0x601 here, it's not legal.  */
  if ((x & 0x400) && !a[4])
    ASSERT (0);
  return;
#endif
}