From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id 5E4E03858D35 for ; Tue, 25 Aug 2020 02:37:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5E4E03858D35 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-423--FaGp441NJ2tnNOlMrg9UA-1; Mon, 24 Aug 2020 22:37:18 -0400 X-MC-Unique: -FaGp441NJ2tnNOlMrg9UA-1 Received: by mail-qk1-f198.google.com with SMTP id s185so6057134qkf.13 for ; Mon, 24 Aug 2020 19:37:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=/vmEvY0i/9ehK39VJrafKbCCtRm1tx4mpFrWDlZr0/E=; b=boNwoZQPiTIBm0NM39k9+a2sv26VcukEvLwWy90F3i2FJ6QZBDXuBgOjccyXmLPSVw 1rfMi5NPnVDABGPYyVDIbQYHxwR7sd3Wd32Nl16FcDH1zYtgEBkth1VqU1NpXK49ao4X AaHYHAjmFjV+TwKf60A+ny0GSJAvhjlIce0y/rjIzZZKdjQ+cFdzWgqeLM/nP6qbqTlO IQIFemTqXv8ba7b9P7qGx3KhSmCK/lQrNLdLW/B1k9SzPqgnFcrwVqbxYU3icWimSvZt 4njqwOjKO1Zc1Z1wlIv6lK1/TbZNVx/0f1pg7vsfCakdwoXSYlc81g0U1R1I/M66Uqo8 YQXA== X-Gm-Message-State: AOAM531kvrVnOOpirv/HL9UUTgdHrffxqoK+Pe2b3XyZNxdEDGzLlx3A yfGx3V62PIZpwR6nizRxmVXMBnhgVOIIYJohw9+B+RR36qjSQnNHjbjgclZd0w2qz3AH7x7+OdK Uq7GowfzovQQaGZ9G9w== X-Received: by 2002:a37:ae03:: with SMTP id x3mr7321863qke.313.1598323037042; Mon, 24 Aug 2020 19:37:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyV8cxC2BaaFgD2ibflWA/44tQGP9ug+sKgn9VDw1jpKXjscmiVGNtZmqNyk3y+g5DUYE7hcg== X-Received: by 2002:a37:ae03:: with SMTP id x3mr7321848qke.313.1598323036609; Mon, 24 Aug 2020 19:37:16 -0700 (PDT) Received: from [192.168.1.148] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id 20sm13310203qtp.53.2020.08.24.19.37.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Aug 2020 19:37:15 -0700 (PDT) Subject: Re: [PATCH] c++: Fix up ptr.~PTR () handling [PR96721] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: <20200824213412.GR2363@tucnak> From: Jason Merrill Message-ID: <9de2080c-0705-bb20-3714-2bf8724d1c72@redhat.com> Date: Mon, 24 Aug 2020 22:37:14 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200824213412.GR2363@tucnak> Content-Language: en-US X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.1 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_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Tue, 25 Aug 2020 02:37:21 -0000 On 8/24/20 5:34 PM, Jakub Jelinek wrote: > Hi! > > The following testcase is miscompiled, because build_trivial_dtor_call > handles the case when instance is a pointer by adding a clobber to what > the pointer points to (which is desirable e.g. for delete) rather than the > pointer itself. That is I think always desirable behavior for references, > but for pointers for the pseudo dtor case it is not. > > Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for > trunk? OK. > 2020-08-24 Jakub Jelinek > > PR c++/96721 > * cp-tree.h (build_trivial_dtor_call): Add bool argument defaulted > to false. > * call.c (build_trivial_dtor_call): Add NO_PTR_DEREF argument. If > instance is a pointer and NO_PTR_DEREF is true, clobber the pointer > rather than what it points to. > * semantics.c (finish_call_expr): Call build_trivial_dtor_call with > true as NO_PTR_DEREF. > > * g++.dg/opt/flifetime-dse8.C: New test. > > --- gcc/cp/cp-tree.h.jj 2020-08-24 10:00:01.383257572 +0200 > +++ gcc/cp/cp-tree.h 2020-08-24 12:28:02.698410896 +0200 > @@ -6248,7 +6248,7 @@ extern bool null_member_pointer_value_p > extern bool sufficient_parms_p (const_tree); > extern tree type_decays_to (tree); > extern tree extract_call_expr (tree); > -extern tree build_trivial_dtor_call (tree); > +extern tree build_trivial_dtor_call (tree, bool = false); > extern tree build_user_type_conversion (tree, tree, int, > tsubst_flags_t); > extern tree build_new_function_call (tree, vec **, > --- gcc/cp/call.c.jj 2020-08-18 07:50:18.564922335 +0200 > +++ gcc/cp/call.c 2020-08-24 12:30:55.211961352 +0200 > @@ -8430,10 +8430,12 @@ conv_binds_ref_to_prvalue (conversion *c > } > > /* Call the trivial destructor for INSTANCE, which can be either an lvalue of > - class type or a pointer to class type. */ > + class type or a pointer to class type. If NO_PTR_DEREF is true and > + INSTANCE has pointer type, clobber the pointer rather than what it points > + to. */ > > tree > -build_trivial_dtor_call (tree instance) > +build_trivial_dtor_call (tree instance, bool no_ptr_deref) > { > gcc_assert (!is_dummy_object (instance)); > > @@ -8443,7 +8445,8 @@ build_trivial_dtor_call (tree instance) > return fold_convert (void_type_node, instance); > } > > - if (INDIRECT_TYPE_P (TREE_TYPE (instance))) > + if (INDIRECT_TYPE_P (TREE_TYPE (instance)) > + && (!no_ptr_deref || TYPE_REF_P (TREE_TYPE (instance)))) > { > if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (instance)))) > goto no_clobber; > --- gcc/cp/semantics.c.jj 2020-08-18 07:50:18.653921086 +0200 > +++ gcc/cp/semantics.c 2020-08-24 12:31:06.564800148 +0200 > @@ -2713,7 +2713,7 @@ finish_call_expr (tree fn, vec denoted by the object expression of the class member access. */ > tree ob = TREE_OPERAND (fn, 0); > if (obvalue_p (ob)) > - result = build_trivial_dtor_call (ob); > + result = build_trivial_dtor_call (ob, true); > else > /* No location to clobber. */ > result = convert_to_void (ob, ICV_STATEMENT, complain); > --- gcc/testsuite/g++.dg/opt/flifetime-dse8.C.jj 2020-08-24 12:36:24.585285134 +0200 > +++ gcc/testsuite/g++.dg/opt/flifetime-dse8.C 2020-08-24 12:36:20.341345380 +0200 > @@ -0,0 +1,12 @@ > +// PR c++/96721 > +// { dg-do run } > +// { dg-options "-O2 -flifetime-dse" } > + > +typedef int *T; > + > +int > +main () > +{ > + T a = T (); > + a.~T (); > +} > > Jakub >