[DWARF parser] Produce correct template parameter packs
Templates can end in parameter packs, like this
template <class T...> struct MyStruct
{ /*...*/ };
LLDB does not currently support these parameter packs;
it does not emit them into the template argument list
at all. This causes problems when you specialize, e.g.:
template <> struct MyStruct<int>
{ /*...*/ };
template <> struct MyStruct<int, int> : MyStruct<int>
{ /*...*/ };
LLDB generates two template specializations, each with
no template arguments, and then when they are imported
by the ASTImporter into a parser's AST context we get a
single specialization that inherits from itself,
causing Clang's record layout mechanism to smash its
stack.
This patch fixes the problem for classes and adds
tests. The tests for functions fail because Clang's
ASTImporter can't import them at the moment, so I've
xfailed that test.
Differential Revision: https://reviews.llvm.org/D33025
llvm-svn: 302833
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index 1f78fb9..a3cdfa9 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -1987,8 +1987,33 @@
.GetOpaqueDeclContext();
clang::FunctionDecl *src_function_decl =
llvm::dyn_cast_or_null<clang::FunctionDecl>(src_decl_context);
-
- if (src_function_decl) {
+ if (src_function_decl &&
+ src_function_decl->getTemplateSpecializationInfo()) {
+ clang::FunctionTemplateDecl *function_template =
+ src_function_decl->getTemplateSpecializationInfo()->getTemplate();
+ clang::FunctionTemplateDecl *copied_function_template =
+ llvm::dyn_cast_or_null<clang::FunctionTemplateDecl>(
+ m_ast_importer_sp->CopyDecl(m_ast_context,
+ src_ast->getASTContext(),
+ function_template));
+ if (copied_function_template) {
+ if (log) {
+ ASTDumper ast_dumper((clang::Decl *)copied_function_template);
+
+ StreamString ss;
+
+ function->DumpSymbolContext(&ss);
+
+ log->Printf(" CEDM::FEVD[%u] Imported decl for function template"
+ " %s (description %s), returned %s",
+ current_id,
+ copied_function_template->getNameAsString().c_str(),
+ ss.GetData(), ast_dumper.GetCString());
+ }
+
+ context.AddNamedDecl(copied_function_template);
+ }
+ } else if (src_function_decl) {
if (clang::FunctionDecl *copied_function_decl =
llvm::dyn_cast_or_null<clang::FunctionDecl>(
m_ast_importer_sp->CopyDecl(m_ast_context,
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 8aec35d..cb00e84 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1595,24 +1595,17 @@
: containing_decl_ctx,
type_name_cstr, clang_type, storage, is_inline);
- // if (template_param_infos.GetSize() >
- // 0)
- // {
- // clang::FunctionTemplateDecl
- // *func_template_decl =
- // CreateFunctionTemplateDecl
- // (containing_decl_ctx,
- // function_decl,
- // type_name_cstr,
- // template_param_infos);
- //
- // CreateFunctionTemplateSpecializationInfo
- // (function_decl,
- // func_template_decl,
- // template_param_infos);
- // }
- // Add the decl to our DIE to decl context map
-
+ if (has_template_params) {
+ ClangASTContext::TemplateParameterInfos template_param_infos;
+ ParseTemplateParameterInfos(die, template_param_infos);
+ clang::FunctionTemplateDecl *func_template_decl =
+ m_ast.CreateFunctionTemplateDecl(
+ containing_decl_ctx, function_decl, type_name_cstr,
+ template_param_infos);
+ m_ast.CreateFunctionTemplateSpecializationInfo(
+ function_decl, func_template_decl, template_param_infos);
+ }
+
lldbassert(function_decl);
if (function_decl) {
@@ -1951,6 +1944,19 @@
const dw_tag_t tag = die.Tag();
switch (tag) {
+ case DW_TAG_GNU_template_parameter_pack: {
+ template_param_infos.packed_args.reset(
+ new ClangASTContext::TemplateParameterInfos);
+ for (DWARFDIE child_die = die.GetFirstChild(); child_die.IsValid();
+ child_die = child_die.GetSibling()) {
+ if (!ParseTemplateDIE(child_die, *template_param_infos.packed_args))
+ return false;
+ }
+ if (const char *name = die.GetName()) {
+ template_param_infos.pack_name = name;
+ }
+ return true;
+ }
case DW_TAG_template_type_parameter:
case DW_TAG_template_value_parameter: {
DWARFAttributes attributes;
@@ -2040,6 +2046,7 @@
switch (tag) {
case DW_TAG_template_type_parameter:
case DW_TAG_template_value_parameter:
+ case DW_TAG_GNU_template_parameter_pack:
ParseTemplateDIE(die, template_param_infos);
break;
@@ -3450,6 +3457,7 @@
case DW_TAG_template_type_parameter:
case DW_TAG_template_value_parameter:
+ case DW_TAG_GNU_template_parameter_pack:
// The one caller of this was never using the template_param_infos,
// and the local variable was taking up a large amount of stack space
// in SymbolFileDWARF::ParseType() so this was removed. If we ever need
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
index e00eda4..022ce55 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -1647,6 +1647,8 @@
break;
case DW_TAG_template_value_parameter:
break;
+ case DW_TAG_GNU_template_parameter_pack:
+ break;
case DW_TAG_thrown_type:
break;
case DW_TAG_try_block:
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp
index f0d6672..2ff0fe3 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp
@@ -610,6 +610,8 @@
return TagCategoryType;
case DW_TAG_template_value_parameter:
return TagCategoryType;
+ case DW_TAG_GNU_template_parameter_pack:
+ return TagCategoryType;
case DW_TAG_thrown_type:
return TagCategoryType;
case DW_TAG_try_block: