]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/Wstringop-overflow-80.c
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / Wstringop-overflow-80.c
1 /* Verify that a separate note is issued for each offset into the same
2 object after a -Wstringop-overflow. Even though the warnings don't
3 need optimization the test enables it to verify they're still issued
4 with it. Wstringop-overflow-78.c verifies they're issued at -O0.
5 { dg-do compile }
6 { dg-options "-O2 -Wno-array-bounds" } */
7
8 extern char a[8]; // dg-message at offset \\\[3, 6] into destination object 'a'" "note 1" }
9 // dg-message at offset \\\[5, 8] into destination object 'a'" "note 2" { target *-*-* } .-1 }
10
11 void test_2_notes (int i)
12 {
13 char *p = i ? a + 3 : a + 5;
14 __builtin_memset (p, 0, 7); // { dg-warning "-Wstringop-overflow" }
15 }
16
17
18 extern char b[8]; // dg-message at offset \\\[3, 6] into destination object 'b'" "note 1" }
19 // dg-message at offset \\\[4, 7] into destination object 'b'" "note 2" { target *-*-* } .-1 }
20 // dg-message at offset \\\[5, 8] into destination object 'b'" "note 3" { target *-*-* } .-2 }
21
22 void test_3_notes (int i)
23 {
24 char *p = i < 0 ? b + 3 : 0 < i ? b + 5 : b + 4;
25 __builtin_memset (p, 0, 7); // { dg-warning "-Wstringop-overflow" }
26 }
27
28
29 extern char c[8]; // dg-message at offset \\\[3, 6] into destination object 'c'" "note 1" }
30 // dg-message at offset \\\[4, 7] into destination object 'c'" "note 2" { target *-*-* } .-1 }
31 // dg-message at offset \\\[5, 8] into destination object 'c'" "note 3" { target *-*-* } .-2 }
32 // dg-message at offset \\\[6, 8] into destination object 'c'" "note 3" { target *-*-* } .-2 }
33
34 void test_4_notes (int i)
35 {
36 char *p;
37 if (i < -1)
38 p = c + 3;
39 else if (i < 0)
40 p = c + 4;
41 else if (0 < i)
42 p = c + 6;
43 else
44 p = c + 5;
45
46 __builtin_memset (p, 0, 7); // { dg-warning "-Wstringop-overflow" }
47 }
48
49
50 extern char d[8]; // dg-message at offset \\\[3, 6] into destination object 'd'" "note 1" }
51 // dg-message at offset \\\[4, 7] into destination object 'd'" "note 2" { target *-*-* } .-1 }
52 // dg-message at offset \\\[5, 8] into destination object 'd'" "note 3" { target *-*-* } .-2 }
53 // dg-message at offset \\\[6, 8] into destination object 'd'" "note 3" { target *-*-* } .-3 }
54 // dg-message at offset \\\[7, 8] into destination object 'd'" "note 3" { target *-*-* } .-4 }
55
56 void test_5_notes (int i)
57 {
58 char *p;
59 switch (i)
60 {
61 case -9: p = d + 3; break;
62 case -5: p = d + 4; break;
63 case 0: p = d + 5; break;
64 case 3: p = d + 6; break;
65 case 4: p = d + 7; break;
66 default: return;
67 }
68
69 __builtin_memset (p, 0, 7); // { dg-warning "-Wstringop-overflow" }
70 }