@@ -488,14 +488,25 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
488488 if (DiscardResult)
489489 return this ->discard (SubExpr);
490490
491- assert (Initializing); // FIXME: Not always correct.
491+ if (!Initializing) {
492+ std::optional<unsigned > LocalIndex = allocateLocal (CE);
493+ if (!LocalIndex)
494+ return false ;
495+ if (!this ->emitGetPtrLocal (*LocalIndex, CE))
496+ return false ;
497+ }
498+
492499 const auto *VT = CE->getType ()->getAs <VectorType>();
493- PrimType ElemT = classifyPrim (SubExpr);
500+ PrimType ElemT = classifyPrim (SubExpr-> getType () );
494501 unsigned ElemOffset = allocateLocalPrimitive (
495502 SubExpr, ElemT, /* IsConst=*/ true , /* IsExtended=*/ false );
496503
504+ // Prepare a local variable for the scalar value.
497505 if (!this ->visit (SubExpr))
498506 return false ;
507+ if (classifyPrim (SubExpr) == PT_Ptr && !this ->emitLoadPop (ElemT, CE))
508+ return false ;
509+
499510 if (!this ->emitSetLocal (ElemT, ElemOffset, CE))
500511 return false ;
501512
@@ -2778,6 +2789,7 @@ template <class Emitter>
27782789bool ByteCodeExprGen<Emitter>::VisitExtVectorElementExpr(
27792790 const ExtVectorElementExpr *E) {
27802791 const Expr *Base = E->getBase ();
2792+ assert (Base->getType ()->isVectorType ());
27812793
27822794 SmallVector<uint32_t , 4 > Indices;
27832795 E->getEncodedElementAccess (Indices);
0 commit comments