fix PR6332, allowing an index of zero into a zero sized array
authorChris Lattner <sabre@nondot.org>
Sat, 17 Apr 2010 19:02:33 +0000 (19:02 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 17 Apr 2010 19:02:33 +0000 (19:02 +0000)
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

lib/Target/TargetData.cpp
test/CodeGen/Generic/crash.ll [new file with mode: 0644]

index abee2e192446c0073f2e5215ee2910209a7cf1bd..d89fafd81373a14f9bb90a99f3aeca6f4d2f83fb 100644 (file)
@@ -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 (file)
index 0000000..7218565
--- /dev/null
@@ -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)]
+