diff options
author | Chris Lattner <sabre@nondot.org> | 2010-04-17 19:02:33 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-04-17 19:02:33 +0000 |
commit | d855b0452816f290dc3b8325ec1616e918e51fb9 (patch) | |
tree | ace778ae97f986b23738b5f3885a2689c4bb2c21 | |
parent | fd0530b37dd99d879e2f16bbd89ad74e9fc7cb3f (diff) | |
download | external_llvm-d855b0452816f290dc3b8325ec1616e918e51fb9.zip external_llvm-d855b0452816f290dc3b8325ec1616e918e51fb9.tar.gz external_llvm-d855b0452816f290dc3b8325ec1616e918e51fb9.tar.bz2 |
fix PR6332, allowing an index of zero into a zero sized array
even if the element of the array has no size.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101662 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Target/TargetData.cpp | 4 | ||||
-rw-r--r-- | test/CodeGen/Generic/crash.ll | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp index abee2e1..d89fafd 100644 --- a/lib/Target/TargetData.cpp +++ b/lib/Target/TargetData.cpp @@ -630,8 +630,8 @@ uint64_t TargetData::getIndexedOffset(const Type *ptrTy, Value* const* Indices, Ty = cast<SequentialType>(Ty)->getElementType(); // Get the array index and the size of each array element. - int64_t arrayIdx = cast<ConstantInt>(Indices[CurIDX])->getSExtValue(); - Result += arrayIdx * (int64_t)getTypeAllocSize(Ty); + if (int64_t arrayIdx = cast<ConstantInt>(Indices[CurIDX])->getSExtValue()) + Result += arrayIdx * (int64_t)getTypeAllocSize(Ty); } } diff --git a/test/CodeGen/Generic/crash.ll b/test/CodeGen/Generic/crash.ll new file mode 100644 index 0000000..7218565 --- /dev/null +++ b/test/CodeGen/Generic/crash.ll @@ -0,0 +1,8 @@ +; RUN: llc %s -o - + +; PR6332 +%struct.AVCodecTag = type opaque +@ff_codec_bmp_tags = external global [0 x %struct.AVCodecTag] +@tags = global [1 x %struct.AVCodecTag*] [%struct.AVCodecTag* getelementptr +inbounds ([0 x %struct.AVCodecTag]* @ff_codec_bmp_tags, i32 0, i32 0)] + |