clang 23.0.0git
AnalysisDeclContext.cpp
Go to the documentation of this file.
1//===- AnalysisDeclContext.cpp - Analysis context for Path Sens analysis --===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines AnalysisDeclContext, a class that manages the analysis
10// context data for path sensitive analysis.
11//
12//===----------------------------------------------------------------------===//
13
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclBase.h"
18#include "clang/AST/DeclCXX.h"
19#include "clang/AST/DeclObjC.h"
21#include "clang/AST/Expr.h"
23#include "clang/AST/ParentMap.h"
25#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
30#include "clang/Analysis/CFG.h"
34#include "clang/Basic/LLVM.h"
37#include "llvm/ADT/DenseMap.h"
38#include "llvm/ADT/FoldingSet.h"
39#include "llvm/ADT/SmallPtrSet.h"
40#include "llvm/ADT/iterator_range.h"
41#include "llvm/Support/Allocator.h"
42#include "llvm/Support/Compiler.h"
43#include "llvm/Support/ErrorHandling.h"
44#include "llvm/Support/SaveAndRestore.h"
45#include "llvm/Support/raw_ostream.h"
46#include <cassert>
47#include <memory>
48
49using namespace clang;
50
51using ManagedAnalysisMap = llvm::DenseMap<const void *, std::unique_ptr<ManagedAnalysis>>;
52
54 const Decl *D,
55 const CFG::BuildOptions &Options)
56 : ADCMgr(ADCMgr), D(D), cfgBuildOptions(Options) {
57 cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs;
58}
59
61 const Decl *D)
62 : ADCMgr(ADCMgr), D(D) {
63 cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs;
64}
65
67 ASTContext &ASTCtx, bool useUnoptimizedCFG, bool addImplicitDtors,
68 bool addInitializers, bool addTemporaryDtors, bool addLifetime,
69 bool addLoopExit, bool addScopes, bool synthesizeBodies,
70 bool addStaticInitBranch, bool addCXXNewAllocator,
71 bool addRichCXXConstructors, bool markElidedCXXConstructors,
72 bool addVirtualBaseBranches, std::unique_ptr<CodeInjector> injector)
73 : Injector(std::move(injector)), FunctionBodyFarm(ASTCtx, Injector.get()),
74 SynthesizeBodies(synthesizeBodies) {
75 cfgBuildOptions.PruneTriviallyFalseEdges = !useUnoptimizedCFG;
76 cfgBuildOptions.AddImplicitDtors = addImplicitDtors;
77 cfgBuildOptions.AddInitializers = addInitializers;
78 cfgBuildOptions.AddTemporaryDtors = addTemporaryDtors;
79 cfgBuildOptions.AddLifetime = addLifetime;
80 cfgBuildOptions.AddLoopExit = addLoopExit;
81 cfgBuildOptions.AddScopes = addScopes;
82 cfgBuildOptions.AddStaticInitBranches = addStaticInitBranch;
83 cfgBuildOptions.AddCXXNewAllocator = addCXXNewAllocator;
84 cfgBuildOptions.AddRichCXXConstructors = addRichCXXConstructors;
85 cfgBuildOptions.MarkElidedCXXConstructors = markElidedCXXConstructors;
86 cfgBuildOptions.AddVirtualBaseBranches = addVirtualBaseBranches;
87}
88
89void AnalysisDeclContextManager::clear() { Contexts.clear(); }
90
91Stmt *AnalysisDeclContext::getBody(bool &IsAutosynthesized) const {
92 IsAutosynthesized = false;
93 if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
94 Stmt *Body = FD->getBody();
95 if (auto *CoroBody = dyn_cast_or_null<CoroutineBodyStmt>(Body))
96 Body = CoroBody->getBody();
97 if (ADCMgr && ADCMgr->synthesizeBodies()) {
98 Stmt *SynthesizedBody = ADCMgr->getBodyFarm().getBody(FD);
99 if (SynthesizedBody) {
100 Body = SynthesizedBody;
101 IsAutosynthesized = true;
102 }
103 }
104 return Body;
105 }
106 else if (const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
107 Stmt *Body = MD->getBody();
108 if (ADCMgr && ADCMgr->synthesizeBodies()) {
109 Stmt *SynthesizedBody = ADCMgr->getBodyFarm().getBody(MD);
110 if (SynthesizedBody) {
111 Body = SynthesizedBody;
112 IsAutosynthesized = true;
113 }
114 }
115 return Body;
116 } else if (const auto *BD = dyn_cast<BlockDecl>(D))
117 return BD->getBody();
118 else if (const auto *FunTmpl = dyn_cast_or_null<FunctionTemplateDecl>(D))
119 return FunTmpl->getTemplatedDecl()->getBody();
120 else if (const auto *VD = dyn_cast_or_null<VarDecl>(D)) {
121 if (VD->isFileVarDecl()) {
122 return const_cast<Stmt *>(dyn_cast_or_null<Stmt>(VD->getInit()));
123 }
124 }
125
126 llvm_unreachable("unknown code decl");
127}
128
130 bool Tmp;
131 return getBody(Tmp);
132}
133
135 bool Tmp;
136 getBody(Tmp);
137 return Tmp;
138}
139
141 bool Tmp;
142 Stmt *Body = getBody(Tmp);
143 return Tmp && Body->getBeginLoc().isValid();
144}
145
146/// Returns true if \param VD is an Objective-C implicit 'self' parameter.
147static bool isSelfDecl(const VarDecl *VD) {
148 return isa_and_nonnull<ImplicitParamDecl>(VD) && VD->getName() == "self";
149}
150
152 if (const auto *MD = dyn_cast<ObjCMethodDecl>(D))
153 return MD->getSelfDecl();
154 if (const auto *BD = dyn_cast<BlockDecl>(D)) {
155 // See if 'self' was captured by the block.
156 for (const auto &I : BD->captures()) {
157 const VarDecl *VD = I.getVariable();
158 if (isSelfDecl(VD))
159 return dyn_cast<ImplicitParamDecl>(VD);
160 }
161 }
162
163 auto *CXXMethod = dyn_cast<CXXMethodDecl>(D);
164 if (!CXXMethod)
165 return nullptr;
166
167 const CXXRecordDecl *parent = CXXMethod->getParent();
168 if (!parent->isLambda())
169 return nullptr;
170
171 for (const auto &LC : parent->captures()) {
172 if (!LC.capturesVariable())
173 continue;
174
175 ValueDecl *VD = LC.getCapturedVar();
176 if (isSelfDecl(dyn_cast<VarDecl>(VD)))
177 return dyn_cast<ImplicitParamDecl>(VD);
178 }
179
180 return nullptr;
181}
182
184 if (!forcedBlkExprs)
185 forcedBlkExprs = new CFG::BuildOptions::ForcedBlkExprs();
186 // Default construct an entry for 'stmt'.
187 if (const auto *e = dyn_cast<Expr>(stmt))
188 stmt = e->IgnoreParens();
189 (void) (*forcedBlkExprs)[stmt];
190}
191
192const CFGBlock *
194 assert(forcedBlkExprs);
195 if (const auto *e = dyn_cast<Expr>(stmt))
196 stmt = e->IgnoreParens();
197 CFG::BuildOptions::ForcedBlkExprs::const_iterator itr =
198 forcedBlkExprs->find(stmt);
199 assert(itr != forcedBlkExprs->end());
200 return itr->second;
201}
202
203/// Add each synthetic statement in the CFG to the parent map, using the
204/// source statement's parent.
205static void addParentsForSyntheticStmts(const CFG *TheCFG, ParentMap &PM) {
206 if (!TheCFG)
207 return;
208
210 E = TheCFG->synthetic_stmt_end();
211 I != E; ++I) {
212 PM.setParent(I->first, PM.getParent(I->second));
213 }
214}
215
217 if (!cfgBuildOptions.PruneTriviallyFalseEdges)
218 return getUnoptimizedCFG();
219
220 if (!builtCFG) {
221 cfg = CFG::buildCFG(D, getBody(), &D->getASTContext(), cfgBuildOptions);
222 // Even when the cfg is not successfully built, we don't
223 // want to try building it again.
224 builtCFG = true;
225
226 if (PM)
227 addParentsForSyntheticStmts(cfg.get(), *PM);
228
229 // The Observer should only observe one build of the CFG.
230 getCFGBuildOptions().Observer = nullptr;
231 }
232 return cfg.get();
233}
234
236 if (!builtCompleteCFG) {
237 SaveAndRestore NotPrune(cfgBuildOptions.PruneTriviallyFalseEdges, false);
238 completeCFG =
239 CFG::buildCFG(D, getBody(), &D->getASTContext(), cfgBuildOptions);
240 // Even when the cfg is not successfully built, we don't
241 // want to try building it again.
242 builtCompleteCFG = true;
243
244 if (PM)
245 addParentsForSyntheticStmts(completeCFG.get(), *PM);
246
247 // The Observer should only observe one build of the CFG.
248 getCFGBuildOptions().Observer = nullptr;
249 }
250 return completeCFG.get();
251}
252
254 if (cfgStmtMap)
255 return &*cfgStmtMap;
256
257 if (const CFG *c = getCFG()) {
258 cfgStmtMap.emplace(*c, getParentMap());
259 return &*cfgStmtMap;
260 }
261
262 return nullptr;
263}
264
266 if (CFA)
267 return CFA.get();
268
269 if (CFG *c = getCFG()) {
270 CFA.reset(new CFGReverseBlockReachabilityAnalysis(*c));
271 return CFA.get();
272 }
273
274 return nullptr;
275}
276
277void AnalysisDeclContext::dumpCFG(bool ShowColors) {
278 getCFG()->dump(getASTContext().getLangOpts(), ShowColors);
279}
280
282 if (!PM) {
283 PM.reset(new ParentMap(getBody()));
284 if (const auto *C = dyn_cast<CXXConstructorDecl>(getDecl())) {
285 for (const auto *I : C->inits()) {
286 PM->addStmt(I->getInit());
287 }
288 }
289 if (builtCFG)
291 if (builtCompleteCFG)
293 }
294 return *PM;
295}
296
298 if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
299 // Calling 'hasBody' replaces 'FD' in place with the FunctionDecl
300 // that has the body.
301 FD->hasBody(FD);
302 D = FD;
303 }
304
305 std::unique_ptr<AnalysisDeclContext> &AC = Contexts[D];
306 if (!AC)
307 AC = std::make_unique<AnalysisDeclContext>(this, D, cfgBuildOptions);
308 return AC.get();
309}
310
312
313const StackFrameContext *
315 const Expr *E, const CFGBlock *Blk,
316 unsigned BlockCount, unsigned Index) {
317 return getLocationContextManager().getStackFrame(this, ParentLC, E, Blk,
318 BlockCount, Index);
319}
320
322 const LocationContext *ParentLC, const BlockDecl *BD, const void *Data) {
323 return getLocationContextManager().getBlockInvocationContext(this, ParentLC,
324 BD, Data);
325}
326
328 const DeclContext *DC = D->getDeclContext()->getEnclosingNamespaceContext();
329 const auto *ND = dyn_cast<NamespaceDecl>(DC);
330 if (!ND)
331 return false;
332
333 while (const DeclContext *Parent = ND->getParent()) {
334 if (!isa<NamespaceDecl>(Parent))
335 break;
336 ND = cast<NamespaceDecl>(Parent);
337 }
338
339 return ND->isStdNamespace();
340}
341
343 std::string Str;
344 llvm::raw_string_ostream OS(Str);
345 const ASTContext &Ctx = D->getASTContext();
346
347 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
348 OS << FD->getQualifiedNameAsString();
349
350 // In C++, there are overloads.
351
352 if (Ctx.getLangOpts().CPlusPlus) {
353 OS << '(';
354 for (const auto &P : FD->parameters()) {
355 if (P != *FD->param_begin())
356 OS << ", ";
357 OS << P->getType();
358 }
359 OS << ')';
360 }
361
362 } else if (isa<BlockDecl>(D)) {
363 PresumedLoc Loc = Ctx.getSourceManager().getPresumedLoc(D->getLocation());
364
365 if (Loc.isValid()) {
366 OS << "block (line: " << Loc.getLine() << ", col: " << Loc.getColumn()
367 << ')';
368 }
369
370 } else if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)) {
371
372 // FIXME: copy-pasted from CGDebugInfo.cpp.
373 OS << (OMD->isInstanceMethod() ? '-' : '+') << '[';
374 const DeclContext *DC = OMD->getDeclContext();
375 if (const auto *OID = dyn_cast<ObjCImplementationDecl>(DC)) {
376 OS << OID->getName();
377 } else if (const auto *OID = dyn_cast<ObjCInterfaceDecl>(DC)) {
378 OS << OID->getName();
379 } else if (const auto *OC = dyn_cast<ObjCCategoryDecl>(DC)) {
380 if (OC->IsClassExtension()) {
381 OS << OC->getClassInterface()->getName();
382 } else {
383 OS << OC->getIdentifier()->getNameStart() << '('
384 << OC->getIdentifier()->getNameStart() << ')';
385 }
386 } else if (const auto *OCD = dyn_cast<ObjCCategoryImplDecl>(DC)) {
387 OS << OCD->getClassInterface()->getName() << '(' << OCD->getName() << ')';
388 }
389 OS << ' ' << OMD->getSelector().getAsString() << ']';
390 }
391
392 return Str;
393}
394
395LocationContextManager &AnalysisDeclContext::getLocationContextManager() {
396 assert(
397 ADCMgr &&
398 "Cannot create LocationContexts without an AnalysisDeclContextManager!");
399 return ADCMgr->getLocationContextManager();
400}
401
402//===----------------------------------------------------------------------===//
403// FoldingSet profiling.
404//===----------------------------------------------------------------------===//
405
406void LocationContext::ProfileCommon(llvm::FoldingSetNodeID &ID,
407 ContextKind ck,
409 const LocationContext *parent,
410 const void *data) {
411 ID.AddInteger(ck);
412 ID.AddPointer(ctx);
413 ID.AddPointer(parent);
414 ID.AddPointer(data);
415}
416
417void StackFrameContext::Profile(llvm::FoldingSetNodeID &ID) {
418 Profile(ID, getAnalysisDeclContext(), getParent(), CallSite, Block,
419 BlockCount, Index);
420}
421
422void BlockInvocationContext::Profile(llvm::FoldingSetNodeID &ID) {
423 Profile(ID, getAnalysisDeclContext(), getParent(), BD, Data);
424}
425
426//===----------------------------------------------------------------------===//
427// LocationContext creation.
428//===----------------------------------------------------------------------===//
429
431 AnalysisDeclContext *Ctx, const LocationContext *Parent, const Expr *E,
432 const CFGBlock *Blk, unsigned BlockCount, unsigned StmtIdx) {
433 llvm::FoldingSetNodeID ID;
434 StackFrameContext::Profile(ID, Ctx, Parent, E, Blk, BlockCount, StmtIdx);
435 void *InsertPos;
436 auto *L =
437 cast_or_null<StackFrameContext>(Contexts.FindNodeOrInsertPos(ID, InsertPos));
438 if (!L) {
439 L = new StackFrameContext(Ctx, Parent, E, Blk, BlockCount, StmtIdx,
440 ++NewID);
441 Contexts.InsertNode(L, InsertPos);
442 }
443 return L;
444}
445
447 AnalysisDeclContext *ADC, const LocationContext *ParentLC,
448 const BlockDecl *BD, const void *Data) {
449 llvm::FoldingSetNodeID ID;
450 BlockInvocationContext::Profile(ID, ADC, ParentLC, BD, Data);
451 void *InsertPos;
452 auto *L =
453 cast_or_null<BlockInvocationContext>(Contexts.FindNodeOrInsertPos(ID,
454 InsertPos));
455 if (!L) {
456 L = new BlockInvocationContext(ADC, ParentLC, BD, Data, ++NewID);
457 Contexts.InsertNode(L, InsertPos);
458 }
459 return L;
460}
461
462//===----------------------------------------------------------------------===//
463// LocationContext methods.
464//===----------------------------------------------------------------------===//
465
467 const LocationContext *LC = this;
468 while (LC) {
469 if (const auto *SFC = dyn_cast<StackFrameContext>(LC))
470 return SFC;
471 LC = LC->getParent();
472 }
473 return nullptr;
474}
475
477 return getStackFrame()->inTopFrame();
478}
479
481 do {
482 const LocationContext *Parent = LC->getParent();
483 if (Parent == this)
484 return true;
485 else
486 LC = Parent;
487 } while (LC);
488
489 return false;
490}
491
492static void printLocation(raw_ostream &Out, const SourceManager &SM,
493 SourceLocation Loc) {
494 if (Loc.isFileID() && SM.isInMainFile(Loc))
495 Out << SM.getExpansionLineNumber(Loc);
496 else
497 Loc.print(Out, SM);
498}
499
500void LocationContext::dumpStack(raw_ostream &Out) const {
502 PrintingPolicy PP(Ctx.getLangOpts());
503 PP.TerseOutput = 1;
504
505 const SourceManager &SM =
507
508 unsigned Frame = 0;
509 for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent()) {
510 switch (LCtx->getKind()) {
511 case StackFrame:
512 Out << "\t#" << Frame << ' ';
513 ++Frame;
514 if (const auto *D = dyn_cast<NamedDecl>(LCtx->getDecl()))
515 Out << "Calling " << AnalysisDeclContext::getFunctionName(D);
516 else
517 Out << "Calling anonymous code";
518 if (const Expr *E = cast<StackFrameContext>(LCtx)->getCallSite()) {
519 Out << " at line ";
520 printLocation(Out, SM, E->getBeginLoc());
521 }
522 break;
523 case Block:
524 Out << "Invoking block";
525 if (const Decl *D = cast<BlockInvocationContext>(LCtx)->getDecl()) {
526 Out << " defined at line ";
527 printLocation(Out, SM, D->getBeginLoc());
528 }
529 break;
530 }
531 Out << '\n';
532 }
533}
534
535void LocationContext::printJson(raw_ostream &Out, const char *NL,
536 unsigned int Space, bool IsDot,
537 std::function<void(const LocationContext *)>
538 printMoreInfoPerContext) const {
540 PrintingPolicy PP(Ctx.getLangOpts());
541 PP.TerseOutput = 1;
542
543 const SourceManager &SM =
545
546 unsigned Frame = 0;
547 for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent()) {
548 Indent(Out, Space, IsDot)
549 << "{ \"lctx_id\": " << LCtx->getID() << ", \"location_context\": \"";
550 switch (LCtx->getKind()) {
551 case StackFrame:
552 Out << '#' << Frame << " Call\", \"calling\": \"";
553 ++Frame;
554 if (const auto *D = dyn_cast<NamedDecl>(LCtx->getDecl()))
555 Out << D->getQualifiedNameAsString();
556 else
557 Out << "anonymous code";
558
559 Out << "\", \"location\": ";
560 if (const Expr *E = cast<StackFrameContext>(LCtx)->getCallSite()) {
561 printSourceLocationAsJson(Out, E->getBeginLoc(), SM);
562 } else {
563 Out << "null";
564 }
565
566 Out << ", \"items\": ";
567 break;
568 case Block:
569 Out << "Invoking block\" ";
570 if (const Decl *D = cast<BlockInvocationContext>(LCtx)->getDecl()) {
571 Out << ", \"location\": ";
572 printSourceLocationAsJson(Out, D->getBeginLoc(), SM);
573 Out << ' ';
574 }
575 break;
576 }
577
578 printMoreInfoPerContext(LCtx);
579
580 Out << '}';
581 if (LCtx->getParent())
582 Out << ',';
583 Out << NL;
584 }
585}
586
587LLVM_DUMP_METHOD void LocationContext::dump() const { printJson(llvm::errs()); }
588
589//===----------------------------------------------------------------------===//
590// Lazily generated map to query the external variables referenced by a Block.
591//===----------------------------------------------------------------------===//
592
593namespace {
594
595class FindBlockDeclRefExprsVals : public StmtVisitor<FindBlockDeclRefExprsVals>{
600
601public:
602 FindBlockDeclRefExprsVals(BumpVector<const VarDecl*> &bevals,
604 : BEVals(bevals), BC(bc) {}
605
606 void VisitStmt(Stmt *S) {
607 for (auto *Child : S->children())
608 if (Child)
609 Visit(Child);
610 }
611
612 void VisitDeclRefExpr(DeclRefExpr *DR) {
613 // Non-local variables are also directly modified.
614 if (const auto *VD = dyn_cast<VarDecl>(DR->getDecl())) {
615 if (!VD->hasLocalStorage()) {
616 if (Visited.insert(VD).second)
617 BEVals.push_back(VD, BC);
618 }
619 }
620 }
621
622 void VisitBlockExpr(BlockExpr *BR) {
623 // Blocks containing blocks can transitively capture more variables.
624 IgnoredContexts.insert(BR->getBlockDecl());
625 Visit(BR->getBlockDecl()->getBody());
626 }
627
628 void VisitPseudoObjectExpr(PseudoObjectExpr *PE) {
630 et = PE->semantics_end(); it != et; ++it) {
631 Expr *Semantic = *it;
632 if (auto *OVE = dyn_cast<OpaqueValueExpr>(Semantic))
633 Semantic = OVE->getSourceExpr();
634 Visit(Semantic);
635 }
636 }
637};
638
639} // namespace
640
642
644 void *&Vec,
645 llvm::BumpPtrAllocator &A) {
646 if (Vec)
647 return (DeclVec*) Vec;
648
649 BumpVectorContext BC(A);
650 DeclVec *BV = (DeclVec*) A.Allocate<DeclVec>();
651 new (BV) DeclVec(BC, 10);
652
653 // Go through the capture list.
654 for (const auto &CI : BD->captures()) {
655 BV->push_back(CI.getVariable(), BC);
656 }
657
658 // Find the referenced global/static variables.
659 FindBlockDeclRefExprsVals F(*BV, BC);
660 F.Visit(BD->getBody());
661
662 Vec = BV;
663 return BV;
664}
665
666llvm::iterator_range<AnalysisDeclContext::referenced_decls_iterator>
668 if (!ReferencedBlockVars)
669 ReferencedBlockVars = new llvm::DenseMap<const BlockDecl*,void*>();
670
671 const DeclVec *V =
672 LazyInitializeReferencedDecls(BD, (*ReferencedBlockVars)[BD], A);
673 return llvm::make_range(V->begin(), V->end());
674}
675
676std::unique_ptr<ManagedAnalysis> &AnalysisDeclContext::getAnalysisImpl(const void *tag) {
677 if (!ManagedAnalyses)
678 ManagedAnalyses = new ManagedAnalysisMap();
679 ManagedAnalysisMap *M = (ManagedAnalysisMap*) ManagedAnalyses;
680 return (*M)[tag];
681}
682
683//===----------------------------------------------------------------------===//
684// Cleanup.
685//===----------------------------------------------------------------------===//
686
688
690 delete forcedBlkExprs;
691 delete ReferencedBlockVars;
692 delete (ManagedAnalysisMap*) ManagedAnalyses;
693}
694
696
700
702 for (llvm::FoldingSet<LocationContext>::iterator I = Contexts.begin(),
703 E = Contexts.end(); I != E; ) {
704 LocationContext *LC = &*I;
705 ++I;
706 delete LC;
707 }
708 Contexts.clear();
709}
Defines the clang::ASTContext interface.
#define V(N, I)
static DeclVec * LazyInitializeReferencedDecls(const BlockDecl *BD, void *&Vec, llvm::BumpPtrAllocator &A)
static bool isSelfDecl(const VarDecl *VD)
Returns true if.
static void addParentsForSyntheticStmts(const CFG *TheCFG, ParentMap &PM)
Add each synthetic statement in the CFG to the parent map, using the source statement's parent.
static void printLocation(raw_ostream &Out, const SourceManager &SM, SourceLocation Loc)
llvm::DenseMap< const void *, std::unique_ptr< ManagedAnalysis > > ManagedAnalysisMap
BumpVector< const VarDecl * > DeclVec
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the LambdaCapture class.
#define SM(sm)
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
__device__ __2f16 float c
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:226
SourceManager & getSourceManager()
Definition ASTContext.h:859
const LangOptions & getLangOpts() const
Definition ASTContext.h:952
AnalysisDeclContextManager(ASTContext &ASTCtx, bool useUnoptimizedCFG=false, bool addImplicitDtors=false, bool addInitializers=false, bool addTemporaryDtors=false, bool addLifetime=false, bool addLoopExit=false, bool addScopes=false, bool synthesizeBodies=false, bool addStaticInitBranches=false, bool addCXXNewAllocator=true, bool addRichCXXConstructors=true, bool markElidedCXXConstructors=true, bool addVirtualBaseBranches=true, std::unique_ptr< CodeInjector > injector=nullptr)
void clear()
Discard all previously created AnalysisDeclContexts.
AnalysisDeclContext * getContext(const Decl *D)
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.
const CFGBlock * getBlockForRegisteredExpression(const Stmt *stmt)
static bool isInStdNamespace(const Decl *D)
const StackFrameContext * getStackFrame(LocationContext const *ParentLC, const Expr *E, const CFGBlock *Blk, unsigned BlockCount, unsigned Index)
Obtain a context of the call stack using its parent context.
CFGReverseBlockReachabilityAnalysis * getCFGReachablityAnalysis()
const ImplicitParamDecl * getSelfDecl() const
ASTContext & getASTContext() const
llvm::iterator_range< referenced_decls_iterator > getReferencedBlockVars(const BlockDecl *BD)
AnalysisDeclContext(AnalysisDeclContextManager *Mgr, const Decl *D)
CFG::BuildOptions & getCFGBuildOptions()
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4689
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition Decl.h:4768
ArrayRef< Capture > captures() const
Definition Decl.h:4816
const BlockDecl * getBlockDecl() const
Definition Expr.h:6683
It represents a block invocation (based on BlockCall).
void Profile(llvm::FoldingSetNodeID &ID) override
void push_back(const_reference Elt, BumpVectorContext &C)
Definition BumpVector.h:168
Represents a single basic block in a source-level CFG.
Definition CFG.h:632
CFGCallback * Observer
Definition CFG.h:1265
llvm::DenseMap< const Stmt *, const CFGBlock * > ForcedBlkExprs
Definition CFG.h:1262
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
Definition CFG.h:1250
static std::unique_ptr< CFG > buildCFG(const Decl *D, Stmt *AST, ASTContext *C, const BuildOptions &BO)
Builds a CFG from an AST.
Definition CFG.cpp:5453
synthetic_stmt_iterator synthetic_stmt_end() const
Definition CFG.h:1417
void dump(const LangOptions &LO, bool ShowColors) const
dump - A simple pretty printer of a CFG that outputs to stderr.
Definition CFG.cpp:6356
synthetic_stmt_iterator synthetic_stmt_begin() const
Iterates over synthetic DeclStmts in the CFG.
Definition CFG.h:1412
llvm::DenseMap< const DeclStmt *, const DeclStmt * >::const_iterator synthetic_stmt_iterator
Definition CFG.h:1403
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition DeclCXX.h:1018
capture_const_range captures() const
Definition DeclCXX.h:1097
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1462
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2122
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
ValueDecl * getDecl()
Definition Expr.h:1341
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
This represents one expression.
Definition Expr.h:112
Represents a function declaration or definition.
Definition Decl.h:2015
void clear()
Discard all previously created LocationContext objects.
const StackFrameContext * getStackFrame(AnalysisDeclContext *ADC, const LocationContext *ParentLC, const Expr *E, const CFGBlock *Block, unsigned BlockCount, unsigned StmtIdx)
Obtain a context of the call stack using its parent context.
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)
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
const StackFrameContext * getStackFrame() const
virtual bool inTopFrame() 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.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
void setParent(const Stmt *S, const Stmt *Parent)
Manually sets the parent of S to Parent.
Stmt * getParent(Stmt *) const
Represents an unpacked "presumed" location which can be presented to the user.
unsigned getColumn() const
Return the presumed column number of this location.
unsigned getLine() const
Return the presumed line number of this location.
semantics_iterator semantics_end()
Definition Expr.h:6868
semantics_iterator semantics_begin()
Definition Expr.h:6864
Expr *const * semantics_iterator
Definition Expr.h:6862
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
void print(raw_ostream &OS, const SourceManager &SM) const
This class handles loading and caching of source files into memory.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
It represents a stack frame of the call stack (based on CallEvent).
void Profile(llvm::FoldingSetNodeID &ID) override
bool inTopFrame() const override
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Stmt - This represents one statement.
Definition Stmt.h:86
child_range children()
Definition Stmt.cpp:304
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:355
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
Represents a variable declaration or definition.
Definition Decl.h:926
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
Definition JsonSupport.h:21
void printSourceLocationAsJson(raw_ostream &Out, SourceLocation Loc, const SourceManager &SM, bool AddBraces=true)
Definition JsonSupport.h:82
U cast(CodeGen::Address addr)
Definition Address.h:327
int const char * function
Definition c++config.h:31
Describes how types, statements, expressions, and declarations should be printed.
unsigned TerseOutput
Provide a 'terse' output.