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
This commit is contained in:
Jason Merrill 2019-02-18 14:34:02 -05:00 committed by Jason Merrill
parent 84fdd8f463
commit 2d9273ca25
4 changed files with 29 additions and 15 deletions

View file

@ -1,3 +1,11 @@
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>
PR c++/89217 - ICE with list-initialization in range-based for loop.

View file

@ -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 %<if%> 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",

View file

@ -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);

View file

@ -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");
}