PR tree-optimization/83369 - Missing diagnostics during inlining
[official-gcc.git] / gcc / testsuite / gcc.dg / Wnonnull.c
blobbe89a5a755cf524628f87120089cc5134a759edf
1 /* PR tree-optimization/83369 - Missing diagnostics during inlining
2 { dg-do compile }
3 { dg-options "-O2 -Wall" } */
5 #include <string.h>
7 char buf[100];
9 struct Test
11 const char* s1;
12 const char* s2;
15 __attribute ((nonnull (1, 2)))
16 inline char*
17 my_strcpy (char *restrict dst, const char *restrict src, size_t size)
19 size_t len = strlen (src); /* { dg-warning "argument 1 null where non-null expected" } */
20 if (len < size)
21 memcpy (dst, src, len + 1); /* { dg-warning "argument 2 null where non-null expected" } */
22 else
24 memcpy (dst, src, size - 1); /* { dg-warning "argument 2 null where non-null expected" } */
25 dst[size - 1] = '\0';
27 return dst;
30 void test (struct Test* test)
32 if (test->s1)
33 my_strcpy (buf, test->s1, sizeof buf);
34 else if (test->s2)
35 my_strcpy (buf, test->s2, sizeof buf);
36 else
37 my_strcpy (buf, test->s2, sizeof buf);
40 /* Verify that the inlining context is printed for -Wnonnull:
41 { dg-message "function .my_strcpy..*inlined from .test." "" { target *-*-* } 0 } */