diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -761,10 +761,13 @@ } SizeOffsetType ObjectSizeOffsetVisitor::visitGlobalVariable(GlobalVariable &GV){ - if (!GV.hasDefinitiveInitializer()) + // Make sure we have an exact definition that cannot be changed. + if (!GV.isDefinitionExact()) return unknown(); - + // Weed out any flexible array types. APInt Size(IntTyBits, DL.getTypeAllocSize(GV.getValueType())); + if (Size.isNullValue()) + return unknown(); return std::make_pair(align(Size, GV.getAlignment()), Zero); } diff --git a/llvm/test/Analysis/BasicAA/bug.23540.ll b/llvm/test/Analysis/BasicAA/bug.23540.ll --- a/llvm/test/Analysis/BasicAA/bug.23540.ll +++ b/llvm/test/Analysis/BasicAA/bug.23540.ll @@ -4,8 +4,11 @@ @c = external global i32 +; Since there are no sizes and both accesses are based on the same global they +; (can) partially overlap. + ; CHECK-LABEL: f -; CHECK: MayAlias: i32* %arrayidx, i32* %arrayidx6 +; CHECK: PartialAlias: i32* %arrayidx, i32* %arrayidx6 define void @f() { %idxprom = zext i32 undef to i64 %add4 = add i32 0, 1