gcc-patches@gcc.gnu.org
[Top] [All Lists]

[PATCH] Fix inlining of K&R functions

Subject: [PATCH] Fix inlining of K&R functions
From: Adam Nemet
Date: Tue, 10 Mar 2009 11:39:47 -0700
The check for type-mismatched inline functions was recently moved to
gimple-low as part of the fix PR c++/36631.  This should have already fixed
the inlining of K&R function since at the time we look at the call we already
have all the information about the callee.  However, some code was left behind
so for a K&R function (i.e. parameters are unknown) we still make the decision
at gimplification time.  The patch removes this bit.  Note that the same check
is performed later in gimple-low so this should be safe.

I found this with Dhrystone, which is K&R.  This is a regression from GCC 4.1.

Bootstrapped and tested on x86_64-linux.

OK to install?

Adam


        * gimplify.c (gimplify_call_expr): Don't set CALL_CANNOT_INLINE_P
        for functions for which the parameter types are unknown.

testsuite/
        * gcc.dg/inline-33.c: New test.

Index: gimplify.c
===================================================================
--- gimplify.c  (revision 144705)
+++ gimplify.c  (working copy)
@@ -2355,11 +2355,7 @@ gimplify_call_expr (tree *expr_p, gimple
   else if (parms)
     p = parms;
   else
-    {
-      if (nargs != 0)
-       CALL_CANNOT_INLINE_P (*expr_p) = 1;
-      p = NULL_TREE;
-    }
+    p = NULL_TREE;
   for (i = 0; i < nargs && p; i++, p = TREE_CHAIN (p))
     ;
 
Index: testsuite/gcc.dg/inline-33.c
===================================================================
--- testsuite/gcc.dg/inline-33.c        (revision 0)
+++ testsuite/gcc.dg/inline-33.c        (revision 0)
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fdump-tree-optimized"  } */
+
+int i;
+
+int foo ();
+
+main ()
+{
+  return foo (i);
+}
+
+int foo (i)
+     int i;
+{
+  return bar(i);
+}
+
+/* { dg-final { scan-tree-dump-times "bar"  2 "optimized"  } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */

<Prev in Thread] Current Thread [Next in Thread>