From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 34554 invoked by alias); 1 Aug 2017 19:47:05 -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 34345 invoked by uid 89); 1 Aug 2017 19:47:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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; Tue, 01 Aug 2017 19:47:03 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B6F3C04A24E; Tue, 1 Aug 2017 19:47:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2B6F3C04A24E 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-25.phx2.redhat.com [10.3.112.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2423D17D5F; Tue, 1 Aug 2017 19:47:00 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: Trevor Saunders , David Malcolm Subject: [PATCH 1/3] matching tokens: c-family parts Date: Tue, 01 Aug 2017 19:47:00 -0000 Message-Id: <1501618904-5593-2-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1501618904-5593-1-git-send-email-dmalcolm@redhat.com> References: <20170712131300.u3ofifbzkp52lcxa@ball> <1501618904-5593-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg00115.txt.bz2 (Unchanged since v1; already approved by Marek, assuming rest is approved) gcc/c-family/ChangeLog: * c-common.c (c_parse_error): Add rich_location * param, using it rather implicitly using input_location. * c-common.h (c_parse_error): Add rich_location * param. gcc/testsuite/ChangeLog: * c-c++-common/missing-close-symbol.c: New test case. * c-c++-common/missing-symbol.c: New test case. --- gcc/c-family/c-common.c | 17 ++++---- gcc/c-family/c-common.h | 3 +- gcc/testsuite/c-c++-common/missing-close-symbol.c | 33 +++++++++++++++ gcc/testsuite/c-c++-common/missing-symbol.c | 50 +++++++++++++++++++++++ 4 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/missing-close-symbol.c create mode 100644 gcc/testsuite/c-c++-common/missing-symbol.c diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index feb0904..30b0603 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -5949,12 +5949,13 @@ catenate_strings (const char *lhs, const char *rhs_start, int rhs_size) return result; } -/* Issue the error given by GMSGID, indicating that it occurred before - TOKEN, which had the associated VALUE. */ +/* Issue the error given by GMSGID at RICHLOC, indicating that it occurred + before TOKEN, which had the associated VALUE. */ void c_parse_error (const char *gmsgid, enum cpp_ttype token_type, - tree value, unsigned char token_flags) + tree value, unsigned char token_flags, + rich_location *richloc) { #define catenate_messages(M1, M2) catenate_strings ((M1), (M2), sizeof (M2)) @@ -5995,7 +5996,7 @@ c_parse_error (const char *gmsgid, enum cpp_ttype token_type, else message = catenate_messages (gmsgid, " before %s'\\x%x'"); - error (message, prefix, val); + error_at_rich_loc (richloc, message, prefix, val); free (message); message = NULL; } @@ -6023,7 +6024,7 @@ c_parse_error (const char *gmsgid, enum cpp_ttype token_type, else if (token_type == CPP_NAME) { message = catenate_messages (gmsgid, " before %qE"); - error (message, value); + error_at_rich_loc (richloc, message, value); free (message); message = NULL; } @@ -6036,16 +6037,16 @@ c_parse_error (const char *gmsgid, enum cpp_ttype token_type, else if (token_type < N_TTYPES) { message = catenate_messages (gmsgid, " before %qs token"); - error (message, cpp_type2name (token_type, token_flags)); + error_at_rich_loc (richloc, message, cpp_type2name (token_type, token_flags)); free (message); message = NULL; } else - error (gmsgid); + error_at_rich_loc (richloc, gmsgid); if (message) { - error (message); + error_at_rich_loc (richloc, message); free (message); } #undef catenate_messages diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index a29f1ad..63fe845 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1124,7 +1124,8 @@ extern void builtin_define_with_int_value (const char *, HOST_WIDE_INT); extern void builtin_define_type_sizeof (const char *, tree); extern void c_stddef_cpp_builtins (void); extern void fe_file_change (const line_map_ordinary *); -extern void c_parse_error (const char *, enum cpp_ttype, tree, unsigned char); +extern void c_parse_error (const char *, enum cpp_ttype, tree, unsigned char, + rich_location *richloc); /* In c-ppoutput.c */ extern void init_pp_output (FILE *); diff --git a/gcc/testsuite/c-c++-common/missing-close-symbol.c b/gcc/testsuite/c-c++-common/missing-close-symbol.c new file mode 100644 index 0000000..85b96f28 --- /dev/null +++ b/gcc/testsuite/c-c++-common/missing-close-symbol.c @@ -0,0 +1,33 @@ +/* { dg-options "-fdiagnostics-show-caret" } */ + +/* Verify that the C/C++ frontends show the pertinent opening symbol when + a closing symbol is missing. */ + +/* Verify that, when they are on the same line, that the opening symbol is + shown as a secondary range within the main diagnostic. */ + +void test_static_assert_same_line (void) +{ + _Static_assert(sizeof(int) >= sizeof(char), "msg"; /* { dg-error "expected '\\)' before ';' token" } */ + /* { dg-begin-multiline-output "" } + _Static_assert(sizeof(int) >= sizeof(char), "msg"; + ~ ^ + { dg-end-multiline-output "" } */ +} + +/* Verify that, when they are on different lines, that the opening symbol is + shown via a secondary diagnostic. */ + +void test_static_assert_different_line (void) +{ + _Static_assert(sizeof(int) >= sizeof(char), /* { dg-message "to match this '\\('" } */ + "msg"; /* { dg-error "expected '\\)' before ';' token" } */ + /* { dg-begin-multiline-output "" } + "msg"; + ^ + { dg-end-multiline-output "" } */ + /* { dg-begin-multiline-output "" } + _Static_assert(sizeof(int) >= sizeof(char), + ^ + { dg-end-multiline-output "" } */ +} diff --git a/gcc/testsuite/c-c++-common/missing-symbol.c b/gcc/testsuite/c-c++-common/missing-symbol.c new file mode 100644 index 0000000..33a501b --- /dev/null +++ b/gcc/testsuite/c-c++-common/missing-symbol.c @@ -0,0 +1,50 @@ +/* { dg-options "-fdiagnostics-show-caret" } */ + +extern int foo (void); +extern int bar (void); + +int missing_close_paren_in_switch (int i) +{ + switch (i /* { dg-message "10: to match this '\\('" } */ + { /* { dg-error "5: expected '\\)' before '.' token" } */ + /* { dg-begin-multiline-output "" } + { + ^ + { dg-end-multiline-output "" } */ + /* { dg-begin-multiline-output "" } + switch (i + ^ + { dg-end-multiline-output "" } */ + + case 0: + return 5; + default: + return i; + } +} /* { dg-error "1: expected" } */ + /* { dg-begin-multiline-output "" } + } + ^ + { dg-end-multiline-output "" } */ + +void missing_close_paren_in_if (void) +{ + if (foo () /* { dg-line start_of_if } */ + && bar () + { /* { dg-error "5: expected '\\)' before '.' token" } */ + /* { dg-begin-multiline-output "" } + { + ^ + { dg-end-multiline-output "" } */ + /* { dg-message "6: to match this '\\('" "" { target *-*-* } start_of_if } */ + /* { dg-begin-multiline-output "" } + if (foo () + ^ + { dg-end-multiline-output "" } */ + } + +} /* { dg-error "1: expected" } */ + /* { dg-begin-multiline-output "" } + } + ^ + { dg-end-multiline-output "" } */ -- 1.8.5.3