Debian Codegraph @

gcc/testsuite/gcc.dg/Wvla-larger-than-3.c

raw
1 /* Verify that VLA definitions with an unknown upper bound don't trigger
2 -Wvla-larger-than= warnings by default.
3 { dg-do compile }
4 { dg-options "-O2 -Wall" } */
5
6 void f (void *, ...);
7
8 void nowarn_vla_int (int n)
9 {
10 char a[n];
11
12 if (n < 1234)
13 n = 1234;
14
15 char b[n];
16 f (a, b);
17 }
18
19 void nowarn_vla_uint (unsigned n)
20 {
21 char a[n];
22 f (a);
23
24 if (n < 2345)
25 n = 2345;
26
27 char b[n];
28 f (a, b);
29 }
30
31 void nowarn_vla_long (long n)
32 {
33 char a[n];
34
35 if (n < 1234)
36 n = 1234;
37
38 char b[n];
39 f (a, b);
40 }
41
42 void nowarn_vla_ulong (unsigned long n)
43 {
44 char a[n];
45 f (a);
46
47 if (n < 2345)
48 n = 2345;
49
50 char b[n];
51 f (a, b);
52 }
53
54 /* Verify that a VLA whose size is definitely in excess of PTRDIFF_MAX
55 is diagnosed by default. */
56
57 void warn_vla (__PTRDIFF_TYPE__ n)
58 {
59 int a[n];
60 f (a);
61
62 if (n <= __PTRDIFF_MAX__)
63 n = __PTRDIFF_MAX__;
64
65 int b[n]; /* { dg-warning "argument to variable-length array is too large" } */
66 f (a, b);
67 }