OSDN Git Service

PR tree-optimize/51694
authorhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 8 Jan 2012 16:32:49 +0000 (16:32 +0000)
committerhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 8 Jan 2012 16:32:49 +0000 (16:32 +0000)
* ipa-cp.c (ipa_get_indirect_edge_target): Add bounds checks.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@182993 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/ipa-cp.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr51694.c [new file with mode: 0644]

index 0e93424..a2648d8 100644 (file)
@@ -1,3 +1,8 @@
+2012-01-08  Jan Hubicka  <jh@suse.cz>
+
+       PR tree-optimize/51694
+       * ipa-cp.c (ipa_get_indirect_edge_target): Add bounds checks.
+
 2012-01-08  Jonathan Wakely  <jwakely.gcc@gmail.com>
 
        * doc/cpp.texi (Predefined Macros): __STRICT_ANSI__ is defined
index 2a82df1..ae38366 100644 (file)
@@ -1112,7 +1112,8 @@ ipa_get_indirect_edge_target (struct cgraph_edge *ie,
 
   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 cgraph_edge *ie,
   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 3385000..b8b9b94 100644 (file)
@@ -1,5 +1,10 @@
 2012-01-07  Jan Hubicka  <jh@suse.cz>
 
+       PR tree-optimize/51694
+       * gcc.c-torture/compile/pr51694.c: new testcase.
+
+2012-01-07  Jan Hubicka  <jh@suse.cz>
+
        PR tree-optimization/51600
        * g++.dg/torture/pr51600.C: New testcase.
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr51694.c b/gcc/testsuite/gcc.c-torture/compile/pr51694.c
new file mode 100644 (file)
index 0000000..579a243
--- /dev/null
@@ -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);
+}