Daily bump.
[official-gcc.git] / gcc / testsuite / gcc.dg / Wnonnull.c
blob0ed06aabe68cf7fa1e90e4526b862dfe8eb6ad51
1 /* PR tree-optimization/83369 - Missing diagnostics during inlining
2 { dg-do compile }
3 { dg-options "-O2 -Wall" } */
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)));
10 char buf[100];
12 struct Test
14 const char* s1;
15 const char* s2;
18 __attribute ((nonnull (1, 2)))
19 inline char*
20 my_strcpy (char *restrict dst, const char *restrict src, __SIZE_TYPE__ size)
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
27 memcpy (dst, src, size - 1); /* { dg-warning "argument 2 null where non-null expected" } */
28 dst[size - 1] = '\0';
30 return dst;
33 void test (struct Test* test)
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);
43 /* Verify that the inlining context is printed for -Wnonnull:
44 { dg-message "function .my_strcpy..*inlined from .test." "" { target *-*-* } 0 } */