[clang] [LifetimeSafety] Track origins for lifetimebound calls returning record types (PR #187917)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 26 03:18:55 PDT 2026


================
@@ -182,14 +190,13 @@ void FactsGenerator::VisitCXXConstructExpr(const CXXConstructExpr *CCE) {
     handleGSLPointerConstruction(CCE);
     return;
   }
-  // Implicit copy/move constructors of lambda closures lack
-  // [[clang::lifetimebound]], so `handleFunctionCall` cannot propagate origins.
-  // Handle them directly to keep the origin chain intact (e.g., `return
-  // lambda;` copies the closure).
-  if (const auto *RD = CCE->getType()->getAsCXXRecordDecl();
-      RD && RD->isLambda() &&
-      CCE->getConstructor()->isCopyOrMoveConstructor() &&
-      CCE->getNumArgs() == 1) {
+  // For defaulted (implicit or `= default`) copy/move constructors, propagate
+  // origins directly. User-defined copy/move constructors have opaque semantics
+  // and fall through to `handleFunctionCall`, where [[clang::lifetimebound]] is
+  // needed to propagate origins.
+  if (CCE->getConstructor()->isCopyOrMoveConstructor() &&
+      CCE->getConstructor()->isDefaulted() && CCE->getNumArgs() == 1 &&
----------------
Xazax-hun wrote:

Do you have a test case for implicit constructors? I am surprised if `isDefaulted` returns true for them. Maybe what we want to se is not user provided?

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


More information about the cfe-commits mailing list