@@ -570,11 +570,11 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
570
570
return false ;
571
571
}
572
572
573
+ PrimType T = classifyPrim (SubExpr->getType ());
573
574
// Init the complex value to {SubExpr, 0}.
574
- if (!this ->visitArrayElemInit (0 , SubExpr))
575
+ if (!this ->visitArrayElemInit (0 , SubExpr, T ))
575
576
return false ;
576
577
// Zero-init the second element.
577
- PrimType T = classifyPrim (SubExpr->getType ());
578
578
if (!this ->visitZeroInitializer (T, SubExpr->getType (), SubExpr))
579
579
return false ;
580
580
return this ->emitInitElem (T, 1 , SubExpr);
@@ -772,7 +772,7 @@ bool Compiler<Emitter>::VisitImaginaryLiteral(const ImaginaryLiteral *E) {
772
772
return false ;
773
773
if (!this ->emitInitElem (SubExprT, 0 , SubExpr))
774
774
return false ;
775
- return this ->visitArrayElemInit (1 , SubExpr);
775
+ return this ->visitArrayElemInit (1 , SubExpr, SubExprT );
776
776
}
777
777
778
778
template <class Emitter >
@@ -1886,6 +1886,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
1886
1886
if (!this ->emitCheckArraySize (NumElems, E))
1887
1887
return false ;
1888
1888
1889
+ std::optional<PrimType> InitT = classify (CAT->getElementType ());
1889
1890
unsigned ElementIndex = 0 ;
1890
1891
for (const Expr *Init : Inits) {
1891
1892
if (const auto *EmbedS =
@@ -1905,7 +1906,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
1905
1906
if (!EmbedS->doForEachDataElement (Eval, ElementIndex))
1906
1907
return false ;
1907
1908
} else {
1908
- if (!this ->visitArrayElemInit (ElementIndex, Init))
1909
+ if (!this ->visitArrayElemInit (ElementIndex, Init, InitT ))
1909
1910
return false ;
1910
1911
++ElementIndex;
1911
1912
}
@@ -1915,7 +1916,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
1915
1916
// FIXME: This should go away.
1916
1917
if (ArrayFiller) {
1917
1918
for (; ElementIndex != NumElems; ++ElementIndex) {
1918
- if (!this ->visitArrayElemInit (ElementIndex, ArrayFiller))
1919
+ if (!this ->visitArrayElemInit (ElementIndex, ArrayFiller, InitT ))
1919
1920
return false ;
1920
1921
}
1921
1922
}
@@ -1998,13 +1999,13 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
1998
1999
// / Pointer to the array(not the element!) must be on the stack when calling
1999
2000
// / this.
2000
2001
template <class Emitter >
2001
- bool Compiler<Emitter>::visitArrayElemInit(unsigned ElemIndex,
2002
- const Expr *Init ) {
2003
- if (std::optional<PrimType> T = classify (Init-> getType ()) ) {
2002
+ bool Compiler<Emitter>::visitArrayElemInit(unsigned ElemIndex, const Expr *Init,
2003
+ std::optional<PrimType> InitT ) {
2004
+ if (InitT ) {
2004
2005
// Visit the primitive element like normal.
2005
2006
if (!this ->visit (Init))
2006
2007
return false ;
2007
- return this ->emitInitElem (*T , ElemIndex, Init);
2008
+ return this ->emitInitElem (*InitT , ElemIndex, Init);
2008
2009
}
2009
2010
2010
2011
InitLinkScope<Emitter> ILS (this , InitLink::Elem (ElemIndex));
@@ -2298,6 +2299,7 @@ bool Compiler<Emitter>::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E) {
2298
2299
// Investigate compiling this to a loop.
2299
2300
const Expr *SubExpr = E->getSubExpr ();
2300
2301
size_t Size = E->getArraySize ().getZExtValue ();
2302
+ std::optional<PrimType> SubExprT = classify (SubExpr);
2301
2303
2302
2304
// So, every iteration, we execute an assignment here
2303
2305
// where the LHS is on the stack (the target array)
@@ -2306,7 +2308,7 @@ bool Compiler<Emitter>::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E) {
2306
2308
ArrayIndexScope<Emitter> IndexScope (this , I);
2307
2309
BlockScope<Emitter> BS (this );
2308
2310
2309
- if (!this ->visitArrayElemInit (I, SubExpr))
2311
+ if (!this ->visitArrayElemInit (I, SubExpr, SubExprT ))
2310
2312
return false ;
2311
2313
if (!BS.destroyLocals ())
2312
2314
return false ;
0 commit comments