[clang] [LifetimeSafety] Give a lifetime-extended temporary a loan (PR #238776)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 4 07:48:48 PST 2026


================
@@ -642,12 +642,14 @@ void FactsGenerator::VisitMaterializeTemporaryExpr(
   OriginList *RValMTEList = MTEList->peelOuterOrigin();
   flow(RValMTEList, SubExprList, /*Kill=*/true);
   OriginID OuterMTEID = MTEList->getOuterOriginID();
-  if (MTE->getStorageDuration() == SD_FullExpression) {
-    // Issue a loan to MTE for the storage location represented by MTE.
-    const Loan *L = createLoan(FactMgr, MTE);
-    CurrentBlockFacts.push_back(
-        FactMgr.createFact<IssueFact>(L->getID(), OuterMTEID));
-  }
+  const Loan *L = createLoan(FactMgr, MTE);
+  CurrentBlockFacts.push_back(
+      FactMgr.createFact<IssueFact>(L->getID(), OuterMTEID));
+  // A temporary extended to static or thread storage duration never expires
+  // within the function. An automatic one expires with its extending variable.
----------------
Xazax-hun wrote:

Could you elaborate on what kind of comment would you find helpful? 

https://github.com/llvm/llvm-project/pull/238776


More information about the cfe-commits mailing list