public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5265] c++: Fix up handling of references to anon union members in initializers [PR53932] Date: Thu, 19 Jan 2023 22:28:18 +0000 (GMT) [thread overview] Message-ID: <20230119222818.D65803858CDA@sourceware.org> (raw) https://gcc.gnu.org/g:9b9a989adc042b304572fd6d4ade46b47be6ccb8 commit r13-5265-g9b9a989adc042b304572fd6d4ade46b47be6ccb8 Author: Jakub Jelinek <jakub@redhat.com> Date: Thu Jan 19 23:27:34 2023 +0100 c++: Fix up handling of references to anon union members in initializers [PR53932] For anonymous union members we create artificial VAR_DECLs which have DECL_VALUE_EXPR for the actual COMPONENT_REF. That works just fine inside of functions (including global dynamic constructors), because during gimplification such VAR_DECLs are gimplified as their DECL_VALUE_EXPR. This is also done during regimplification. But references to these artificial vars in DECL_INITIAL expressions aren't ever replaced by the DECL_VALUE_EXPRs, so we end up either with link failures like on the testcase below, or worse ICEs with LTO. The following patch fixes those during cp_fully_fold_init where we already walk all the trees (!data->genericize means that function rather than cp_fold_function). 2023-01-19 Jakub Jelinek <jakub@redhat.com> PR c++/53932 * cp-gimplify.cc (cp_fold_r): During cp_fully_fold_init replace DECL_ANON_UNION_VAR_P VAR_DECLs with their corresponding DECL_VALUE_EXPR. * g++.dg/init/pr53932.C: New test. Diff: --- gcc/cp/cp-gimplify.cc | 10 ++++++++++ gcc/testsuite/g++.dg/init/pr53932.C | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index a28215655e7..340b4641046 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -1010,6 +1010,16 @@ cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data_) } break; + case VAR_DECL: + /* In initializers replace anon union artificial VAR_DECLs + with their DECL_VALUE_EXPRs, as nothing will do it later. */ + if (DECL_ANON_UNION_VAR_P (stmt) && !data->genericize) + { + *stmt_p = stmt = unshare_expr (DECL_VALUE_EXPR (stmt)); + break; + } + break; + default: break; } diff --git a/gcc/testsuite/g++.dg/init/pr53932.C b/gcc/testsuite/g++.dg/init/pr53932.C new file mode 100644 index 00000000000..3b129e7d68a --- /dev/null +++ b/gcc/testsuite/g++.dg/init/pr53932.C @@ -0,0 +1,25 @@ +// PR c++/53932 +// { dg-do link } + +static union { int i; }; +int &r = i; +int s = i; +int *t = &i; + +void +foo (int **p, int *q) +{ + static int &u = i; + static int v = i; + static int *w = &i; + int &x = i; + int y = i; + int *z = &i; + *p = &i; + *q = i; +} + +int +main () +{ +}
reply other threads:[~2023-01-19 22:28 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=20230119222818.D65803858CDA@sourceware.org \ --to=jakub@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).