From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 63D6F3858C52 for ; Thu, 19 Jan 2023 20:46:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 63D6F3858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674161199; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jgNOcdR1muUmbC2r7etgy1qUv6c7s1PuKGwaocfXnLw=; b=PhKdIKO87JGhySyWmuNaslJZbGElL/SDcdP6A5YqezYjOel2ZTf51izh7vsLptpHYiVuYq kD21yCIPYWH1KWiTL6L9a+XIIRotdnPP2lV2QcbfF7rvMdIJIThHjCS0wfRPyTWWF7ST3S MsHasdM4JQpC9o+6/Yqt7tgdxwnPfL8= Received: from mail-vk1-f199.google.com (mail-vk1-f199.google.com [209.85.221.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-622-RtFd0TRxPj-Bb7co8TzZJA-1; Thu, 19 Jan 2023 15:46:38 -0500 X-MC-Unique: RtFd0TRxPj-Bb7co8TzZJA-1 Received: by mail-vk1-f199.google.com with SMTP id b77-20020a1f1b50000000b003bbf35b919bso995555vkb.11 for ; Thu, 19 Jan 2023 12:46:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jgNOcdR1muUmbC2r7etgy1qUv6c7s1PuKGwaocfXnLw=; b=45I9fJ8PoWMB9awtOWCCTtyjGqneyzj0PAWvtYdym2s0Xe7HB5cBe7J7fP1mjUyCml 2lSrTGVHXc1fiDVYMz+GWUVgXyeGwlUkxwnLYUx532eoDpAS1vlUWp7qqoig/nDIDN5b 9BmsYS6wroSC3P0wo0NiSZSlcmRRML53yqyBv+JxfuXVKVCKJ7GcfWG8OnegonKQnP/m TBuLcRDSzxBz0+68Ot1CXzioxt2rFia01F3jrvQJ76zVKVl/M5VZk27my6H3n+PCQwrV k4kBeoRfO6BfGm10AwA9p4rT6P/VPpv2FODcSb+EwGXhg4rHqAjcf29qBt/g7OCCphQf OHHQ== X-Gm-Message-State: AFqh2kpR0DoU4wcgluWFxIs20lv9rvs61SaVP1aHbXuh1s/oPbcrIX88 D3ntj0c5NlkAXCVjQ209pP9h8+wV5PzqKQm88PRXOcUE4MQPx1EBmsNU8+bm5a7Rb7eOvYtzvwm eVPWF+BGvh+AYduX8Ig== X-Received: by 2002:a05:6102:91c:b0:3d3:c7c9:5ce6 with SMTP id x28-20020a056102091c00b003d3c7c95ce6mr7993349vsh.0.1674161197819; Thu, 19 Jan 2023 12:46:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXsZovo62zuvaV+hR0wZ3rFqP1ekR04jH80UKmK7IIcTmyyHbd4i51qn3DOAee5jvpgtINn1YQ== X-Received: by 2002:a05:6102:91c:b0:3d3:c7c9:5ce6 with SMTP id x28-20020a056102091c00b003d3c7c95ce6mr7993334vsh.0.1674161197503; Thu, 19 Jan 2023 12:46:37 -0800 (PST) Received: from [192.168.1.108] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id t5-20020a05620a450500b006fa8299b4d5sm24924988qkp.100.2023.01.19.12.46.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Jan 2023 12:46:36 -0800 (PST) Message-ID: Date: Thu, 19 Jan 2023 15:46:35 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH] c++: Fix up handling of references to anon union members in initializers [PR53932] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 List-Id: On 1/19/23 15:13, Jakub Jelinek 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? OK. > 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 >