DebugInfo: Mangle K&R declarations for debug info linkage names

This fixes a gap in the `overloadable` attribute support (K&R declared
functions would get mangled symbol names, but that name wouldn't be
represented in the debug info linkage name field for the function) and
in -funique-internal-linkage-names (this came up in review discussion on
D98799) where K&R static declarations would not get the uniqued linkage
names.
This commit is contained in:
David Blaikie 2021-07-06 16:25:45 -07:00
parent a0ab45799b
commit 6c9559b67b
4 changed files with 11 additions and 19 deletions

View File

@ -649,7 +649,7 @@ bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl(
// For C functions without prototypes, return false as their
// names should not be mangled.
if (!FD->hasPrototype())
if (!FD->getType()->getAs<FunctionProtoType>())
return false;
if (isInternalLinkageDecl(ND))

View File

@ -3546,7 +3546,7 @@ void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
const auto *FD = cast<FunctionDecl>(GD.getCanonicalDecl().getDecl());
Name = getFunctionName(FD);
// Use mangled name as linkage name for C/C++ functions.
if (FD->hasPrototype()) {
if (FD->getType()->getAs<FunctionProtoType>()) {
LinkageName = CGM.getMangledName(GD);
Flags |= llvm::DINode::FlagPrototyped;
}

View File

@ -0,0 +1,6 @@
// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
__attribute__((overloadable)) void f1(a) int a; {
}
// CHECK: !DISubprogram(name: "f1", linkageName: "_Z2f1i"

View File

@ -13,27 +13,15 @@ static int foo(void) {
return glob;
}
// bar should not be given a uniquefied name under -funique-internal-linkage-names,
// since it doesn't come with valid prototype.
// K&R prototypes should be given uniquefied names under -funique-internal-linkage-names.
static int bar(a) int a;
{
return glob + a;
}
// go should be given a uniquefied name under -funique-internal-linkage-names, even
// if its definition doesn't come with a valid prototype, but the declaration here
// has a prototype.
static int go(int);
void baz() {
foo();
bar(1);
go(2);
}
static int go(a) int a;
{
return glob + a;
}
@ -43,13 +31,11 @@ static int go(a) int a;
// PLAIN: distinct !DIGlobalVariable(name: "glob"{{.*}})
// PLAIN: distinct !DISubprogram(name: "foo"{{.*}})
// PLAIN: distinct !DISubprogram(name: "bar"{{.*}})
// PLAIN: distinct !DISubprogram(name: "go"{{.*}})
// PLAIN-NOT: linkageName:
//
// UNIQUE: @glob = internal global i32
// UNIQUE: define internal i32 @_ZL3foov.[[MODHASH:__uniq.[0-9]+]]()
// UNIQUE: define internal i32 @bar(i32 %a)
// UNIQUE: define internal i32 @_ZL2goi.[[MODHASH]](i32 %a)
// UNIQUE: define internal i32 @_ZL3bari.[[MODHASH]](i32 %a)
// UNIQUE: distinct !DIGlobalVariable(name: "glob"{{.*}})
// UNIQUE: distinct !DISubprogram(name: "foo", linkageName: "_ZL3foov.[[MODHASH]]"{{.*}})
// UNIQUE: distinct !DISubprogram(name: "go", linkageName: "_ZL2goi.[[MODHASH]]"{{.*}})
// UNIQUE: distinct !DISubprogram(name: "bar", linkageName: "_ZL3bari.[[MODHASH]]"{{.*}})