Fix handling of CreateTemplateParameterList when there is an empty pack
authorShafik Yaghmour <syaghmour@apple.com>
Wed, 30 Jan 2019 21:48:56 +0000 (21:48 +0000)
committerShafik Yaghmour <syaghmour@apple.com>
Wed, 30 Jan 2019 21:48:56 +0000 (21:48 +0000)
Summary:
When we are creating a ClassTemplateSpecializationDecl in ParseTypeFromDWARF(...) we are not handling the case where variadic pack is empty in the specialization. This patch handles that case and adds a test to prevent future regressions.

Differential Revision: https://reviews.llvm.org/D57363

llvm-svn: 352677

lldb/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/Makefile [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/TestClassTemplateSpecializationParametersHandling.py [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/main.cpp [new file with mode: 0644]
lldb/source/Symbol/ClangASTContext.cpp

diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/Makefile b/lldb/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/Makefile
new file mode 100644 (file)
index 0000000..8a7102e
--- /dev/null
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/TestClassTemplateSpecializationParametersHandling.py b/lldb/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/TestClassTemplateSpecializationParametersHandling.py
new file mode 100644 (file)
index 0000000..d1974d0
--- /dev/null
@@ -0,0 +1,23 @@
+"""
+Test Expression Parser code gen for ClassTemplateSpecializationDecl to insure
+that we generate a TemplateTypeParmDecl in the TemplateParameterList for empty
+variadic packs.
+"""
+
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class TestClassTemplateSpecializationParametersHandling(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    def test_class_template_specialization(self):
+        self.build()
+
+        lldbutil.run_to_source_breakpoint(self, '// break here',
+                lldb.SBFileSpec("main.cpp", False))
+
+        self.expect("expr -u 0 -- b.foo()", substrs=['$0 = 1'])
diff --git a/lldb/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/main.cpp b/lldb/packages/Python/lldbsuite/test/expression_command/class_template_specialization_empty_pack/main.cpp
new file mode 100644 (file)
index 0000000..bc83160
--- /dev/null
@@ -0,0 +1,9 @@
+template <typename N, class... P>
+struct A {
+    int foo() { return 1;}
+};
+
+int main() {
+  A<int> b;
+  return b.foo(); // break here
+}
index 0439159..5d22afa 100644 (file)
@@ -1549,25 +1549,24 @@ static TemplateParameterList *CreateTemplateParameterList(
     }
   }
 
-  if (template_param_infos.packed_args &&
-      template_param_infos.packed_args->args.size()) {
+  if (template_param_infos.packed_args) {
     IdentifierInfo *identifier_info = nullptr;
     if (template_param_infos.pack_name && template_param_infos.pack_name[0])
       identifier_info = &ast->Idents.get(template_param_infos.pack_name);
     const bool parameter_pack_true = true;
-    if (IsValueParam(template_param_infos.packed_args->args[0])) {
+
+    if (!template_param_infos.packed_args->args.empty() &&
+        IsValueParam(template_param_infos.packed_args->args[0])) {
       template_param_decls.push_back(NonTypeTemplateParmDecl::Create(
-          *ast, decl_context,
-          SourceLocation(), SourceLocation(), depth, num_template_params,
-          identifier_info,
+          *ast, decl_context, SourceLocation(), SourceLocation(), depth,
+          num_template_params, identifier_info,
           template_param_infos.packed_args->args[0].getIntegralType(),
           parameter_pack_true, nullptr));
     } else {
       template_param_decls.push_back(TemplateTypeParmDecl::Create(
-          *ast, decl_context,
-          SourceLocation(), SourceLocation(), depth, num_template_params,
-          identifier_info,
-          is_typename, parameter_pack_true));
+          *ast, decl_context, SourceLocation(), SourceLocation(), depth,
+          num_template_params, identifier_info, is_typename,
+          parameter_pack_true));
     }
   }
   clang::Expr *const requires_clause = nullptr; // TODO: Concepts