<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - ACQUIRED_BEFORE and ACQUIRED_AFTER are noops"
href="https://bugs.llvm.org/show_bug.cgi?id=52446">52446</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>ACQUIRED_BEFORE and ACQUIRED_AFTER are noops
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Static Analyzer
</td>
</tr>
<tr>
<th>Assignee</th>
<td>dcoughlin@apple.com
</td>
</tr>
<tr>
<th>Reporter</th>
<td>atait@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>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: <a href="https://godbolt.org/z/3c8KbzGq4">https://godbolt.org/z/3c8KbzGq4</a>
```
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: <a class="bz_bug_link
bz_status_NEW "
title="NEW - Better warning for contradictory thread safety annotations"
href="show_bug.cgi?id=38400">https://bugs.llvm.org/show_bug.cgi?id=38400</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>