Prevent two function with same mangled name but different types from being declared.

Previously, LDC would crash in the backend due to the fact that the IR is typed in such cases (we recently had such an instance with Tango, where an extern( C ) function was declared once with int and once with size_t).
This commit is contained in:
David Nadlinger 2011-07-27 23:01:22 +02:00
parent 882e81ec1c
commit 15c5316e26
3 changed files with 22 additions and 29 deletions

View file

@ -474,8 +474,11 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
// construct function
const llvm::FunctionType* functype = DtoFunctionType(fdecl);
llvm::Function* func = vafunc ? vafunc : gIR->module->getFunction(mangled_name);
if (!func)
if (!func) {
func = llvm::Function::Create(functype, DtoLinkage(fdecl), mangled_name, gIR->module);
} else if (func->getFunctionType() != functype) {
error(fdecl->loc, "Function type does not match previously declared function with the same mangled name: %s", fdecl->mangle());
}
if (Logger::enabled())
Logger::cout() << "func = " << *func << std::endl;