If we're dealing with a zero-length array, don't lower to any
authorEric Christopher <echristo@apple.com>
Wed, 3 Feb 2010 23:56:07 +0000 (23:56 +0000)
committerEric Christopher <echristo@apple.com>
Wed, 3 Feb 2010 23:56:07 +0000 (23:56 +0000)
particular size, we just don't know what the length is yet.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95266 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCalls.cpp
test/Transforms/InstCombine/objsize.ll

index 7ad3f186cb05dfca03ac3048df90dcf2ccf753b8..ebadfbcd373532df9e0e366247f332c0dba1a858 100644 (file)
@@ -648,14 +648,19 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
 
       if (const ArrayType *AT = dyn_cast<ArrayType>(ObjTy->getElementType())) {
 
-            // Deal with multi-dimensional arrays
+        // Deal with multi-dimensional arrays
         const ArrayType *SAT = AT;
         while ((AT = dyn_cast<ArrayType>(AT->getElementType())))
           SAT = AT;
 
         size_t numElems = SAT->getNumElements();
-            // We return the remaining bytes, so grab the size of an element
-            // in bytes.
+        
+        // If numElems is 0, we don't know how large the array is so we can't
+        // make any determinations yet.
+        if (numElems == 0) break;
+        
+        // We return the remaining bytes, so grab the size of an element
+        // in bytes.
         size_t sizeofElem = SAT->getElementType()->getPrimitiveSizeInBits() / 8;
 
         ConstantInt *Const = 
@@ -665,7 +670,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
           ConstantInt::get(ReturnTy,
           ((numElems - indx) * sizeofElem)));
       }
-    }    
+    }
     // TODO: Add more types here.
   }
   }
index 13bb487c13efeeeca801d365587d671a4413c40b..fed067c0c6a09c38bb6549a30a8c7c8b75e3d647 100644 (file)
@@ -27,4 +27,15 @@ cond.false:
   ret i8* %2;
 }
 
+@window = external global [0 x i8]
+
+define i1 @baz() nounwind {
+; CHECK: @baz
+; CHECK-NEXT: llvm.objectsize.i32
+  %1 = tail call i32 @llvm.objectsize.i32(i8* getelementptr inbounds ([0 x i8]* @window, i32 0, i32 0), i1 false)
+  %2 = icmp eq i32 %1, -1
+  ret i1 %2
+}
+
+
 declare i32 @llvm.objectsize.i32(i8*, i1) nounwind readonly
\ No newline at end of file