summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-07-06 19:28:42 +0000
committerChris Lattner <sabre@nondot.org>2004-07-06 19:28:42 +0000
commit9eb9ccd9f651c6db20726267b557ecfdb79cf392 (patch)
treedec48a36f15e40e9cc84f0e952ca579a6b9d2b6c /llvm/lib/Transforms/Scalar/InstructionCombining.cpp
parenta501be556f2a9a677bf772f6328e13fb006ac1dc (diff)
downloadbcm5719-llvm-9eb9ccd9f651c6db20726267b557ecfdb79cf392.tar.gz
bcm5719-llvm-9eb9ccd9f651c6db20726267b557ecfdb79cf392.zip
Check to make sure types are sized before calling getTypeSize on them.
llvm-svn: 14649
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 4f6724ff52f..d43011da5bc 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -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);
+ }
}
}
OpenPOWER on IntegriCloud