https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119611
Bug ID: 119611 Summary: Function call substitution cause confusing warning messages Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: siddhesh at gcc dot gnu.org Target Milestone: --- Consider the following: ``` #include <string.h> void f (void*); void h (void) { char a[8]; stpcpy (stpcpy (a, "12345678"), "abcdefgh"); f (a); } $ gcc -D_FORTIFY_SOURCE=2 -O2 -S f.c f.c: In function ‘h’: f.c:7:3: warning: ‘__builtin___stpcpy_chk’ writing 9 bytes into a region of size 8 [-Wstringop-overflow=] 7 | stpcpy (stpcpy (a, "12345678"), "abcdefgh"); | ^ f.c:6:8: note: destination object ‘a’ of size 8 6 | char a[8]; | ^ f.c:7:3: warning: ‘__builtin_memcpy’ writing 9 bytes into a region of size 8 [-Wstringop-overflow=] 7 | stpcpy (stpcpy (a, "12345678"), "abcdefgh"); | ^ f.c:6:8: note: at offset [0, 7] into destination object ‘a’ of size 8 6 | char a[8]; | ^ ``` Here, instead of referring to stpcpy (or its _chk variant), the warning refers to __builtin_memcpy, which does not appear anywhere in the program. It's not exactly a serious issue, but it can cause some confusion for users. When doing call substitution, there should be a way to somehow retain a reference to the original function so that the warning message can refer to it instead.