[PATCH] D139953: [llvm][DebugInfo] Backport DW_AT_default_value for template args

Michael Buch via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 13 17:02:53 PST 2022


Michael137 updated this revision to Diff 482664.
Michael137 added a comment.

- Use `CHECK-DAG` for attributes
- Also compile with non-strict DWARFv4
- Widen the `STRICT-NOT` checks


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139953/new/

https://reviews.llvm.org/D139953

Files:
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h


Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -350,6 +350,10 @@
 
   virtual bool isDwoUnit() const = 0;
   const MCSymbol *getCrossSectionRelativeBaseAddress() const override;
+
+  /// Returns 'true' if the current DwarfVersion is compatible
+  /// with the specified \p Version.
+  bool isCompatibleWithVersion(uint16_t Version) const;
 };
 
 class DwarfTypeUnit final : public DwarfUnit {
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1060,7 +1060,7 @@
     addType(ParamDIE, TP->getType());
   if (!TP->getName().empty())
     addString(ParamDIE, dwarf::DW_AT_name, TP->getName());
-  if (TP->isDefault() && (DD->getDwarfVersion() >= 5))
+  if (TP->isDefault() && isCompatibleWithVersion(5))
     addFlag(ParamDIE, dwarf::DW_AT_default_value);
 }
 
@@ -1074,7 +1074,7 @@
     addType(ParamDIE, VP->getType());
   if (!VP->getName().empty())
     addString(ParamDIE, dwarf::DW_AT_name, VP->getName());
-  if (VP->isDefault() && (DD->getDwarfVersion() >= 5))
+  if (VP->isDefault() && isCompatibleWithVersion(5))
     addFlag(ParamDIE, dwarf::DW_AT_default_value);
   if (Metadata *Val = VP->getValue()) {
     if (ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Val))
@@ -1852,3 +1852,7 @@
 void DwarfTypeUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {
   DD->getAddressPool().resetUsedFlag(true);
 }
+
+bool DwarfUnit::isCompatibleWithVersion(uint16_t Version) const {
+  return !Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= Version;
+}
Index: clang/test/CodeGenCXX/debug-info-template-parameter.cpp
===================================================================
--- clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ clang/test/CodeGenCXX/debug-info-template-parameter.cpp
@@ -4,6 +4,8 @@
 // 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
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -gstrict-dwarf -triple x86_64 %s -O0 -disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,STRICT
+// RUN: %clang_cc1 %std_cxx17- -dwarf-version=4 -triple x86_64 %s -O0 -disable-llvm-passes -debug-info-kind=standalone -emit-obj -o - %s | llvm-dwarfdump --debug-info - | FileCheck %s --check-prefixes=DWARF-DUMP,DWARFv4
 
 // CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
 // CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[F1_TYPE:[0-9]+]]
@@ -21,6 +23,24 @@
 // PRE17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, defaulted: true, value: i8 1)
 // CXX17: [[THIRD]] = !DITemplateValueParameter(name: "b", type: !{{[0-9]*}}, defaulted: true, value: i1 true)
 
+// DWARF-DUMP:       DW_TAG_class_type
+// DWARF-DUMPABEL:     DW_AT_name      ("foo<char, 3, true, 1>")
+// DWARF-DUMP:         DW_TAG_template_type_parameter
+// DWARF-DUMP-DAG:       DW_AT_type    ({{.*}} "char")
+// DWARF-DUMP-DAG:       DW_AT_name    ("T")
+// DWARFv4-DAG:          DW_AT_default_value   (true)
+// STRICT-NOT:           DW_AT_default_value
+// DWARF-DUMP:         DW_TAG_template_value_parameter
+// DWARF-DUMP-DAG:       DW_AT_type    ({{.*}} "int")
+// DWARF-DUMP-DAG:       DW_AT_name    ("i")
+// DWARFv4-DAG:          DW_AT_default_value   (true)
+// STRICT-NOT:           DW_AT_default_value   (true)
+// DWARF-DUMP:         DW_TAG_template_value_parameter
+// DWARF-DUMP-DAG:       DW_AT_type    ({{.*}} "bool")
+// DWARF-DUMP-DAG:       DW_AT_name    ("b")
+// DWARFv4-DAG:          DW_AT_default_value   (true)
+// STRICT-NOT:           DW_AT_default_value
+
 template <typename T = char, int i = 3, bool b = true, int x = sizeof(T)>
 class foo {
 };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139953.482664.patch
Type: text/x-patch
Size: 4475 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221214/1e745b08/attachment.bin>


More information about the cfe-commits mailing list