public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Alexandre Oliva <aoliva@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testme)] harden conds: detach without decls Date: Fri, 19 Nov 2021 11:10:20 +0000 (GMT) [thread overview] Message-ID: <20211119111020.0EB843857C51@sourceware.org> (raw) https://gcc.gnu.org/g:28cab866b951826f22390088b4cd7cf9a4c11806 commit 28cab866b951826f22390088b4cd7cf9a4c11806 Author: Alexandre Oliva <oliva@adacore.com> Date: Fri Nov 19 08:09:30 2021 -0300 harden conds: detach without decls When we create copies of SSA_NAMEs to hold "detached" copies of the values for the hardening tests, we end up with assignments to SSA_NAMEs that refer to the same decls. That would be generally desirable, since it enables the variable to be recognized in dumps, and makes coalescing more likely if the original variable dies at that point. When the decl is a DECL_BY_REFERENCE, the SSA_NAME holds the address of a parm or result, and it's read-only, so we shouldn't create assignments to it. Gimple checkers flag at least the case of results. This patch arranges for us to avoid referencing the same decls, which cures the problem, but retaining the visible association between the SSA_NAMEs, by using the same identifier for the copy. for gcc/ChangeLog PR tree-optimization/102988 * gimple-harden-conditionals.cc (detach_value): Copy SSA_NAME without decl sharing. for gcc/testsuite/ChangeLog PR tree-optimization/102988 * g++.dg/pr102988.C: New. Diff: --- gcc/gimple-harden-conditionals.cc | 9 ++++++++- gcc/testsuite/g++.dg/pr102988.C | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/gcc/gimple-harden-conditionals.cc b/gcc/gimple-harden-conditionals.cc index 8916420d7df..cfa2361d65b 100644 --- a/gcc/gimple-harden-conditionals.cc +++ b/gcc/gimple-harden-conditionals.cc @@ -123,7 +123,14 @@ detach_value (location_t loc, gimple_stmt_iterator *gsip, tree val) return val; } - tree ret = copy_ssa_name (val); + /* Create a SSA "copy" of VAL. This could be an anonymous + temporary, but it's nice to have it named after the corresponding + variable. Alas, when VAL is a DECL_BY_REFERENCE RESULT_DECL, + setting (a copy of) it would be flagged by checking, so we don't + use copy_ssa_name: we create an anonymous SSA name, and then give + it the same identifier (rather than decl) as VAL. */ + tree ret = make_ssa_name (TREE_TYPE (val)); + SET_SSA_NAME_VAR_OR_IDENTIFIER (ret, SSA_NAME_IDENTIFIER (val)); /* Output asm ("" : "=g" (ret) : "0" (val)); */ vec<tree, va_gc> *inputs = NULL; diff --git a/gcc/testsuite/g++.dg/pr102988.C b/gcc/testsuite/g++.dg/pr102988.C new file mode 100644 index 00000000000..05a1a8f67ed --- /dev/null +++ b/gcc/testsuite/g++.dg/pr102988.C @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fharden-conditional-branches -fchecking=1" } */ + +/* DECL_BY_REFERENCE RESULT_DECL is read-only, we can't create a copy + of its (address) default def and set it. */ + +void ll(); +struct k { + ~k(); +}; +k ice(k *a) +{ + k v; + if (&v!= a) + ll(); + return v; +}
reply other threads:[~2021-11-19 11:10 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=20211119111020.0EB843857C51@sourceware.org \ --to=aoliva@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).