This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix always-inline diagnostics
- From: Jan Hubicka <jh at suse dot cz>
- To: gcc-patches at gcc dot gnu dot org, rth at redhat dot com
- Date: Mon, 12 Jan 2004 20:08:02 +0100
- Subject: Fix always-inline diagnostics
Hi,
it seems to be common belief that when we fail inlining always_inline function,
we should output error message, but it is not happening. Perhaps I killed that
in the inlining reorganization, but I don't even see any artefacts of that code.
This patch makes the error messages to happen and also adds a testcase for this.
Bootstrapped/regtested i686-pc-gnu-linux. OK?
Honza
2004-01-12 Jan Hubicka <jh@suse.cz>
* cgraphunit.c (cgraph_optimize_function): Always do
optimize_inline_calls when there is always_inline callee.
(cgraph_decide_inlining): Fix formating.
* tree-inline.c (inlinable_function_p): Do sorry for alwaysinline
functions.
(expand_call_inline): Likewise.
* toplev.h (sorry): Fix prototype.
* gcc.dg/always_inline.c: New test.
* gcc.dg/debug/20031231-1.c: Fix.
Index: cgraphunit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cgraphunit.c,v
retrieving revision 1.43
diff -c -3 -p -r1.43 cgraphunit.c
*** cgraphunit.c 8 Jan 2004 22:57:49 -0000 1.43
--- cgraphunit.c 12 Jan 2004 13:25:28 -0000
*************** cgraph_optimize_function (struct cgraph_
*** 481,487 ****
struct cgraph_edge *e;
for (e = node->callees; e; e = e->next_callee)
! if (!e->inline_failed || warn_inline)
break;
if (e)
optimize_inline_calls (decl);
--- 481,490 ----
struct cgraph_edge *e;
for (e = node->callees; e; e = e->next_callee)
! if (!e->inline_failed || warn_inline
! || (DECL_DECLARED_INLINE_P (e->callee->decl)
! && lookup_attribute ("always_inline",
! DECL_ATTRIBUTES (e->callee->decl))))
break;
if (e)
optimize_inline_calls (decl);
*************** cgraph_decide_inlining (void)
*** 1178,1187 ****
cgraph_node_name (node->callees->caller),
node->callees->caller->global.insns);
}
! if (cgraph_dump_file && node->global.cloned_times > 0)
! fprintf (cgraph_dump_file,
! " Inlined %i times for a net change of %+i insns.\n",
! node->global.cloned_times, overall_insns - old_insns);
for (y = 0; y < ninlined; y++)
inlined[y]->output = 0, node->aux = 0;
}
--- 1181,1190 ----
cgraph_node_name (node->callees->caller),
node->callees->caller->global.insns);
}
! if (cgraph_dump_file && node->global.cloned_times > 0)
! fprintf (cgraph_dump_file,
! " Inlined %i times for a net change of %+i insns.\n",
! node->global.cloned_times, overall_insns - old_insns);
for (y = 0; y < ninlined; y++)
inlined[y]->output = 0, node->aux = 0;
}
Index: tree-inline.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-inline.c,v
retrieving revision 1.89
diff -c -3 -p -r1.89 tree-inline.c
*** tree-inline.c 4 Jan 2004 14:39:12 -0000 1.89
--- tree-inline.c 12 Jan 2004 13:25:29 -0000
*************** inlinable_function_p (tree fn)
*** 1213,1219 ****
&& DECL_DECLARED_INLINE_P (fn)
&& !DECL_IN_SYSTEM_HEADER (fn));
! if (do_warning)
warning (inline_forbidden_reason, fn, fn);
inlinable = false;
--- 1213,1222 ----
&& DECL_DECLARED_INLINE_P (fn)
&& !DECL_IN_SYSTEM_HEADER (fn));
! if (lookup_attribute ("always_inline",
! DECL_ATTRIBUTES (fn)))
! sorry (inline_forbidden_reason, fn, fn);
! else if (do_warning)
warning (inline_forbidden_reason, fn, fn);
inlinable = false;
*************** expand_call_inline (tree *tp, int *walk_
*** 1330,1338 ****
inlining. */
if (!cgraph_inline_p (id->current_decl, fn, &reason))
{
! if (warn_inline && DECL_DECLARED_INLINE_P (fn)
! && !DECL_IN_SYSTEM_HEADER (fn)
! && strlen (reason))
{
warning ("%Jinlining failed in call to '%F': %s", fn, fn, reason);
warning ("called from here");
--- 1333,1346 ----
inlining. */
if (!cgraph_inline_p (id->current_decl, fn, &reason))
{
! if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)))
! {
! sorry ("%Jinlining failed in call to '%F': %s", fn, fn, reason);
! sorry ("called from here");
! }
! else if (warn_inline && DECL_DECLARED_INLINE_P (fn)
! && !DECL_IN_SYSTEM_HEADER (fn)
! && strlen (reason))
{
warning ("%Jinlining failed in call to '%F': %s", fn, fn, reason);
warning ("called from here");
Index: testsuite/gcc.dg/always_inline.c
===================================================================
RCS file: testsuite/gcc.dg/always_inline.c
diff -N testsuite/gcc.dg/always_inline.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/always_inline.c 12 Jan 2004 13:25:53 -0000
***************
*** 0 ****
--- 1,21 ----
+ /* { dg-do compile } */
+ /* { dg-options "-Winline -O2" } */
+ #include <stdarg.h>
+ inline __attribute__ ((always_inline)) void t(void); /* { dg-error "body not available" "" } */
+ void
+ q(void)
+ {
+ t(); /* { dg-error "called from here" "" } */
+ }
+ inline __attribute__ ((always_inline)) void
+ q2(void)
+ { /* { dg-error "recursive" "" } */
+ q2(); /* { dg-error "called from here" "" } */
+ q2(); /* { dg-error "called from here" "" } */
+ }
+ inline __attribute__ ((always_inline)) void
+ e(int t, ...)
+ { /* { dg-error "variable argument" "" } */
+ va_list q;
+ va_start (q, t);
+ }
Index: toplev.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.h,v
retrieving revision 1.116
diff -c -3 -p -r1.116 toplev.h
*** toplev.h 21 Nov 2003 04:05:05 -0000 1.116
--- toplev.h 12 Jan 2004 16:00:03 -0000
*************** extern void error (const char *, ...);
*** 60,66 ****
extern void fatal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
ATTRIBUTE_NORETURN;
extern void pedwarn (const char *, ...);
! extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
extern void inform (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
extern void rest_of_decl_compilation (tree, const char *, int, int);
--- 60,66 ----
extern void fatal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
ATTRIBUTE_NORETURN;
extern void pedwarn (const char *, ...);
! extern void sorry (const char *, ...);
extern void inform (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
extern void rest_of_decl_compilation (tree, const char *, int, int);
Index: testsuite/gcc.dg/debug/20031231-1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/debug/20031231-1.c,v
retrieving revision 1.1
diff -c -3 -p -r1.1 20031231-1.c
*** testsuite/gcc.dg/debug/20031231-1.c 1 Jan 2004 13:59:02 -0000 1.1
--- testsuite/gcc.dg/debug/20031231-1.c 12 Jan 2004 18:41:34 -0000
*************** void pp_c_string_literal (c_pretty_print
*** 12,18 ****
static __inline__ __attribute__((always_inline)) void
pp_c_shift_expression (c_pretty_printer *pp, tree e)
{
- pp_c_shift_expression (pp,e);
}
static void
--- 12,17 ----