Commit 2d9273ca by Jason Merrill Committed by 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.

From-SVN: r268994
parent 84fdd8f4
2019-02-18 Jason Merrill <jason@redhat.com>
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 <polacek@redhat.com> 2019-02-17 Marek Polacek <polacek@redhat.com>
PR c++/89217 - ICE with list-initialization in range-based for loop. PR c++/89217 - ICE with list-initialization in range-based for loop.
......
...@@ -206,7 +206,7 @@ genericize_if_stmt (tree *stmt_p) ...@@ -206,7 +206,7 @@ genericize_if_stmt (tree *stmt_p)
richloc.add_range (EXPR_LOC_OR_LOC (fe, locus)); richloc.add_range (EXPR_LOC_OR_LOC (fe, locus));
warning_at (&richloc, OPT_Wattributes, warning_at (&richloc, OPT_Wattributes,
"both branches of %<if%> statement marked as %qs", "both branches of %<if%> statement marked as %qs",
predictor_name (pr)); pr == PRED_HOT_LABEL ? "likely" : "unlikely");
} }
} }
...@@ -2765,7 +2765,7 @@ remove_hotness_attribute (tree list) ...@@ -2765,7 +2765,7 @@ remove_hotness_attribute (tree list)
PREDICT_EXPR. */ PREDICT_EXPR. */
tree 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) if (std_attrs == error_mark_node)
return std_attrs; return std_attrs;
...@@ -2776,7 +2776,7 @@ process_stmt_hotness_attribute (tree std_attrs) ...@@ -2776,7 +2776,7 @@ process_stmt_hotness_attribute (tree std_attrs)
|| is_attribute_p ("likely", name)); || is_attribute_p ("likely", name));
tree pred = build_predict_expr (hot ? PRED_HOT_LABEL : PRED_COLD_LABEL, tree pred = build_predict_expr (hot ? PRED_HOT_LABEL : PRED_COLD_LABEL,
hot ? TAKEN : NOT_TAKEN); hot ? TAKEN : NOT_TAKEN);
SET_EXPR_LOCATION (pred, input_location); SET_EXPR_LOCATION (pred, attrs_loc);
add_stmt (pred); add_stmt (pred);
if (tree other = lookup_hotness_attribute (TREE_CHAIN (attr))) if (tree other = lookup_hotness_attribute (TREE_CHAIN (attr)))
warning (OPT_Wattributes, "ignoring attribute %qE after earlier %qE", warning (OPT_Wattributes, "ignoring attribute %qE after earlier %qE",
......
...@@ -7576,7 +7576,7 @@ extern tree cp_fully_fold (tree); ...@@ -7576,7 +7576,7 @@ extern tree cp_fully_fold (tree);
extern tree cp_fully_fold_init (tree); extern tree cp_fully_fold_init (tree);
extern void clear_fold_cache (void); extern void clear_fold_cache (void);
extern tree lookup_hotness_attribute (tree); 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 */ /* in name-lookup.c */
extern tree strip_using_decl (tree); extern tree strip_using_decl (tree);
......
...@@ -11060,7 +11060,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, ...@@ -11060,7 +11060,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
{ {
tree statement, std_attrs = NULL_TREE; tree statement, std_attrs = NULL_TREE;
cp_token *token; cp_token *token;
location_t statement_location, attrs_location; location_t statement_location, attrs_loc;
restart: restart:
if (if_p != NULL) if (if_p != NULL)
...@@ -11069,13 +11069,19 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, ...@@ -11069,13 +11069,19 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
statement = NULL_TREE; statement = NULL_TREE;
saved_token_sentinel saved_tokens (parser->lexer); 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 ()) if (c_dialect_objc ())
/* In obj-c++, seeing '[[' might be the either the beginning of /* In obj-c++, seeing '[[' might be the either the beginning of
c++11 attributes, or a nested objc-message-expression. So c++11 attributes, or a nested objc-message-expression. So
let's parse the c++11 attributes tentatively. */ let's parse the c++11 attributes tentatively. */
cp_parser_parse_tentatively (parser); cp_parser_parse_tentatively (parser);
std_attrs = cp_parser_std_attribute_spec_seq (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 (c_dialect_objc ())
{ {
if (!cp_parser_parse_definitely (parser)) if (!cp_parser_parse_definitely (parser))
...@@ -11107,14 +11113,14 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, ...@@ -11107,14 +11113,14 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
case RID_IF: case RID_IF:
case RID_SWITCH: 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); statement = cp_parser_selection_statement (parser, if_p, chain);
break; break;
case RID_WHILE: case RID_WHILE:
case RID_DO: case RID_DO:
case RID_FOR: 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); statement = cp_parser_iteration_statement (parser, if_p, false, 0);
break; break;
...@@ -11122,7 +11128,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, ...@@ -11122,7 +11128,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
case RID_CONTINUE: case RID_CONTINUE:
case RID_RETURN: case RID_RETURN:
case RID_GOTO: 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); statement = cp_parser_jump_statement (parser);
break; break;
...@@ -11132,12 +11138,12 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, ...@@ -11132,12 +11138,12 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
case RID_AT_FINALLY: case RID_AT_FINALLY:
case RID_AT_SYNCHRONIZED: case RID_AT_SYNCHRONIZED:
case RID_AT_THROW: 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); statement = cp_parser_objc_statement (parser);
break; break;
case RID_TRY: 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); statement = cp_parser_try_block (parser);
break; break;
...@@ -11158,11 +11164,11 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, ...@@ -11158,11 +11164,11 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
case RID_SYNCHRONIZED: case RID_SYNCHRONIZED:
case RID_ATOMIC_NOEXCEPT: case RID_ATOMIC_NOEXCEPT:
case RID_ATOMIC_CANCEL: 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); statement = cp_parser_transaction (parser, token);
break; break;
case RID_TRANSACTION_CANCEL: 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); statement = cp_parser_transaction_cancel (parser);
break; break;
...@@ -11239,7 +11245,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, ...@@ -11239,7 +11245,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
if (loc_after_labels != NULL) if (loc_after_labels != NULL)
*loc_after_labels = statement_location; *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. */ /* Look for an expression-statement instead. */
statement = cp_parser_expression_statement (parser, in_statement_expr); statement = cp_parser_expression_statement (parser, in_statement_expr);
...@@ -11269,7 +11275,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, ...@@ -11269,7 +11275,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
/* Allow "[[fallthrough]];", but warn otherwise. */ /* Allow "[[fallthrough]];", but warn otherwise. */
if (std_attrs != NULL_TREE) if (std_attrs != NULL_TREE)
warning_at (attrs_location, warning_at (attrs_loc,
OPT_Wattributes, OPT_Wattributes,
"attributes at the beginning of statement are ignored"); "attributes at the beginning of statement are ignored");
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment