From 4c8836c61b19b88ddbfc3502c12dfcd9e87cee71 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Sun, 8 Jan 2012 17:32:49 +0100 Subject: [PATCH] re PR tree-optimization/51694 (ICE while compiling alliance package) PR tree-optimize/51694 * ipa-cp.c (ipa_get_indirect_edge_target): Add bounds checks. From-SVN: r182993 --- gcc/ChangeLog | 5 +++++ gcc/ipa-cp.c | 5 +++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.c-torture/compile/pr51694.c | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr51694.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0e93424521d5..a2648d8ea4c9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2012-01-08 Jan Hubicka + + PR tree-optimize/51694 + * ipa-cp.c (ipa_get_indirect_edge_target): Add bounds checks. + 2012-01-08 Jonathan Wakely * doc/cpp.texi (Predefined Macros): __STRICT_ANSI__ is defined diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c index 2a82df1032ff..ae38366c2ca2 100644 --- a/gcc/ipa-cp.c +++ b/gcc/ipa-cp.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3385000ec004..b8b9b94468d4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-01-07 Jan Hubicka + + PR tree-optimize/51694 + * gcc.c-torture/compile/pr51694.c: new testcase. + 2012-01-07 Jan Hubicka PR tree-optimization/51600 diff --git a/gcc/testsuite/gcc.c-torture/compile/pr51694.c b/gcc/testsuite/gcc.c-torture/compile/pr51694.c new file mode 100644 index 000000000000..579a2434d82b --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr51694.c @@ -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); +} -- 2.47.3