[GlobalsAA] An indirect global that is initialized is not fair game

When checking if an indirect global (a global with pointer type) is only assigned by allocation functions, first check if the global is itself initialized. If it is, it's not only assigned by allocation functions.

This fixes PR25309. Thanks to David Majnemer for reducing the test case!

llvm-svn: 251508
This commit is contained in:
James Molloy
2015-10-28 10:41:29 +00:00
parent 89ea433bd6
commit c67dec690f
3 changed files with 34 additions and 2 deletions

View File

@@ -395,11 +395,16 @@ bool GlobalsAAResult::AnalyzeUsesOfPointer(Value *V,
/// Further, all loads out of GV must directly use the memory, not store the
/// pointer somewhere. If this is true, we consider the memory pointed to by
/// GV to be owned by GV and can disambiguate other pointers from it.
bool GlobalsAAResult::AnalyzeIndirectGlobalMemory(GlobalValue *GV) {
bool GlobalsAAResult::AnalyzeIndirectGlobalMemory(GlobalVariable *GV) {
// Keep track of values related to the allocation of the memory, f.e. the
// value produced by the malloc call and any casts.
std::vector<Value *> AllocRelatedValues;
// If the initializer is a valid pointer, bail.
if (Constant *C = GV->getInitializer())
if (!C->isNullValue())
return false;
// Walk the user list of the global. If we find anything other than a direct
// load or store, bail out.
for (User *U : GV->users()) {