diff options
author | Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> | 2018-05-15 06:07:48 +0000 |
---|---|---|
committer | Prathamesh Kulkarni <prathamesh3492@gcc.gnu.org> | 2018-05-15 06:07:48 +0000 |
commit | a8c80d03d4e0fab9cf4edb7bd5acb7edafd2438c (patch) | |
tree | 4cc4883b6dd1ef245b4bef9ff5fef8cf94775da0 /gcc/ipa-pure-const.c | |
parent | 0fac5f2a7f15974deabf6432f4f510d0f4bcc6bc (diff) | |
download | gcc-a8c80d03d4e0fab9cf4edb7bd5acb7edafd2438c.zip gcc-a8c80d03d4e0fab9cf4edb7bd5acb7edafd2438c.tar.gz gcc-a8c80d03d4e0fab9cf4edb7bd5acb7edafd2438c.tar.bz2 |
re PR tree-optimization/83648 (missing -Wsuggest-attribute=malloc on a trivial malloc-like function)
2018-05-15 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
PR tree-optimization/83648
* ipa-pure-const.c (malloc_candidate_p): Allow function with NULL
return value as malloc candidate.
testsuite/
* gcc.dg/tree-ssa/pr83648.c: New test.
* gcc.dg/tree-ssa/pr83648-2.c: Likewise.
From-SVN: r260250
Diffstat (limited to 'gcc/ipa-pure-const.c')
-rw-r--r-- | gcc/ipa-pure-const.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c index 7665358..567b615 100644 --- a/gcc/ipa-pure-const.c +++ b/gcc/ipa-pure-const.c @@ -919,11 +919,13 @@ malloc_candidate_p (function *fun, bool ipa) #define DUMP_AND_RETURN(reason) \ { \ if (dump_file && (dump_flags & TDF_DETAILS)) \ - fprintf (dump_file, "%s", (reason)); \ + fprintf (dump_file, "\n%s is not a malloc candidate, reason: %s\n", \ + (node->name()), (reason)); \ return false; \ } - if (EDGE_COUNT (exit_block->preds) == 0) + if (EDGE_COUNT (exit_block->preds) == 0 + || !flag_delete_null_pointer_checks) return false; FOR_EACH_EDGE (e, ei, exit_block->preds) @@ -938,6 +940,9 @@ malloc_candidate_p (function *fun, bool ipa) if (!retval) DUMP_AND_RETURN("No return value.") + if (integer_zerop (retval)) + continue; + if (TREE_CODE (retval) != SSA_NAME || TREE_CODE (TREE_TYPE (retval)) != POINTER_TYPE) DUMP_AND_RETURN("Return value is not SSA_NAME or not a pointer type.") @@ -970,11 +975,14 @@ malloc_candidate_p (function *fun, bool ipa) for (unsigned i = 0; i < gimple_phi_num_args (phi); ++i) { tree arg = gimple_phi_arg_def (phi, i); + if (integer_zerop (arg)) + continue; + if (TREE_CODE (arg) != SSA_NAME) - DUMP_AND_RETURN("phi arg is not SSA_NAME.") - if (!(arg == null_pointer_node || check_retval_uses (arg, phi))) - DUMP_AND_RETURN("phi arg has uses outside phi" - " and comparisons against 0.") + DUMP_AND_RETURN ("phi arg is not SSA_NAME."); + if (!check_retval_uses (arg, phi)) + DUMP_AND_RETURN ("phi arg has uses outside phi" + " and comparisons against 0.") gimple *arg_def = SSA_NAME_DEF_STMT (arg); gcall *call_stmt = dyn_cast<gcall *> (arg_def); |