diff mbox

PR tree-optimize/51694

Message ID 20120108153647.GB15372@kam.mff.cuni.cz
State New
Headers show

Commit Message

Jan Hubicka Jan. 8, 2012, 3:36 p.m. UTC
Hi,
in the testcase bellow there is the usual problem with mismatched function
arguments.  I've added bounds check to avoid the ICE.

Bootstrapped/regtested x86_64-linux.
Will commit it shortly.
Honza
	PR tree-optimize/51694
	* ipa-cp.c (ipa_get_indirect_edge_target): Add bounds checks.
diff mbox

Patch

Index: ipa-cp.c
===================================================================
--- ipa-cp.c	(revision 182992)
+++ ipa-cp.c	(working copy)
@@ -1112,7 +1112,8 @@  ipa_get_indirect_edge_target (struct cgr
 
   if (!ie->indirect_info->polymorphic)
     {
-      tree t = VEC_index (tree, known_vals, param_index);
+      tree t = (VEC_length (tree, known_vals) > param_index
+	        ? VEC_index (tree, known_vals, param_index) : NULL);
       if (t &&
 	  TREE_CODE (t) == ADDR_EXPR
 	  && TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL)
@@ -1126,7 +1127,7 @@  ipa_get_indirect_edge_target (struct cgr
   otr_type = ie->indirect_info->otr_type;
 
   t = VEC_index (tree, known_vals, param_index);
-  if (!t && known_binfos)
+  if (!t && known_binfos && VEC_length (tree, known_binfos) > param_index)
     t = VEC_index (tree, known_binfos, param_index);
   if (!t)
     return NULL_TREE;
Index: testsuite/gcc.c-torture/compile/pr51694.c
===================================================================
--- testsuite/gcc.c-torture/compile/pr51694.c	(revision 0)
+++ testsuite/gcc.c-torture/compile/pr51694.c	(revision 0)
@@ -0,0 +1,14 @@ 
+void
+foo (x, fn)
+  void (*fn) ();
+{
+  int a = baz ((void *) 0, x);
+  (*fn) (x, 0);
+}
+
+void
+bar (void)
+{
+  void *x = 0;
+  foo (x);
+}