[llvm-commits] CVS:	llvm/lib/Transforms/Scalar/InstructionCombining.cpp
    Chris Lattner 
    sabre at nondot.org
       
    Fri May  4 18:59:49 PDT 2007
    
    
  
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.757 -> 1.758
---
Log message:
Fix InstCombine/2007-05-04-Crash.ll and PR1384: http://llvm.org/PR1384 
---
Diffs of the changes:  (+14 -10)
 InstructionCombining.cpp |   24 ++++++++++++++----------
 1 files changed, 14 insertions(+), 10 deletions(-)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.757 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.758
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.757	Wed May  2 20:11:54 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Fri May  4 20:59:31 2007
@@ -6404,21 +6404,25 @@
         if (GEPIdxTy->isSized()) {
           SmallVector<Value*, 8> NewIndices;
           
-          // Start with the index over the outer type.
+          // Start with the index over the outer type.  Note that the type size
+          // might be zero (even if the offset isn't zero) if the indexed type
+          // is something like [0 x {int, int}]
           const Type *IntPtrTy = TD->getIntPtrType();
-          int64_t TySize = TD->getTypeSize(GEPIdxTy);
-          int64_t FirstIdx = Offset/TySize;
-          Offset %= TySize;
+          int64_t FirstIdx = 0;
+          if (int64_t TySize = TD->getTypeSize(GEPIdxTy)) {
+            FirstIdx = Offset/TySize;
+            Offset %= TySize;
           
-          // Handle silly modulus not returning values values [0..TySize).
-          if (Offset < 0) {
-            --FirstIdx;
-            Offset += TySize;
-            assert(Offset >= 0);
+            // Handle silly modulus not returning values values [0..TySize).
+            if (Offset < 0) {
+              --FirstIdx;
+              Offset += TySize;
+              assert(Offset >= 0);
+            }
+            assert((uint64_t)Offset < (uint64_t)TySize && "Out of range offset");
           }
           
           NewIndices.push_back(ConstantInt::get(IntPtrTy, FirstIdx));
-          assert((uint64_t)Offset < (uint64_t)TySize && "Out of range offset");
 
           // Index into the types.  If we fail, set OrigBase to null.
           while (Offset) {
    
    
More information about the llvm-commits
mailing list