[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 12:52:49 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:

I guess we could at least make sure we clean up the temporaries when/if the compiler context gets torn down, but I don't know if that ever actually happens in practice :D

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


More information about the cfe-commits mailing list