From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18665 invoked by alias); 17 Dec 2017 16:26:34 -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 18651 invoked by uid 89); 17 Dec 2017 16:26:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Pull 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; Sun, 17 Dec 2017 16:26:32 +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 230EC5D5ED; Sun, 17 Dec 2017 16:26:31 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-35.phx2.redhat.com [10.3.112.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DD226E700; Sun, 17 Dec 2017 16:26:29 +0000 (UTC) From: David Malcolm To: Jason Merrill Cc: Nathan Sidwell , Jakub Jelinek , Richard Biener , gcc-patches List , David Malcolm Subject: [v2 of PATCH 13/14] c-format.c: handle location wrappers Date: Sun, 17 Dec 2017 16:26:00 -0000 Message-Id: <1513528183-16972-1-git-send-email-dmalcolm@redhat.com> In-Reply-To: <479bff3c-baaa-26c0-c7b4-c5c69cee2d32@redhat.com> References: <479bff3c-baaa-26c0-c7b4-c5c69cee2d32@redhat.com> X-IsSubscribed: yes X-SW-Source: 2017-12/txt/msg01136.txt.bz2 On Mon, 2017-12-11 at 18:45 -0500, Jason Merrill wrote: > On 11/10/2017 04:45 PM, David Malcolm wrote: > > gcc/c-family/ChangeLog: > > * c-format.c (check_format_arg): Strip any location wrapper > > around > > format_tree. > > --- > > gcc/c-family/c-format.c | 9 ++++++++- > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c > > index 164d035..6b436ec 100644 > > --- a/gcc/c-family/c-format.c > > +++ b/gcc/c-family/c-format.c > > @@ -1536,6 +1536,8 @@ check_format_arg (void *ctx, tree > > format_tree, > > > > location_t fmt_param_loc = EXPR_LOC_OR_LOC (format_tree, > > input_location); > > > > + STRIP_ANY_LOCATION_WRAPPER (format_tree); > > + > > if (VAR_P (format_tree)) > > { > > /* Pull out a constant value if the front end didn't. */ > > It seems like we want fold_for_warn here instead of the special > variable > handling. That probably makes sense for the other places you change > in > this patch, too. > > Jason Here's an updated version of the patch which uses fold_for_warn, rather than STRIP_ANY_LOCATION_WRAPPER. In one place it was necessary to add a STRIP_NOPS, since the fold_for_warn can add a cast around a: ADDR_EXPR ( STRING_CST) turning it into a: NOP_EXPR ( ADDR_EXPR ( STRING_CST)) which without a STRIP_NOPS leads to a bail-out here: 1596 if (TREE_CODE (format_tree) != ADDR_EXPR) 1597 { 1598 res->number_non_literal++; 1599 return; 1600 } and thus -Wformat-security not recognizing string literals. Successfully bootstrapped®rtested on x86_64-pc-linux-gnu, as part of the kit. Is this OK for trunk, assuming the rest of the kit is approved? gcc/c-family/ChangeLog: * c-format.c (check_format_arg): Strip any location wrapper around format_tree. --- gcc/c-family/c-format.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c index 164d035..47aca55 100644 --- a/gcc/c-family/c-format.c +++ b/gcc/c-family/c-format.c @@ -1536,6 +1536,8 @@ check_format_arg (void *ctx, tree format_tree, location_t fmt_param_loc = EXPR_LOC_OR_LOC (format_tree, input_location); + format_tree = fold_for_warn (format_tree); + if (VAR_P (format_tree)) { /* Pull out a constant value if the front end didn't. */ @@ -1591,13 +1593,14 @@ check_format_arg (void *ctx, tree format_tree, } offset = int_cst_value (arg1); } + STRIP_NOPS (format_tree); if (TREE_CODE (format_tree) != ADDR_EXPR) { res->number_non_literal++; return; } res->format_string_loc = EXPR_LOC_OR_LOC (format_tree, input_location); - format_tree = TREE_OPERAND (format_tree, 0); + format_tree = fold_for_warn (TREE_OPERAND (format_tree, 0)); if (format_types[info->format_type].flags & (int) FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL) { @@ -1634,7 +1637,9 @@ check_format_arg (void *ctx, tree format_tree, if (TREE_CODE (format_tree) == ARRAY_REF && tree_fits_shwi_p (TREE_OPERAND (format_tree, 1)) && (offset += tree_to_shwi (TREE_OPERAND (format_tree, 1))) >= 0) - format_tree = TREE_OPERAND (format_tree, 0); + { + format_tree = fold_for_warn (TREE_OPERAND (format_tree, 0)); + } if (offset < 0) { res->number_non_literal++; -- 1.8.5.3