1 /* PR tree-optimization/86614 - duplicate -Warray-bounds for a strncpy
2    call with out-of-bounds offset
3    { dg-do compile }
4    { dg-options "-O2 -Warray-bounds" } */
5 
6 #if __cplusplus
7 extern "C"
8 #endif
9 char *strncpy (char *, const char *, __SIZE_TYPE__);
10 
11 void sink (void *);
12 
13 struct A { char b[17]; } a[2];
14 
15 void g (const char *s, unsigned n)
16 {
17   int i = (char *)a[1].b - (char *)a + 1;
18   char *d = a[1].b;
19   /* Verify the bug is diagnosed exactly once, using either form
20      of the warning.  */
21   strncpy (d + i, s, n);	/* { dg-warning "array subscript \[0-9]+ is outside array bounds|offset \[0-9]+ is out of the bounds" } */
22 				/* { dg-bogus "offset \[0-9]+ is out of the bounds|array subscript \[0-9]+ is outside array bounds" "" { target *-*-* } .-1 } */
23 }
24