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.129.124]) by sourceware.org (Postfix) with ESMTPS id 794FF385783A for ; Mon, 17 Jan 2022 17:01:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 794FF385783A Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-9-a_CpdmWYOCCblFYyBP9zPg-1; Mon, 17 Jan 2022 12:01:16 -0500 X-MC-Unique: a_CpdmWYOCCblFYyBP9zPg-1 Received: by mail-qk1-f197.google.com with SMTP id k3-20020a378803000000b0047a7e7cc2d5so5191993qkd.0 for ; Mon, 17 Jan 2022 09:01:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=Byca/wIA0lDfwnM8jVBIKSH8fnDlMVxjbF9JlfXA3zI=; b=PZsbNnYAJ6lHGxko0t8QzJ2C9sVhi7S+S9QCeZEcsSAzq23UEzuebyZsPiuKwLTu0S QnY2ySdnQzlIwt5tq0TWao9vy8pvVSHRBRoSD4ZmOULmr6ccQjUGNA5GB10iKCeXR70E tmWHpc3OD+eKuH0tMEoVb+DxaKokMxDgwV1CRk10PBy94KljJFSQgGtg4ZQ8obi6oHVr BQfkPxKbUTHt1iaXexpUnmBWhbKVugeYsqumY6uwKhqG8Lhma2eK7UPBuBUTG/jSpM9I ZVt/E2zesdMMSs7gV23SKIAMqZ1JTN109GlGF5sVnmKry6nmMTrgsZ0BY9rrIfpsDbOO 1Y/A== X-Gm-Message-State: AOAM532El5s9wMiFfZAal2HuxPm+ZvAOZuj31mpxN3Vqhy5pZ7C7LEmN hGxSJNt7ZP2vAN7oAPpT12q7Md+cD4DbflYMrfZH9ONTnXTWVw8BJrHeOpp3Msh2U8kJrBABdHh 2X68JYhljNZxspVuOxQ== X-Received: by 2002:ac8:7d54:: with SMTP id h20mr360480qtb.449.1642438870598; Mon, 17 Jan 2022 09:01:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJyavKzd7FX/PmB1KKqhGW65vlhRtIg1YB6YxHAT+JvV611GTtHagX/Tkd0P6nmIQM07ukX4GQ== X-Received: by 2002:ac8:7d54:: with SMTP id h20mr360409qtb.449.1642438869944; Mon, 17 Jan 2022 09:01:09 -0800 (PST) Received: from [192.168.1.149] (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 y17sm1386689qtw.0.2022.01.17.09.01.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Jan 2022 09:01:09 -0800 (PST) Message-ID: <306ee123-8ef1-642e-c8af-515a741c0b9b@redhat.com> Date: Mon, 17 Jan 2022 12:01:08 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] c++: Fix cp_genericize_target_expr for TARGET_EXPRs created for global initialization [PR104031] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: <20220117085651.GF2646553@tucnak> From: Jason Merrill In-Reply-To: <20220117085651.GF2646553@tucnak> 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=-7.2 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_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Mon, 17 Jan 2022 17:01:18 -0000 On 1/17/22 03:56, Jakub Jelinek wrote: > Hi! > > The following patch is miscompiled, cp_genericize_target_expr expects > that for the constant part split_nonconstant_init will emit an INIT_EXPR > that will initialize it, but that doesn't happen and instead we get > DECL_INITIAL on the TARGET_EXPR_SLOT that isn't initialized anywhere > in the IL. > > The problem is that the TARGET_EXPR has been created while > current_function_decl was NULL, it is inside a global var initializer. > That means the build_local_temp created VAR_DECL has NULL DECL_CONTEXT. > Later on when genericizing the ssdf (current_function_decl is already > non-NULL), the new cp_genericize_target_expr is called and during > split_nonconstant_init it checks is_local_temp, but that due to the NULL > DECL_CONTEXT returns false. DECL_CONTEXT is set only later on during > gimplification. > > The following patch fixes it by setting DECL_CONTEXT also inside of > cp_genericize_target_expr, which fixes the testcase. But if there are > better spots to do that, please let me know... > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2022-01-17 Jakub Jelinek > > PR c++/104031 > * cp-gimplify.c (cp_genericize_target_expr): Set DECL_CONTEXT of > TARGET_EXPR_SLOT to current_function_decl if it was NULL. > > * g++.dg/cpp1y/pr104031.C: New test. > > --- gcc/cp/cp-gimplify.c.jj 2022-01-14 12:09:13.003250834 +0100 > +++ gcc/cp/cp-gimplify.c 2022-01-16 21:34:52.300937996 +0100 > @@ -930,6 +930,11 @@ cp_genericize_init_expr (tree *stmt_p) > static void > cp_genericize_target_expr (tree *stmt_p) > { > + /* If TARGET_EXPR is created for some global var initializer, the slot > + will have NULL and so is_local_temp will return false for it. If > + this is a ssdf, set DECL_CONTEXT now. */ > + if (DECL_CONTEXT (TARGET_EXPR_SLOT (*stmt_p)) == NULL_TREE) > + DECL_CONTEXT (TARGET_EXPR_SLOT (*stmt_p)) = current_function_decl; > cp_genericize_init (&TARGET_EXPR_INITIAL (*stmt_p), > TARGET_EXPR_INITIAL (*stmt_p), > TARGET_EXPR_SLOT (*stmt_p)); We could use a local variable for TARGET_EXPR_SLOT (*stmt_p) instead of repeating it. OK either way. > --- gcc/testsuite/g++.dg/cpp1y/pr104031.C.jj 2022-01-16 21:30:14.977838079 +0100 > +++ gcc/testsuite/g++.dg/cpp1y/pr104031.C 2022-01-16 21:30:46.028401294 +0100 > @@ -0,0 +1,23 @@ > +// PR c++/104031 > +// { dg-do run { target c++14 } } > +// { dg-options "-O2" } > + > +struct A { > + A () {} > + ~A () {} > +}; > +struct B { > + A a; > + int b = 0; > +}; > +struct C > +{ > + [[gnu::noipa]] > + C (B x) { if (x.b != 42) __builtin_abort (); } > +}; > +static C c ({ .a = A{}, .b = 42 }); > + > +int > +main () > +{ > +} > > Jakub >