aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/c-c++-common/ubsan/vla-1.c
blob: 0fecfa2a3d5fb9501d2209d65ead3adb6f46c2db (plain)
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
/* { dg-do run } */
/* { dg-options "-fsanitize=vla-bound -Wall -Wno-unused-variable" } */

typedef long int V;
int x = -1;
double di = -3.2;
V v = -6;

static int __attribute__ ((noinline, noclone))
bar (void)
{
  return -4;
}

static void __attribute__ ((noinline, noclone))
fn1 (void)
{
  int a[x];
}

static void __attribute__ ((noinline, noclone))
fn2 (void)
{
  int a[x][x];
}

static void __attribute__ ((noinline, noclone))
fn3 (void)
{
  int a[x][x][x];
}

static void __attribute__ ((noinline, noclone))
fn4 (void)
{
  int b[x - 4];
}

static void __attribute__ ((noinline, noclone))
fn5 (void)
{
  int c[(int) di];
}

static void __attribute__ ((noinline, noclone))
fn6 (void)
{
  int d[1 + x];
}

static void __attribute__ ((noinline, noclone))
fn7 (void)
{
  int e[1 ? x : -1];
}

static void __attribute__ ((noinline, noclone))
fn8 (void)
{
  int f[++x];
}

static void __attribute__ ((noinline, noclone))
fn9 (void)
{
  int g[(signed char) --x];
}

static void __attribute__ ((noinline, noclone))
fn10 (void)
{
  int h[(++x, --x, x)];
}

static void __attribute__ ((noinline, noclone))
fn11 (void)
{
  int i[v];
}

static void __attribute__ ((noinline, noclone))
fn12 (void)
{
  int j[bar ()];
}

int
main (void)
{
  fn1 ();
  fn2 ();
  fn3 ();
  fn4 ();
  fn5 ();
  fn6 ();
  fn7 ();
  fn8 ();
  fn9 ();
  fn10 ();
  fn11 ();
  fn12 ();
  return 0;
}

/* { dg-output "variable length array bound evaluates to non-positive value -1(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -5(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -3(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value 0(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value 0(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -6(\n|\r\n|\r)" } */
/* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -4" } */