public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-9829] tree-optimization/114624 - fix use-after-free in SCCP Date: Mon, 8 Apr 2024 09:37:42 +0000 (GMT) [thread overview] Message-ID: <20240408093743.296B13858CD1@sourceware.org> (raw) https://gcc.gnu.org/g:97d5cd8740384dbce5a83080916388f80d8976dd commit r14-9829-g97d5cd8740384dbce5a83080916388f80d8976dd Author: Richard Biener <rguenther@suse.de> Date: Mon Apr 8 10:38:49 2024 +0200 tree-optimization/114624 - fix use-after-free in SCCP We're inspecting the replaced PHI node after releasing it. PR tree-optimization/114624 * tree-scalar-evolution.cc (final_value_replacement_loop): Get at the PHI arg location before releasing the PHI node. * gcc.dg/torture/pr114624.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/torture/pr114624.c | 20 ++++++++++++++++++++ gcc/tree-scalar-evolution.cc | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr114624.c b/gcc/testsuite/gcc.dg/torture/pr114624.c new file mode 100644 index 00000000000..ae031356982 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr114624.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ + +int a, b; +int main() { + int c, d = 1; + while (a) { + while (b) + if (d) + while (a) + ; + for (; b < 2; b++) + if (b) + for (c = 0; c < 8; c++) + d = 0; + else + for (a = 0; a < 2; a++) + ; + } + return 0; +} diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc index 25e3130e2f1..b0a5e09a77c 100644 --- a/gcc/tree-scalar-evolution.cc +++ b/gcc/tree-scalar-evolution.cc @@ -3877,6 +3877,7 @@ final_value_replacement_loop (class loop *loop) to a GIMPLE sequence or to a statement list (keeping this a GENERIC interface). */ def = unshare_expr (def); + auto loc = gimple_phi_arg_location (phi, exit->dest_idx); remove_phi_node (&psi, false); /* Propagate constants immediately, but leave an unused initialization @@ -3888,8 +3889,7 @@ final_value_replacement_loop (class loop *loop) gimple_seq stmts; def = force_gimple_operand (def, &stmts, false, NULL_TREE); gassign *ass = gimple_build_assign (rslt, def); - gimple_set_location (ass, - gimple_phi_arg_location (phi, exit->dest_idx)); + gimple_set_location (ass, loc); gimple_seq_add_stmt (&stmts, ass); /* If def's type has undefined overflow and there were folded
reply other threads:[~2024-04-08 9:37 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240408093743.296B13858CD1@sourceware.org \ --to=rguenth@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).