From 4882e5badaad9a0174a8ace1d71448e0f824bdf1 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 15 Jan 2019 09:37:22 +0000 Subject: [PATCH] re PR ipa/88788 (Infinite loop in malloc_candidate_p_1 since r264838) 2019-01-15 Richard Biener Prathamesh Kulkarni PR ipa/88788 * ipa-pure-const.c (malloc_candidate_p_1): Add parameter visited and return true if SSA_NAME is already marked in visited bitmap. (malloc_candidate_p): Pass visited to malloc_candidate_p_1. Co-Authored-By: Prathamesh Kulkarni From-SVN: r267933 --- gcc/ChangeLog | 8 ++++++++ gcc/ipa-pure-const.c | 10 +++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c350d1cec0f..576541e5e3c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2019-01-15 Richard Biener + Prathamesh Kulkarni + + PR ipa/88788 + * ipa-pure-const.c (malloc_candidate_p_1): Add parameter visited and + return true if SSA_NAME is already marked in visited bitmap. + (malloc_candidate_p): Pass visited to malloc_candidate_p_1. + 2019-01-15 Jakub Jelinek PR tree-optimization/88775 diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c index 37b58853fe1..8227eed29bc 100644 --- a/gcc/ipa-pure-const.c +++ b/gcc/ipa-pure-const.c @@ -878,9 +878,12 @@ check_retval_uses (tree retval, gimple *stmt) } static bool -malloc_candidate_p_1 (function *fun, tree retval, gimple *ret_stmt, bool ipa) +malloc_candidate_p_1 (function *fun, tree retval, gimple *ret_stmt, bool ipa, + bitmap visited) { cgraph_node *node = cgraph_node::get_create (fun->decl); + if (!bitmap_set_bit (visited, SSA_NAME_VERSION (retval))) + return true; if (!check_retval_uses (retval, ret_stmt)) DUMP_AND_RETURN("Return value has uses outside return stmt" @@ -925,7 +928,7 @@ malloc_candidate_p_1 (function *fun, tree retval, gimple *ret_stmt, bool ipa) gimple *arg_def = SSA_NAME_DEF_STMT (arg); if (is_a (arg_def)) { - if (!malloc_candidate_p_1 (fun, arg, phi, ipa)) + if (!malloc_candidate_p_1 (fun, arg, phi, ipa, visited)) DUMP_AND_RETURN ("nested phi fail") continue; } @@ -971,6 +974,7 @@ malloc_candidate_p (function *fun, bool ipa) || !flag_delete_null_pointer_checks) return false; + auto_bitmap visited; FOR_EACH_EDGE (e, ei, exit_block->preds) { gimple_stmt_iterator gsi = gsi_last_bb (e->src); @@ -987,7 +991,7 @@ malloc_candidate_p (function *fun, bool ipa) || TREE_CODE (TREE_TYPE (retval)) != POINTER_TYPE) DUMP_AND_RETURN("Return value is not SSA_NAME or not a pointer type.") - if (!malloc_candidate_p_1 (fun, retval, ret_stmt, ipa)) + if (!malloc_candidate_p_1 (fun, retval, ret_stmt, ipa, visited)) return false; } -- 2.30.2