https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/187982
... if they are already cached. >From c28b8066aa2b9dbbe4d2db5fd0c796850749f3cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Mon, 23 Mar 2026 07:59:08 +0100 Subject: [PATCH] [clang][bytecode] Handle discarded OpaqueValueExpr ... if they are already cached. --- clang/lib/AST/ByteCode/Compiler.cpp | 21 ++++++++++++--------- clang/test/AST/ByteCode/arrays.cpp | 12 ++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index a881d77a73cbd..5e029643fb0d4 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -2709,6 +2709,7 @@ bool Compiler<Emitter>::VisitMemberExpr(const MemberExpr *E) { template <class Emitter> bool Compiler<Emitter>::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E) { + assert(!DiscardResult); // ArrayIndex might not be set if a ArrayInitIndexExpr is being evaluated // stand-alone, e.g. via EvaluateAsInt(). if (!ArrayIndex) @@ -2753,12 +2754,17 @@ bool Compiler<Emitter>::VisitOpaqueValueExpr(const OpaqueValueExpr *E) { if (!SourceExpr) return false; - if (Initializing) + if (Initializing) { + assert(!DiscardResult); return this->visitInitializer(SourceExpr); + } PrimType SubExprT = classify(SourceExpr).value_or(PT_Ptr); - if (auto It = OpaqueExprs.find(E); It != OpaqueExprs.end()) + if (auto It = OpaqueExprs.find(E); It != OpaqueExprs.end()) { + if (DiscardResult) + return true; return this->emitGetLocal(SubExprT, It->second, E); + } if (!this->visit(SourceExpr)) return false; @@ -2770,16 +2776,13 @@ bool Compiler<Emitter>::VisitOpaqueValueExpr(const OpaqueValueExpr *E) { if (!this->emitSetLocal(SubExprT, LocalIndex, E)) return false; - // Here the local variable is created but the value is removed from the stack, - // so we put it back if the caller needs it. - if (!DiscardResult) { - if (!this->emitGetLocal(SubExprT, LocalIndex, E)) - return false; - } - // This is cleaned up when the local variable is destroyed. OpaqueExprs.insert({E, LocalIndex}); + // Here the local variable is created but the value is removed from the stack, + // so we put it back if the caller needs it. + if (!DiscardResult) + return this->emitGetLocal(SubExprT, LocalIndex, E); return true; } diff --git a/clang/test/AST/ByteCode/arrays.cpp b/clang/test/AST/ByteCode/arrays.cpp index d83ae97fc8213..cb5b7ad99070e 100644 --- a/clang/test/AST/ByteCode/arrays.cpp +++ b/clang/test/AST/ByteCode/arrays.cpp @@ -835,3 +835,15 @@ namespace MultiDimConstructExpr { constexpr b d; static_assert(d.m[2][1].p == &d.m[2][1]); } + +namespace MultiDimArrayInitLoop { + struct S { + float x[2][2]; + }; + struct T { + S y; + }; + + constexpr S s = {1}; + constexpr T t = {s}; +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
