[clang] 8717831 - [LifetimeSafety] Do not propagate origins to `InitListExpr` when first `Init` is a type with no origins (#203772)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 15 04:35:49 PDT 2026
Author: NeKon69
Date: 2026-06-15T13:35:44+02:00
New Revision: 8717831a8c94a91e98e7ecb3c56de8e33ed59502
URL: https://github.com/llvm/llvm-project/commit/8717831a8c94a91e98e7ecb3c56de8e33ed59502
DIFF: https://github.com/llvm/llvm-project/commit/8717831a8c94a91e98e7ecb3c56de8e33ed59502.diff
LOG: [LifetimeSafety] Do not propagate origins to `InitListExpr` when first `Init` is a type with no origins (#203772)
Fixes #203768
Added:
Modified:
clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp
clang/test/Sema/LifetimeSafety/safety.cpp
Removed:
################################################################################
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};
+}
More information about the cfe-commits
mailing list