Debian Codegraph @

gcc/testsuite/gcc.dg/Wstringop-overflow-15.c

raw
1 /* PR middle-end/91458 - inconsistent warning for writing past the end
2 of an array member
3 Verify that the -Wstringop-overflow detection doesn't cause an ICE
4 for either kind of VLAs (member and non-member).
5 Diagnosing the accesses is the subject of pr82608.
6 { dg-do compile }
7 { dg-options "-O2 -Wall -Wno-array-bounds" } */
8
9 void sink (void*);
10
11 void vla_unbounded (int n)
12 {
13 char a[n];
14
15 a[0] = 0;
16 a[1] = 1;
17 a[n] = n; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" { xfail *-*-* } }
18
19 sink (&a);
20 }
21
22 void vla_bounded (int n)
23 {
24 if (n > 32)
25 n = 32;
26
27 char a[n];
28
29 a[0] = 0;
30 a[1] = 1;
31 a[31] = 31;
32
33 sink (&a);
34
35 a[n] = n; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" { xfail *-*-* } }
36 a[32] = 32; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" }
37 a[69] = 69; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" }
38
39 sink (&a);
40 }
41
42
43 void member_vla_unbounded (int n)
44 {
45 struct S { char i, a[n]; } s;
46
47 s.a[0] = 0;
48 s.a[1] = 1;
49 s.a[n] = n; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" { xfail *-*-* } }
50
51 sink (&s);
52 }
53
54 void member_vla_bounded (int n)
55 {
56 if (n > 32)
57 n = 32;
58
59 struct S { char i, a[n]; } s;
60
61 s.a[0] = 0;
62 s.a[1] = 1;
63 s.a[31] = 31;
64
65 sink (&s);
66
67 s.a[n] = n; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" { xfail *-*-* } }
68 s.a[32] = 32; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" }
69 s.a[69] = 69; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" }
70
71 sink (&s);
72 }