[clang] c9861e5 - [llvm][DebugInfo] Backport DW_AT_default_value for template args
Michael Buch via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 14 14:32:06 PST 2022
Author: Michael Buch
Date: 2022-12-14T22:31:46Z
New Revision: c9861e5718f6352bb1ee9fe6b5c3e16a0e649360
URL: https://github.com/llvm/llvm-project/commit/c9861e5718f6352bb1ee9fe6b5c3e16a0e649360
DIFF: https://github.com/llvm/llvm-project/commit/c9861e5718f6352bb1ee9fe6b5c3e16a0e649360.diff
LOG: [llvm][DebugInfo] Backport DW_AT_default_value for template args
**Summary**
Starting with DWARFv5, DW_AT_default_value can be used to indicate
that a template argument has a default value. With this patch LLVM
will emit the this attribute earlier versions of DWARF, unless
compiling with -gstrict-dwarf.
Differential Revision: https://reviews.llvm.org/D139953
Added:
Modified:
clang/test/CodeGenCXX/debug-info-template-parameter.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
Removed:
################################################################################
diff --git a/clang/test/CodeGenCXX/debug-info-template-parameter.cpp b/clang/test/CodeGenCXX/debug-info-template-parameter.cpp
index 46ef45197460..1b36eb430812 100644
--- a/clang/test/CodeGenCXX/debug-info-template-parameter.cpp
+++ b/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,25 @@
// 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-DUMP-LABEL: 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
+// DWARF-DUMP: {{DW_TAG|NULL}}
+
template <typename T = char, int i = 3, bool b = true, int x = sizeof(T)>
class foo {
};
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 9cd6532a2d5a..5e376f0441a4 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1056,7 +1056,7 @@ void DwarfUnit::constructTemplateTypeParameterDIE(
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);
}
@@ -1070,7 +1070,7 @@ void DwarfUnit::constructTemplateValueParameterDIE(
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))
@@ -1845,3 +1845,7 @@ void DwarfUnit::addRnglistsBase() {
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;
+}
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
index 395539fcc1c7..0caa6adbfa62 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -350,6 +350,10 @@ class DwarfUnit : public DIEUnit {
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 {
More information about the cfe-commits
mailing list