clang: include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CHECKERCONTEXT_H

15#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CHECKERCONTEXT_H

16

19#include

20

22namespace ento {

23

26

28

29

30

31 bool Changed;

32

35

36public:

37

38

40

46 : Eng(eng),

47 Pred(pred),

49 Location(loc),

50 NB(builder),

53 "We should not call the checkers on an empty state.");

54 }

55

58 }

59

62 }

63

66 }

67

68

69

70

74

75

76

78

79

80

83 }

84

87 }

88

90

93 }

94

97 }

98

101 }

102

103

105

108 }

109

112 }

113

115

118 }

119

122 }

123

126 }

127

130 }

131

132

135 }

136

137

138

139

140

141

144 if (std::optional PSL = L.getAs<PostStore>())

145 return reinterpret_cast<const MemRegion*>(PSL->getLocationValue());

146 return nullptr;

147 }

148

149

152 }

153

154

155

157

158

160

161

162

163

164

165

166

167

168

169

172 return addTransitionImpl(State ? State : getState(), false, nullptr, Tag);

173 }

174

175

176

177

178

179

180

181

184 return addTransitionImpl(State, false, Pred, Tag);

185 }

186

187

188

189

192 return addTransitionImpl(State ? State : getState(), true, Pred, Tag);

193 }

194

195

198 if (!State)

201 }

202

203

204

205

206

207

208

209

213 (Tag ? Tag : Location.getTag()));

214 }

215

216

217

218

219

220

221

222

223

224

229 (Tag ? Tag : Location.getTag()));

230 }

231

232

233

234

235

236

237

238

243 }

244

245

246

247

248

249

250

251

252

253

259 }

260

261

263 Changed = true;

265 }

266

267

268

269

270

271

272

273

274

275

276

277 LLVM_ATTRIBUTE_RETURNS_NONNULL

280 }

281

282

283

284

285

286

287

288

291 bool IsPrunable = false) {

295 IsPrunable);

296 }

297

298

299

300

301

302

303

304

306 bool IsPrunable = false) {

309 IsPrunable);

310 }

311

312

313

314

315

316

317

322 IsPrunable);

323 }

324

325

326

327

328

329

330

331

334 bool IsPrunable = false) {

338 llvm::raw_svector_ostream OS(Str);

339 Cb(BR, OS);

340 return std::string(OS.str());

341 },

342 IsPrunable);

343 }

344

345

346

348

349

351

352

354

355

358 if (FunDecl)

360 else

361 return nullptr;

362 }

363

364

368 }

369

370

371

372

373

374

375

376

377

378

380 StringRef Name = StringRef());

381

382

383

384

385

386

387

388

389

390

391

392

394

395

396

397

398

399

400

401

402

403

405

406private:

408 bool MarkAsSink,

411

412

413

414

415

416

417

418

419

420

421

422

423 if (!State || (State == Pred->getState() && !Tag && !MarkAsSink))

424 return Pred;

425

426 Changed = true;

428 if (P)

429 P = Pred;

430

432 if (MarkAsSink)

434 else

436 return node;

437 }

438};

439

440}

441

442}

443

444#endif

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

const LangOptions & getLangOpts() const

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

unsigned getBlockID() const

CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).

Decl - This represents one declaration (or definition), e.g.

This represents one expression.

Represents a function declaration or definition.

One of these records is kept for each identifier that is lexed.

Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...

It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...

LLVM_ATTRIBUTE_RETURNS_NONNULL AnalysisDeclContext * getAnalysisDeclContext() const

virtual bool inTopFrame() const

IdentifierInfo * getIdentifier() const

Get the identifier that names this declaration, if there is one.

Represents a program point after a store evaluation.

Engages in a tight little dance with the lexer to efficiently preprocess tokens.

ProgramPoints can be "tagged" as representing points specific to a given analysis entity.

const ProgramPointTag * getTag() const

ProgramPoint withTag(const ProgramPointTag *tag) const

Create a new ProgramPoint object that is the same as the original except for using the specified tag ...

std::optional< T > getAs() const

Convert to the specified ProgramPoint type, returning std::nullopt if this ProgramPoint is not of the...

Encodes a location in the source.

This class handles loading and caching of source files into memory.

It represents a stack frame of the call stack (based on CallEvent).

Stmt - This represents one statement.

BugReporter is a utility class for generating PathDiagnostics for analysis.

Preprocessor & getPreprocessor()

const SourceManager & getSourceManager()

virtual void emitReport(std::unique_ptr< BugReport > R)

Add the given report to the set of reports tracked by BugReporter.

ExplodedNode * getPredecessor()

Returns the previous node in the exploded graph, which includes the state of the program before the c...

ExplodedNode * generateErrorNode(ProgramStateRef State, ExplodedNode *Pred, const ProgramPointTag *Tag=nullptr)

Generate a transition to a node that will be used to report an error.

const IdentifierInfo * getCalleeIdentifier(const CallExpr *CE) const

Get the identifier of the called function (path-sensitive).

static const MemRegion * getLocationRegionIfPostStore(const ExplodedNode *N)

If the given node corresponds to a PostStore program point, retrieve the location region as it was ut...

SymbolManager & getSymbolManager()

StringRef getDeclDescription(const Decl *D)

Returns the word that should be used to refer to the declaration in the report.

Preprocessor & getPreprocessor()

unsigned blockCount() const

Returns the number of times the current block has been visited along the analyzed path.

ExplodedNode * generateSink(ProgramStateRef State, ExplodedNode *Pred, const ProgramPointTag *Tag=nullptr)

Generate a sink node.

const SourceManager & getSourceManager()

SValBuilder & getSValBuilder()

