]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gcc.dg/Wnonnull.c
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / Wnonnull.c
CommitLineData
48fe6bbb
MS
1/* PR tree-optimization/83369 - Missing diagnostics during inlining
2 { dg-do compile }
3 { dg-options "-O2 -Wall" } */
4
24b54eb2
IS
5extern __SIZE_TYPE__ strlen (const char *__s)
6 __attribute ((pure)) __attribute ((nonnull (1)));
2366bf60 7extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
24b54eb2 8 __SIZE_TYPE__ __n) __attribute ((nonnull (1, 2)));
48fe6bbb
MS
9
10char buf[100];
11
12struct Test
13{
14 const char* s1;
15 const char* s2;
16};
17
18__attribute ((nonnull (1, 2)))
19inline char*
24b54eb2 20my_strcpy (char *restrict dst, const char *restrict src, __SIZE_TYPE__ size)
48fe6bbb 21{
24b54eb2 22 __SIZE_TYPE__ len = strlen (src); /* { dg-warning "argument 1 null where non-null expected" } */
48fe6bbb
MS
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
33void 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 } */