Hi,
ipa-inline-analysis.c took an assumption that number of parameters of callee
match number of parameters of call stmt or we will not inline at type mismatch.
Our type checking code actually allows callee to have more arguments than 
caller,
thus we need to be more permissive here, too.

Bootstrapped/regtested x86_64-linux, commited.

Honza

        PR tree-optimization/48893
        PR tree-optimization/49091
        PR tree-optimization/49179
        * ipa-inline-analysis.c (evaluate_conditions_for_known_args):
        Bounds check.

        * gfortran.dg/pr49179.f90: New testcase
        
Index: ipa-inline-analysis.c
===================================================================
--- ipa-inline-analysis.c       (revision 174641)
+++ ipa-inline-analysis.c       (working copy)
@@ -555,9 +555,17 @@ evaluate_conditions_for_known_args (stru
 
   for (i = 0; VEC_iterate (condition, info->conds, i, c); i++)
     {
-      tree val = VEC_index (tree, known_vals, c->operand_num);
+      tree val;
       tree res;
 
+      /* We allow call stmt to have fewer arguments than the callee
+        function (especially for K&R style programs).  So bound
+        check here.  */
+      if (c->operand_num < (int)VEC_length (tree, known_vals))
+        val = VEC_index (tree, known_vals, c->operand_num);
+      else
+       val = NULL;
+
       if (!val)
        {
          clause |= 1 << (i + predicate_first_dynamic_condition);
Index: testsuite/gfortran.dg/pr49179.f90
===================================================================
--- testsuite/gfortran.dg/pr49179.f90   (revision 0)
+++ testsuite/gfortran.dg/pr49179.f90   (revision 0)
@@ -0,0 +1,11 @@
+! { dg-options " -O -findirect-inlining" }
+function more_OK (fcn)
+  character(*) more_OK
+  character (*), external :: fcn
+  more_OK = fcn ()
+end function more_OK
+  character(4) :: answer
+  character(4), external :: is_OK, more_OK
+  answer = more_OK (is_OK)
+contains
+END

Reply via email to