[clang] 5996ce1 - [clang][DebugInfo] Attach DW_AT_default_value to template arg metadata regardless of DwarfVersion

Michael Buch via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 14 14:32:03 PST 2022


Author: Michael Buch
Date: 2022-12-14T22:31:45Z
New Revision: 5996ce17fb265e461b5d580c1873cb8e3ff8d62d

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

LOG: [clang][DebugInfo] Attach DW_AT_default_value to template arg metadata regardless of DwarfVersion

**Summary**

Starting with DWARFv5, DW_AT_default_value can be used to indicate
that a template argument has a default value. With this patch Clang
will attach the attribute to the debug metadata regardless of version.

In a follow-up patch we will change llvm to emit this attribute in
earlier versions of DWARF, unless compiling with -gstrict-dwarf.

**Details**

* Previously the DwarfVersion check in CGDebugInfo was inconsistent:
  For non-type template arguments we attached the attribute to the debug
  metadata in DWARFv5 only. Whereas for type template arguments we didn't
  have such a version restriction. With this patch we attach the attribute
  regardless of DWARF version (and instead offload the check to the AsmPrinter
  in a future patch).

Added: 
    

Modified: 
    clang/lib/CodeGen/CGDebugInfo.cpp
    clang/test/CodeGenCXX/debug-info-template-parameter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 3e370fb17b1d..9e2e1842e5e9 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2018,7 +2018,7 @@ CGDebugInfo::CollectTemplateParams(Optional<TemplateArgs> OArgs,
     } break;
     case TemplateArgument::Integral: {
       llvm::DIType *TTy = getOrCreateType(TA.getIntegralType(), Unit);
-      if (Args.TList && CGM.getCodeGenOpts().DwarfVersion >= 5)
+      if (Args.TList)
         if (auto *templateType = dyn_cast_or_null<NonTypeTemplateParmDecl>(
                 Args.TList->getParam(i)))
           if (templateType->hasDefaultArgument() &&

diff  --git a/clang/test/CodeGenCXX/debug-info-template-parameter.cpp b/clang/test/CodeGenCXX/debug-info-template-parameter.cpp
index dac7871803c5..46ef45197460 100644
--- a/clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ b/clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -3,6 +3,7 @@
 
 // RUN: %clang_cc1 -emit-llvm %std_cxx11-14 -dwarf-version=5 -triple x86_64 %s -O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s --check-prefixes=CHECK,PRE17
 // RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=5 -triple x86_64 %s -O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s --check-prefixes=CHECK,CXX17
+// RUN: %clang_cc1 -emit-llvm %std_cxx17- -dwarf-version=4 -triple x86_64 %s -O0 -disable-llvm-passes -debug-info-kind=standalone -o - | FileCheck %s --check-prefixes=CHECK,CXX17
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[F1_TYPE:[0-9]+]]


        


More information about the cfe-commits mailing list