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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17#ifndef LLVM_CLANG_ANALYSIS_ANALYSISDECLCONTEXT_H

18#define LLVM_CLANG_ANALYSIS_ANALYSISDECLCONTEXT_H

19

25#include "llvm/ADT/DenseMap.h"

26#include "llvm/ADT/FoldingSet.h"

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

28#include "llvm/ADT/iterator_range.h"

29#include "llvm/Support/Allocator.h"

30#include

31#include

32

34

35class AnalysisDeclContextManager;

36class ASTContext;

37class BlockDecl;

38class BlockInvocationContext;

39class CFGReverseBlockReachabilityAnalysis;

40class CFGStmtMap;

41class ImplicitParamDecl;

42class LocationContext;

43class LocationContextManager;

44class ParentMap;

45class StackFrameContext;

46class Stmt;

47class VarDecl;

48

49

50

52protected:

54

55public:

57

58

59

60

61

62

63

64

65

66

67

68};

69

70

71

73

74

76

77 const Decl *const D;

78

79 std::unique_ptr cfg, completeCFG;

80 std::unique_ptr cfgStmtMap;

81

84

85 bool builtCFG = false;

86 bool builtCompleteCFG = false;

87 std::unique_ptr PM;

88 std::unique_ptr CFA;

89

90 llvm::BumpPtrAllocator A;

91

92 llvm::DenseMap<const BlockDecl *, void *> *ReferencedBlockVars = nullptr;

93

94 void *ManagedAnalyses = nullptr;

95

96public:

98

101

103

105

107

109

111

113 return cfgBuildOptions;

114 }

115

116

117

118

122 }

125

128

129

131

132

133

134

135 Stmt *getBody(bool &IsAutosynthesized) const;

136

137

138

139

140

141

143

144

145

146

147

148

149

151

153

155

157

158

160

162

163

164

165

166

168

170

172

173 llvm::iterator_range<referenced_decls_iterator>

175

176

177

179

180

183 unsigned BlockCount, unsigned Index);

184

185

189

190

191

193 const void *tag = T::getTag();

194 std::unique_ptr &data = getAnalysisImpl(tag);

195 if (!data)

196 data = T::create(*this);

197 return static_cast<T *>(data.get());

198 }

199

200

202

204

205private:

206 std::unique_ptr &getAnalysisImpl(const void *tag);

207

209};

210

211

212

213

214

216public:

218

219private:

221

222

223

225

227 int64_t ID;

228

229protected:

232 : Kind(k), Ctx(ctx), Parent(parent), ID(ID) {

233 assert(ctx);

234 }

235

236public:

238

240

241 int64_t getID() const { return ID; }

242

243 LLVM_ATTRIBUTE_RETURNS_NONNULL

245

246

248

250

251 const Decl *getDecl() const { return Ctx->getDecl(); }

252

253 CFG *getCFG() const { return Ctx->getCFG(); }

254

255 template T *getAnalysis() const { return Ctx->getAnalysis<T>(); }

256

258

259

261

263

264

266

267 virtual void Profile(llvm::FoldingSetNodeID &ID) = 0;

268

269

270

271

272 LLVM_DUMP_METHOD void dumpStack(raw_ostream &Out) const;

273

274

275

276

277

278

279

280

281

282

283

284

286 raw_ostream &Out, const char *NL = "\n", unsigned int Space = 0,

287 bool IsDot = false,

288 std::function<void(const LocationContext *)> printMoreInfoPerContext =

290

291 LLVM_DUMP_METHOD void dump() const;

292

296};

297

298

301

302

303 const Stmt *CallSite;

304

305

307

308

309

310

311 const unsigned BlockCount;

312

313

314 const unsigned Index;

315

318 unsigned Index, int64_t ID)

320 Block(Block), BlockCount(BlockCount), Index(Index) {}

321

322public:

324

326

328

330

331 unsigned getIndex() const { return Index; }

332

334

335 void Profile(llvm::FoldingSetNodeID &ID) override;

336

340 unsigned Index) {

343 ID.AddInteger(BlockCount);

344 ID.AddInteger(Index);

345 }

346

349 }

350};

351

352

355

357

358

359 const void *Data;

360

363 const void *Data, int64_t ID)

365

366public:

368

370

372

373 void Profile(llvm::FoldingSetNodeID &ID) override;

374

377 const void *Data) {

380 }

381

384 }

385};

386

388 llvm::FoldingSet Contexts;

389

390

391 int64_t NewID = 0;

392

393public:

395

396

397

398

399

400

401

402

403

404

408 unsigned BlockCount, unsigned Index);

409

410

411

412

413

414

415

420

421

423};

424

426 using ContextMap =

427 llvm::DenseMap<const Decl *, std::unique_ptr>;

428

429 ContextMap Contexts;

432

433

434

435 std::unique_ptr Injector;

436

437

438

440

441

442

443 bool SynthesizeBodies;

444

445public:

447 ASTContext &ASTCtx, bool useUnoptimizedCFG = false,

448 bool addImplicitDtors = false, bool addInitializers = false,

449 bool addTemporaryDtors = false, bool addLifetime = false,

450 bool addLoopExit = false, bool addScopes = false,

451 bool synthesizeBodies = false, bool addStaticInitBranches = false,

452 bool addCXXNewAllocator = true, bool addRichCXXConstructors = true,

453 bool markElidedCXXConstructors = true, bool addVirtualBaseBranches = true,

455

457

460 }

461

463

464

466

467

468

469

472 0);

473 }

474

475

479 unsigned BlockCount, unsigned Index) {

481 }

482

484

485

487

488private:

490

492};

493

494}

495

496#endif

