[clang] 6c9559b - DebugInfo: Mangle K&R declarations for debug info linkage names

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 6 16:28:13 PDT 2021


Author: David Blaikie
Date: 2021-07-06T16:28:02-07:00
New Revision: 6c9559b67b91966bfeff9e17808a3e84a92e64a0

URL: https://github.com/llvm/llvm-project/commit/6c9559b67b91966bfeff9e17808a3e84a92e64a0
DIFF: https://github.com/llvm/llvm-project/commit/6c9559b67b91966bfeff9e17808a3e84a92e64a0.diff

LOG: 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.

Added: 
    clang/test/CodeGen/overloadable-debug.c

Modified: 
    clang/lib/AST/ItaniumMangle.cpp
    clang/lib/CodeGen/CGDebugInfo.cpp
    clang/test/CodeGen/unique-internal-linkage-names-dwarf.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b5b9cd7535196..c40916308611b 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -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))

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 8a5b246275b15..0363fd7023f32 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -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;
   }

diff  --git a/clang/test/CodeGen/overloadable-debug.c b/clang/test/CodeGen/overloadable-debug.c
new file mode 100644
index 0000000000000..6eda318844960
--- /dev/null
+++ b/clang/test/CodeGen/overloadable-debug.c
@@ -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"

diff  --git a/clang/test/CodeGen/unique-internal-linkage-names-dwarf.c b/clang/test/CodeGen/unique-internal-linkage-names-dwarf.c
index e5d507e154aeb..cae839830c6e2 100644
--- a/clang/test/CodeGen/unique-internal-linkage-names-dwarf.c
+++ b/clang/test/CodeGen/unique-internal-linkage-names-dwarf.c
@@ -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]]"{{.*}})


        


More information about the cfe-commits mailing list