[clang] [LifetimeSafety] Add support for tracking non-trivially destructed temporary objects (PR #172007)

Abhinav Pradeep via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 12 05:22:01 PST 2026


================
@@ -325,19 +348,27 @@ void FactsGenerator::VisitInitListExpr(const InitListExpr *ILE) {
 void FactsGenerator::VisitMaterializeTemporaryExpr(
     const MaterializeTemporaryExpr *MTE) {
   OriginList *MTEList = getOriginsList(*MTE);
-  if (!MTEList)
+  // Here we also defer from handling lifetime extended materializations.
+  if (!MTEList || MTE->getStorageDuration() != SD_FullExpression)
     return;
   OriginList *SubExprList = getOriginsList(*MTE->getSubExpr());
   if (MTE->isGLValue()) {
     assert(!SubExprList ||
            MTEList->getLength() == SubExprList->getLength() + 1 &&
                "MTE top level origin should contain a loan to the MTE itself");
     MTEList = getRValueOrigins(MTE, MTEList);
-    // TODO: Issue a loan to the MTE.
+    if (getChildBinding(MTE)) {
+      // Issue a loan to MTE for the storage location represented by MTE.
+      const Loan *L = createLoan(FactMgr, MTE);
+      OriginList *List = getOriginsList(*MTE);
+      CurrentBlockFacts.push_back(
+          FactMgr.createFact<IssueFact>(L->getID(), List->getOuterOriginID()));
+    }
     flow(MTEList, SubExprList, /*Kill=*/true);
   } else {
-    assert(MTE->isXValue());
-    flow(MTEList, SubExprList, /*Kill=*/true);
+    // A temporary object's origin is the same as the origin of the
----------------
AbhinavPradeep wrote:

I did this and no assert fired! I do believe that branch was dead.

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


More information about the cfe-commits mailing list