[cfe-commits] r159607 - in /cfe/trunk: include/clang/Analysis/Analyses/ThreadSafety.h include/clang/Basic/DiagnosticSemaKinds.td lib/Analysis/ThreadSafety.cpp lib/Sema/AnalysisBasedWarnings.cpp test/SemaCXX/warn-thread-safety-analysis.cpp
DeLesley Hutchins
delesley at google.com
Mon Jul 2 15:16:55 PDT 2012
Author: delesley
Date: Mon Jul 2 17:16:54 2012
New Revision: 159607
URL: http://llvm.org/viewvc/llvm-project?rev=159607&view=rev
Log:
Thread safety analysis: fixed incorrect error message at the end of a locks_required function.
Modified:
cfe/trunk/include/clang/Analysis/Analyses/ThreadSafety.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Analysis/ThreadSafety.cpp
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
Modified: cfe/trunk/include/clang/Analysis/Analyses/ThreadSafety.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/ThreadSafety.h?rev=159607&r1=159606&r2=159607&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/ThreadSafety.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/ThreadSafety.h Mon Jul 2 17:16:54 2012
@@ -60,7 +60,8 @@
enum LockErrorKind {
LEK_LockedSomeLoopIterations,
LEK_LockedSomePredecessors,
- LEK_LockedAtEndOfFunction
+ LEK_LockedAtEndOfFunction,
+ LEK_NotLockedAtEndOfFunction
};
/// Handler class for thread safety warnings.
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=159607&r1=159606&r2=159607&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jul 2 17:16:54 2012
@@ -1775,6 +1775,9 @@
def warn_no_unlock : Warning<
"mutex '%0' is still locked at the end of function">,
InGroup<ThreadSafetyAnalysis>, DefaultIgnore;
+def warn_expecting_locked : Warning<
+ "expecting mutex '%0' to be locked at the end of function">,
+ InGroup<ThreadSafetyAnalysis>, DefaultIgnore;
// FIXME: improve the error message about locks not in scope
def warn_lock_some_predecessors : Warning<
"mutex '%0' is not locked on every path through here">,
Modified: cfe/trunk/lib/Analysis/ThreadSafety.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ThreadSafety.cpp?rev=159607&r1=159606&r2=159607&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Mon Jul 2 17:16:54 2012
@@ -951,7 +951,13 @@
const CFGBlock *CurrBlock);
Lockset intersectAndWarn(const Lockset &LSet1, const Lockset &LSet2,
- SourceLocation JoinLoc, LockErrorKind LEK);
+ SourceLocation JoinLoc,
+ LockErrorKind LEK1, LockErrorKind LEK2);
+
+ Lockset intersectAndWarn(const Lockset &LSet1, const Lockset &LSet2,
+ SourceLocation JoinLoc, LockErrorKind LEK1) {
+ return intersectAndWarn(LSet1, LSet2, JoinLoc, LEK1, LEK1);
+ }
void runAnalysis(AnalysisDeclContext &AC);
};
@@ -1541,11 +1547,13 @@
/// \param LSet1 The first lockset.
/// \param LSet2 The second lockset.
/// \param JoinLoc The location of the join point for error reporting
-/// \param LEK The error message to report.
+/// \param LEK1 The error message to report if a mutex is missing from LSet1
+/// \param LEK2 The error message to report if a mutex is missing from Lset2
Lockset ThreadSafetyAnalyzer::intersectAndWarn(const Lockset &LSet1,
const Lockset &LSet2,
SourceLocation JoinLoc,
- LockErrorKind LEK) {
+ LockErrorKind LEK1,
+ LockErrorKind LEK2) {
Lockset Intersection = LSet1;
for (Lockset::iterator I = LSet2.begin(), E = LSet2.end(); I != E; ++I) {
@@ -1564,7 +1572,7 @@
if (!LSet2LockData.Managed)
Handler.handleMutexHeldEndOfScope(LSet2Mutex.getName(),
LSet2LockData.AcquireLoc,
- JoinLoc, LEK);
+ JoinLoc, LEK1);
}
}
@@ -1576,7 +1584,7 @@
if (!MissingLock.Managed)
Handler.handleMutexHeldEndOfScope(Mutex.getName(),
MissingLock.AcquireLoc,
- JoinLoc, LEK);
+ JoinLoc, LEK2);
Intersection = LocksetFactory.remove(Intersection, Mutex);
}
}
@@ -1818,7 +1826,8 @@
// FIXME: Should we call this function for all blocks which exit the function?
intersectAndWarn(Initial->EntrySet, Final->ExitSet,
Final->ExitLoc,
- LEK_LockedAtEndOfFunction);
+ LEK_LockedAtEndOfFunction,
+ LEK_NotLockedAtEndOfFunction);
}
} // end anonymous namespace
Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=159607&r1=159606&r2=159607&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Mon Jul 2 17:16:54 2012
@@ -1061,6 +1061,9 @@
case LEK_LockedAtEndOfFunction:
DiagID = diag::warn_no_unlock;
break;
+ case LEK_NotLockedAtEndOfFunction:
+ DiagID = diag::warn_expecting_locked;
+ break;
}
if (LocEndOfScope.isInvalid())
LocEndOfScope = FunEndLocation;
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=159607&r1=159606&r2=159607&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:16:54 2012
@@ -2451,6 +2451,22 @@
};
+namespace UnlockBug {
+class Foo {
+public:
+ Mutex mutex_;
+
+ void foo1() EXCLUSIVE_LOCKS_REQUIRED(mutex_) { // expected-note {{mutex acquired here}}
+ mutex_.Unlock();
+ } // expected-warning {{expecting mutex 'mutex_' to be locked at the end of function}}
+
+
+ void foo2() SHARED_LOCKS_REQUIRED(mutex_) { // expected-note {{mutex acquired here}}
+ mutex_.Unlock();
+ } // expected-warning {{expecting mutex 'mutex_' to be locked at the end of function}}
+};
+
+} // end namespace UnlockBug
More information about the cfe-commits
mailing list