From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by sourceware.org (Postfix) with ESMTPS id 5911B3858D20 for ; Fri, 20 Jan 2023 00:11:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5911B3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x1030.google.com with SMTP id o13so4088700pjg.2 for ; Thu, 19 Jan 2023 16:11:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=8cd2DNwKVghz3HURrg9RK2RXhZGdhm1aMgdKlRPv0Mw=; b=cmCtMnB6gHIlD4UZJbSyvHtd5KYeBQgnnkI4jdL359P5OUIQbNXQmhzeEG/Pdued5R N7baIYHN2rVF67gE1cG1Xd/y0tfb8totsKwsgMoXDxNQGHEA4Ulj9Z9Vnol2f3Gpezch yrNbSOuAI7ZdamRZe5KTu8gX6Hqe+LgTFDqWyp3+gPyl6mCp658pvqdSDJopFzOJX39m G4ABIh9QubJMJd00UVMgUg3LjBOY49cARSFsoc5m2iRjXioHMvLuLrPhe1DmocBB7jHy jBBfn1RpJCP6lTzVg/j/aBjBiB2+nzxwd9eRE1KPmiqeaXS7PVGCsDgUn31jiPRbh66o gFHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8cd2DNwKVghz3HURrg9RK2RXhZGdhm1aMgdKlRPv0Mw=; b=w3hooQcaH6nI6vapxvo/qgHIT05cRrXWvZw5gngu/Wc0chA2ckRpdGOv6DsgqfM9n0 Fm1Kxy4T+Fr26hzCfhssxjMoQB+rSiaNjhMDkHOew8Mf1fDc67nzcBeG8rr0qrwXQ3dB EV9c9EvYlhKx8/J0nRHk962Ya9J/6Dpks/Sok80GWBKKxKfrAwTF7G7wftFiGVVAxsHj 69KX7Ggx3ccOyJOqwxcXjyzJhFIlqvoQD/1KHLdXOHsQhCDaFYY7C7sJ1Du68qCz1vuA /aDXwYi7PWjJhik13LMjztO2GUIt9Kz0yCH2EOEaV5rVXnBxDitYn3p0nKXHa/GzbVFC 5BHQ== X-Gm-Message-State: AFqh2kr1o20jz/Cch6YhwjpOfL4H3jPmUsJB6wVTpS6kJGiEsNMMaDWL VGHC445xTpxamJS1tAjI2l1Y3flDp9qMhLQbjnU= X-Google-Smtp-Source: AMrXdXuRkbS+zkuim1w2VT6d/biNG+q/UQqqw/v8lEfGFEC0mfqcu9ZqGKEyIbZejeoLPYVaJY96qJjPx7po5q3QzCs= X-Received: by 2002:a17:90a:de04:b0:223:4d09:2523 with SMTP id m4-20020a17090ade0400b002234d092523mr1476549pjv.161.1674173504126; Thu, 19 Jan 2023 16:11:44 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Andrew Pinski Date: Thu, 19 Jan 2023 16:11:32 -0800 Message-ID: Subject: Re: [PATCH] c++: Fix up handling of references to anon union members in initializers [PR53932] To: Jakub Jelinek Cc: Jason Merrill , gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, Jan 19, 2023 at 12:13 PM Jakub Jelinek via Gcc-patches wrote: > > Hi! > > 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). > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? I noticed (static) structured bindings has a similar issue but is not fixed by this because this checks to see if it is an anonymous union decl. I filed PR 108474 for that. Thanks, Andrew Pinski > > 2023-01-19 Jakub Jelinek > > 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. > > --- gcc/cp/cp-gimplify.cc.jj 2023-01-16 11:52:16.065734330 +0100 > +++ gcc/cp/cp-gimplify.cc 2023-01-19 18:13:54.592661735 +0100 > @@ -1010,6 +1010,16 @@ cp_fold_r (tree *stmt_p, int *walk_subtr > } > 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; > } > --- gcc/testsuite/g++.dg/init/pr53932.C.jj 2023-01-19 18:22:24.837231192 +0100 > +++ gcc/testsuite/g++.dg/init/pr53932.C 2023-01-19 18:20:51.776586408 +0100 > @@ -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 () > +{ > +} > > Jakub >