From fae10102189dda83b6567428ce3448d96ce58ff1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 6 Jul 2004 19:28:42 +0000 Subject: [PATCH] Check to make sure types are sized before calling getTypeSize on them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14649 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Scalar/InstructionCombining.cpp | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 4f6724ff52f..d43011da5bc 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2098,22 +2098,24 @@ Instruction *InstCombiner::visitCastInst(CastInst &CI) { if (const PointerType *PTy = dyn_cast(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(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(AI)) + New = new MallocInst(CastElTy, Amt, Name); + else + New = new AllocaInst(CastElTy, Amt, Name); + InsertNewInstBefore(New, *AI); + return ReplaceInstUsesWith(CI, New); + } } }