CheckerContext(NodeBuilder &builder, ExprEngine &eng, ExplodedNode *pred, const ProgramPoint &loc, bool wasInlined=false)

const NoteTag * getNoteTag(std::function< std::string()> &&Cb, bool IsPrunable=false)

A shorthand version of getNoteTag that doesn't require you to accept the arguments when you don't nee...

StringRef getCalleeName(const FunctionDecl *FunDecl) const

Get the name of the called function (path-sensitive).

const NoteTag * getNoteTag(StringRef Note, bool IsPrunable=false)

A shorthand version of getNoteTag that accepts a plain note.

const StackFrameContext * getStackFrame() const

ASTContext & getASTContext()

StringRef getCalleeName(const CallExpr *CE) const

Get the name of the called function (path-sensitive).

const ProgramStateRef & getState() const

ExplodedNode * addTransition(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)

Generates a new transition in the program state graph (ExplodedGraph).

ConstraintManager & getConstraintManager()

SVal getSVal(const Stmt *S) const

Get the value of arbitrary expressions at this point in the path.

BugReporter & getBugReporter()

bool isDifferent()

Check if the checker changed the state of the execution; ex: added a new transition or a bug report.

ExplodedNode * addTransition(ProgramStateRef State, ExplodedNode *Pred, const ProgramPointTag *Tag=nullptr)

Generates a new transition with the given predecessor.

bool isNegative(const Expr *E)

Returns true if the value of E is negative.

AnalysisDeclContext * getCurrentAnalysisDeclContext() const

bool isGreaterOrEqual(const Expr *E, unsigned long long Val)

Returns true if the value of E is greater than or equal to Val under unsigned comparison.

const ProgramPoint getLocation() const

static bool isCLibraryFunction(const FunctionDecl *FD, StringRef Name=StringRef())

Returns true if the given function is an externally-visible function in the top-level namespace,...

ExplodedNode * generateNonFatalErrorNode(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)

Generate a transition to a node that will be used to report an error.

LLVM_ATTRIBUTE_RETURNS_NONNULL const NoteTag * getNoteTag(NoteTag::Callback &&Cb, bool IsPrunable=false)

Produce a program point tag that displays an additional path note to the user.

const ASTContext & getASTContext() const

AnalysisManager & getAnalysisManager()

ExplodedNode * generateErrorNode(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)

Generate a transition to a node that will be used to report an error.

const FunctionDecl * getCalleeDecl(const CallExpr *CE) const

Get the declaration of the called function (path-sensitive).

void addSink(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)

Add a sink node to the current path of execution, halting analysis.

const NoteTag * getNoteTag(std::function< void(PathSensitiveBugReport &BR, llvm::raw_ostream &OS)> &&Cb, bool IsPrunable=false)

A shorthand version of getNoteTag that accepts a lambda with stream for note.

ProgramStateManager & getStateManager()

StringRef getMacroNameOrSpelling(SourceLocation &Loc)

Depending on wither the location corresponds to a macro, return either the macro name or the token sp...

const LangOptions & getLangOpts() const

bool inTopFrame() const

Return true if the current LocationContext has no caller context.

const LocationContext * getLocationContext() const

const bool wasInlined

If we are post visiting a call, this flag will be set if the call was inlined.

ExplodedNode * generateNonFatalErrorNode(ProgramStateRef State, ExplodedNode *Pred, const ProgramPointTag *Tag=nullptr)

Generate a transition to a node that will be used to report an error.

StoreManager & getStoreManager()

const NoteTag * getNoteTag(std::function< std::string(PathSensitiveBugReport &)> &&Cb, bool IsPrunable=false)

A shorthand version of getNoteTag that doesn't require you to accept the 'BugReporterContext' argumen...

static bool isHardenedVariantOf(const FunctionDecl *FD, StringRef Name)

In builds that use source hardening (-D_FORTIFY_SOURCE), many standard functions are implemented as m...

void emitReport(std::unique_ptr< BugReport > R)

Emit the diagnostics report.

unsigned getBlockID() const

Get the blockID.

const DataTagType * make(Args &&... ConstructorArgs)

const ProgramStateRef & getState() const

ProgramPoint getLocation() const

getLocation - Returns the edge associated with the given node.

const StackFrameContext * getStackFrame() const

SVal getSVal(const Stmt *S) const

Get the value of an arbitrary expression at this node.

const LocationContext * getLocationContext() const

ProgramStateManager & getStateManager()

ASTContext & getContext() const

getContext - Return the ASTContext associated with this analysis.

StoreManager & getStoreManager()

BugReporter & getBugReporter()

ConstraintManager & getConstraintManager()

DataTag::Factory & getDataTags()

AnalysisManager & getAnalysisManager()

SValBuilder & getSValBuilder()

MemRegion - The root abstract class for all memory regions.

const CFGBlock * getBlock() const

Return the CFGBlock associated with this builder.

unsigned blockCount() const

Returns the number of times the current basic block has been visited on the exploded graph path.

This is the simplest builder which generates nodes in the ExplodedGraph.

ExplodedNode * generateNode(const ProgramPoint &PP, ProgramStateRef State, ExplodedNode *Pred)

Generates a node in the ExplodedGraph.

ExplodedNode * generateSink(const ProgramPoint &PP, ProgramStateRef State, ExplodedNode *Pred)

Generates a sink in the ExplodedGraph.

const NodeBuilderContext & getContext()

The tag upon which the TagVisitor reacts.

std::function< std::string(BugReporterContext &, PathSensitiveBugReport &)> Callback

SymbolManager & getSymbolManager()

SVal - This represents a symbolic expression, which can be either an L-value or an R-value.

@ OS

Indicates that the tracking object is a descendant of a referenced-counted OSObject,...

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