diff options
author | Eric Christopher <echristo@apple.com> | 2010-02-03 23:56:07 +0000 |
---|---|---|
committer | Eric Christopher <echristo@apple.com> | 2010-02-03 23:56:07 +0000 |
commit | f12e18db21c9d156c374b11037a623f1e26322fc (patch) | |
tree | aecff6aa8aa52b31404ebb4afaab2c8d3ef367c3 | |
parent | e5177e685c7e72406951963ea84cc2d78ce0a9ca (diff) | |
download | bcm5719-llvm-f12e18db21c9d156c374b11037a623f1e26322fc.tar.gz bcm5719-llvm-f12e18db21c9d156c374b11037a623f1e26322fc.zip |
If we're dealing with a zero-length array, don't lower to any
particular size, we just don't know what the length is yet.
llvm-svn: 95266
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 13 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/objsize.ll | 11 |
2 files changed, 20 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 7ad3f186cb0..ebadfbcd373 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -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. } } diff --git a/llvm/test/Transforms/InstCombine/objsize.ll b/llvm/test/Transforms/InstCombine/objsize.ll index 13bb487c13e..fed067c0c6a 100644 --- a/llvm/test/Transforms/InstCombine/objsize.ll +++ b/llvm/test/Transforms/InstCombine/objsize.ll @@ -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 |