https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83369
Bug ID: 83369 Summary: Missing diagnostics during inlining Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: bugzi...@poradnik-webmastera.com Target Milestone: --- When code below is compiled, gcc prints warnings that null is passed to function with nonnull attribute. However gcc does not point that error is caused by inlining of my_strcpy at line 32 of test.cc. Code was compiled using gcc (GCC) 8.0.0 20171210 (experimental). [code] #include <string.h> char buf[100]; struct Test { const char* s1; const char* s2; }; __attribute((nonnull(1, 2))) inline char* my_strcpy(char* __restrict__ dst, const char* __restrict__ src, size_t size) { size_t len = strlen(src); if (len < size) memcpy(dst, src, len + 1); else { memcpy(dst, src, size - 1); dst[size - 1] = '\0'; } return dst; } void test(Test* test) { if (test->s1) my_strcpy(buf, test->s1, sizeof(buf)); else if (test->s2) my_strcpy(buf, test->s2, sizeof(buf)); else my_strcpy(buf, test->s2, sizeof(buf)); // error, line 32 } [/code] [out] $ g++ -c -o test.o test.cc -O2 -Wall test.cc: In function ‘void test(Test*)’: test.cc:14:24: warning: argument 1 null where non-null expected [-Wnonnull] size_t len = strlen(src); ~~~~~~^~~~~ In file included from test.cc:1: /usr/include/string.h:395:15: note: in a call to function ‘size_t strlen(const char*)’ declared here extern size_t strlen (const char *__s) ^~~~~~ test.cc:16:15: warning: argument 2 null where non-null expected [-Wnonnull] memcpy(dst, src, len + 1); ~~~~~~^~~~~~~~~~~~~~~~~~~ In file included from test.cc:1: /usr/include/string.h:42:14: note: in a call to function ‘void* memcpy(void*, const void*, size_t)’ declared here extern void *memcpy (void *__restrict __dest, const void *__restrict __src, ^~~~~~ test.cc:19:15: warning: argument 2 null where non-null expected [-Wnonnull] memcpy(dst, src, size - 1); ~~~~~~^~~~~~~~~~~~~~~~~~~~ In file included from test.cc:1: /usr/include/string.h:42:14: note: in a call to function ‘void* memcpy(void*, const void*, size_t)’ declared here extern void *memcpy (void *__restrict __dest, const void *__restrict __src, ^~~~~~ [/out]