1 /* PR middle-end/95667 - unintended warning for memset writing across multiple
4 { dg-options "-O2 -Wall" }
5 { dg-require-effective-target alloca } */
7 extern void sink (void*);
9 struct S1
{ char a
[3], b
[5]; };
11 void warn_strcpy_s1 (void)
13 struct S1
*p
= __builtin_malloc (sizeof *p
);
15 __builtin_strcpy (p
->a
, s
); // { dg-warning "\\\[-Wstringop-overflow" }
19 void nowarn_memset_s1 (void)
21 struct S1
*p
= __builtin_malloc (sizeof *p
);
22 __builtin_memset (p
->a
, 0, 8); // { dg-bogus "\\\[-Wstringop-overflow" }
26 struct S2
{ char a
[2], b
[2][2], c
[3]; };
28 void nowarn_memset_s2 (void)
30 struct S2
*p
= __builtin_malloc (sizeof *p
);
32 __builtin_memset (p
->a
, 0, sizeof *p
);
35 __builtin_memset (p
->b
, 0, 7);
38 __builtin_memset (&p
->b
[0], 0, 7);
41 __builtin_memset (&p
->b
[1], 0, 5);
44 __builtin_memset (&p
->b
[0][0], 0, 7);
47 __builtin_memset (&p
->b
[0][1], 0, 6);
50 __builtin_memset (&p
->b
[1][0], 0, 5);
53 __builtin_memset (&p
->b
[1][1], 0, 4);
57 void warn_memset_s2 (void)
59 const unsigned n
= sizeof (struct S2
);
60 struct S2
*p
= __builtin_malloc (n
);
62 /* These should trigger -Wstringop-overflow rather than -Warray-bounds
63 but the main purpose of the test is to verify the absence of warnings
64 above so the exact warning for these overflwing calls isn't important
67 __builtin_memset (p
->a
, 0, n
+ 1); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" }
70 __builtin_memset (p
->b
, 0, 8); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" }
73 __builtin_memset (&p
->b
[0], 0, 8); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" }
76 __builtin_memset (&p
->b
[0][0], 0, 8); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" }
79 __builtin_memset (&p
->b
[1], 0, 6); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" }
82 __builtin_memset (&p
->b
[0][1], 0, 7); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" }
86 void nowarn_vl_struct (unsigned n
)
91 struct V
{ char a
[3], b
[n
], c
[7]; } v
;
93 __builtin_memset (v
.a
, 0, 15);
96 __builtin_memset (v
.b
, 0, 12);
99 __builtin_memset (v
.c
, 0, 7);
102 __builtin_memset (v
.a
, 0, 16); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" }
105 __builtin_memset (v
.b
, 0, 13); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" }
108 /* The &V.C argument is represented as a variable offset from
109 the beginning of the allocated object and there's no good
110 way to figure out from its variable offset that it's base
112 s.1_12 = __builtin_alloca_with_align (prephitmp_24, 8);
113 _9 = s.1_12 + prephitmp_27;
114 __builtin_memset (_9, 0, 2);
117 __builtin_memset (v
.c
, 0, 8); // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" "pr?????" { xfail *-*-* } }