Revert "Revert "Check existing runtime function declarations for matching type""

This reverts commit 2de6538241.
This commit is contained in:
Martin 2016-10-15 23:30:07 +02:00
parent bb2b648d8e
commit d7b45f7c7d

View file

@ -127,22 +127,24 @@ llvm::Function *getRuntimeFunction(const Loc &loc, llvm::Module &target,
const char *name) {
checkForImplicitGCCall(loc, name);
if (!M) {
if (!M)
initRuntime();
}
LLFunction *fn = target.getFunction(name);
if (fn) {
return fn;
}
fn = M->getFunction(name);
LLFunction *fn = M->getFunction(name);
if (!fn) {
error(loc, "Runtime function '%s' was not found", name);
fatal();
}
LLFunctionType *fnty = fn->getFunctionType();
if (LLFunction *existing = target.getFunction(name)) {
if (existing->getFunctionType() != fnty) {
error(Loc(), "Incompatible declaration of runtime function '%s'", name);
fatal();
}
return existing;
}
LLFunction *resfn =
llvm::cast<llvm::Function>(target.getOrInsertFunction(name, fnty));
resfn->setAttributes(fn->getAttributes());