1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
//===- ThreadSafety.h ------------------------------------------*- C++ --*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//
// A intra-procedural analysis for thread safety (e.g. deadlocks and race
// conditions), based off of an annotation system.
//
// See http://gcc.gnu.org/wiki/ThreadSafetyAnnotation for the gcc version.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_THREADSAFETY_H
#define LLVM_CLANG_THREADSAFETY_H
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/StringRef.h"
#include "clang/Analysis/AnalysisContext.h"
#include "clang/Sema/SemaInternal.h"
namespace clang {
namespace thread_safety {
enum ProtectedOperationKind {
POK_VarDereference,
POK_VarAccess,
POK_FunctionCall
};
enum LockKind {
LK_Shared,
LK_Exclusive
};
enum AccessKind {
AK_Read,
AK_Written
};
class ThreadSafetyHandler {
public:
typedef llvm::StringRef Name;
ThreadSafetyHandler() {}
virtual ~ThreadSafetyHandler() {}
virtual void handleInvalidLockExp(SourceLocation Loc) {}
virtual void handleUnmatchedUnlock(Name LockName, SourceLocation Loc) {}
virtual void handleDoubleLock(Name LockName, SourceLocation Loc) {}
virtual void handleMutexHeldEndOfScope(Name LockName, SourceLocation Loc){}
virtual void handleNoLockLoopEntry(Name LockName, SourceLocation Loc) {}
virtual void handleNoUnlock(Name LockName, Name FunName,
SourceLocation Loc) {}
virtual void handleExclusiveAndShared(Name LockName, SourceLocation Loc1,
SourceLocation Loc2) {}
virtual void handleNoMutexHeld(const NamedDecl *D, ProtectedOperationKind POK,
AccessKind AK, SourceLocation Loc) {}
virtual void handleMutexNotHeld(const NamedDecl *D,
ProtectedOperationKind POK, Name LockName,
LockKind LK, SourceLocation Loc) {}
virtual void handleFunExcludesLock(Name FunName, Name LockName,
SourceLocation Loc) {}
};
void runThreadSafetyAnalysis(AnalysisContext &AC, ThreadSafetyHandler &Handler);
LockKind getLockKindFromAccessKind(AccessKind AK);
}} // end namespace clang::thread_safety
#endif
|