From patchwork Thu Jan 19 20:13:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 45954 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp524563wrn; Thu, 19 Jan 2023 12:13:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXtT+8Fm3eiiUnZFI0pVOyeD3Rz9YB4slY7x5pC4zZiB0QThVdzPGWB+W0XB2pTp4OuC5ixZ X-Received: by 2002:a05:6402:5d3:b0:49b:58ca:ebbc with SMTP id n19-20020a05640205d300b0049b58caebbcmr14528612edx.32.1674159234999; Thu, 19 Jan 2023 12:13:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674159234; cv=none; d=google.com; s=arc-20160816; b=zRRKt9eXjkZbpIGEKm1k1DHRXiLAWvG7DZzh+/C30pm71yZ0lQKmKSHtI+GWUeh8zX U4+FINklr+dGG8UrBXFcn+LCiXEQzeoCZsOPYICz1btB2J3GXJ99qe6CAHpOQUcuU+rN UwuNMkdRSLY862xIuh2C1cfeqBKzFrw0vm+6rtCV4/PxVN/z0hLcEJdNNruXykMOjd5X i+gSALnhHK4jJqiOYfUtL9/SdGlpAQQ26eLwOPbNfVGjqkrnLauRx1MuwDnD+ros7e1v ajc6DcbhVX8j1RyapT95sIKDlDYR1gZ+k3WjaauXomgbtM5Ai+wLRRRmDd2J2Mxb2Atf 5D+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=9Z8v62J4bnC1SwgehlM7PjOEW1d/BabE+zK8RzSd8ms=; b=qQSK4lFQY7HRIOKveNYncQalXJkuptcWvvGLrEJcX+KU3nKngJE+ljthW/Nbi2u4jm jSNjcKiEj6Cw+TxOG+DC0udM9NdMxog3vCNeR/KPbDZyfSZld9piwasQYr7xSbiODFvE fbhIscMhQJvbqeNel8up4Oy1axpURQowFJooW9ttT2xFP6SBdMGu3ERfgq1zb18Rj1oj SKjrcIMPIys/CpUzP1A2Y/fijKvwVq0NjgXFaFhtxy4HJlYd7EmvV1iTRofolzTBWVUu MEuqnOYTEnkblg7RWd+YZal+kWm9Voj2SYCR5ysbf96orSJcQssO51zHVi9KNqW2j8yN 0bmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CbTgcXhG; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n26-20020aa7c79a000000b0046eff871046si37556953eds.367.2023.01.19.12.13.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jan 2023 12:13:54 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CbTgcXhG; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C7F723858288 for ; Thu, 19 Jan 2023 20:13:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7F723858288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674159233; bh=9Z8v62J4bnC1SwgehlM7PjOEW1d/BabE+zK8RzSd8ms=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=CbTgcXhGf7NM+HQ+F2yRDCb1/g9Ooctfx1Rjp1N1TXNZiWqCsPPwsUSZ5EJ7agRFL 8+fC9bBNqXn0NtM8F1c7/oSYiIY7AZbGHrFS0TfgmdCnNFtCE3jfhfMgMdKgOm7fCn qWCOydDOOWp8ByBui91wsoQhiOtSRAOCfPRGoaeg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4F3E73858C52 for ; Thu, 19 Jan 2023 20:13:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4F3E73858C52 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-648-2AVtXlLcPUCTYjr7T_B2iw-1; Thu, 19 Jan 2023 15:13:08 -0500 X-MC-Unique: 2AVtXlLcPUCTYjr7T_B2iw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3EB1B8533E1 for ; Thu, 19 Jan 2023 20:13:08 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE028492C3C; Thu, 19 Jan 2023 20:13:07 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 30JKD5NV3366286 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 19 Jan 2023 21:13:05 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 30JKD48x3366284; Thu, 19 Jan 2023 21:13:04 +0100 Date: Thu, 19 Jan 2023 21:13:04 +0100 To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix up handling of references to anon union members in initializers [PR53932] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755483193568862708?= X-GMAIL-MSGID: =?utf-8?q?1755483193568862708?= 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? 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. Jakub --- 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 () +{ +}