forked from OSchip/llvm-project
[UniqueLinkageName] Use consistent checks when mangling symbo linkage name and debug linkage name.
C functions may be declared and defined in different prototypes like below. This patch unifies the checks for mangling names in symbol linkage name emission and debug linkage name emission so that the two names are consistent. static int go(int); static int go(a) int a; { return a; } Test Plan: Differential Revision: https://reviews.llvm.org/D98799
This commit is contained in:
parent
1410db70b9
commit
fc1812a0ad
|
@ -640,7 +640,7 @@ bool ItaniumMangleContextImpl::isUniqueInternalLinkageDecl(
|
|||
|
||||
// For C functions without prototypes, return false as their
|
||||
// names should not be mangled.
|
||||
if (!FD->getType()->getAs<FunctionProtoType>())
|
||||
if (!FD->hasPrototype())
|
||||
return false;
|
||||
|
||||
if (isInternalLinkageDecl(ND))
|
||||
|
|
|
@ -3522,7 +3522,7 @@ void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
|
|||
llvm::DIScope *&FDContext,
|
||||
llvm::DINodeArray &TParamsArray,
|
||||
llvm::DINode::DIFlags &Flags) {
|
||||
const auto *FD = cast<FunctionDecl>(GD.getDecl());
|
||||
const auto *FD = cast<FunctionDecl>(GD.getCanonicalDecl().getDecl());
|
||||
Name = getFunctionName(FD);
|
||||
// Use mangled name as linkage name for C/C++ functions.
|
||||
if (FD->hasPrototype()) {
|
||||
|
|
|
@ -8,21 +8,48 @@
|
|||
// RUN: %clang_cc1 -triple x86_64-unknown-linux -debug-info-kind=limited -dwarf-version=5 -funique-internal-linkage-names -emit-llvm -o - %s | FileCheck %s --check-prefix=UNIQUE
|
||||
|
||||
static int glob;
|
||||
// foo should be given a uniquefied name under -funique-internal-linkage-names.
|
||||
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.
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
// PLAIN: @glob = internal global i32
|
||||
// PLAIN: define internal i32 @foo()
|
||||
// PLAIN: define internal i32 @bar(i32 %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: distinct !DIGlobalVariable(name: "glob"{{.*}})
|
||||
// UNIQUE: distinct !DISubprogram(name: "foo", linkageName: "_ZL3foov.[[MODHASH]]"{{.*}})
|
||||
// UNIQUE: distinct !DISubprogram(name: "go", linkageName: "_ZL2goi.[[MODHASH]]"{{.*}})
|
||||
|
|
Loading…
Reference in New Issue