Handle multiple function definitions with same mangled name

By discarding (and warning about) all but the first definition.
compilable/test17352.d tests that the compiler accepts 2 distinct but
equivalent templated function instantiations (with an alias to a
different local of the same type and name) ending up with a common
mangled name.
See https://issues.dlang.org/show_bug.cgi?id=17352.
This commit is contained in:
Martin 2017-09-23 13:06:13 +02:00
parent 1fa90a0381
commit 610a1c37e4
2 changed files with 13 additions and 6 deletions

View file

@ -834,7 +834,6 @@ ldc::DISubprogram ldc::DIBuilder::EmitSubProgram(FuncDeclaration *fd) {
#endif #endif
); );
#if LDC_LLVM_VER >= 308 #if LDC_LLVM_VER >= 308
if (fd->fbody)
DtoFunction(fd)->setSubprogram(SP); DtoFunction(fd)->setSubprogram(SP);
#endif #endif
return SP; return SP;

View file

@ -921,15 +921,24 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
return; return;
} }
IrFunction *irFunc = getIrFunc(fd); IrFunction *const irFunc = getIrFunc(fd);
llvm::Function *const func = irFunc->getLLVMFunc();
// debug info if (!func->empty()) {
irFunc->diSubprogram = gIR->DBuilder.EmitSubProgram(fd); warning(fd->loc,
"skipping definition of function `%s` due to previous definition "
"for the same mangled name: %s",
fd->toPrettyChars(), mangleExact(fd));
return;
}
if (!fd->fbody) { if (!fd->fbody) {
return; return;
} }
// debug info
irFunc->diSubprogram = gIR->DBuilder.EmitSubProgram(fd);
IF_LOG Logger::println("Doing function body for: %s", fd->toChars()); IF_LOG Logger::println("Doing function body for: %s", fd->toChars());
gIR->funcGenStates.emplace_back(new FuncGenState(*irFunc, *gIR)); gIR->funcGenStates.emplace_back(new FuncGenState(*irFunc, *gIR));
auto &funcGen = gIR->funcGen(); auto &funcGen = gIR->funcGen();
@ -940,7 +949,6 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
const auto f = static_cast<TypeFunction *>(fd->type->toBasetype()); const auto f = static_cast<TypeFunction *>(fd->type->toBasetype());
IrFuncTy &irFty = irFunc->irFty; IrFuncTy &irFty = irFunc->irFty;
llvm::Function *func = irFunc->getLLVMFunc();
const auto lwc = lowerFuncLinkage(fd); const auto lwc = lowerFuncLinkage(fd);
if (linkageAvailableExternally) { if (linkageAvailableExternally) {