[llvm-bugs] [Bug 52446] New: ACQUIRED_BEFORE and ACQUIRED_AFTER are noops

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Nov 9 06:43:24 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=52446

            Bug ID: 52446
           Summary: ACQUIRED_BEFORE and ACQUIRED_AFTER are noops
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: atait at google.com
                CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org

Description: The ACQUIRED_BEFORE and ACQUIRED_AFTER thread annotations produce
neither a warning nor an error when annotated locks are acquired out of order.

Minimal repro case: https://godbolt.org/z/3c8KbzGq4

```
class __attribute__((capability("mutex"))) MyLock {
    public:
    void lock() __attribute__((__acquire_capability__)) {}
    void unlock() __attribute__((__release_capability__)) {}
};

class Foo {

    public:
    void TryLock() {
        b.lock();
        a.lock();
        a.unlock();
        b.unlock();
    }
    void TryLock2() {
        a.lock();
        b.lock();
        b.unlock();
        a.unlock();
    }
    void AnnotationsWork() {
        a.lock();
    }

    private:
        MyLock a __attribute__((acquired_before(b)));
        MyLock b;
};

int main() {
    Foo f;
    f.TryLock();
    f.TryLock2();
    f.AnnotationsWork();
}
```

Output:

```
<source>:24:5: warning: mutex 'a' is still held at the end of function
[-Wthread-safety-analysis]
    }
    ^
<source>:23:11: note: mutex acquired here
        a.lock();
          ^
1 warning generated.
Compiler returned: 0
```

Expected: We should see some sort of warning or error from the invocation of
`Foo::TryLock()`, since it acquires a lock on mutex `b` before `a`, the
converse of the order specified with the annotation. Instead, we only see the
expected warning from the invocation of `Foo::AnnotationsWork()` because a lock
is still held on mutex `a` at the end of the invocation.

Build Version: This bug reproduces on all clang versions on Godbolt.

Possibly related bug: https://bugs.llvm.org/show_bug.cgi?id=38400

-- 
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/20211109/5829cd42/attachment.html>


More information about the llvm-bugs mailing list