From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27951 invoked by alias); 22 Feb 2018 02:53:23 -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 27722 invoked by uid 89); 22 Feb 2018 02:53:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: =?ISO-8859-1?Q?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=The=c2, by=c2, guideline, no?= 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; Thu, 22 Feb 2018 02:53:08 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA5E73DE40; Thu, 22 Feb 2018 02:53:07 +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 B6965600D3; Thu, 22 Feb 2018 02:53:06 +0000 (UTC) Subject: Re: [PATCH] avoid bogus -Wstringop-truncation when inlining (PR 84480) To: Martin Sebor , Gcc Patch List References: From: Jeff Law Message-ID: <573588f4-aa4d-ccbe-3eda-dce9e78e308a@redhat.com> Date: Thu, 22 Feb 2018 02:53: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/msg01256.txt.bz2 On 02/21/2018 02:19 PM, Martin Sebor wrote: > The attached patch eliminates -Wstringop-truncation false > positives reported in bug 84480 - bogus -Wstringop-truncation > despite assignment with an inlined string literal.  It does > that by delegating early strncpy checks during folding to > the same machinery in tree-ssa-strlen that looks for a NUL > assignment to the destination the next statement. > > The patch also adds inlining context to the warnings via > the %G directive. > > Tested on x86_64-linux with no regressions. > > Martin > > gcc-84480.diff > > > PR tree-optimization/84480 - bogus -Wstringop-truncation despite assignment with an inlined string literal > > gcc/ChangeLog: > > PR tree-optimization/84480 > * gimple-fold.c (gimple_fold_builtin_strcpy): Move warnings > to maybe_diag_stxncpy_trunc. Call it. > * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Integrate warnings > from gimple_fold_builtin_strcpy. Print inlining stack. > (handle_builtin_stxncpy): Print inlining stack. > * tree-ssa-strlen.h (maybe_diag_stxncpy_trunc): Declare. > > gcc/testsuite/ChangeLog: > > PR tree-optimization/84480 > * c-c++-common/Wstringop-truncation.c: Adjust text of expected warnings. > * g++.dg/warn/Wstringop-truncation-1.C: New test. In general our guidelines are that the users of a .h file should include any dependencies rather than having the .h file itself include other .h files (Now that we've detangled the header files we may want to revisit that guideline, but that's not a gcc-8 item). It looks like gimple-fold.c and tree-ssa-strlen.c already have the prereqs. So in theory you should be able to just remove the bogus #includes from tree-ssa-strlen.h. In general we want to avoid adding more warnings to folding code. But I think the argument here is that we're already trying to warn within the folder and just doing a poor job -- so we're removing that implementation and delegating the warning to a better implementation. Right? So I think you just need to remove the bogus #includes from tree-ssa-strlen and this is OK. jeff