aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorEric Christopher <echristo@apple.com>2010-02-03 23:56:07 +0000
committerEric Christopher <echristo@apple.com>2010-02-03 23:56:07 +0000
commitec5ef6d8b0fcdf7bf9df397a0e3d03e1d57b6fc1 (patch)
tree04aa92d6909225621f4656eadf169a844d6dba15 /lib/Transforms
parent9e90619a0e0e7042079dc93fe2f764bd3f46240a (diff)
downloadexternal_llvm-ec5ef6d8b0fcdf7bf9df397a0e3d03e1d57b6fc1.zip
external_llvm-ec5ef6d8b0fcdf7bf9df397a0e3d03e1d57b6fc1.tar.gz
external_llvm-ec5ef6d8b0fcdf7bf9df397a0e3d03e1d57b6fc1.tar.bz2
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95266 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/InstCombine/InstCombineCalls.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 7ad3f18..ebadfbc 100644
--- a/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/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.
}
}