1 /* PR tree-optimization/83369 - Missing diagnostics during inlining
2    { dg-do compile }
3    { dg-options "-O2 -Wall" } */
4 
5 extern __SIZE_TYPE__ strlen (const char *__s)
6 			     __attribute ((pure)) __attribute ((nonnull (1)));
7 extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
8 		     __SIZE_TYPE__ __n) __attribute ((nonnull (1, 2)));
9 
10 char buf[100];
11 
12 struct Test
13 {
14   const char* s1;
15   const char* s2;
16 };
17 
18 __attribute ((nonnull (1, 2)))
19 inline char*
my_strcpy(char * restrict dst,const char * restrict src,__SIZE_TYPE__ size)20 my_strcpy (char *restrict dst, const char *restrict src, __SIZE_TYPE__ size)
21 {
22   __SIZE_TYPE__ len = strlen (src); /* { dg-warning "argument 1 null where non-null expected" } */
23   if (len < size)
24     memcpy (dst, src, len + 1);     /* { dg-warning "argument 2 null where non-null expected" } */
25   else
26     {
27       memcpy (dst, src, size - 1);  /* { dg-warning "argument 2 null where non-null expected" } */
28       dst[size - 1] = '\0';
29     }
30   return dst;
31 }
32 
test(struct Test * test)33 void test (struct Test* test)
34 {
35   if (test->s1)
36     my_strcpy (buf, test->s1, sizeof buf);
37   else if (test->s2)
38     my_strcpy (buf, test->s2, sizeof buf);
39   else
40     my_strcpy (buf, test->s2, sizeof buf);
41 }
42 
43 /* Verify that the inlining context is printed for -Wnonnull:
44    { dg-message "function .my_strcpy..*inlined from .test." "" { target *-*-* } 0 }  */
45