<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 - Thread Annotation doesn't recognize a mutex is hold"
href="https://bugs.llvm.org/show_bug.cgi?id=38908">38908</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Thread Annotation doesn't recognize a mutex is hold
</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>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</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>mendola@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Compiling the following snippet the compiler is not able to recognize that the
privateAddComponent caller is holding the mutex:
#include <iostream>
#include <mutex>
#include <optional>
#include <map>
#define THREAD_ANNOTATION_ATTRIBUTE(x) __attribute__((x))
#define MUTEX_CAPABILITY THREAD_ANNOTATION_ATTRIBUTE(capability("mutex"))
#define ACQUIRE_CAPABILITY(m)
THREAD_ANNOTATION_ATTRIBUTE(acquire_capability(m))
#define SCOPED_LOCKABLE THREAD_ANNOTATION_ATTRIBUTE(scoped_lockable)
#define RELEASE_CAPABILITY THREAD_ANNOTATION_ATTRIBUTE(release_capability())
#define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE(guarded_by(x))
#define EXCLUDES(...)
THREAD_ANNOTATION_ATTRIBUTE(locks_excluded(__VA_ARGS__))
namespace blp {
using mutex MUTEX_CAPABILITY = std::mutex;
template <class T>
class SCOPED_LOCKABLE unique_lock
{
public:
explicit unique_lock(T& aMutex) ACQUIRE_CAPABILITY(aMutex)
: theLock(aMutex) {
}
~unique_lock() RELEASE_CAPABILITY = default;
void foo(T& aMutex) EXCLUDES(aMutex) { }
private:
std::unique_lock<T> theLock;
};
}
class TSCollection {
public:
void addComponent(int aQuery, int aReply) EXCLUDES(theMutex) {
blp::unique_lock<blp::mutex> myGuard(theMutex);
privateAddComponent(aQuery, aReply);
}
void addDefaultComponent(int aQuery) EXCLUDES(theMutex) {
blp::unique_lock<blp::mutex> myGuard(theMutex);
privateAddComponent(aQuery, 42);
}
std::optional<int> component(int aQuery) const EXCLUDES(theMutex) {
blp::unique_lock<blp::mutex> myGuard(theMutex);
auto it = theCollection.find(aQuery);
return it !=
theCollection.end() ? std::optional<int>(it->second) : std::nullopt;
}
private:
void privateAddComponent(int aQuery, int aReply) {
theCollection[aQuery] = aReply;
}
mutable blp::mutex theMutex;
std::map<int, int> theCollection GUARDED_BY(theMutex);
};
int main() {
std::cout << "hello" << std::endl;
}</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>