@@ -570,11 +570,11 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
570570 return false ;
571571 }
572572
573+ PrimType T = classifyPrim (SubExpr->getType ());
573574 // Init the complex value to {SubExpr, 0}.
574- if (!this ->visitArrayElemInit (0 , SubExpr))
575+ if (!this ->visitArrayElemInit (0 , SubExpr, T ))
575576 return false ;
576577 // Zero-init the second element.
577- PrimType T = classifyPrim (SubExpr->getType ());
578578 if (!this ->visitZeroInitializer (T, SubExpr->getType (), SubExpr))
579579 return false ;
580580 return this ->emitInitElem (T, 1 , SubExpr);
@@ -772,7 +772,7 @@ bool Compiler<Emitter>::VisitImaginaryLiteral(const ImaginaryLiteral *E) {
772772 return false ;
773773 if (!this ->emitInitElem (SubExprT, 0 , SubExpr))
774774 return false ;
775- return this ->visitArrayElemInit (1 , SubExpr);
775+ return this ->visitArrayElemInit (1 , SubExpr, SubExprT );
776776}
777777
778778template <class Emitter >
@@ -1886,6 +1886,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
18861886 if (!this ->emitCheckArraySize (NumElems, E))
18871887 return false ;
18881888
1889+ std::optional<PrimType> InitT = classify (CAT->getElementType ());
18891890 unsigned ElementIndex = 0 ;
18901891 for (const Expr *Init : Inits) {
18911892 if (const auto *EmbedS =
@@ -1905,7 +1906,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
19051906 if (!EmbedS->doForEachDataElement (Eval, ElementIndex))
19061907 return false ;
19071908 } else {
1908- if (!this ->visitArrayElemInit (ElementIndex, Init))
1909+ if (!this ->visitArrayElemInit (ElementIndex, Init, InitT ))
19091910 return false ;
19101911 ++ElementIndex;
19111912 }
@@ -1915,7 +1916,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
19151916 // FIXME: This should go away.
19161917 if (ArrayFiller) {
19171918 for (; ElementIndex != NumElems; ++ElementIndex) {
1918- if (!this ->visitArrayElemInit (ElementIndex, ArrayFiller))
1919+ if (!this ->visitArrayElemInit (ElementIndex, ArrayFiller, InitT ))
19191920 return false ;
19201921 }
19211922 }
@@ -1998,13 +1999,13 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
19981999// / Pointer to the array(not the element!) must be on the stack when calling
19992000// / this.
20002001template <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 ) {
20042005 // Visit the primitive element like normal.
20052006 if (!this ->visit (Init))
20062007 return false ;
2007- return this ->emitInitElem (*T , ElemIndex, Init);
2008+ return this ->emitInitElem (*InitT , ElemIndex, Init);
20082009 }
20092010
20102011 InitLinkScope<Emitter> ILS (this , InitLink::Elem (ElemIndex));
@@ -2298,6 +2299,7 @@ bool Compiler<Emitter>::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E) {
22982299 // Investigate compiling this to a loop.
22992300 const Expr *SubExpr = E->getSubExpr ();
23002301 size_t Size = E->getArraySize ().getZExtValue ();
2302+ std::optional<PrimType> SubExprT = classify (SubExpr);
23012303
23022304 // So, every iteration, we execute an assignment here
23032305 // where the LHS is on the stack (the target array)
@@ -2306,7 +2308,7 @@ bool Compiler<Emitter>::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *E) {
23062308 ArrayIndexScope<Emitter> IndexScope (this , I);
23072309 BlockScope<Emitter> BS (this );
23082310
2309- if (!this ->visitArrayElemInit (I, SubExpr))
2311+ if (!this ->visitArrayElemInit (I, SubExpr, SubExprT ))
23102312 return false ;
23112313 if (!BS.destroyLocals ())
23122314 return false ;
0 commit comments