[clang] 922e916 - [clang][bytecode] Handle discarded OpaqueValueExpr (#187982)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 23 01:25:52 PDT 2026
Author: Timm Baeder
Date: 2026-03-23T09:25:45+01:00
New Revision: 922e916350f272bbc47d271c832051f4b0531b67
URL: https://github.com/llvm/llvm-project/commit/922e916350f272bbc47d271c832051f4b0531b67
DIFF: https://github.com/llvm/llvm-project/commit/922e916350f272bbc47d271c832051f4b0531b67.diff
LOG: [clang][bytecode] Handle discarded OpaqueValueExpr (#187982)
... if they are already cached.
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/arrays.cpp
Removed:
################################################################################
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};
+}
More information about the cfe-commits
mailing list