Skip to content

Commit 922e916

Browse files
authored
[clang][bytecode] Handle discarded OpaqueValueExpr (llvm#187982)
... if they are already cached.
1 parent 5dcda94 commit 922e916

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,6 +2709,7 @@ bool Compiler<Emitter>::VisitMemberExpr(const MemberExpr *E) {
27092709

27102710
template <class Emitter>
27112711
bool Compiler<Emitter>::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *E) {
2712+
assert(!DiscardResult);
27122713
// ArrayIndex might not be set if a ArrayInitIndexExpr is being evaluated
27132714
// stand-alone, e.g. via EvaluateAsInt().
27142715
if (!ArrayIndex)
@@ -2753,12 +2754,17 @@ bool Compiler<Emitter>::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
27532754
if (!SourceExpr)
27542755
return false;
27552756

2756-
if (Initializing)
2757+
if (Initializing) {
2758+
assert(!DiscardResult);
27572759
return this->visitInitializer(SourceExpr);
2760+
}
27582761

27592762
PrimType SubExprT = classify(SourceExpr).value_or(PT_Ptr);
2760-
if (auto It = OpaqueExprs.find(E); It != OpaqueExprs.end())
2763+
if (auto It = OpaqueExprs.find(E); It != OpaqueExprs.end()) {
2764+
if (DiscardResult)
2765+
return true;
27612766
return this->emitGetLocal(SubExprT, It->second, E);
2767+
}
27622768

27632769
if (!this->visit(SourceExpr))
27642770
return false;
@@ -2770,16 +2776,13 @@ bool Compiler<Emitter>::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
27702776
if (!this->emitSetLocal(SubExprT, LocalIndex, E))
27712777
return false;
27722778

2773-
// Here the local variable is created but the value is removed from the stack,
2774-
// so we put it back if the caller needs it.
2775-
if (!DiscardResult) {
2776-
if (!this->emitGetLocal(SubExprT, LocalIndex, E))
2777-
return false;
2778-
}
2779-
27802779
// This is cleaned up when the local variable is destroyed.
27812780
OpaqueExprs.insert({E, LocalIndex});
27822781

2782+
// Here the local variable is created but the value is removed from the stack,
2783+
// so we put it back if the caller needs it.
2784+
if (!DiscardResult)
2785+
return this->emitGetLocal(SubExprT, LocalIndex, E);
27832786
return true;
27842787
}
27852788

clang/test/AST/ByteCode/arrays.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,3 +835,15 @@ namespace MultiDimConstructExpr {
835835
constexpr b d;
836836
static_assert(d.m[2][1].p == &d.m[2][1]);
837837
}
838+
839+
namespace MultiDimArrayInitLoop {
840+
struct S {
841+
float x[2][2];
842+
};
843+
struct T {
844+
S y;
845+
};
846+
847+
constexpr S s = {1};
848+
constexpr T t = {s};
849+
}

0 commit comments

Comments
 (0)