On 2/18/19 7:44 AM, Martin Liška wrote:
PING^1
On 11/30/18 11:26 AM, Martin Liška wrote:
Hi Jason.
Just small nits I noticed for:
cat test4.C
int a, b, c;
void
__attribute__((noinline))
bar()
{
if (a == 123)
[[likely]] c = 5;
else
[[likely]] b = 77;
}
int main()
{
bar ();
return 0;
}
$ g++ test4.C -c
test4.C: In function ‘void bar()’:
test4.C:8:16: warning: both branches of ‘if’ statement marked as ‘hot label’
[-Wattributes]
8 | [[likely]] c = 5;
| ^
9 | else
10 | [[likely]] b = 77;
| ~
1) I would expect 'likely' instead of 'hot label'
2) maybe we can put the carousel to the attribute instead of the first
statement in the block?
Fixed thus:
commit 4f0e3ea77fd14dc9931cade9add07f1aa70e8ef4
Author: Jason Merrill <ja...@redhat.com>
Date: Mon Feb 18 08:49:49 2019 -1000
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.
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 60ca1366cf6..ac3654467ac 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/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 33111bd14bf..56f717de85d 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 %<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",
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index ffecce4e29b..adb5f6f27a1 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");
}