This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Possible patch for tree-optimization/13000


PR 13000, a gcc 4.0 regression, is about the lack of a warning about
an inline function which does not return a value.  That warning is
normally generated by execute_warn_function_return() in tree-cfg.c,
which simply looks at the CFG to decide whether the function falls
through.  Unfortunately, if a function is only inlined and never has
an outline copy, no CFG is ever generated for the standalone function.

This patch fixes the test case in the PR by checking the inline
function at the point where it is inlined.  It does not cause any new
failures in the testsuite on i686-pc-linux-gnu.

This is probably not the ideal patch, as the warning is less
conclusive.  There are probably some cases where it will produce a
false positive.  The CFG is more reliable.  However, this patch is at
least reasonably cheap and reasonably accurate.  I think this is a
fairly important warning for a fairly important coding error, and not
one that we want to lose.

To try to reflect the possible false positive, the new warning reads 
    control may reach end of non-void function %qD being inlined
The warning is issued at the point where the function is being
inlined, not at the point of the inline function definition.

Any comments?  OK to commit if a bootstrap succeeds?

Ian


ChangeLog:
2005-01-19  Ian Lance Taylor  <ian@c2micro.com>

	PR tree-optimization/13000
	* tree-inline.c: Include "tree-flow.h".
	(expand_call_inline): If warn_return_type, warn if non-void inline
	function falls through.
	* tree-cfg.c (execute_warn_function_return): Don't warn about
	control reaching end if TREE_NO_WARNING is set.  Set
	TREE_NO_WARNING.


testsuite/ChangeLog:

2005-01-19  Ian Lance Taylor  <ian@c2micro.com>

	PR tree-optimization/13000
	* gcc.dg/20040206-1.c: Change warning to point where function is
	being inlined.


Index: tree-inline.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-inline.c,v
retrieving revision 1.166
diff -p -u -r1.166 tree-inline.c
--- tree-inline.c	18 Jan 2005 23:06:59 -0000	1.166
+++ tree-inline.c	19 Jan 2005 15:42:23 -0000
@@ -41,6 +41,7 @@ Boston, MA 02111-1307, USA.  */
 #include "cgraph.h"
 #include "intl.h"
 #include "tree-mudflap.h"
+#include "tree-flow.h"
 #include "function.h"
 #include "diagnostic.h"
 #include "debug.h"
@@ -1607,9 +1608,22 @@ expand_call_inline (tree *tp, int *walk_
      function itself.  */
   {
     struct cgraph_node *old_node = id->current_node;
+    tree copy;
 
     id->current_node = edge->callee;
-    append_to_statement_list (copy_body (id), &BIND_EXPR_BODY (expr));
+    copy = copy_body (id);
+
+    if (warn_return_type
+	&& !TREE_NO_WARNING (fn)
+	&& !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fn)))
+	&& block_may_fallthru (copy))
+      {
+	warning ("control may reach end of non-void function %qD being inlined",
+		 fn);
+	TREE_NO_WARNING (fn) = 1;
+      }
+
+    append_to_statement_list (copy, &BIND_EXPR_BODY (expr));
     id->current_node = old_node;
   }
   inlined_body = &BIND_EXPR_BODY (expr);
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfg.c,v
retrieving revision 2.139
diff -p -u -r2.139 tree-cfg.c
--- tree-cfg.c	17 Jan 2005 18:44:18 -0000	2.139
+++ tree-cfg.c	19 Jan 2005 15:42:22 -0000
@@ -5460,6 +5460,7 @@ execute_warn_function_return (void)
   /* If we see "return;" in some basic block, then we do reach the end
      without returning a value.  */
   else if (warn_return_type
+	   && !TREE_NO_WARNING (cfun->decl)
 	   && EDGE_COUNT (EXIT_BLOCK_PTR->preds) > 0
 	   && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (cfun->decl))))
     {
@@ -5480,6 +5481,7 @@ execute_warn_function_return (void)
 		locus = &cfun->function_end_locus;
 	      warning ("%Hcontrol reaches end of non-void function", locus);
 #endif
+	      TREE_NO_WARNING (cfun->decl) = 1;
 	      break;
 	    }
 	}
Index: gcc.dg/20040206-1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/20040206-1.c,v
retrieving revision 1.4
diff -u -r1.4 20040206-1.c
--- gcc.dg/20040206-1.c	17 Jan 2005 17:17:02 -0000	1.4
+++ gcc.dg/20040206-1.c	19 Jan 2005 15:47:16 -0000
@@ -7,5 +7,5 @@
     The warning about "no return statement in function
     returning non-void" is PR 13000. */
 
-static int foo (int a __attribute__((unused)) ) { }  /* { dg-warning "return" "" { xfail *-*-* } } */
-int main (void) { return foo (0); }
+static int foo (int a __attribute__((unused)) ) { }
+int main (void) { return foo (0); } /* { dg-warning "control reaches end" } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]