@@ -820,14 +820,24 @@ bool ByteCodeExprGen<Emitter>::VisitArrayInitLoopExpr(
820
820
// Investigate compiling this to a loop.
821
821
822
822
const Expr *SubExpr = E->getSubExpr ();
823
+ const Expr *CommonExpr = E->getCommonExpr ();
823
824
size_t Size = E->getArraySize ().getZExtValue ();
824
825
std::optional<PrimType> ElemT = classify (SubExpr->getType ());
825
826
827
+ // If the common expression is an opaque expression, we visit it
828
+ // here once so we have its value cached.
829
+ // FIXME: This might be necessary (or useful) for all expressions.
830
+ if (isa<OpaqueValueExpr>(CommonExpr)) {
831
+ if (!this ->discard (CommonExpr))
832
+ return false ;
833
+ }
834
+
826
835
// So, every iteration, we execute an assignment here
827
836
// where the LHS is on the stack (the target array)
828
837
// and the RHS is our SubExpr.
829
838
for (size_t I = 0 ; I != Size ; ++I) {
830
839
ArrayIndexScope<Emitter> IndexScope (this , I);
840
+ BlockScope<Emitter> BS (this );
831
841
832
842
if (ElemT) {
833
843
if (!this ->visit (SubExpr))
@@ -856,7 +866,7 @@ bool ByteCodeExprGen<Emitter>::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
856
866
857
867
PrimType SubExprT = classify (E->getSourceExpr ()).value_or (PT_Ptr);
858
868
if (auto It = OpaqueExprs.find (E); It != OpaqueExprs.end ())
859
- return this ->emitGetLocal (SubExprT, It->getSecond () , E);
869
+ return this ->emitGetLocal (SubExprT, It->second , E);
860
870
861
871
if (!this ->visit (E->getSourceExpr ()))
862
872
return false ;
@@ -873,8 +883,10 @@ bool ByteCodeExprGen<Emitter>::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
873
883
874
884
// Here the local variable is created but the value is removed from the stack,
875
885
// so we put it back, because the caller might need it.
876
- if (!this ->emitGetLocal (SubExprT, *LocalIndex, E))
877
- return false ;
886
+ if (!DiscardResult) {
887
+ if (!this ->emitGetLocal (SubExprT, *LocalIndex, E))
888
+ return false ;
889
+ }
878
890
879
891
// FIXME: Ideally the cached value should be cleaned up later.
880
892
OpaqueExprs.insert ({E, *LocalIndex});
0 commit comments