From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21266 invoked by alias); 26 Feb 2018 19:13:47 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 21250 invoked by uid 89); 26 Feb 2018 19:13:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=Hx-languages-length:1612, HContent-Transfer-Encoding:8bit X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Feb 2018 19:13:44 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A95D5117D; Mon, 26 Feb 2018 19:13:43 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-67.rdu2.redhat.com [10.10.112.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7188160C82; Mon, 26 Feb 2018 19:13:42 +0000 (UTC) Subject: Re: [PING] [PATCH] consider successor blocks when avoiding -Wstringop-truncation (PR 84468) To: Martin Sebor , Gcc Patch List References: From: Jeff Law Message-ID: Date: Mon, 26 Feb 2018 19:13:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2018-02/txt/msg01453.txt.bz2 On 02/24/2018 05:11 PM, Martin Sebor wrote: > Attached is an updated patch with a fix for a bad assumption > exposed by building the linux kernel. > > On 02/19/2018 07:50 PM, Martin Sebor wrote: >> PR 84468 points out a false positive in -Wstringop-truncation >> in code like this: >> >>   struct A { char a[4]; }; >> >>   void f (struct A *p, const struct A *q) >>   { >>     if (p->a) >>       strncpy (p->a, q->a, sizeof p->a - 1);   // warning here >> >>     p->a[3] = '\0'; >>   } >> >> The warning is due to the code checking only the same basic block >> as the one with the strncpy call for an assignment to the destination >> to avoid it, but failing to check the successor basic block if there >> is no subsequent statement in the current block.  (Eliminating >> the conditional is being tracked in PR 21474.) >> >> The attached test case adds logic to avoid this false positive. >> I don't know under what circumstances there could be more than >> one successor block here so I don't handle that case. So this is feeling more and more like we need to go back to the ideas behind checking the virtual operand chains. The patch as-written does not properly handle the case where BB has multiple outgoing edges. For gcc-8 you could probably get away with checking that you have precisely one outgoing edge without EDGE_ABNORMAL set in its flags in addition to the checks you're already doing. But again, it's feeling more and more like the right fix is to go back and walk the virtual operands. Jeff