mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-02 13:21:43 +00:00
Allow global address space forward decls using IDs in .ll files.
Summary: This fixes bugzilla bug 24656. Fixes the case where there is a forward reference to a global variable using an ID (i.e. @0). It does this by passing the address space of the initializer pointer for which the forward referenced global is used. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246788 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3610c9fe55
commit
b80c5f51a4
@ -1040,6 +1040,17 @@ bool LLParser::ParseFnAttributeValuePairs(AttrBuilder &B,
|
||||
// GlobalValue Reference/Resolution Routines.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
static inline GlobalValue *createGlobalFwdRef(Module *M, PointerType *PTy,
|
||||
const std::string &Name) {
|
||||
if (auto *FT = dyn_cast<FunctionType>(PTy->getElementType()))
|
||||
return Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M);
|
||||
else
|
||||
return new GlobalVariable(*M, PTy->getElementType(), false,
|
||||
GlobalValue::ExternalWeakLinkage, nullptr, Name,
|
||||
nullptr, GlobalVariable::NotThreadLocal,
|
||||
PTy->getAddressSpace());
|
||||
}
|
||||
|
||||
/// GetGlobalVal - Get a value with the specified name or ID, creating a
|
||||
/// forward reference record if needed. This can return null if the value
|
||||
/// exists but does not have the right type.
|
||||
@ -1073,15 +1084,7 @@ GlobalValue *LLParser::GetGlobalVal(const std::string &Name, Type *Ty,
|
||||
}
|
||||
|
||||
// Otherwise, create a new forward reference for this value and remember it.
|
||||
GlobalValue *FwdVal;
|
||||
if (FunctionType *FT = dyn_cast<FunctionType>(PTy->getElementType()))
|
||||
FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M);
|
||||
else
|
||||
FwdVal = new GlobalVariable(*M, PTy->getElementType(), false,
|
||||
GlobalValue::ExternalWeakLinkage, nullptr, Name,
|
||||
nullptr, GlobalVariable::NotThreadLocal,
|
||||
PTy->getAddressSpace());
|
||||
|
||||
GlobalValue *FwdVal = createGlobalFwdRef(M, PTy, Name);
|
||||
ForwardRefVals[Name] = std::make_pair(FwdVal, Loc);
|
||||
return FwdVal;
|
||||
}
|
||||
@ -1113,13 +1116,7 @@ GlobalValue *LLParser::GetGlobalVal(unsigned ID, Type *Ty, LocTy Loc) {
|
||||
}
|
||||
|
||||
// Otherwise, create a new forward reference for this value and remember it.
|
||||
GlobalValue *FwdVal;
|
||||
if (FunctionType *FT = dyn_cast<FunctionType>(PTy->getElementType()))
|
||||
FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, "", M);
|
||||
else
|
||||
FwdVal = new GlobalVariable(*M, PTy->getElementType(), false,
|
||||
GlobalValue::ExternalWeakLinkage, nullptr, "");
|
||||
|
||||
GlobalValue *FwdVal = createGlobalFwdRef(M, PTy, "");
|
||||
ForwardRefValIDs[ID] = std::make_pair(FwdVal, Loc);
|
||||
return FwdVal;
|
||||
}
|
||||
|
@ -7,3 +7,12 @@
|
||||
; CHECK: @a = addrspace(1) global i8 0
|
||||
@a2 = global i8 addrspace(1)* @a
|
||||
@a = addrspace(1) global i8 0
|
||||
|
||||
; Now test with global IDs instead of global names.
|
||||
|
||||
; CHECK: @a3 = global i8 addrspace(1)* @0
|
||||
; CHECK: @0 = addrspace(1) global i8 0
|
||||
|
||||
@a3 = global i8 addrspace(1)* @0
|
||||
@0 = addrspace(1) global i8 0
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user