https://bugs.llvm.org/show_bug.cgi?id=49425
Bug ID: 49425
Summary: Erroneous -Wunreachable-code in some cases when C++20
`[[likely]]`/`[[unlikely]]` are used.
Product: clang
Version: unspecified
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++2a
Assignee: unassignedclangb...@nondot.org
Reporter: i...@geometrian.com
CC: blitzrak...@gmail.com, erik.pilking...@gmail.com,
llvm-bugs@lists.llvm.org, richard-l...@metafoo.co.uk
Consider the following simple, complete example:
//Compile with "-std=c++20 -Wunreachable-code -O3"
bool foo();
int bar() {
if (foo()) [[likely]] return 1;
else return 0;
}
The compiler of course cannot tell what `foo()` returns in this translation
unit. However, clang (tested 13.0.0) complains:
<source>:4:13: warning: code will never be executed [-Wunreachable-code]
if (foo()) [[likely]] return 1;
^~~~~~~~~~~~~~~~~~~
This is an incorrect claim. Note that the generated code is correct, and in
particular the positive branch is correctly implemented. Removing `[[likely]]`
also removes the warning (which makes no sense since `[[likely]]` is a hint);
the generated code in that case happens to be the same.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs