[clang] [Clang] Fix stack-use-after-return in TryArrayCopy by allocating OpaqueValueExpr on the ASTContext (PR #192080)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 28 13:55:15 PDT 2026


================
@@ -4380,10 +4380,10 @@ static void TryArrayCopy(Sema &S, const InitializationKind &Kind,
       InitializedEntity::InitializeElement(S.Context, 0, Entity);
   QualType InitEltT =
       S.Context.getAsArrayType(Initializer->getType())->getElementType();
-  OpaqueValueExpr OVE(Initializer->getExprLoc(), InitEltT,
-                      Initializer->getValueKind(),
-                      Initializer->getObjectKind());
-  Expr *OVEAsExpr = &OVE;
+  OpaqueValueExpr *OVE = new (S.Context) OpaqueValueExpr(
+      Initializer->getExprLoc(), InitEltT, Initializer->getValueKind(),
+      Initializer->getObjectKind());
----------------
ojhunt wrote:

In principle we could try doing a stack allocated InitializationSequence as well, and then if that all succeeds, regenerate an actual heap allocated node and place that in the destination init sequence? but that assumes the stack allocated initialization sequence is (1) possible (no trailing data) and (2) doesn't do any heap allocation behind the scenes.

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


More information about the cfe-commits mailing list