Defines the clang::CodeInjector interface which is responsible for injecting AST of function definiti...

Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.

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

bool synthesizeBodies() const

CFG::BuildOptions & getCFGBuildOptions()

void clear()

Discard all previously created AnalysisDeclContexts.

AnalysisDeclContext * getContext(const Decl *D)

const StackFrameContext * getStackFrame(const Decl *D)

Obtain the beginning context of the analysis.

bool getUseUnoptimizedCFG() const

const StackFrameContext * getStackFrame(AnalysisDeclContext *ADC, const LocationContext *Parent, const Stmt *S, const CFGBlock *Block, unsigned BlockCount, unsigned Index)

Obtain a context of the call stack using its parent context.

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

static std::string getFunctionName(const Decl *D)

void registerForcedBlockExpression(const Stmt *stmt)

const BlockInvocationContext * getBlockInvocationContext(const LocationContext *ParentLC, const BlockDecl *BD, const void *Data)

Obtain a context of the block invocation using its parent context.

CFGStmtMap * getCFGStmtMap()

const CFGBlock * getBlockForRegisteredExpression(const Stmt *stmt)

bool getUseUnoptimizedCFG() const

ParentMap & getParentMap()

const VarDecl *const * referenced_decls_iterator

const Decl * getDecl() const

bool getAddImplicitDtors() const

bool getAddEHEdges() const

static bool isInStdNamespace(const Decl *D)

bool getAddInitializers() const

CFGReverseBlockReachabilityAnalysis * getCFGReachablityAnalysis()

const CFG::BuildOptions & getCFGBuildOptions() const

const ImplicitParamDecl * getSelfDecl() const

const StackFrameContext * getStackFrame(LocationContext const *ParentLC, const Stmt *S, const CFGBlock *Blk, unsigned BlockCount, unsigned Index)

Obtain a context of the call stack using its parent context.

ASTContext & getASTContext() const

AnalysisDeclContextManager * getManager() const

llvm::iterator_range< referenced_decls_iterator > getReferencedBlockVars(const BlockDecl *BD)

bool isBodyAutosynthesized() const

CFG * getUnoptimizedCFG()

void dumpCFG(bool ShowColors)

CFG::BuildOptions & getCFGBuildOptions()

bool isBodyAutosynthesizedFromModelFile() const

Represents a block literal declaration, which is like an unnamed FunctionDecl.

It represents a block invocation (based on BlockCall).

void Profile(llvm::FoldingSetNodeID &ID) override

static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ADC, const LocationContext *ParentLC, const BlockDecl *BD, const void *Data)

const BlockDecl * getBlockDecl() const

~BlockInvocationContext() override=default

static bool classof(const LocationContext *LC)

const void * getData() const

Represents a single basic block in a source-level CFG.

Represents a top-level expression in a basic block.

bool PruneTriviallyFalseEdges

llvm::DenseMap< const Stmt *, const CFGBlock * > ForcedBlkExprs

Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.

CodeInjector is an interface which is responsible for injecting AST of function definitions that may ...

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

~LocationContextManager()

const StackFrameContext * getStackFrame(AnalysisDeclContext *ADC, const LocationContext *ParentLC, const Stmt *S, const CFGBlock *Block, unsigned BlockCount, unsigned Index)

Obtain a context of the call stack using its parent context.

void clear()

Discard all previously created LocationContext objects.

const BlockInvocationContext * getBlockInvocationContext(AnalysisDeclContext *ADC, const LocationContext *ParentLC, const BlockDecl *BD, const void *Data)

Obtain a context of the block invocation using its parent context.

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

bool isParentOf(const LocationContext *LC) const

const Decl * getDecl() const

LocationContext(ContextKind k, AnalysisDeclContext *ctx, const LocationContext *parent, int64_t ID)

const ParentMap & getParentMap() const

LLVM_ATTRIBUTE_RETURNS_NONNULL AnalysisDeclContext * getAnalysisDeclContext() const

static void ProfileCommon(llvm::FoldingSetNodeID &ID, ContextKind ck, AnalysisDeclContext *ctx, const LocationContext *parent, const void *data)

const LocationContext * getParent() const

It might return null.

LLVM_DUMP_METHOD void dumpStack(raw_ostream &Out) const

Prints out the call stack.

LLVM_DUMP_METHOD void dump() const

virtual void Profile(llvm::FoldingSetNodeID &ID)=0

const StackFrameContext * getStackFrame() const

virtual bool inTopFrame() const

virtual ~LocationContext()

const ImplicitParamDecl * getSelfDecl() const

void printJson(raw_ostream &Out, const char *NL="\n", unsigned int Space=0, bool IsDot=false, std::function< void(const LocationContext *)> printMoreInfoPerContext=[](const LocationContext *) {}) const

Prints out the call stack in json format.

ContextKind getKind() const

The base class of a hierarchy of objects representing analyses tied to AnalysisDeclContext.

ManagedAnalysis()=default

virtual ~ManagedAnalysis()

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

void Profile(llvm::FoldingSetNodeID &ID) override

unsigned getIndex() const

~StackFrameContext() override=default

CFGElement getCallSiteCFGElement() const

static bool classof(const LocationContext *LC)

const Stmt * getCallSite() const

static void Profile(llvm::FoldingSetNodeID &ID, AnalysisDeclContext *ADC, const LocationContext *ParentLC, const Stmt *S, const CFGBlock *Block, unsigned BlockCount, unsigned Index)

const CFGBlock * getCallSiteBlock() const

bool inTopFrame() const override

Stmt - This represents one statement.

Represents a variable declaration or definition.

const internal::VariadicAllOfMatcher< Stmt > stmt

Matches statements.

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

const FunctionProtoType * T