mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 03:33:20 +01:00
For PR1142:
When an unresolved definition is found, check to see if it is only unresolved because the csretcc was upgraded to the sret param attribute. Such changes change the function type and lead to unresolved definitions. In such cases, just cast the function to the type expected by the CallInst. That is, cast to the version of the function that has the sret param attribute. llvm-svn: 33623
This commit is contained in:
parent
eba0cf04e5
commit
8a00fdcf3b
@ -505,6 +505,25 @@ static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) {
|
|||||||
// and back patchs after we are done.
|
// and back patchs after we are done.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
/// This function determines if two function types differ only in their use of
|
||||||
|
/// the sret parameter attribute in the first argument. If they are identical
|
||||||
|
/// in all other respects, it returns true. Otherwise, it returns false.
|
||||||
|
bool FuncTysDifferOnlyBySRet(const FunctionType *F1,
|
||||||
|
const FunctionType *F2) {
|
||||||
|
if (F1->getReturnType() != F2->getReturnType() ||
|
||||||
|
F1->getNumParams() != F2->getNumParams() ||
|
||||||
|
F1->getParamAttrs(0) != F2->getParamAttrs(0))
|
||||||
|
return false;
|
||||||
|
unsigned SRetMask = ~unsigned(FunctionType::StructRetAttribute);
|
||||||
|
for (unsigned i = 0; i < F1->getNumParams(); ++i) {
|
||||||
|
if (F1->getParamType(i) != F2->getParamType(i) ||
|
||||||
|
unsigned(F1->getParamAttrs(i+1)) & SRetMask !=
|
||||||
|
unsigned(F2->getParamAttrs(i+1)) & SRetMask)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// ResolveDefinitions - If we could not resolve some defs at parsing
|
// ResolveDefinitions - If we could not resolve some defs at parsing
|
||||||
// time (forward branches, phi functions for loops, etc...) resolve the
|
// time (forward branches, phi functions for loops, etc...) resolve the
|
||||||
// defs now...
|
// defs now...
|
||||||
@ -537,10 +556,26 @@ ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
|
|||||||
InsertValue(V, *FutureLateResolvers);
|
InsertValue(V, *FutureLateResolvers);
|
||||||
} else {
|
} else {
|
||||||
if (DID.Type == ValID::NameVal) {
|
if (DID.Type == ValID::NameVal) {
|
||||||
error("Reference to an invalid definition: '" +DID.getName()+
|
// The upgrade of csretcc to sret param attribute may have caused a
|
||||||
"' of type '" + V->getType()->getDescription() + "'",
|
// function to not be found because the param attribute changed the
|
||||||
PHI->second.second);
|
// type of the called function. Detect this situation and insert a
|
||||||
return;
|
// cast as necessary.
|
||||||
|
bool fixed = false;
|
||||||
|
if (const PointerType *PTy = dyn_cast<PointerType>(V->getType()))
|
||||||
|
if (const FunctionType *FTy =
|
||||||
|
dyn_cast<FunctionType>(PTy->getElementType()))
|
||||||
|
if (Function *OtherF =
|
||||||
|
CurModule.CurrentModule->getNamedFunction(DID.getName()))
|
||||||
|
if (FuncTysDifferOnlyBySRet(FTy,OtherF->getFunctionType())) {
|
||||||
|
V->replaceAllUsesWith(ConstantExpr::getBitCast(OtherF, PTy));
|
||||||
|
fixed = true;
|
||||||
|
}
|
||||||
|
if (!fixed) {
|
||||||
|
error("Reference to an invalid definition: '" +DID.getName()+
|
||||||
|
"' of type '" + V->getType()->getDescription() + "'",
|
||||||
|
PHI->second.second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
error("Reference to an invalid definition: #" +
|
error("Reference to an invalid definition: #" +
|
||||||
itostr(DID.Num) + " of type '" +
|
itostr(DID.Num) + " of type '" +
|
||||||
|
Loading…
Reference in New Issue
Block a user