From a1e1b6036586c489a66919aaac3ee03bf548ab8b Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 18 Feb 2019 19:34:02 +0000 Subject: [PATCH] Improve duplicate [[likely]] diagnostic. * parser.c (cp_parser_statement): Make attrs_loc a range. Pass it to process_stmt_hotness_attribute. * cp-gimplify.c (process_stmt_hotness_attribute): Take attrs_loc. (genericize_if_stmt): Use likely/unlikely instead of predictor_name. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@268994 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/cp-gimplify.c | 6 +++--- gcc/cp/cp-tree.h | 2 +- gcc/cp/parser.c | 28 +++++++++++++++++----------- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d4e062539aff..d820e9410932 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2019-02-18 Jason Merrill + + Improve duplicate [[likely]] diagnostic. + * parser.c (cp_parser_statement): Make attrs_loc a range. Pass it + to process_stmt_hotness_attribute. + * cp-gimplify.c (process_stmt_hotness_attribute): Take attrs_loc. + (genericize_if_stmt): Use likely/unlikely instead of predictor_name. + 2019-02-17 Marek Polacek PR c++/89217 - ICE with list-initialization in range-based for loop. diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 33111bd14bff..56f717de85db 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -206,7 +206,7 @@ genericize_if_stmt (tree *stmt_p) richloc.add_range (EXPR_LOC_OR_LOC (fe, locus)); warning_at (&richloc, OPT_Wattributes, "both branches of % statement marked as %qs", - predictor_name (pr)); + pr == PRED_HOT_LABEL ? "likely" : "unlikely"); } } @@ -2765,7 +2765,7 @@ remove_hotness_attribute (tree list) PREDICT_EXPR. */ tree -process_stmt_hotness_attribute (tree std_attrs) +process_stmt_hotness_attribute (tree std_attrs, location_t attrs_loc) { if (std_attrs == error_mark_node) return std_attrs; @@ -2776,7 +2776,7 @@ process_stmt_hotness_attribute (tree std_attrs) || is_attribute_p ("likely", name)); tree pred = build_predict_expr (hot ? PRED_HOT_LABEL : PRED_COLD_LABEL, hot ? TAKEN : NOT_TAKEN); - SET_EXPR_LOCATION (pred, input_location); + SET_EXPR_LOCATION (pred, attrs_loc); add_stmt (pred); if (tree other = lookup_hotness_attribute (TREE_CHAIN (attr))) warning (OPT_Wattributes, "ignoring attribute %qE after earlier %qE", diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 60ca1366cf63..ac3654467ace 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7576,7 +7576,7 @@ extern tree cp_fully_fold (tree); extern tree cp_fully_fold_init (tree); extern void clear_fold_cache (void); extern tree lookup_hotness_attribute (tree); -extern tree process_stmt_hotness_attribute (tree); +extern tree process_stmt_hotness_attribute (tree, location_t); /* in name-lookup.c */ extern tree strip_using_decl (tree); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index ffecce4e29b2..adb5f6f27a18 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -11060,7 +11060,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, { tree statement, std_attrs = NULL_TREE; cp_token *token; - location_t statement_location, attrs_location; + location_t statement_location, attrs_loc; restart: if (if_p != NULL) @@ -11069,13 +11069,19 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, statement = NULL_TREE; saved_token_sentinel saved_tokens (parser->lexer); - attrs_location = cp_lexer_peek_token (parser->lexer)->location; + attrs_loc = cp_lexer_peek_token (parser->lexer)->location; if (c_dialect_objc ()) /* In obj-c++, seeing '[[' might be the either the beginning of c++11 attributes, or a nested objc-message-expression. So let's parse the c++11 attributes tentatively. */ cp_parser_parse_tentatively (parser); std_attrs = cp_parser_std_attribute_spec_seq (parser); + if (std_attrs) + { + location_t end_loc + = cp_lexer_previous_token (parser->lexer)->location; + attrs_loc = make_location (attrs_loc, attrs_loc, end_loc); + } if (c_dialect_objc ()) { if (!cp_parser_parse_definitely (parser)) @@ -11107,14 +11113,14 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, case RID_IF: case RID_SWITCH: - std_attrs = process_stmt_hotness_attribute (std_attrs); + std_attrs = process_stmt_hotness_attribute (std_attrs, attrs_loc); statement = cp_parser_selection_statement (parser, if_p, chain); break; case RID_WHILE: case RID_DO: case RID_FOR: - std_attrs = process_stmt_hotness_attribute (std_attrs); + std_attrs = process_stmt_hotness_attribute (std_attrs, attrs_loc); statement = cp_parser_iteration_statement (parser, if_p, false, 0); break; @@ -11122,7 +11128,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, case RID_CONTINUE: case RID_RETURN: case RID_GOTO: - std_attrs = process_stmt_hotness_attribute (std_attrs); + std_attrs = process_stmt_hotness_attribute (std_attrs, attrs_loc); statement = cp_parser_jump_statement (parser); break; @@ -11132,12 +11138,12 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, case RID_AT_FINALLY: case RID_AT_SYNCHRONIZED: case RID_AT_THROW: - std_attrs = process_stmt_hotness_attribute (std_attrs); + std_attrs = process_stmt_hotness_attribute (std_attrs, attrs_loc); statement = cp_parser_objc_statement (parser); break; case RID_TRY: - std_attrs = process_stmt_hotness_attribute (std_attrs); + std_attrs = process_stmt_hotness_attribute (std_attrs, attrs_loc); statement = cp_parser_try_block (parser); break; @@ -11158,11 +11164,11 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, case RID_SYNCHRONIZED: case RID_ATOMIC_NOEXCEPT: case RID_ATOMIC_CANCEL: - std_attrs = process_stmt_hotness_attribute (std_attrs); + std_attrs = process_stmt_hotness_attribute (std_attrs, attrs_loc); statement = cp_parser_transaction (parser, token); break; case RID_TRANSACTION_CANCEL: - std_attrs = process_stmt_hotness_attribute (std_attrs); + std_attrs = process_stmt_hotness_attribute (std_attrs, attrs_loc); statement = cp_parser_transaction_cancel (parser); break; @@ -11239,7 +11245,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, if (loc_after_labels != NULL) *loc_after_labels = statement_location; - std_attrs = process_stmt_hotness_attribute (std_attrs); + std_attrs = process_stmt_hotness_attribute (std_attrs, attrs_loc); /* Look for an expression-statement instead. */ statement = cp_parser_expression_statement (parser, in_statement_expr); @@ -11269,7 +11275,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, /* Allow "[[fallthrough]];", but warn otherwise. */ if (std_attrs != NULL_TREE) - warning_at (attrs_location, + warning_at (attrs_loc, OPT_Wattributes, "attributes at the beginning of statement are ignored"); } -- 2.39.5