https://bugs.llvm.org/show_bug.cgi?id=50275
Bug ID: 50275
Summary: [[likely]]/[[unlikely]] is sensitive to surrounding
braces
Product: clang
Version: trunk
Hardware: Macintosh
OS: MacOS X
Status: NEW
Severity: normal
Priority: P
Component: C++2a
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected],
[email protected], [email protected]
Example adapted from the example code in the standard (section 9.12.6)
(https://godbolt.org/z/58bxzo8oW):
void g(int);
int f(int n) {
if (n > 5) [[unlikely]] {
g(0);
return n * 2 + 1;
} else {
g(1);
return n * 5;
}
}
The clang-tidy readability-braces-around-statements check (and the hicpp/google
equivalents) triggers here, and suggests adding braces before the attribute:
<source>:3:15: warning: statement should be inside braces
[readability-braces-around-statements]
if (n > 5) [[unlikely]] {
^
{
1 warning generated.
However, inserting the braces as suggested results in the attribute having no
effect on the generated assembly.
The assembly produced by GCC 11.1, for comparison, does depend on the
presence/absence of [[unlikely]] regardless of the presence of the extra
braces.
I'm not entirely sure whether clang-tidy's warning here is correct, but the
presence/absence of braces affecting generated code here seems unintuitive.
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs