blob: 9f82d73e3114c0fda0f4971dae2dc7c356df3bde (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/* PR middle-end/96963 - -Wstringop-overflow false positive with
-ftree-vectorize when assigning consecutive char struct members
{ dg-do compile }
{ dg-options "-O2 -Wall -ftree-vectorize" } */
void sink (void*);
struct Char
{
int i;
char c, d, e, f;
char a[2], b[2];
};
void nowarn_char_assign (struct Char *p)
{
sink (&p->c);
/* Verify the bogus warning triggered by the tree-ssa-strlen.c pass
is not issued. */
p->c = 1; // { dg-bogus "\\\[-Wstringop-overflow" }
p->d = 2;
p->e = 3;
p->f = 4;
}
void nowarn_char_array_assign (struct Char *p)
{
sink (p->a);
p->a[0] = 1; // { dg-bogus "\\\[-Wstringop-overflow" }
p->a[1] = 2;
p->b[0] = 3;
p->b[1] = 4;
}
void warn_char_array_assign_interior (struct Char *p)
{
sink (p->a);
p->a[0] = 1;
p->a[1] = 2;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
/* Warnings are only suppressed for trailing arrays. Verify
one is issued for an interior array. */
p->a[2] = 5; // { dg-warning "\\\[-Wstringop-overflow" }
#pragma GCC diagnostic pop
}
void warn_char_array_assign_trailing (struct Char *p)
{
/* This is separated from warn_char_array_assign_interior because
otherwise GCC removes the store to p->a[2] as dead since it's
overwritten by p->b[0]. */
sink (p->b);
p->b[0] = 3;
p->b[1] = 4;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
/* Warnings are only suppressed for trailing arrays with at most
one element. Verify one is issued for a two-element array. */
p->b[2] = 5; // { dg-warning "\\\[-Wstringop-overflow" }
#pragma GCC diagnostic pop
}
/* Also verify there's no warning for other types than char (even though
the problem was limited to chars and -Wstringop-overflow should only
trigger for character accesses). */
struct Short
{
int i;
short c, d, e, f;
short a[2], b[2];
};
void nowarn_short_assign (struct Short *p)
{
sink (&p->c);
p->c = 1;
p->d = 2;
p->e = 3;
p->f = 4;
}
void nowarn_short_array_assign (struct Short *p)
{
sink (p->a);
p->a[0] = 1;
p->a[1] = 2;
p->b[0] = 3;
p->b[1] = 4;
}
|