From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 607FD3857C42 for ; Wed, 29 Jul 2020 20:27:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 607FD3857C42 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-226-ezM-HgMFO6yxqxG2ZbOspw-1; Wed, 29 Jul 2020 16:27:37 -0400 X-MC-Unique: ezM-HgMFO6yxqxG2ZbOspw-1 Received: by mail-qv1-f71.google.com with SMTP id p15so3497054qvv.7 for ; Wed, 29 Jul 2020 13:27:37 -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:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=3KavSAolEFhucHFsLFRzZyvPD2kOagx+Ne9a0Lldslw=; b=kv0O8GCMvFbRvCkYpThSeTo26vjcnxiKExdCrGzAr840UuG1gp+v7wgrK7MFGFPrb1 PYtmmQ7EB9gPO/4QrB+27q4dxVnAOVyUwrIuZwbPPc1SXmpRTlOqkSdI8+GNbRL6BjJ5 qbrprQ8QARZVVO9d3RZElDIltMAdwG3DzUOlfMhRBWu6gBpIN6TJudbohgqg4IMOSQtd 3NiENoKLYIVGK+2n0oyYdg6LbpawQ6Gy2tJtFGxnY4p6YgRgkia6WOdTGtB2N25yEjvI u/H5YhhUbmFwzJ7SQfdLkTZu/wIr1/eDup/vQkOmzcwziIS2jWQhIcfZnq9OdQhdiU6u kUJQ== X-Gm-Message-State: AOAM532Sav7nfBcbGmWfzU/M/XSutYdADFVNBqZa4y/rhq+oc4VLgOSE Ecf3i2Mycb2VbfoMSlRCgSJK+dVGbha35ra+OuYQDZGoUw34QsimLMQSCGk0SnMEyI8gUw7lvA6 Cxjzb813Ei8lETS5OLQ== X-Received: by 2002:a37:855:: with SMTP id 82mr21091108qki.32.1596054456461; Wed, 29 Jul 2020 13:27:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQKSnqXUAdAZGlXSJn2nWJJ5/You0o3PoWydM5OouZAGxYteyVlj84HvqjtOfZL+r9f7P7sw== X-Received: by 2002:a37:855:: with SMTP id 82mr21091083qki.32.1596054456110; Wed, 29 Jul 2020 13:27:36 -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 w32sm790671qtw.66.2020.07.29.13.27.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jul 2020 13:27:35 -0700 (PDT) Subject: Re: [PATCH] avoid -Wnonnull on synthesized condition in static_cast (PR 96003) To: Martin Sebor , gcc-patches References: From: Jason Merrill Message-ID: <807b1f13-3ad1-48b1-340b-a448deb827ac@redhat.com> Date: Wed, 29 Jul 2020 16:27:34 -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: Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, BODY_8BITS, 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: Wed, 29 Jul 2020 20:27:40 -0000 On 7/23/20 3:08 PM, Martin Sebor wrote: > Another test case added to the bug since I posted the patch shows > that the no-warning bit set by the C++ front end is easily lost > during early folding, triggering the -Wnonull again despite > the suppression.  The attached revision tweaks the folder in just > this one case to let the suppression take effect in this situation. > > In light of how pervasive this potential for stripping looks (none > of the other folders preserves the bit) the tweak feels like a band- > aid rather than a general solution.  But implementing something > better (and mainly developing tests to verify that it works in > general) would probably be quite the project.  So I leave it for > some other time. How about in check_function_arguments_recurse COND_EXPR handling, checking for TREE_NO_WARNING on the condition? Then we wouldn't need to deal with setting and copying it on the COND_EXPR itself. > > On 7/17/20 1:00 PM, Martin Sebor wrote: >> The recent enhancement to treat the implicit this pointer argument >> as nonnull in member functions triggers spurious -Wnonnull for >> the synthesized conditional expression the C++ front end replaces >> the pointer with in some static_cast expressions.  The front end >> already sets the no-warning bit for the test but not for the whole >> conditional expression, so the attached fix extends the same solution >> to it. >> >> The consequence of this fix is that user-written code like this: >> >>    static_cast(p ? p : 0)->f (); >> or >>    static_cast(p ? p : nullptr)->f (); >> >> don't trigger the warning because they are both transformed into >> the same expression as: >> >>    static_cast(p)->f (); >> >> What still does trigger it is this: >> >>    static_cast(p ? p : (T*)0)->f (); >> >> because here it's the inner COND_EXPR's no-warning bit that's set >> (the outer one is clear), whereas in the former expressions it's >> the other way around.  It would be nice if this worked consistently >> but I didn't see an easy way to do that and more than a quick fix >> seems outside the scope for this bug. >> >> Another case reported by someone else in the same bug involves >> a dynamic_cast.  A simplified test case goes something like this: >> >>    if (dynamic_cast(p)) >>      dynamic_cast(p)->f (); >> >> The root cause is the same: the front end emitting the COND_EXPR >> >>    ((p != 0) ? ((T*)__dynamic_cast(p, (& _ZTI1B), (& _ZTI1C), 0)) : 0) >> >> I decided not to suppress the warning in this case because doing >> so would also suppress it in unconditional calls with the result >> of the cast: >> >>    dynamic_cast(p)->f (); >> >> and that doesn't seem helpful.  Instead, I'd suggest to make >> the second cast in the if statement to reference to T&: >> >>    if (dynamic_cast(p)) >>      dynamic_cast(*p).f (); >> >> Martin