[llvm-bugs] [Bug 49425] New: Erroneous -Wunreachable-code in some cases when C++20 `[[likely]]`/`[[unlikely]]` are used.

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 3 22:26:28 PST 2021


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: unassignedclangbugs at nondot.org
          Reporter: ian at geometrian.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210304/9ad9e91d/attachment-0001.html>


More information about the llvm-bugs mailing list