From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12427 invoked by alias); 10 Nov 2017 21:44:11 -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 12364 invoked by uid 89); 10 Nov 2017 21:44:11 -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=families, spaghetti, Hx-languages-length:4282 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; Fri, 10 Nov 2017 21:44:09 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 582687E420; Fri, 10 Nov 2017 21:44:08 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-13.phx2.redhat.com [10.3.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3DCA708F3; Fri, 10 Nov 2017 21:44:06 +0000 (UTC) From: David Malcolm To: Jason Merrill Cc: Nathan Sidwell , Jakub Jelinek , Richard Biener , gcc-patches List , David Malcolm Subject: [PATCH 14/14] pp_c_cast_expression: don't print casts for location wrappers Date: Fri, 10 Nov 2017 21:44:00 -0000 Message-Id: <1510350329-48956-15-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1510350329-48956-1-git-send-email-dmalcolm@redhat.com> References: <1510350329-48956-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg00895.txt.bz2 This patch suppresses the user-visible printing of location wrappers for "%E" (and "%qE"), adding test coverage via selftests. Seen via a failure of g++.dg/parse/error34.C and g++.dg/parse/error35.C. gcc/c-family/ChangeLog: * c-common.c (selftest::c_family_tests): Call selftest::c_pretty_print_c_tests. * c-common.h (selftest::c_pretty_print_c_tests): New decl. * c-pretty-print.c: Include "selftest.h". (pp_c_cast_expression): Don't print casts for location wrappers. (selftest::assert_c_pretty_printer_output): New function. (ASSERT_C_PRETTY_PRINTER_OUTPUT): New macro. (selftest::test_location_wrappers): New function. (selftest::c_pretty_print_c_tests): New function. --- gcc/c-family/c-common.c | 1 + gcc/c-family/c-common.h | 1 + gcc/c-family/c-pretty-print.c | 66 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 739c54e..bfcf7b9 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -8126,6 +8126,7 @@ void c_family_tests (void) { c_format_c_tests (); + c_pretty_print_c_tests (); } } // namespace selftest diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 7e1877e..1f15762 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1559,6 +1559,7 @@ namespace selftest { /* Declarations for specific families of tests within c-family, by source file, in alphabetical order. */ extern void c_format_c_tests (void); + extern void c_pretty_print_c_tests (void); /* The entrypoint for running all of the above tests. */ extern void c_family_tests (void); diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c index 0f48b9e..fd4cf0e 100644 --- a/gcc/c-family/c-pretty-print.c +++ b/gcc/c-family/c-pretty-print.c @@ -28,6 +28,7 @@ along with GCC; see the file COPYING3. If not see #include "attribs.h" #include "intl.h" #include "tree-pretty-print.h" +#include "selftest.h" /* The pretty-printer code is primarily designed to closely follow (GNU) C and C++ grammars. That is to be contrasted with spaghetti @@ -1819,7 +1820,8 @@ pp_c_cast_expression (c_pretty_printer *pp, tree e) case FIX_TRUNC_EXPR: CASE_CONVERT: case VIEW_CONVERT_EXPR: - pp_c_type_cast (pp, TREE_TYPE (e)); + if (!location_wrapper_p (e)) + pp_c_type_cast (pp, TREE_TYPE (e)); pp_c_cast_expression (pp, TREE_OPERAND (e, 0)); break; @@ -2409,3 +2411,65 @@ pp_c_tree_decl_identifier (c_pretty_printer *pp, tree t) pp_c_identifier (pp, name); } + +#if CHECKING_P + +namespace selftest { + +/* Selftests for pretty-printing trees. */ + +/* Verify that EXPR printed by c_pretty_printer is EXPECTED, using + LOC as the effective location for any failures. */ + +static void +assert_c_pretty_printer_output (const location &loc, const char *expected, + tree expr) +{ + c_pretty_printer pp; + pp.expression (expr); + ASSERT_STREQ_AT (loc, expected, pp_formatted_text (&pp)); +} + +/* Helper function for calling assert_c_pretty_printer_output. + This is to avoid having to write SELFTEST_LOCATION. */ + +#define ASSERT_C_PRETTY_PRINTER_OUTPUT(EXPECTED, EXPR) \ + SELFTEST_BEGIN_STMT \ + assert_c_pretty_printer_output ((SELFTEST_LOCATION), \ + (EXPECTED), \ + (EXPR)); \ + SELFTEST_END_STMT + +/* Verify that location wrappers don't show up in pretty-printed output. */ + +static void +test_location_wrappers () +{ + /* VAR_DECL. */ + tree id = get_identifier ("foo"); + tree decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, id, + integer_type_node); + tree wrapped_decl = maybe_wrap_with_location (decl, BUILTINS_LOCATION); + ASSERT_NE (wrapped_decl, decl); + ASSERT_C_PRETTY_PRINTER_OUTPUT ("foo", decl); + ASSERT_C_PRETTY_PRINTER_OUTPUT ("foo", wrapped_decl); + + /* INTEGER_CST. */ + tree int_cst = build_int_cst (integer_type_node, 42); + tree wrapped_cst = maybe_wrap_with_location (int_cst, BUILTINS_LOCATION); + ASSERT_NE (wrapped_cst, int_cst); + ASSERT_C_PRETTY_PRINTER_OUTPUT ("42", int_cst); + ASSERT_C_PRETTY_PRINTER_OUTPUT ("42", wrapped_cst); +} + +/* Run all of the selftests within this file. */ + +void +c_pretty_print_c_tests () +{ + test_location_wrappers (); +} + +} // namespace selftest + +#endif /* CHECKING_P */ -- 1.8.5.3