https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83336
Bug ID: 83336 Summary: Issues with displaying inlining chain for middle-end warnings Product: gcc Version: 8.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: dmalcolm at gcc dot gnu.org CC: msebor at gcc dot gnu.org Target Milestone: --- msebor reported this issue on the gcc-patches list: https://gcc.gnu.org/ml/gcc-patches/2017-12/msg00163.html where the following test case... VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV #include <string.h> #define FOO(d, s) strcpy (d, s) void foo (char *d, const char *s) { FOO (d, s); } void sink (char*); void bar (void) { char a[3]; foo (a, "1234567"); // bug here sink (a); } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...leads to confusing output for the middle-end warning -Wstringop-overflow: $ ./xgcc -B. -c /tmp/test.c -Wall -O2 /tmp/test.c: In function ‘bar’: /tmp/test.c:3:19: warning: ‘__builtin_memcpy’ writing 8 bytes into a region of size 3 overflows the destination [-Wstringop-overflow=] #define FOO(d, s) strcpy (d, s) ^~~~~~~~~~~~~ /tmp/test.c:5:37: note: in expansion of macro ‘FOO’ void foo (char *d, const char *s) { FOO (d, s); } ^~~ It should report something like: ./xgcc -B. -c /tmp/test.c -Wall -O2 /tmp/test.c: In function ‘bar’: /tmp/test.c:3:19: warning: ‘__builtin_memcpy’ writing 8 bytes into a region of size 3 overflows the destination [-Wstringop-overflow=] #define FOO(d, s) strcpy (d, s) ^~~~~~~~~~~~~ /tmp/test.c:5:37: note: in expansion of macro ‘FOO’ inlined from ‘void bar()’ at /tmp/test.c:13:??: foo (a, "1234567"); // bug here ^~~ void foo (char *d, const char *s) { FOO (d, s); } ^~~ i.e. displaying the chain of function inlining that led to the bogus call. There are various issues here: * non-display of inlining information * interaction of chain-of-inlining with chain-of-macro-expansion when printing diagnostics * we don't print the source code for the inlined callsites (diagnostic_show_locus) * lack of test coverage for how we print the chain of inlining * surprising API for middle-end warnings: use of a location_t for warning_at (used for determining if we're in a system header), *then* %K/%G and an expr, which is then used for the location of the diagnostic. I've been working on a set of patches for the above.