@@ -125,7 +125,7 @@ Value *PromoteSubByte::convertI1ToI8(Value *value, IRBuilder<> &builder) {
125125
126126 auto zext = builder.CreateZExt (value, getOrCreatePromotedType (value->getType ()));
127127 if (isa<Instruction>(zext) && isa<Instruction>(value)) {
128- cast <Instruction>(zext)->setDebugLoc (cast <Instruction>(value)->getDebugLoc ());
128+ dyn_cast <Instruction>(zext)->setDebugLoc (dyn_cast <Instruction>(value)->getDebugLoc ());
129129 }
130130 return zext;
131131}
@@ -142,16 +142,17 @@ Value *PromoteSubByte::convertI8ToI1(Value *value, IRBuilder<> &builder) {
142142
143143 auto trunc = builder.CreateTrunc (value, createDemotedType (value->getType ()));
144144 if (isa<Instruction>(trunc) && isa<Instruction>(value)) {
145- cast <Instruction>(trunc)->setDebugLoc (cast <Instruction>(value)->getDebugLoc ());
145+ dyn_cast <Instruction>(trunc)->setDebugLoc (dyn_cast <Instruction>(value)->getDebugLoc ());
146146 }
147147 return trunc;
148148}
149149
150150Value *PromoteSubByte::castAggregate (Value *value, Type *desiredType, IRBuilder<> &builder) {
151151
152152 if (auto *srcST = dyn_cast<StructType>(value->getType ())) {
153- auto *dstST = cast <StructType>(desiredType);
153+ auto *dstST = dyn_cast <StructType>(desiredType);
154154
155+ IGC_ASSERT (srcST && dstST);
155156 IGC_ASSERT (srcST->getNumElements () == dstST->getNumElements ());
156157
157158 Value *Accum = PoisonValue::get (dstST);
@@ -168,8 +169,9 @@ Value *PromoteSubByte::castAggregate(Value *value, Type *desiredType, IRBuilder<
168169 }
169170
170171 if (auto *srcAT = dyn_cast<ArrayType>(value->getType ())) {
171- auto *dstAT = cast <ArrayType>(desiredType);
172+ auto *dstAT = dyn_cast <ArrayType>(desiredType);
172173
174+ IGC_ASSERT (srcAT && dstAT);
173175 IGC_ASSERT (srcAT->getNumElements () == dstAT->getNumElements ());
174176
175177 auto *dstElType = dstAT->getElementType ();
@@ -527,7 +529,7 @@ Function *PromoteSubByte::promoteFunction(Function *function) {
527529 }
528530#endif
529531
530- auto newFunction = Function::Create (cast <FunctionType>(getOrCreatePromotedType (function->getFunctionType ())),
532+ auto newFunction = Function::Create (dyn_cast <FunctionType>(getOrCreatePromotedType (function->getFunctionType ())),
531533 function->getLinkage (), function->getName () + " .promoted" , function->getParent ());
532534
533535 newFunction->setCallingConv (function->getCallingConv ());
@@ -673,7 +675,7 @@ Constant *PromoteSubByte::promoteConstant(Constant *constant) {
673675 }
674676
675677 auto newType = getOrCreatePromotedType (constantArray->getType ());
676- return ConstantArray::get (cast <ArrayType>(newType), values);
678+ return ConstantArray::get (dyn_cast <ArrayType>(newType), values);
677679 } else if (auto constantStruct = dyn_cast<ConstantStruct>(constant)) {
678680 if (!typeNeedsPromotion (constantStruct->getType ())) {
679681 return constant;
@@ -685,11 +687,11 @@ Constant *PromoteSubByte::promoteConstant(Constant *constant) {
685687 }
686688
687689 auto newType = getOrCreatePromotedType (constantStruct->getType ());
688- return ConstantStruct::get (cast <StructType>(newType), values);
690+ return ConstantStruct::get (dyn_cast <StructType>(newType), values);
689691 } else if (auto constantExpr = dyn_cast<ConstantExpr>(constant)) {
690692 if (constantExpr->isCast () && isa<GlobalValue>(constantExpr->getOperand (0 ))) {
691693 return ConstantExpr::getCast (constantExpr->getOpcode (),
692- cast <Constant>(getOrCreatePromotedValue (constantExpr->getOperand (0 ))),
694+ dyn_cast <Constant>(getOrCreatePromotedValue (constantExpr->getOperand (0 ))),
693695 constantExpr->getType ());
694696 }
695697 return constantExpr;
@@ -868,7 +870,7 @@ InlineAsm *PromoteSubByte::promoteInlineAsm(InlineAsm *inlineAsm) {
868870 return inlineAsm;
869871 }
870872
871- return InlineAsm::get (cast <FunctionType>(getOrCreatePromotedType (inlineAsm->getFunctionType ())),
873+ return InlineAsm::get (dyn_cast <FunctionType>(getOrCreatePromotedType (inlineAsm->getFunctionType ())),
872874 inlineAsm->getAsmString (), inlineAsm->getConstraintString (), inlineAsm->hasSideEffects (),
873875 inlineAsm->isAlignStack (), inlineAsm->getDialect ());
874876}
0 commit comments