[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:01 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:
Yeah, it's a non-trivial amount of work, especially detecting the "don't end up in the AST" - because you could imagine an API where you do a trial evaluation or similar and say "ok this wasn't used" but the node got cached somewhere so it escaped. A true misery pit.
https://github.com/llvm/llvm-project/pull/192080
More information about the cfe-commits
mailing list