clang: include/clang/Analysis/Analyses/ThreadSafety.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETY_H

19#define LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETY_H

20

22#include "llvm/ADT/StringRef.h"

23

25

26class AnalysisDeclContext;

27class FunctionDecl;

28class NamedDecl;

29

30namespace threadSafety {

31

33

34

35

37

39

40

42

43

45

46

48

49

51

52

54

55

57};

58

59

60

61

63

65

66

68

69

72

73

74

76

78

79

82

83

84

85

86

87

88

89

90

97

98

100public:

102

105

106

107

109

110

111

112

113

114

115

116

120

121

122

123

124

125

126

127

128

129

130

135

136

137

138

139

140

141

145

146

147

148

149

150

151

152

153

154

155

156

157

158

163

164

165

166

167

168

169

170

171

175

176

177

178

179

180

183

184

185

186

187

188

189

190

191

192

196 Name *PossibleMatch = nullptr) {}

197

198

199

200

201

202

203

204

207

208

209

210

211

212

215

216

217

218

219

220

221

222

225

226

227

228

229

230

231

232

233

236 Name ScopeName, StringRef Kind,

238

239

240

241

242

243

244

247 Name ScopeName, StringRef Kind,

249

250

251

252

253

254

255

258 Name ScopeName,

259 StringRef Kind, Name Actual) {

260 }

261

262

265

266

268

269

270

272

273

275

278

279private:

280 bool IssueBetaWarnings = false;

281};

282

283

284

285

286

287

289 ThreadSafetyHandler &Handler,

290 BeforeSet **Bset);

291

293

294

295

297

298}

299}

300

301#endif

enum clang::sema::@1727::IndirectLocalPathEntry::EntryKind Kind

Defines the clang::SourceLocation class and associated facilities.

TypePropertyCache< Private > Cache

AnalysisDeclContext contains the context data for the function, method or block under analysis.

Represents a function declaration or definition.

This represents a decl that may have a name.

Encodes a location in the source.

Handler class for thread safety warnings.

virtual ~ThreadSafetyHandler()

virtual void handleBeforeAfterCycle(Name L1Name, SourceLocation Loc)

Warn that there is a cycle in acquired_before/after dependencies.

ThreadSafetyHandler()=default

virtual void handleExpectMoreUnderlyingMutexes(SourceLocation Loc, SourceLocation DLoc, Name ScopeName, StringRef Kind, Name Expected)

Warn when we get fewer underlying mutexes than expected.

virtual void handleInvalidLockExp(SourceLocation Loc)

Warn about lock expressions which fail to resolve to lockable objects.

virtual void handleUnmatchedUnderlyingMutexes(SourceLocation Loc, SourceLocation DLoc, Name ScopeName, StringRef Kind, Name Expected, Name Actual)

Warn when an actual underlying mutex of a scoped lockable does not match the expected.

virtual void handleExpectFewerUnderlyingMutexes(SourceLocation Loc, SourceLocation DLoc, Name ScopeName, StringRef Kind, Name Actual)

Warn when we get more underlying mutexes than expected.

virtual void enterFunction(const FunctionDecl *FD)

Called by the analysis when starting analysis of a function.

virtual void handleIncorrectUnlockKind(StringRef Kind, Name LockName, LockKind Expected, LockKind Received, SourceLocation LocLocked, SourceLocation LocUnlock)

Warn about an unlock function call that attempts to unlock a lock with the incorrect lock kind.

virtual void leaveFunction(const FunctionDecl *FD)

Called by the analysis when finishing analysis of a function.

void setIssueBetaWarnings(bool b)

virtual void handleExclusiveAndShared(StringRef Kind, Name LockName, SourceLocation Loc1, SourceLocation Loc2)

Warn when a mutex is held exclusively and shared at the same point.

virtual void handleLockAcquiredBefore(StringRef Kind, Name L1Name, Name L2Name, SourceLocation Loc)

Warn that L1 cannot be acquired before L2.

virtual void handleMutexNotHeld(StringRef Kind, const NamedDecl *D, ProtectedOperationKind POK, Name LockName, LockKind LK, SourceLocation Loc, Name *PossibleMatch=nullptr)

Warn when a protected operation occurs while the specific mutex protecting the operation is not locke...

virtual void handleFunExcludesLock(StringRef Kind, Name FunName, Name LockName, SourceLocation Loc)

Warn when a function is called while an excluded mutex is locked.

virtual void handleNoMutexHeld(const NamedDecl *D, ProtectedOperationKind POK, AccessKind AK, SourceLocation Loc)

Warn when a protected operation occurs while no locks are held.

virtual void handleNegativeNotHeld(const NamedDecl *D, Name LockName, SourceLocation Loc)

Warn when calling a function that a negative capability is not held.

virtual void handleUnmatchedUnlock(StringRef Kind, Name LockName, SourceLocation Loc, SourceLocation LocPreviousUnlock)

Warn about unlock function calls that do not have a prior matching lock expression.

virtual void handleNegativeNotHeld(StringRef Kind, Name LockName, Name Neg, SourceLocation Loc)

Warn when acquiring a lock that the negative capability is not held.

virtual void handleMutexHeldEndOfScope(StringRef Kind, Name LockName, SourceLocation LocLocked, SourceLocation LocEndOfScope, LockErrorKind LEK)

Warn about situations where a mutex is sometimes held and sometimes not.

virtual void handleDoubleLock(StringRef Kind, Name LockName, SourceLocation LocLocked, SourceLocation LocDoubleLock)

Warn about lock function calls for locks which are already held.

LockKind getLockKindFromAccessKind(AccessKind AK)

Helper function that returns a LockKind required for the given level of access.

@ LEK_NotLockedAtEndOfFunction

@ LEK_LockedSomePredecessors

@ LEK_LockedAtEndOfFunction

@ LEK_LockedSomeLoopIterations

void threadSafetyCleanup(BeforeSet *Cache)

AccessKind

This enum distinguishes between different ways to access (read or write) a variable.

@ AK_Written

Writing a variable.

@ AK_Read

Reading a variable.

LockKind

This enum distinguishes between different kinds of lock actions.

@ LK_Shared

Shared/reader lock of a mutex.

@ LK_Exclusive

Exclusive/writer lock of a mutex.

@ LK_Generic

Can be either Shared or Exclusive.

void runThreadSafetyAnalysis(AnalysisDeclContext &AC, ThreadSafetyHandler &Handler, BeforeSet **Bset)

Check a function's CFG for thread-safety violations.

ProtectedOperationKind

This enum distinguishes between different kinds of operations that may need to be protected by locks.

@ POK_PtPassByRef

Passing a pt-guarded variable by reference.

@ POK_VarDereference

Dereferencing a variable (e.g. p in *p = 5;)

@ POK_PassByRef

Passing a guarded variable by reference.

@ POK_ReturnByRef

Returning a guarded variable by reference.

@ POK_VarAccess

Reading or writing a variable (e.g. x in x = 5;)

@ POK_FunctionCall

Making a function call (e.g. fool())

@ POK_PtReturnByRef

Returning a pt-guarded variable by reference.

The JSON file list parser is used to communicate input to InstallAPI.