aboutsummaryrefslogtreecommitdiff
path: root/include/clang
diff options
context:
space:
mode:
authorCaitlin Sadowski <supertri@google.com>2011-09-15 17:25:19 +0000
committerCaitlin Sadowski <supertri@google.com>2011-09-15 17:25:19 +0000
commit4e4bc75d3570835e13183c66ac08974cdc016007 (patch)
treec2c143a55fca0297f305816bbc394e4aee78ca29 /include/clang
parent0f50b08940ea0a9a44f2715f49ccf6bc64b95491 (diff)
Thread safety: refactoring various out of scope warnings to use the same inteface. This eliminates a lot of unnecessary duplicated code.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139801 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang')
-rw-r--r--include/clang/Analysis/Analyses/ThreadSafety.h41
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td2
2 files changed, 23 insertions, 20 deletions
diff --git a/include/clang/Analysis/Analyses/ThreadSafety.h b/include/clang/Analysis/Analyses/ThreadSafety.h
index db1ef8f312..a32505624a 100644
--- a/include/clang/Analysis/Analyses/ThreadSafety.h
+++ b/include/clang/Analysis/Analyses/ThreadSafety.h
@@ -49,6 +49,20 @@ enum AccessKind {
AK_Written /// Writing a variable
};
+/// This enum distinguishes between different situations where we warn due to
+/// inconsistent locking.
+/// \enum SK_LockedSomeLoopIterations -- a mutex is locked for some but not all
+/// loop iterations.
+/// \enum SK_LockedSomePredecessors -- a mutex is locked in some but not all
+/// predecessors of a CFGBlock.
+/// \enum SK_LockedAtEndOfFunction -- a mutex is still locked at the end of a
+/// function.
+enum LockErrorKind {
+ LEK_LockedSomeLoopIterations,
+ LEK_LockedSomePredecessors,
+ LEK_LockedAtEndOfFunction
+};
+
/// Handler class for thread safety warnings.
class ThreadSafetyHandler {
public:
@@ -73,27 +87,16 @@ public:
virtual void handleDoubleLock(Name LockName, SourceLocation Loc) {}
/// Warn about situations where a mutex is sometimes held and sometimes not.
- /// For example, a mutex is locked on an "if" branch but not the "else"
- /// branch.
- /// \param LockName -- A StringRef name for the lock expression, to be printed
- /// in the error message.
- /// \param Loc -- The location of the lock expression where the mutex is
- /// locked
- virtual void handleMutexHeldEndOfScope(Name LockName, SourceLocation Loc){}
-
- /// Warn when a mutex is only held at the start of some loop iterations.
+ /// The three situations are:
+ /// 1. a mutex is locked on an "if" branch but not the "else" branch,
+ /// 2, or a mutex is only held at the start of some loop iterations,
+ /// 3. or when a mutex is locked but not unlocked inside a function.
/// \param LockName -- A StringRef name for the lock expression, to be printed
/// in the error message.
- /// \param Loc -- The Loc of the lock expression.
- virtual void handleNoLockLoopEntry(Name LockName, SourceLocation Loc) {}
-
- /// Warn when a mutex is locked but not unlocked inside a function.
- /// \param LockName -- A StringRef name for the lock expression, to be printed
- /// in the error message.
- /// \param FunName -- The name of the function
- /// \param Loc -- The location of the lock expression
- virtual void handleNoUnlock(Name LockName, Name FunName,
- SourceLocation Loc) {}
+ /// \param Loc -- The location of the lock expression where the mutex is locked
+ /// \param LEK -- which of the three above cases we should warn for
+ virtual void handleMutexHeldEndOfScope(Name LockName, SourceLocation Loc,
+ LockErrorKind LEK){}
/// Warn when a mutex is held exclusively and shared at the same point. For
/// example, if a mutex is locked exclusively during an if branch and shared
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 332aa69432..8bb7db6939 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1398,7 +1398,7 @@ def warn_double_lock : Warning<
"locking '%0' that is already locked">,
InGroup<ThreadSafety>, DefaultIgnore;
def warn_no_unlock : Warning<
- "mutex '%0' is still held at the end of function '%1'">,
+ "mutex '%0' is still held at the end of function">,
InGroup<ThreadSafety>, DefaultIgnore;
// FIXME: improve the error message about locks not in scope
def warn_lock_at_end_of_scope : Warning<