@@ -448,6 +448,10 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
448448
449449 QualType SubExprTy = SubExpr->getType ();
450450 std::optional<PrimType> FromT = classify (SubExprTy);
451+ // Casts from integer to vectors in C.
452+ if (FromT && CE->getType ()->isVectorType ())
453+ return this ->emitBuiltinBitCast (CE);
454+
451455 std::optional<PrimType> ToT = classify (CE->getType ());
452456 if (!FromT || !ToT)
453457 return false ;
@@ -6494,8 +6498,23 @@ bool Compiler<Emitter>::emitBuiltinBitCast(const CastExpr *E) {
64946498 }
64956499
64966500 // Get a pointer to the value-to-cast on the stack.
6497- if (!this ->visit (SubExpr))
6498- return false ;
6501+ // For CK_LValueToRValueBitCast, this is always an lvalue and
6502+ // we later assume it to be one (i.e. a PT_Ptr). However,
6503+ // we call this function for other utility methods where
6504+ // a bitcast might be useful, so convert it to a PT_Ptr in that case.
6505+ if (SubExpr->isGLValue ()) {
6506+ if (!this ->visit (SubExpr))
6507+ return false ;
6508+ } else if (std::optional<PrimType> FromT = classify (SubExpr)) {
6509+ unsigned TempOffset = allocateLocalPrimitive (
6510+ SubExpr, *FromT, /* IsConst=*/ true , /* IsExtended=*/ false );
6511+ if (!this ->visit (SubExpr))
6512+ return false ;
6513+ if (!this ->emitSetLocal (*FromT, TempOffset, E))
6514+ return false ;
6515+ if (!this ->emitGetPtrLocal (TempOffset, E))
6516+ return false ;
6517+ }
64996518
65006519 if (!ToT || ToT == PT_Ptr) {
65016520 if (!this ->emitBitCastPtr (E))
0 commit comments