In https://sourceware.org/ml/libc-alpha/2014-12/msg00300.html, we give a "called from here" note without actually having a location, which looks strange. I haven't been able to generate such a testcase. If this happens, try to at least point to the current function being called. If that location is also unknown, skip the extra note.
gcc/ChangeLog: 2015-09-21 Manuel López-Ibáñez <m...@gcc.gnu.org> * tree-inline.c (expand_call_inline): Use inform for extra note. Do not give a note with UNKNOWN_LOCATION. Replace input_location with gimple_location (stmt). Use true instead of TRUE. gcc/testsuite/ChangeLog: 2015-09-21 Manuel López-Ibáñez <m...@gcc.gnu.org> * gcc.target/i386/inline_error.c (int bar): Use dg-message for note. * gcc.target/i386/pr57756.c (static __inline int caller): Likewise. * gcc.target/i386/pr59789.c (f1): Likewise. * gcc.target/i386/intrinsics_5.c (__m128i foo): Likewise. * gcc.target/i386/intrinsics_6.c: Likewise. * gcc.dg/winline-5.c (int t): Likewise. * gcc.dg/winline-9.c (t): Likewise. * gcc.dg/always_inline2.c (q): Likewise. * gcc.dg/winline-2.c (inline int t): Likewise. * gcc.dg/winline-6.c: Likewise. * gcc.dg/winline-10.c (void g): Likewise. * gcc.dg/pr49243.c (void parse): Likewise. * gcc.dg/always_inline3.c (q2): Likewise. * gcc.dg/winline-3.c: Likewise. * gcc.dg/winline-7.c (inline void *t): Likewise.
Index: gcc/testsuite/gcc.target/i386/inline_error.c =================================================================== --- gcc/testsuite/gcc.target/i386/inline_error.c (revision 227965) +++ gcc/testsuite/gcc.target/i386/inline_error.c (working copy) @@ -7,7 +7,7 @@ foo () /* { dg-error "inlining failed in return 0; } int bar() { - return foo (); /* { dg-error "called from here" } */ + return foo (); /* { dg-message "called from here" } */ } Index: gcc/testsuite/gcc.target/i386/pr57756.c =================================================================== --- gcc/testsuite/gcc.target/i386/pr57756.c (revision 227965) +++ gcc/testsuite/gcc.target/i386/pr57756.c (working copy) @@ -9,11 +9,11 @@ __inline int callee () /* { dg-error "in } __attribute__((target("sse"))) static __inline int caller () { - return callee(); /* { dg-error "called from here" } */ + return callee(); /* { dg-message "called from here" } */ } int main () { return caller(); Index: gcc/testsuite/gcc.target/i386/pr59789.c =================================================================== --- gcc/testsuite/gcc.target/i386/pr59789.c (revision 227965) +++ gcc/testsuite/gcc.target/i386/pr59789.c (working copy) @@ -16,7 +16,7 @@ _mm_set_epi32 (int __q3, int __q2, int _ __m128i f1(void) { /* { dg-message "warning: SSE vector return without SSE enabled changes the ABI" } */ - return _mm_set_epi32 (0, 0, 0, 0); /* { dg-error "called from here" } */ + return _mm_set_epi32 (0, 0, 0, 0); /* { dg-message "called from here" } */ } Index: gcc/testsuite/gcc.target/i386/intrinsics_5.c =================================================================== --- gcc/testsuite/gcc.target/i386/intrinsics_5.c (revision 227965) +++ gcc/testsuite/gcc.target/i386/intrinsics_5.c (working copy) @@ -8,9 +8,9 @@ #include <smmintrin.h> __m128i foo(__m128i *V) { - return _mm_stream_load_si128(V); /* { dg-error "called from here" } */ + return _mm_stream_load_si128(V); /* { dg-message "called from here" } */ } /* { dg-prune-output ".*inlining failed.*" } */ Index: gcc/testsuite/gcc.target/i386/intrinsics_6.c =================================================================== --- gcc/testsuite/gcc.target/i386/intrinsics_6.c (revision 227965) +++ gcc/testsuite/gcc.target/i386/intrinsics_6.c (working copy) @@ -8,9 +8,9 @@ #include <smmintrin.h> __m128i foo(__m128i *V) { - return _mm_stream_load_si128(V); /* { dg-error "called from here" } */ + return _mm_stream_load_si128(V); /* { dg-message "called from here" } */ } /* { dg-prune-output ".*inlining failed.*" } */ Index: gcc/testsuite/gcc.dg/winline-5.c =================================================================== --- gcc/testsuite/gcc.dg/winline-5.c (revision 227965) +++ gcc/testsuite/gcc.dg/winline-5.c (working copy) @@ -15,7 +15,7 @@ inline int q(void) /* { dg-warning "inli big(); big(); } int t (void) { - return q (); /* { dg-warning "called from here" } */ + return q (); /* { dg-message "called from here" } */ } Index: gcc/testsuite/gcc.dg/winline-9.c =================================================================== --- gcc/testsuite/gcc.dg/winline-9.c (revision 227965) +++ gcc/testsuite/gcc.dg/winline-9.c (working copy) @@ -20,7 +20,7 @@ int t() { if (a) aa(); if (b) - bb(); /* { dg-warning "called from here" "" } */ + bb(); /* { dg-message "called from here" } */ } Index: gcc/testsuite/gcc.dg/always_inline2.c =================================================================== --- gcc/testsuite/gcc.dg/always_inline2.c (revision 227965) +++ gcc/testsuite/gcc.dg/always_inline2.c (working copy) @@ -2,7 +2,7 @@ /* { dg-options "-O2 -fgnu89-inline" } */ inline __attribute__ ((always_inline)) void t(void); /* { dg-error "body not available" } */ void q(void) { - t(); /* { dg-error "called from here" } */ + t(); /* { dg-message "called from here" } */ } Index: gcc/testsuite/gcc.dg/winline-2.c =================================================================== --- gcc/testsuite/gcc.dg/winline-2.c (revision 227965) +++ gcc/testsuite/gcc.dg/winline-2.c (working copy) @@ -2,7 +2,7 @@ /* { dg-options "-Winline -O2 -fgnu89-inline" } */ inline int q(void); /* { dg-warning "body not available" "" } */ inline int t(void) { - return q(); /* { dg-warning "called from here" "" } */ + return q(); /* { dg-message "called from here" } */ } Index: gcc/testsuite/gcc.dg/winline-6.c =================================================================== --- gcc/testsuite/gcc.dg/winline-6.c (revision 227965) +++ gcc/testsuite/gcc.dg/winline-6.c (working copy) @@ -15,7 +15,7 @@ inline int q(void) /* { dg-warning "larg big(); big(); } inline int t (void) { - return q () + 1; /* { dg-warning "called from here" } */ + return q () + 1; /* { dg-message "called from here" } */ } Index: gcc/testsuite/gcc.dg/winline-10.c =================================================================== --- gcc/testsuite/gcc.dg/winline-10.c (revision 227965) +++ gcc/testsuite/gcc.dg/winline-10.c (working copy) @@ -9,9 +9,9 @@ inline void f (x) /* { dg-warning "inlin asm (""); } void g (struct s x) { - f (x); /* { dg-warning "called from here" "" } */ + f (x); /* { dg-message "called from here" } */ } void f (int x); /* { dg-warning "follows non-prototype definition" } */ Index: gcc/testsuite/gcc.dg/pr49243.c =================================================================== --- gcc/testsuite/gcc.dg/pr49243.c (revision 227965) +++ gcc/testsuite/gcc.dg/pr49243.c (working copy) @@ -18,8 +18,8 @@ static inline int wrapper(const char **s } void parse(const char *data) { const char *s = data; - if (!(wrapper(&s) == -1 && (s - data) == 1)) /* { dg-warning "called from here" } */ + if (!(wrapper(&s) == -1 && (s - data) == 1)) /* { dg-message "called from here" } */ __builtin_abort(); } Index: gcc/testsuite/gcc.dg/always_inline3.c =================================================================== --- gcc/testsuite/gcc.dg/always_inline3.c (revision 227965) +++ gcc/testsuite/gcc.dg/always_inline3.c (working copy) @@ -4,8 +4,8 @@ int do_something_evil (void); inline __attribute__ ((always_inline)) void q2(void) /* { dg-error "recursive inlining" } */ { if (do_something_evil ()) return; - q2(); /* { dg-error "called from here" } */ + q2(); /* { dg-message "called from here" } */ q2(); /* With -O2 we don't warn here, it is eliminated by tail recursion. */ } Index: gcc/testsuite/gcc.dg/winline-3.c =================================================================== --- gcc/testsuite/gcc.dg/winline-3.c (revision 227965) +++ gcc/testsuite/gcc.dg/winline-3.c (working copy) @@ -15,7 +15,7 @@ inline int q(void) /* { dg-warning "max- big(); big(); } inline int t (void) { - return q (); /* { dg-warning "called from here" "" } */ + return q (); /* { dg-message "called from here" } */ } Index: gcc/testsuite/gcc.dg/winline-7.c =================================================================== --- gcc/testsuite/gcc.dg/winline-7.c (revision 227965) +++ gcc/testsuite/gcc.dg/winline-7.c (working copy) @@ -9,7 +9,7 @@ inline void *q (void) /* { dg-warning "( { return alloca (10); } inline void *t (void) { - return q (); /* { dg-warning "called from here" } */ + return q (); /* { dg-message "called from here" } */ } Index: gcc/tree-inline.c =================================================================== --- gcc/tree-inline.c (revision 227965) +++ gcc/tree-inline.c (working copy) @@ -4382,27 +4382,20 @@ expand_call_inline (basic_block bb, gimp hash_map<tree, tree> *dst; hash_map<tree, tree> *st = NULL; tree return_slot; tree modify_dest; tree return_bounds = NULL; - location_t saved_location; struct cgraph_edge *cg_edge; cgraph_inline_failed_t reason; basic_block return_block; edge e; gimple_stmt_iterator gsi, stmt_gsi; - bool successfully_inlined = FALSE; + bool successfully_inlined = false; bool purge_dead_abnormal_edges; gcall *call_stmt; unsigned int i; - /* Set input_location here so we get the right instantiation context - if we call instantiate_decl from inlinable_function_p. */ - /* FIXME: instantiate_decl isn't called by inlinable_function_p. */ - saved_location = input_location; - input_location = gimple_location (stmt); - /* From here on, we're only interested in CALL_EXPRs. */ call_stmt = dyn_cast <gcall *> (stmt); if (!call_stmt) goto egress; @@ -4452,11 +4445,15 @@ expand_call_inline (basic_block bb, gimp /* PR 20090218-1_0.c. Body can be provided by another module. */ && (reason != CIF_BODY_NOT_AVAILABLE || !flag_generate_lto)) { error ("inlining failed in call to always_inline %q+F: %s", fn, cgraph_inline_failed_string (reason)); - error ("called from here"); + if (gimple_location (stmt) != UNKNOWN_LOCATION) + inform (gimple_location (stmt), "called from here"); + else if (DECL_SOURCE_LOCATION (cfun->decl) != UNKNOWN_LOCATION) + inform (DECL_SOURCE_LOCATION (cfun->decl), + "called from this function"); } else if (warn_inline && DECL_DECLARED_INLINE_P (fn) && !DECL_NO_INLINE_WARNING_P (fn) && !DECL_IN_SYSTEM_HEADER (fn) @@ -4465,13 +4461,19 @@ expand_call_inline (basic_block bb, gimp /* Do not warn about not inlined recursive calls. */ && !cg_edge->recursive_p () /* Avoid warnings during early inline pass. */ && symtab->global_info_ready) { - warning (OPT_Winline, "inlining failed in call to %q+F: %s", - fn, _(cgraph_inline_failed_string (reason))); - warning (OPT_Winline, "called from here"); + if (warning (OPT_Winline, "inlining failed in call to %q+F: %s", + fn, _(cgraph_inline_failed_string (reason)))) + { + if (gimple_location (stmt) != UNKNOWN_LOCATION) + inform (gimple_location (stmt), "called from here"); + else if (DECL_SOURCE_LOCATION (cfun->decl) != UNKNOWN_LOCATION) + inform (DECL_SOURCE_LOCATION (cfun->decl), + "called from this function"); + } } goto egress; } fn = cg_edge->callee->decl; cg_edge->callee->get_untransformed_body (); @@ -4532,11 +4533,12 @@ expand_call_inline (basic_block bb, gimp not refer to them in any way to not break GC for locations. */ if (gimple_block (stmt)) { id->block = make_node (BLOCK); BLOCK_ABSTRACT_ORIGIN (id->block) = fn; - BLOCK_SOURCE_LOCATION (id->block) = LOCATION_LOCUS (input_location); + BLOCK_SOURCE_LOCATION (id->block) + = LOCATION_LOCUS (gimple_location (stmt)); prepend_lexical_block (gimple_block (stmt), id->block); } /* Local declarations will be replaced by their equivalents in this map. */ @@ -4797,14 +4798,13 @@ expand_call_inline (basic_block bb, gimp /* Update callgraph if needed. */ cg_edge->callee->remove (); id->block = NULL_TREE; - successfully_inlined = TRUE; + successfully_inlined = true; egress: - input_location = saved_location; return successfully_inlined; } /* Expand call statements reachable from STMT_P. We can only have CALL_EXPRs as the "toplevel" tree code or nested