Skip to content

Commit 1877937

Browse files
committed
[LifetimeSafety] Track view types/gsl::Pointer.
1 parent f590db6 commit 1877937

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

clang/lib/Analysis/LifetimeSafety.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,18 +396,30 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
396396
// initializations and destructions are processed in the correct sequence.
397397
for (const CFGBlock *Block : *AC.getAnalysis<PostOrderCFGView>()) {
398398
CurrentBlockFacts.clear();
399+
VisitedStmts.clear();
399400
for (unsigned I = 0; I < Block->size(); ++I) {
400401
const CFGElement &Element = Block->Elements[I];
401-
if (std::optional<CFGStmt> CS = Element.getAs<CFGStmt>())
402+
if (std::optional<CFGStmt> CS = Element.getAs<CFGStmt>()) {
403+
DEBUG_WITH_TYPE("PrintCFG",
404+
llvm::dbgs()
405+
<< "======CFGStmt and ASTStmt========\n");
406+
DEBUG_WITH_TYPE("PrintCFG", CS->dump());
407+
DEBUG_WITH_TYPE("PrintCFG", CS->getStmt()->dumpColor());
402408
Visit(CS->getStmt());
403-
else if (std::optional<CFGAutomaticObjDtor> DtorOpt =
404-
Element.getAs<CFGAutomaticObjDtor>())
409+
} else if (std::optional<CFGAutomaticObjDtor> DtorOpt =
410+
Element.getAs<CFGAutomaticObjDtor>())
405411
handleDestructor(*DtorOpt);
406412
}
407413
FactMgr.addBlockFacts(Block, CurrentBlockFacts);
408414
}
409415
}
410416

417+
void Visit(const Stmt *S) {
418+
if(!S || VisitedStmts.insert(S).second)
419+
return;
420+
Base::Visit(S);
421+
}
422+
411423
void VisitDeclStmt(const DeclStmt *DS) {
412424
for (const Decl *D : DS->decls())
413425
if (const auto *VD = dyn_cast<VarDecl>(D))
@@ -551,6 +563,7 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
551563
FactManager &FactMgr;
552564
AnalysisDeclContext &AC;
553565
llvm::SmallVector<Fact *> CurrentBlockFacts;
566+
llvm::DenseSet<const Stmt *> VisitedStmts;
554567
};
555568

556569
// ========================================================================= //

0 commit comments

Comments
 (0)