[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:38:18 PDT 2026
https://github.com/NeKon69 created https://github.com/llvm/llvm-project/pull/203772
Fixes #203768
>From b4a9bf715e8afcf1da1d8056b96f95ec8bcfec41 Mon Sep 17 00:00:00 2001
From: NeKon69 <nobodqwe at gmail.com>
Date: Sun, 14 Jun 2026 17:37:10 +0300
Subject: [PATCH] [LifetimeSafety] Do not propogate origins to InitListExpr
when first Init is a type with no origins
---
clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp | 7 ++++++-
clang/test/Sema/LifetimeSafety/safety.cpp | 5 +++++
2 files changed, 11 insertions(+), 1 deletion(-)
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