From patchwork Sat Nov 18 02:52:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 839203 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-467248-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="HlxWwS9A"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ydzxv0wd1z9s72 for ; Sat, 18 Nov 2017 13:50:58 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=KK4jzpxPNNmH+Ood0CL3sd8fjZqTMyLXgTM2CkbzrmcsL+fKs9kka 6GbNyicUMYRdUBmXVJc+evpIZvccHDdEiHwLbd6Dvj62LgrxeD7g3+wJFTq4HxKS yxLu7KzRpuUSHU1n+eNFtFs3zkwzXnpOcjX7uIqbsgMLiHxdFvsHdQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=98b4itBEFGC1NIJ2TDUVHbD0UYg=; b=HlxWwS9AkF/b+vQ02ulA Sj9pRtl7j1vPpMdOQbNPMaS13Py8hM6b6BoBNgMPXG+qF0Hd+972b2mf+D/vyGDD OgUs+r5z5WL3R2l0Ged/7ySZoVsQ3nFkV/HWcmSP6wVdM5DOYxGY7fQhy7wgGVmB +RQwtwLzjrrquvdtvdg1IYY= Received: (qmail 67337 invoked by alias); 18 Nov 2017 02:50:42 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 67216 invoked by uid 89); 18 Nov 2017 02:50:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KB_WAM_FROM_NAME_SINGLEWORD, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=idk, LOCATION, va_gc 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, 18 Nov 2017 02:50:40 +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 6A37CC049D5F; Sat, 18 Nov 2017 02:50:38 +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 C1DF060BF3; Sat, 18 Nov 2017 02:50:36 +0000 (UTC) From: David Malcolm To: Jason Merrill Cc: Nathan Sidwell , Jakub Jelinek , Richard Biener , gcc-patches List , David Malcolm Subject: [PATCH 01/11] C++: Add location wrappers for all constants and decls Date: Fri, 17 Nov 2017 21:52:33 -0500 Message-Id: <1510973563-10046-2-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1510973563-10046-1-git-send-email-dmalcolm@redhat.com> References: <1510350329-48956-1-git-send-email-dmalcolm@redhat.com> <1510973563-10046-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes This redoes the approach in the v1 patch, doing it for all constants and decls, rather than just at callsite args. gcc/cp/ChangeLog: * parser.c (cp_parser_primary_expression): Add location wrappers to constants. (cp_parser_postfix_expression): Remove the "wrap_locations_p" param to cp_parser_parenthesized_expression_list from the earlier patch. (cp_parser_parenthesized_expression_list): Likewise; don't add location wrappers. * semantics.c (finish_id_expression): Rename to... (finish_id_expression_1): ...this. (finish_id_expression): Reintroduce, wrapping the result in a location wrapper, if necessary. --- gcc/cp/parser.c | 29 ++++++++++++---------------- gcc/cp/semantics.c | 56 ++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 54 insertions(+), 31 deletions(-) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 15489c1..8834542 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -2054,8 +2054,7 @@ static tree cp_parser_postfix_open_square_expression static tree cp_parser_postfix_dot_deref_expression (cp_parser *, enum cpp_ttype, cp_expr, bool, cp_id_kind *, location_t); static vec *cp_parser_parenthesized_expression_list - (cp_parser *, int, bool, bool, bool *, location_t * = NULL, - bool = false); + (cp_parser *, int, bool, bool, bool *, location_t * = NULL); /* Values for the second parameter of cp_parser_parenthesized_expression_list. */ enum { non_attr = 0, normal_attr = 1, id_attr = 2 }; static void cp_parser_pseudo_destructor_name @@ -5066,7 +5065,8 @@ cp_parser_primary_expression (cp_parser *parser, if (!cast_p) cp_parser_non_integral_constant_expression (parser, NIC_FLOAT); } - return cp_expr (token->u.value, token->location); + return (cp_expr (token->u.value, token->location) + .maybe_add_location_wrapper ()); case CPP_CHAR_USERDEF: case CPP_CHAR16_USERDEF: @@ -5088,9 +5088,10 @@ cp_parser_primary_expression (cp_parser *parser, /* ??? Should wide strings be allowed when parser->translate_strings_p is false (i.e. in attributes)? If not, we can kill the third argument to cp_parser_string_literal. */ - return cp_parser_string_literal (parser, - parser->translate_strings_p, - true); + return (cp_parser_string_literal (parser, + parser->translate_strings_p, + true) + .maybe_add_location_wrapper ()); case CPP_OPEN_PAREN: /* If we see `( { ' then we are looking at the beginning of @@ -7099,8 +7100,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p, (parser, non_attr, /*cast_p=*/false, /*allow_expansion_p=*/true, /*non_constant_p=*/NULL, - /*close_paren_loc=*/&close_paren_loc, - /*wrap_locations_p=*/true)); + /*close_paren_loc=*/&close_paren_loc)); if (is_builtin_constant_p) { parser->integral_constant_expression_p @@ -7764,8 +7764,7 @@ cp_parser_parenthesized_expression_list (cp_parser* parser, bool cast_p, bool allow_expansion_p, bool *non_constant_p, - location_t *close_paren_loc, - bool wrap_locations_p) + location_t *close_paren_loc) { vec *expression_list; bool fold_expr_p = is_attribute_list != non_attr; @@ -7788,12 +7787,12 @@ cp_parser_parenthesized_expression_list (cp_parser* parser, = parser->greater_than_is_operator_p; parser->greater_than_is_operator_p = true; - cp_expr expr (NULL_TREE); - /* Consume expressions until there are no more. */ if (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN)) while (true) { + tree expr; + /* At the beginning of attribute lists, check to see if the next token is an identifier. */ if (is_attribute_list == id_attr @@ -7847,15 +7846,11 @@ cp_parser_parenthesized_expression_list (cp_parser* parser, expr = make_pack_expansion (expr); } - if (wrap_locations_p) - if (!processing_template_decl) - expr.maybe_add_location_wrapper (); - /* Add it to the list. We add error_mark_node expressions to the list, so that we can still tell if the correct form for a parenthesized expression-list is found. That gives better errors. */ - vec_safe_push (expression_list, expr.get_value ()); + vec_safe_push (expression_list, expr); if (expr == error_mark_node) goto skip_comma; diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 51489d1..dfdc458 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3453,20 +3453,20 @@ process_outer_var_ref (tree decl, tsubst_flags_t complain, bool odr_use) the use of "this" explicit. Upon return, *IDK will be filled in appropriately. */ -cp_expr -finish_id_expression (tree id_expression, - tree decl, - tree scope, - cp_id_kind *idk, - bool integral_constant_expression_p, - bool allow_non_integral_constant_expression_p, - bool *non_integral_constant_expression_p, - bool template_p, - bool done, - bool address_p, - bool template_arg_p, - const char **error_msg, - location_t location) +static cp_expr +finish_id_expression_1 (tree id_expression, + tree decl, + tree scope, + cp_id_kind *idk, + bool integral_constant_expression_p, + bool allow_non_integral_constant_expression_p, + bool *non_integral_constant_expression_p, + bool template_p, + bool done, + bool address_p, + bool template_arg_p, + const char **error_msg, + location_t location) { decl = strip_using_decl (decl); @@ -3766,6 +3766,34 @@ finish_id_expression (tree id_expression, return cp_expr (decl, location); } +/* As per finish_id_expression_1, but adding a wrapper node + around the result if needed to express LOCATION. */ + +cp_expr +finish_id_expression (tree id_expression, + tree decl, + tree scope, + cp_id_kind *idk, + bool integral_constant_expression_p, + bool allow_non_integral_constant_expression_p, + bool *non_integral_constant_expression_p, + bool template_p, + bool done, + bool address_p, + bool template_arg_p, + const char **error_msg, + location_t location) +{ + cp_expr result + = finish_id_expression_1 (id_expression, decl, scope, idk, + integral_constant_expression_p, + allow_non_integral_constant_expression_p, + non_integral_constant_expression_p, + template_p, done, address_p, template_arg_p, + error_msg, location); + return result.maybe_add_location_wrapper (); +} + /* Implement the __typeof keyword: Return the type of EXPR, suitable for use as a type-specifier. */