@@ -816,22 +816,18 @@ bool ByteCodeExprGen<Emitter>::VisitArrayInitLoopExpr(
816
816
const ArrayInitLoopExpr *E) {
817
817
assert (Initializing);
818
818
assert (!DiscardResult);
819
+
820
+ // We visit the common opaque expression here once so we have its value
821
+ // cached.
822
+ if (!this ->discard (E->getCommonExpr ()))
823
+ return false ;
824
+
819
825
// TODO: This compiles to quite a lot of bytecode if the array is larger.
820
826
// Investigate compiling this to a loop.
821
-
822
827
const Expr *SubExpr = E->getSubExpr ();
823
- const Expr *CommonExpr = E->getCommonExpr ();
824
828
size_t Size = E->getArraySize ().getZExtValue ();
825
829
std::optional<PrimType> ElemT = classify (SubExpr->getType ());
826
830
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
-
835
831
// So, every iteration, we execute an assignment here
836
832
// where the LHS is on the stack (the target array)
837
833
// and the RHS is our SubExpr.
@@ -882,13 +878,13 @@ bool ByteCodeExprGen<Emitter>::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
882
878
return false ;
883
879
884
880
// Here the local variable is created but the value is removed from the stack,
885
- // so we put it back, because the caller might need it.
881
+ // so we put it back if the caller needs it.
886
882
if (!DiscardResult) {
887
883
if (!this ->emitGetLocal (SubExprT, *LocalIndex, E))
888
884
return false ;
889
885
}
890
886
891
- // FIXME: Ideally the cached value should be cleaned up later .
887
+ // This is cleaned up when the local variable is destroyed .
892
888
OpaqueExprs.insert ({E, *LocalIndex});
893
889
894
890
return true ;
0 commit comments