[clang] [LifetimeSafety] Do not propogate origins to `InitListExpr` when first `Init` is a type with no origins (PR #203772)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 14 07:39:00 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-analysis
Author: NeKon69
<details>
<summary>Changes</summary>
Fixes #<!-- -->203768
---
Full diff: https://github.com/llvm/llvm-project/pull/203772.diff
2 Files Affected:
- (modified) clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp (+6-1)
- (modified) clang/test/Sema/LifetimeSafety/safety.cpp (+5)
``````````diff
diff --git a/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp b/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp
index 9fbfaf8ae606b..be0577b0f3f8f 100644
--- a/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp
@@ -566,8 +566,13 @@ void FactsGenerator::VisitInitListExpr(const InitListExpr *ILE) {
return;
// For list initialization with a single element, like `View{...}`, the
// origin of the list itself is the origin of its single element.
- if (ILE->getNumInits() == 1)
+ if (ILE->getNumInits() == 1) {
+ // A type with origins may be list-initialized from an element with none
+ // (e.g., an int). Only flow if the element carries any.
+ if (!hasOrigins(ILE->getInit(0)))
+ return;
killAndFlowOrigin(*ILE, *ILE->getInit(0));
+ }
}
void FactsGenerator::VisitCXXBindTemporaryExpr(
diff --git a/clang/test/Sema/LifetimeSafety/safety.cpp b/clang/test/Sema/LifetimeSafety/safety.cpp
index c838918eb556d..56226f954fee3 100644
--- a/clang/test/Sema/LifetimeSafety/safety.cpp
+++ b/clang/test/Sema/LifetimeSafety/safety.cpp
@@ -3714,3 +3714,8 @@ void capturing_multiple_locals() {
} // expected-note 2 {{destroyed here}}
(void)v; // expected-note 2 {{later used here}}
}
+
+struct [[gsl::Pointer()]] PtrWithInt { int x; };
+PtrWithInt f() {
+ return PtrWithInt{10};
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/203772
More information about the cfe-commits
mailing list