Check to make sure types are sized before calling getTypeSize on them.

llvm-svn: 14649
This commit is contained in:
Chris Lattner 2004-07-06 19:28:42 +00:00
parent a501be556f
commit 9eb9ccd9f6
1 changed files with 15 additions and 13 deletions

View File

@ -2098,22 +2098,24 @@ Instruction *InstCombiner::visitCastInst(CastInst &CI) {
if (const PointerType *PTy = dyn_cast<PointerType>(CI.getType())) {
// Get the type really allocated and the type casted to...
const Type *AllocElTy = AI->getAllocatedType();
unsigned AllocElTySize = TD->getTypeSize(AllocElTy);
const Type *CastElTy = PTy->getElementType();
unsigned CastElTySize = TD->getTypeSize(CastElTy);
if (AllocElTy->isSized() && CastElTy->isSized()) {
unsigned AllocElTySize = TD->getTypeSize(AllocElTy);
unsigned CastElTySize = TD->getTypeSize(CastElTy);
// If the allocation is for an even multiple of the cast type size
if (CastElTySize && (AllocElTySize % CastElTySize == 0)) {
Value *Amt = ConstantUInt::get(Type::UIntTy,
// If the allocation is for an even multiple of the cast type size
if (CastElTySize && (AllocElTySize % CastElTySize == 0)) {
Value *Amt = ConstantUInt::get(Type::UIntTy,
AllocElTySize/CastElTySize);
std::string Name = AI->getName(); AI->setName("");
AllocationInst *New;
if (isa<MallocInst>(AI))
New = new MallocInst(CastElTy, Amt, Name);
else
New = new AllocaInst(CastElTy, Amt, Name);
InsertNewInstBefore(New, *AI);
return ReplaceInstUsesWith(CI, New);
std::string Name = AI->getName(); AI->setName("");
AllocationInst *New;
if (isa<MallocInst>(AI))
New = new MallocInst(CastElTy, Amt, Name);
else
New = new AllocaInst(CastElTy, Amt, Name);
InsertNewInstBefore(New, *AI);
return ReplaceInstUsesWith(CI, New);
}
}
}