avoid dividing by zero when dealing with zero sized types (like [0 x double])
authorChris Lattner <sabre@nondot.org>
Mon, 23 Jun 2003 17:36:49 +0000 (17:36 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 23 Jun 2003 17:36:49 +0000 (17:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6862 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/ExprTypeConvert.cpp
lib/Transforms/TransformInternals.cpp

index b7936377e7672d75cf8a8871d9641b2a07d3ec38..e830beee44b9dd66fd15780bdc5ce4c7da11de8d 100644 (file)
@@ -49,6 +49,7 @@ static bool MallocConvertibleToType(MallocInst *MI, const Type *Ty,
 
   // Get information about the base datatype being allocated, before & after
   int ReqTypeSize = TD.getTypeSize(Ty);
+  if (ReqTypeSize == 0) return false;
   unsigned OldTypeSize = TD.getTypeSize(MI->getType()->getElementType());
 
   // Must have a scale or offset to analyze it...
index 7aa5564fbee13b6744b39b4248ad85bcddc1ca91..c8e5ecc5f2b76ffaa39c2c4267d2122763988393 100644 (file)
@@ -119,6 +119,7 @@ const Type *ConvertibleToGEP(const Type *Ty, Value *OffsetVal,
       if (!ElTy->isSized() || (isa<PointerType>(CompTy) && !Indices.empty()))
         return 0; // Type is unreasonable... escape!
       unsigned ElSize = TD.getTypeSize(ElTy);
+      if (ElSize == 0) return 0;   // Avoid division by zero...
       int64_t ElSizeS = ElSize;
 
       // See if the user is indexing into a different cell of this array...