[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Jul 6 14:30:03 PDT 2004


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.220 -> 1.221

---
Log message:

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


---
Diffs of the changes:  (+15 -13)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.220 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.221
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.220	Tue Jul  6 02:38:18 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Tue Jul  6 14:28:42 2004
@@ -2098,22 +2098,24 @@
       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);
+          }
         }
       }
 





More information about the llvm-commits mailing list