Author: Liu Ke
Date: 2026-01-14T10:53:19+08:00
New Revision: be8924740325ba74232ba083cd86f940c01b354c

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

LOG: [DebugInfo] Set the DI flag for the simplified name of a template 
function/type (2/3). (#175708)

Set the `NameIsSimplified` flag for a template function/type that is
treated as having simplified names. Previous patch: #175130 .
Based on:
[RFC](https://discourse.llvm.org/t/rfc-debuginfo-selectively-generate-template-parameters-in-the-skeleton-cu/89395).

Added: 
    

Modified: 
    clang/lib/CodeGen/CGDebugInfo.cpp
    clang/lib/CodeGen/CGDebugInfo.h
    clang/test/DebugInfo/CXX/simple-template-names.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index d63d4c59382b6..9e21d3a5626d3 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -436,8 +436,9 @@ PrintingPolicy CGDebugInfo::getPrintingPolicy() const {
   return PP;
 }
 
-StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) {
-  return internString(GetName(FD));
+StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD,
+                                       bool *NameIsSimplified) {
+  return internString(GetName(FD, false, NameIsSimplified));
 }
 
 StringRef CGDebugInfo::getObjCMethodName(const ObjCMethodDecl *OMD) {
@@ -468,10 +469,11 @@ StringRef CGDebugInfo::getSelectorName(Selector S) {
   return internString(S.getAsString());
 }
 
-StringRef CGDebugInfo::getClassName(const RecordDecl *RD) {
+StringRef CGDebugInfo::getClassName(const RecordDecl *RD,
+                                    bool *NameIsSimplified) {
   if (isa<ClassTemplateSpecializationDecl>(RD)) {
     // Copy this name on the side and use its reference.
-    return internString(GetName(RD));
+    return internString(GetName(RD, false, NameIsSimplified));
   }
 
   // quick optimization to avoid having to intern strings that are already
@@ -4260,9 +4262,10 @@ CGDebugInfo::getOrCreateLimitedType(const RecordType 
*Ty) {
 // TODO: Currently used for context chains when limiting debug info.
 llvm::DICompositeType *CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
   RecordDecl *RD = Ty->getDecl()->getDefinitionOrSelf();
+  bool NameIsSimplified = false;
 
   // Get overall information about the record type for the debug info.
-  StringRef RDName = getClassName(RD);
+  StringRef RDName = getClassName(RD, &NameIsSimplified);
   const SourceLocation Loc = RD->getLocation();
   llvm::DIFile *DefUnit = nullptr;
   unsigned Line = 0;
@@ -4298,6 +4301,8 @@ llvm::DICompositeType 
*CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
   // Explicitly record the calling convention and export symbols for C++
   // records.
   auto Flags = llvm::DINode::FlagZero;
+  if (NameIsSimplified)
+    Flags |= llvm::DINode::FlagNameIsSimplified;
   if (auto CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
     if (CGM.getCXXABI().getRecordArgABI(CXXRD) == CGCXXABI::RAA_Indirect)
       Flags |= llvm::DINode::FlagTypePassByReference;
@@ -4403,6 +4408,10 @@ void CGDebugInfo::collectFunctionDeclProps(GlobalDecl 
GD, llvm::DIFile *Unit,
                                            llvm::DINodeArray &TParamsArray,
                                            llvm::DINode::DIFlags &Flags) {
   const auto *FD = cast<FunctionDecl>(GD.getCanonicalDecl().getDecl());
+  bool NameIsSimplified = false;
+  Name = getFunctionName(FD, &NameIsSimplified);
+  if (NameIsSimplified)
+    Flags |= llvm::DINode::FlagNameIsSimplified;
   Name = getFunctionName(FD);
   // Use mangled name as linkage name for C/C++ functions.
   if (FD->getType()->getAs<FunctionProtoType>())
@@ -5965,7 +5974,8 @@ bool CGDebugInfo::HasReconstitutableArgs(
   });
 }
 
-std::string CGDebugInfo::GetName(const Decl *D, bool Qualified) const {
+std::string CGDebugInfo::GetName(const Decl *D, bool Qualified,
+                                 bool *NameIsSimplified) const {
   std::string Name;
   llvm::raw_string_ostream OS(Name);
   const NamedDecl *ND = dyn_cast<NamedDecl>(D);
@@ -6022,6 +6032,9 @@ std::string CGDebugInfo::GetName(const Decl *D, bool 
Qualified) const {
       !Reconstitutable) {
     ND->getNameForDiagnostic(OS, PP, Qualified);
   } else {
+    // Treat both "simple" and "mangled" as simplified.
+    if (NameIsSimplified)
+      *NameIsSimplified = true;
     bool Mangled = TemplateNamesKind ==
                    llvm::codegenoptions::DebugTemplateNamesKind::Mangled;
     // check if it's a template

diff  --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 2378bdd780b3b..31b40f06f09d0 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -714,7 +714,8 @@ class CGDebugInfo {
   };
 
   bool HasReconstitutableArgs(ArrayRef<TemplateArgument> Args) const;
-  std::string GetName(const Decl *, bool Qualified = false) const;
+  std::string GetName(const Decl *, bool Qualified = false,
+                      bool *NameIsSimplified = nullptr) const;
 
   /// Build up structure info for the byref.  See \a BuildByRefType.
   BlockByRefType EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
@@ -837,7 +838,8 @@ class CGDebugInfo {
   /// Get function name for the given FunctionDecl. If the name is
   /// constructed on demand (e.g., C++ destructor) then the name is
   /// stored on the side.
-  StringRef getFunctionName(const FunctionDecl *FD);
+  StringRef getFunctionName(const FunctionDecl *FD,
+                            bool *NameIsSimplified = nullptr);
 
   /// Returns the unmangled name of an Objective-C method.
   /// This is the display name for the debugging info.
@@ -848,7 +850,8 @@ class CGDebugInfo {
   StringRef getSelectorName(Selector S);
 
   /// Get class name including template argument list.
-  StringRef getClassName(const RecordDecl *RD);
+  StringRef getClassName(const RecordDecl *RD,
+                         bool *NameIsSimplified = nullptr);
 
   /// Get the vtable name for the given class.
   StringRef getVTableName(const CXXRecordDecl *Decl);

diff  --git a/clang/test/DebugInfo/CXX/simple-template-names.cpp 
b/clang/test/DebugInfo/CXX/simple-template-names.cpp
index 3c8ff2780b66a..a682a087e1406 100644
--- a/clang/test/DebugInfo/CXX/simple-template-names.cpp
+++ b/clang/test/DebugInfo/CXX/simple-template-names.cpp
@@ -39,20 +39,20 @@ void f4() {
 void f() {
   // Basic examples of simplifiable/rebuildable names
   f1<>();
-  // CHECK: !DISubprogram(name: "_STN|f1|<>",
-  // SIMPLE: !DISubprogram(name: "f1",
+  // CHECK: !DISubprogram(name: "_STN|f1|<>", 
{{.*}}flags:{{.*}}DIFlagNameIsSimplified,
+  // SIMPLE: !DISubprogram(name: "f1", 
{{.*}}flags:{{.*}}DIFlagNameIsSimplified,
   // FULL: !DISubprogram(name: "f1<>",
   f1<int>();
-  // CHECK: !DISubprogram(name: "_STN|f1|<int>",
+  // CHECK: !DISubprogram(name: "_STN|f1|<int>", 
{{.*}}flags:{{.*}}DIFlagNameIsSimplified,
   f1<void()>();
-  // CHECK: !DISubprogram(name: "_STN|f1|<void ()>",
+  // CHECK: !DISubprogram(name: "_STN|f1|<void ()>", 
{{.*}}flags:{{.*}}DIFlagNameIsSimplified,
   f2<int, 42>();
-  // CHECK: !DISubprogram(name: "_STN|f2|<int, 42>",
+  // CHECK: !DISubprogram(name: "_STN|f2|<int, 42>", 
{{.*}}flags:{{.*}}DIFlagNameIsSimplified,
 
   // Check that even though the nested name can't be rebuilt, it'll carry its
   // full name and the outer name can be rebuilt from that.
   f1<t1<void() noexcept>>();
-  // CHECK: !DISubprogram(name: "_STN|f1|<t1<void () noexcept> >",
+  // CHECK: !DISubprogram(name: "_STN|f1|<t1<void () noexcept> >", 
{{.*}}flags:{{.*}}DIFlagNameIsSimplified,
 
   // Vector array types are encoded in DWARF but the decoding in llvm-dwarfdump
   // isn't implemented yet.
@@ -105,6 +105,7 @@ void f() {
   t2().operator t1<int>();
   // FIXME: This should be something like "operator t1<int><float>"
   // CHECK: !DISubprogram(name: "operator t1<float>",
+  // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"_STN|t1|<int>", {{.*}}flags:{{.*}}DIFlagNameIsSimplified,
 
   // Function pointer non-type-template parameters currently don't get any 
DWARF
   // value (GCC doesn't provide one either) and even if there was a value, if
@@ -113,25 +114,25 @@ void f() {
   // worry about seeing conversion operators as parameters to other templates.
 
   f3<t1>();
-  // CHECK: !DISubprogram(name: "_STN|f3|<t1>",
+  // CHECK: !DISubprogram(name: "_STN|f3|<t1>", 
{{.*}}flags:{{.*}}DIFlagNameIsSimplified,
 
   f1<_BitInt(3)>();
-  // CHECK: !DISubprogram(name: "_STN|f1|<_BitInt(3)>",
+  // CHECK: !DISubprogram(name: "_STN|f1|<_BitInt(3)>", 
{{.*}}flags:{{.*}}DIFlagNameIsSimplified,
 
   f1<const unsigned _BitInt(5)>();
-  // CHECK: !DISubprogram(name: "_STN|f1|<const unsigned _BitInt(5)>",
+  // CHECK: !DISubprogram(name: "_STN|f1|<const unsigned _BitInt(5)>", 
{{.*}}flags:{{.*}}DIFlagNameIsSimplified,
 
   f1<_BitInt(120)>();
-  // CHECK: !DISubprogram(name: "_STN|f1|<_BitInt(120)>",
+  // CHECK: !DISubprogram(name: "_STN|f1|<_BitInt(120)>", 
{{.*}}flags:{{.*}}DIFlagNameIsSimplified,
 
   f1<const unsigned _BitInt(120)>();
-  // CHECK: !DISubprogram(name: "_STN|f1|<const unsigned _BitInt(120)>",
+  // CHECK: !DISubprogram(name: "_STN|f1|<const unsigned _BitInt(120)>", 
{{.*}}flags:{{.*}}DIFlagNameIsSimplified,
 
   f2<_BitInt(2), 1>();
-  // CHECK: !DISubprogram(name: "_STN|f2|<_BitInt(2), (_BitInt(2))1>",
+  // CHECK: !DISubprogram(name: "_STN|f2|<_BitInt(2), (_BitInt(2))1>", 
{{.*}}flags:{{.*}}DIFlagNameIsSimplified,
 
   f2<_BitInt(64), 12>();
-  // CHECK: !DISubprogram(name: "_STN|f2|<_BitInt(64), (_BitInt(64))12>",
+  // CHECK: !DISubprogram(name: "_STN|f2|<_BitInt(64), (_BitInt(64))12>", 
{{.*}}flags:{{.*}}DIFlagNameIsSimplified,
 
   // FIXME: make block forms reconstitutable
   f2<_BitInt(65), 1>();


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to