[llvm-branch-commits] [clang] [LifetimeSafety] Track view types/gsl::Pointer. (PR #153661)
Utkarsh Saxena via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Aug 14 12:59:04 PDT 2025
https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/153661
[LifetimeSafety] Track view types/gsl::Pointer.
[LifetimeSafety] Do not create two loans for the same expression
>From 43d28dc6df5b5ae437b2970d424d8625d6ea090a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Thu, 14 Aug 2025 06:57:44 +0000
Subject: [PATCH 1/2] [LifetimeSafety] Track view types/gsl::Pointer.
---
clang/lib/Analysis/LifetimeSafety.cpp | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Analysis/LifetimeSafety.cpp b/clang/lib/Analysis/LifetimeSafety.cpp
index c762f63c45e09..0e3f7c8590803 100644
--- a/clang/lib/Analysis/LifetimeSafety.cpp
+++ b/clang/lib/Analysis/LifetimeSafety.cpp
@@ -398,10 +398,15 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
CurrentBlockFacts.clear();
for (unsigned I = 0; I < Block->size(); ++I) {
const CFGElement &Element = Block->Elements[I];
- if (std::optional<CFGStmt> CS = Element.getAs<CFGStmt>())
+ if (std::optional<CFGStmt> CS = Element.getAs<CFGStmt>()) {
+ DEBUG_WITH_TYPE("PrintCFG",
+ llvm::dbgs()
+ << "======CFGStmt and ASTStmt========\n");
+ DEBUG_WITH_TYPE("PrintCFG", CS->dump());
+ DEBUG_WITH_TYPE("PrintCFG", CS->getStmt()->dumpColor());
Visit(CS->getStmt());
- else if (std::optional<CFGAutomaticObjDtor> DtorOpt =
- Element.getAs<CFGAutomaticObjDtor>())
+ } else if (std::optional<CFGAutomaticObjDtor> DtorOpt =
+ Element.getAs<CFGAutomaticObjDtor>())
handleDestructor(*DtorOpt);
}
FactMgr.addBlockFacts(Block, CurrentBlockFacts);
>From e61817a17681c47a4369bdd1cce85940d02b2420 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Thu, 14 Aug 2025 19:54:49 +0000
Subject: [PATCH 2/2] [LifetimeSafety] Do not create two loans for the same
expression
---
clang/lib/Analysis/LifetimeSafety.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/lib/Analysis/LifetimeSafety.cpp b/clang/lib/Analysis/LifetimeSafety.cpp
index 0e3f7c8590803..d5d7e20a9f0cd 100644
--- a/clang/lib/Analysis/LifetimeSafety.cpp
+++ b/clang/lib/Analysis/LifetimeSafety.cpp
@@ -396,6 +396,7 @@ class FactGenerator : public ConstStmtVisitor<FactGenerator> {
// initializations and destructions are processed in the correct sequence.
for (const CFGBlock *Block : *AC.getAnalysis<PostOrderCFGView>()) {
CurrentBlockFacts.clear();
+ VisitedStmts.clear();
for (unsigned I = 0; I < Block->size(); ++I) {
const CFGElement &Element = Block->Elements[I];
if (std::optional<CFGStmt> CS = Element.getAs<CFGStmt>()) {
More information about the llvm-branch-commits
mailing list