[llvm-bugs] [Bug 50275] New: [[likely]]/[[unlikely]] is sensitive to surrounding braces

via llvm-bugs llvm-bugs at lists.llvm.org
Sat May 8 12:01:35 PDT 2021


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: unassignedclangbugs at nondot.org
          Reporter: aw1621107 at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210508/94bb6c1f/attachment.html>


More information about the llvm-bugs mailing list