From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 114957 invoked by alias); 19 Aug 2017 00:23:32 -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 114359 invoked by uid 89); 19 Aug 2017 00:23:30 -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,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=RANGE 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; Sat, 19 Aug 2017 00:23:29 +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 E6DA3C0587D7 for ; Sat, 19 Aug 2017 00:23:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E6DA3C0587D7 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=dmalcolm@redhat.com Received: from c64.redhat.com (ovpn-112-20.phx2.redhat.com [10.3.112.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D29F619D7; Sat, 19 Aug 2017 00:23:26 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH 2/2] C: use full locations within c_parser_expr_list's vec Date: Sat, 19 Aug 2017 18:22:00 -0000 Message-Id: <1503104324-51207-2-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1503104324-51207-1-git-send-email-dmalcolm@redhat.com> References: <1503104324-51207-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg01167.txt.bz2 The previous patch uncovered a bug in how c_parser_expr_list builds the vec: it was only using the location of the first token within each assignment-expression in the expr-list. This shows up in e.g. this -Wformat warning, where only part of the 2nd param is underlined: printf("hello %i", (long)0); ~^ ~ %li This patch fixes c_parser_expr_list to use the full range of each assignment-expression in the list for the vec, so that for the above we print: printf("hello %i", (long)0); ~^ ~~~~~~~ %li Successfully bootstrapped®rtested on x86_64-pc-linux-gnu. OK for trunk? gcc/c/ChangeLog: * c-parser.c (c_parser_expr_list): Use c_expr::get_location () rather than peeking the location of the first token. * c-tree.h (c_expr::get_location): New method. gcc/testsuite/ChangeLog: * gcc.dg/format/diagnostic-ranges.c (test_mismatching_types): Update expected result to show all of "(long)0" being underlined. * gcc.dg/plugin/diagnostic-test-string-literals-1.c (test_multitoken_macro): Update expected underlining. --- gcc/c/c-parser.c | 11 +++++------ gcc/c/c-tree.h | 8 ++++++++ gcc/testsuite/gcc.dg/format/diagnostic-ranges.c | 2 +- .../gcc.dg/plugin/diagnostic-test-string-literals-1.c | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 1402ba6..dfc75e0 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -8933,7 +8933,6 @@ c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, vec *ret; vec *orig_types; struct c_expr expr; - location_t loc = c_parser_peek_token (parser)->location; unsigned int idx = 0; ret = make_tree_vector (); @@ -8946,14 +8945,14 @@ c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, c_parser_check_literal_zero (parser, literal_zero_mask, 0); expr = c_parser_expr_no_commas (parser, NULL); if (convert_p) - expr = convert_lvalue_to_rvalue (loc, expr, true, true); + expr = convert_lvalue_to_rvalue (expr.get_location (), expr, true, true); if (fold_p) expr.value = c_fully_fold (expr.value, false, NULL); ret->quick_push (expr.value); if (orig_types) orig_types->quick_push (expr.original_type); if (locations) - locations->safe_push (loc); + locations->safe_push (expr.get_location ()); if (sizeof_arg != NULL && expr.original_code == SIZEOF_EXPR) { @@ -8963,19 +8962,19 @@ c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, while (c_parser_next_token_is (parser, CPP_COMMA)) { c_parser_consume_token (parser); - loc = c_parser_peek_token (parser)->location; if (literal_zero_mask) c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1); expr = c_parser_expr_no_commas (parser, NULL); if (convert_p) - expr = convert_lvalue_to_rvalue (loc, expr, true, true); + expr = convert_lvalue_to_rvalue (expr.get_location (), expr, true, + true); if (fold_p) expr.value = c_fully_fold (expr.value, false, NULL); vec_safe_push (ret, expr.value); if (orig_types) vec_safe_push (orig_types, expr.original_type); if (locations) - locations->safe_push (loc); + locations->safe_push (expr.get_location ()); if (++idx < 3 && sizeof_arg != NULL && expr.original_code == SIZEOF_EXPR) diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 92bcc70..5182cc5 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -147,6 +147,14 @@ struct c_expr location_t get_start () const { return src_range.m_start; } location_t get_finish () const { return src_range.m_finish; } + location_t get_location () const + { + if (CAN_HAVE_LOCATION_P (value)) + return EXPR_LOCATION (value); + else + return make_location (get_start (), get_start (), get_finish ()); + } + /* Set the value to error_mark_node whilst ensuring that src_range is initialized. */ void set_error () diff --git a/gcc/testsuite/gcc.dg/format/diagnostic-ranges.c b/gcc/testsuite/gcc.dg/format/diagnostic-ranges.c index bc6f665..e56e159 100644 --- a/gcc/testsuite/gcc.dg/format/diagnostic-ranges.c +++ b/gcc/testsuite/gcc.dg/format/diagnostic-ranges.c @@ -25,7 +25,7 @@ void test_mismatching_types (const char *msg) printf("hello %i", (long)0); /* { dg-warning "format '%i' expects argument of type 'int', but argument 2 has type 'long int' " } */ /* { dg-begin-multiline-output "" } printf("hello %i", (long)0); - ~^ ~ + ~^ ~~~~~~~ %li { dg-end-multiline-output "" } */ } diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c index 03f042a..bea86af 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c @@ -250,7 +250,7 @@ test_multitoken_macro (void) __emit_string_literal_range (RANGE, 4, 3, 6); /* { dg-begin-multiline-output "" } #define RANGE ("0123456789") - ^ + ^~~~~~~~~~~~~~ { dg-end-multiline-output "" } */ /* { dg-begin-multiline-output "" } __emit_string_literal_range (RANGE, 4, 3, 6); -- 1.8.5.3