[cfe-commits] r159606 - in /cfe/trunk: lib/Analysis/ThreadSafety.cpp test/SemaCXX/warn-thread-safety-analysis.cpp
DeLesley Hutchins
delesley at google.com
Mon Jul 2 15:12:12 PDT 2012
Author: delesley
Date: Mon Jul 2 17:12:12 2012
New Revision: 159606
URL: http://llvm.org/viewvc/llvm-project?rev=159606&view=rev
Log:
Thread safety analysis: don't warn in case of duplicate annotation.
Modified:
cfe/trunk/lib/Analysis/ThreadSafety.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
Modified: cfe/trunk/lib/Analysis/ThreadSafety.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ThreadSafety.cpp?rev=159606&r1=159605&r2=159606&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Mon Jul 2 17:12:12 2012
@@ -924,9 +924,9 @@
ThreadSafetyAnalyzer(ThreadSafetyHandler &H) : Handler(H) {}
Lockset addLock(const Lockset &LSet, const MutexID &Mutex,
- const LockData &LDat);
+ const LockData &LDat, bool Warn=true);
Lockset addLock(const Lockset &LSet, Expr *MutexExp, const NamedDecl *D,
- const LockData &LDat);
+ const LockData &LDat, bool Warn=true);
Lockset removeLock(const Lockset &LSet, const MutexID &Mutex,
SourceLocation UnlockLoc,
bool Warn=true, bool FullyRemove=false);
@@ -962,11 +962,13 @@
/// \param LDat -- the LockData for the lock
Lockset ThreadSafetyAnalyzer::addLock(const Lockset &LSet,
const MutexID &Mutex,
- const LockData &LDat) {
+ const LockData &LDat,
+ bool Warn) {
// FIXME: deal with acquired before/after annotations.
// FIXME: Don't always warn when we have support for reentrant locks.
if (LSet.lookup(Mutex)) {
- Handler.handleDoubleLock(Mutex.getName(), LDat.AcquireLoc);
+ if (Warn)
+ Handler.handleDoubleLock(Mutex.getName(), LDat.AcquireLoc);
return LSet;
} else {
return LocksetFactory.add(LSet, Mutex, LDat);
@@ -976,13 +978,14 @@
/// \brief Construct a new mutex and add it to the lockset.
Lockset ThreadSafetyAnalyzer::addLock(const Lockset &LSet,
Expr *MutexExp, const NamedDecl *D,
- const LockData &LDat) {
+ const LockData &LDat,
+ bool Warn) {
MutexID Mutex(MutexExp, 0, D);
if (!Mutex.isValid()) {
MutexID::warnInvalidLock(Handler, MutexExp, 0, D);
return LSet;
}
- return addLock(LSet, Mutex, LDat);
+ return addLock(LSet, Mutex, LDat, Warn);
}
@@ -1637,14 +1640,14 @@
SLRIter = SLRAttr->args_begin(),
SLREnd = SLRAttr->args_end(); SLRIter != SLREnd; ++SLRIter)
InitialLockset = addLock(InitialLockset, *SLRIter, D,
- LockData(AttrLoc, LK_Shared));
+ LockData(AttrLoc, LK_Shared), false);
} else if (ExclusiveLocksRequiredAttr *ELRAttr
= dyn_cast<ExclusiveLocksRequiredAttr>(Attr)) {
for (ExclusiveLocksRequiredAttr::args_iterator
ELRIter = ELRAttr->args_begin(),
ELREnd = ELRAttr->args_end(); ELRIter != ELREnd; ++ELRIter)
InitialLockset = addLock(InitialLockset, *ELRIter, D,
- LockData(AttrLoc, LK_Exclusive));
+ LockData(AttrLoc, LK_Exclusive), false);
} else if (isa<UnlockFunctionAttr>(Attr)) {
// Don't try to check unlock functions for now
return;
Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=159606&r1=159605&r2=159606&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Mon Jul 2 17:12:12 2012
@@ -2433,4 +2433,24 @@
+namespace DoubleLockBug {
+
+class Foo {
+public:
+ Mutex mu_;
+ int a GUARDED_BY(mu_);
+
+ void foo() EXCLUSIVE_LOCKS_REQUIRED(mu_);
+};
+
+
+void Foo::foo() EXCLUSIVE_LOCKS_REQUIRED(mu_) {
+ a = 0;
+}
+
+};
+
+
+
+
More information about the cfe-commits
mailing list