]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/Wstringop-overflow-15.c
Use enclosing object size if it's smaller than member [PR 101475].
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / Wstringop-overflow-15.c
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 { dg-require-effective-target alloca } */
9
10 void sink (void*);
11
12 void vla_unbounded (int n)
13 {
14 char a[n];
15
16 a[0] = 0;
17 a[1] = 1;
18 a[n] = n; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" { xfail *-*-* } }
19
20 sink (&a);
21 }
22
23 void vla_bounded (int n)
24 {
25 if (n > 32)
26 n = 32;
27
28 char a[n];
29
30 a[0] = 0;
31 a[1] = 1;
32 a[31] = 31;
33
34 sink (&a);
35
36 a[n] = n; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" { xfail *-*-* } }
37 a[32] = 32; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" }
38 a[69] = 69; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" }
39
40 sink (&a);
41 }
42
43
44 void member_vla_unbounded (int n)
45 {
46 struct S { char i, a[n]; } s;
47
48 s.a[0] = 0;
49 s.a[1] = 1;
50 s.a[n] = n; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" { xfail *-*-* } }
51
52 sink (&s);
53 }
54
55 void member_vla_bounded (int n)
56 {
57 if (n > 32)
58 n = 32;
59
60 struct S { char i, a[n]; } s;
61
62 s.a[0] = 0;
63 s.a[1] = 1;
64 s.a[31] = 31;
65
66 sink (&s);
67
68 s.a[n] = n; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" { xfail *-*-* } }
69 s.a[32] = 32; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" }
70 s.a[69] = 69; // { dg-warning "\\\[-Wstringop-overflow" "pr82608" }
71
72 sink (&s);
73 }