2014-04-15 Max Ostapenko <m.ostapenko@partner.samsung.com>
[official-gcc.git] / gcc / testsuite / c-c++-common / ubsan / vla-1.c
blob141220324107da4bb047b45425949f9bbf288a9f
1 /* { dg-do run } */
2 /* { dg-options "-fsanitize=vla-bound -Wall -Wno-unused-variable" } */
4 typedef long int V;
5 int x = -1;
6 double di = -3.2;
7 V v = -6;
9 static int __attribute__ ((noinline, noclone))
10 bar (void)
12 return -4;
15 static void __attribute__ ((noinline, noclone))
16 fn1 (void)
18 int a[x];
21 static void __attribute__ ((noinline, noclone))
22 fn2 (void)
24 int a[x][x];
27 static void __attribute__ ((noinline, noclone))
28 fn3 (void)
30 int a[x][x][x];
33 static void __attribute__ ((noinline, noclone))
34 fn4 (void)
36 int b[x - 4];
39 static void __attribute__ ((noinline, noclone))
40 fn5 (void)
42 int c[(int) di];
45 static void __attribute__ ((noinline, noclone))
46 fn6 (void)
48 int d[1 + x];
51 static void __attribute__ ((noinline, noclone))
52 fn7 (void)
54 int e[1 ? x : -1];
57 static void __attribute__ ((noinline, noclone))
58 fn8 (void)
60 int f[++x];
63 static void __attribute__ ((noinline, noclone))
64 fn9 (void)
66 int g[(signed char) --x];
69 static void __attribute__ ((noinline, noclone))
70 fn10 (void)
72 int h[(++x, --x, x)];
75 static void __attribute__ ((noinline, noclone))
76 fn11 (void)
78 int i[v];
81 static void __attribute__ ((noinline, noclone))
82 fn12 (void)
84 int j[bar ()];
87 int
88 main (void)
90 fn1 ();
91 fn2 ();
92 fn3 ();
93 fn4 ();
94 fn5 ();
95 fn6 ();
96 fn7 ();
97 fn8 ();
98 fn9 ();
99 fn10 ();
100 fn11 ();
101 fn12 ();
102 return 0;
105 /* { dg-output "variable length array bound evaluates to non-positive value -1\[^\n\r]*(\n|\r\n|\r)" } */
106 /* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1\[^\n\r]*(\n|\r\n|\r)" } */
107 /* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1\[^\n\r]*(\n|\r\n|\r)" } */
108 /* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1\[^\n\r]*(\n|\r\n|\r)" } */
109 /* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1\[^\n\r]*(\n|\r\n|\r)" } */
110 /* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1\[^\n\r]*(\n|\r\n|\r)" } */
111 /* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -5\[^\n\r]*(\n|\r\n|\r)" } */
112 /* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -3\[^\n\r]*(\n|\r\n|\r)" } */
113 /* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value 0\[^\n\r]*(\n|\r\n|\r)" } */
114 /* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1\[^\n\r]*(\n|\r\n|\r)" } */
115 /* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value 0\[^\n\r]*(\n|\r\n|\r)" } */
116 /* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1\[^\n\r]*(\n|\r\n|\r)" } */
117 /* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -1\[^\n\r]*(\n|\r\n|\r)" } */
118 /* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -6\[^\n\r]*(\n|\r\n|\r)" } */
119 /* { dg-output "\[^\n\r]*variable length array bound evaluates to non-positive value -4\[^\n\r]*" } */