fix rdar://8813415 - a miscompilation of 164.gzip that loop-idiom
authorChris Lattner <sabre@nondot.org>
Mon, 3 Jan 2011 21:03:33 +0000 (21:03 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 3 Jan 2011 21:03:33 +0000 (21:03 +0000)
exposed.  It turns out to be a latent bug in basicaa, scary.

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

lib/Analysis/BasicAliasAnalysis.cpp
test/Analysis/BasicAA/global-size.ll

index 1a526fc930648e1e0c70f66afae0d11e8c2a0450..8e0637a49b58c9043d868ec192dcc943b45a4dae 100644 (file)
@@ -103,6 +103,8 @@ static bool isObjectSmallerThan(const Value *V, uint64_t Size,
                                 const TargetData &TD) {
   const Type *AccessTy;
   if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
+    if (!GV->hasDefinitiveInitializer())
+      return false;
     AccessTy = GV->getType()->getElementType();
   } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(V)) {
     if (!AI->isArrayAllocation())
index 810322e54d1f75c64805dbf811a019d44f498497..a7e5aab6c1f228a03cef2241ce2c5b3145e1e673 100644 (file)
@@ -16,3 +16,25 @@ define i16 @test1(i32* %P) {
 ; CHECK: ret i16 0
 }
 
+; Cannot know anything about the size of this global.
+; rdar://8813415
+@window = external global [0 x i8]
+
+; CHECK: @test2
+define i8 @test2(i32 %tmp79, i32 %w.2, i32 %indvar89) nounwind {
+  %tmp92 = add i32 %tmp79, %indvar89
+  %arrayidx412 = getelementptr [0 x i8]* @window, i32 0, i32 %tmp92
+  %tmp93 = add i32 %w.2, %indvar89
+  %arrayidx416 = getelementptr [0 x i8]* @window, i32 0, i32 %tmp93
+
+  %A = load i8* %arrayidx412, align 1
+  store i8 4, i8* %arrayidx416, align 1
+
+  %B = load i8* %arrayidx412, align 1
+  %C = sub i8 %A, %B
+  ret i8 %C
+
+; CHECK: %B = load i8
+; CHECK: ret i8 %C
+}
+