llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Benedek Kaibas (benedekaibas)

<details>
<summary>Changes</summary>

In #<!-- -->211552 `MemRegion::getDescriptiveName` got generalized and now has 
an `AllowFallback` functionality which makes it possible to remove 
`getRegionName()` from the modeling checker and from both of the dependent 
checkers (`UseAfterLifetimeEnd` and `DanglingPtrDeref`).

---
Full diff: https://github.com/llvm/llvm-project/pull/214245.diff


4 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/DanglingPtrDeref.cpp (+4-2) 
- (modified) clang/lib/StaticAnalyzer/Checkers/LifetimeModeling.cpp (-8) 
- (modified) clang/lib/StaticAnalyzer/Checkers/LifetimeModeling.h (-4) 
- (modified) clang/lib/StaticAnalyzer/Checkers/UseAfterLifetimeEnd.cpp (+12-7) 


``````````diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/DanglingPtrDeref.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DanglingPtrDeref.cpp
index bd4cd864cb768..a34bf20eebafb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DanglingPtrDeref.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DanglingPtrDeref.cpp
@@ -71,7 +71,8 @@ void DanglingPtrDeref::reportUseAfterScope(const MemRegion 
*Region,
                                            CheckerContext &C) const {
   auto BR = std::make_unique<PathSensitiveBugReport>(
       BugMsg,
-      (llvm::Twine("Use of ") + lifetime_modeling::getRegionName(Region) +
+      (llvm::Twine("Use of ") +
+       Region->getDescriptiveName(/*UseQuotes=*/true, /*AllowFallback=*/true) +
        " after its lifetime ended."),
       N);
   BR->addVisitor<DanglingPtrDerefBRVisitor>(Region);
@@ -103,7 +104,8 @@ DanglingPtrDerefBRVisitor::VisitNode(const ExplodedNode *N,
       S, BRC.getSourceManager(), N->getStackFrame());
   return std::make_shared<PathDiagnosticEventPiece>(
       Pos,
-      (lifetime_modeling::getRegionName(SourceRegion) +
+      (SourceRegion->getDescriptiveName(/*UseQuotes=*/true,
+                                        /*AllowFallback=*/true) +
        llvm::Twine(" is destroyed here"))
           .str(),
       true);
diff --git a/clang/lib/StaticAnalyzer/Checkers/LifetimeModeling.cpp 
b/clang/lib/StaticAnalyzer/Checkers/LifetimeModeling.cpp
index 7b9fb7acb21ab..85ea496cdfb0e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/LifetimeModeling.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/LifetimeModeling.cpp
@@ -92,14 +92,6 @@ static ProgramStateRef bindSource(ProgramStateRef State, 
SVal RetVal,
   return State;
 }
 
-std::string lifetime_modeling::getRegionName(const MemRegion *Reg) {
-  // FIXME: Once the checker supports heap allocation, more region kinds
-  // should be handled to produce the correct descriptive name.
-  if (const std::string RegName = Reg->getDescriptiveName(); !RegName.empty())
-    return RegName;
-  return "the region";
-}
-
 void LifetimeModeling::checkPostCall(const CallEvent &Call,
                                      CheckerContext &C) const {
   ProgramStateRef State = C.getState();
diff --git a/clang/lib/StaticAnalyzer/Checkers/LifetimeModeling.h 
b/clang/lib/StaticAnalyzer/Checkers/LifetimeModeling.h
index 8d6c8e4882d1c..747bd8d6fd74c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/LifetimeModeling.h
+++ b/clang/lib/StaticAnalyzer/Checkers/LifetimeModeling.h
@@ -18,10 +18,6 @@ bool isDeallocated(ProgramStateRef State, const MemRegion 
*Region);
 
 /// Returns true if \p Val is a key in the LifetimeBoundMap.
 bool isBoundToLifetimeSource(ProgramStateRef State, SVal Val);
-
-/// Returns the descriptive name of the memory region or a placeholder if a
-/// descriptive name cannot be constructed for it.
-std::string getRegionName(const MemRegion *Reg);
 } // namespace clang::ento::lifetime_modeling
 
 #endif // LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_LIFETIMEMODELING_H
diff --git a/clang/lib/StaticAnalyzer/Checkers/UseAfterLifetimeEnd.cpp 
b/clang/lib/StaticAnalyzer/Checkers/UseAfterLifetimeEnd.cpp
index a9065352adae6..c36f986c5e3b8 100644
--- a/clang/lib/StaticAnalyzer/Checkers/UseAfterLifetimeEnd.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/UseAfterLifetimeEnd.cpp
@@ -99,7 +99,8 @@ void UseAfterLifetimeEnd::reportDanglingSource(const 
MemRegion *Source,
   auto BR = std::make_unique<PathSensitiveBugReport>(
       BugMsg,
       (llvm::Twine("Returning value bound to ") +
-       lifetime_modeling::getRegionName(Source) + " that will go out of 
scope"),
+       Source->getDescriptiveName(/*UseQuotes=*/true, /*AllowFallback=*/true) +
+       " that will go out of scope"),
       N);
 
   if (SourceRange Range = getRegionDeclRange(Source); Range.isValid())
@@ -146,7 +147,9 @@ UseAfterLifetimeEndBRVisitor::VisitNode(const ExplodedNode 
*N,
   auto Piece = createSourcePiece(
       N, BRC,
       (llvm::Twine("Value's lifetime bound to the lifetime of ") +
-       lifetime_modeling::getRegionName(SourceRegion) + " here")
+       SourceRegion->getDescriptiveName(/*UseQuotes=*/true,
+                                        /*AllowFallback=*/true) +
+       " here")
           .str());
   return Piece;
 }
@@ -155,11 +158,13 @@ PathDiagnosticPieceRef
 UseAfterLifetimeEndBRVisitor::getEndPath(const ExplodedNode *N,
                                          BugReporterContext &BRC,
                                          PathSensitiveBugReport &BR) {
-  auto Piece = createSourcePiece(
-      N, BRC,
-      (llvm::Twine("Lifetime of ") +
-       lifetime_modeling::getRegionName(SourceRegion) + " ended here")
-          .str());
+  auto Piece =
+      createSourcePiece(N, BRC,
+                        (llvm::Twine("Lifetime of ") +
+                         SourceRegion->getDescriptiveName(
+                             /*UseQuotes=*/true, /*AllowFallback=*/true) +
+                         " ended here")
+                            .str());
   return Piece;
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/214245
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to