1 
2 /* PR middle-end/97023 - missing warning on buffer overflow in chained mempcpy
3    Verify that writes by built-in functions to objects through pointers
4    returned by ordinary (non-built-int) function are assumed to point to
5    the beginning of objects.
6    { dg-do compile }
7    { dg-options "-O2" } */
8 
9 #include "range.h"
10 
11 void* memcpy (void*, const void*, size_t);
12 void* memset (void*, int, size_t);
13 
14 void sink (void*, ...);
15 
16 extern char* arrptr[];
17 extern char* ptr;
18 extern char* retptr (void);
19 struct S { char *p; };
20 extern struct S retstruct (void);
21 
nowarn_ptr(void)22 void nowarn_ptr (void)
23 {
24   {
25     void *p = arrptr;
26     memset (p - 1, 0, 12345);           // { dg-warning "\\\[-Wstringop-overflow" }
27     memset (p,0, 12345);
28     memset (p,0, DIFF_MAX - 1);
29   }
30 
31   {
32     char *p = arrptr[0];
33     memset (p - 1, 0, 12345);
34     memset (p - 12345, 0, 12345);
35     memset (p - 1234, 0, DIFF_MAX - 1);
36     memset (p - DIFF_MAX + 1, 0, 12345);
37   }
38 
39   {
40     char *p = ptr;
41     memset (p - 1, 0, 12345);
42     memset (p - 12345, 0, 12345);
43     memset (p - 1234, 0, DIFF_MAX - 1);
44     memset (p - DIFF_MAX + 1, 0, 12345);
45   }
46 
47   {
48     char *p = retptr ();
49     memset (p - 1, 0, 12345);
50     memset (p - 12345, 0, 12345);
51     memset (p - 1234, 0, DIFF_MAX - 1);
52     memset (p - DIFF_MAX + 1, 0, 12345);
53   }
54 
55   {
56     char *p = retstruct ().p;
57     memset (p - 1, 0, 12345);
58     memset (p - 12345, 0, 12345);
59     memset (p - 1234, 0, DIFF_MAX - 1);
60     memset (p - DIFF_MAX + 1, 0, 12345);
61   }
62 }
63