[Lldb-commits] [PATCH] D71909: [lldb] Fix crash in AccessDeclContextSanity when copying FunctionTemplateDecl inside a record.

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Dec 26 12:05:23 PST 2019


teemperor updated this revision to Diff 235369.
teemperor added a comment.

- Add unit test.


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

https://reviews.llvm.org/D71909

Files:
  lldb/packages/Python/lldbsuite/test/commands/expression/completion-crash2/TestCompletionCrash2.py
  lldb/packages/Python/lldbsuite/test/commands/expression/completion-crash2/main.cpp
  lldb/packages/Python/lldbsuite/test/commands/expression/regression-access-function-template-in-record/TestRegressionAccessFunctionTemplateInRecord.py
  lldb/packages/Python/lldbsuite/test/commands/expression/regression-access-function-template-in-record/main.cpp
  lldb/source/Symbol/ClangASTContext.cpp
  lldb/unittests/Symbol/TestClangASTContext.cpp


Index: lldb/unittests/Symbol/TestClangASTContext.cpp
===================================================================
--- lldb/unittests/Symbol/TestClangASTContext.cpp
+++ lldb/unittests/Symbol/TestClangASTContext.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "TestingSupport/SubsystemRAII.h"
+#include "TestingSupport/Symbol/ClangTestUtils.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Host/HostInfo.h"
 #include "lldb/Symbol/ClangASTContext.h"
@@ -471,3 +472,51 @@
   QualType t = ctxt.getTypeOfType(t_base);
   EXPECT_EQ(lldb::eTypeClassBuiltin, m_ast->GetTypeClass(t.getAsOpaquePtr()));
 }
+
+TEST_F(TestClangASTContext, TestFunctionTemplateConstruction) {
+  // Tests creating a function template.
+
+  CompilerType int_type = m_ast->GetBasicType(lldb::eBasicTypeInt);
+  clang::TranslationUnitDecl *TU = m_ast->GetTranslationUnitDecl();
+
+  // Prepare the declarations/types we need for the template.
+  CompilerType clang_type =
+      m_ast->CreateFunctionType(int_type, nullptr, 0U, false, 0U);
+  FunctionDecl *func =
+      m_ast->CreateFunctionDeclaration(TU, "foo", clang_type, 0, false);
+  ClangASTContext::TemplateParameterInfos empty_params;
+
+  // Create the actual function template.
+  clang::FunctionTemplateDecl *func_template =
+      m_ast->CreateFunctionTemplateDecl(TU, func, "foo", empty_params);
+
+  EXPECT_EQ(TU, func_template->getDeclContext());
+  EXPECT_EQ("foo", func_template->getName());
+  EXPECT_EQ(clang::AccessSpecifier::AS_none, func_template->getAccess());
+}
+
+TEST_F(TestClangASTContext, TestFunctionTemplateInRecordConstruction) {
+  // Tests creating a function template inside a record.
+
+  CompilerType int_type = m_ast->GetBasicType(lldb::eBasicTypeInt);
+
+  // Create a record we can put the function template int.
+  CompilerType record_type =
+      clang_utils::createRecordWithField(*m_ast, "record", int_type, "field");
+  clang::TagDecl *record = ClangUtil::GetAsTagDecl(record_type);
+
+  // Prepare the declarations/types we need for the template.
+  CompilerType clang_type =
+      m_ast->CreateFunctionType(int_type, nullptr, 0U, false, 0U);
+  FunctionDecl *func =
+      m_ast->CreateFunctionDeclaration(record, "foo", clang_type, 0, false);
+  ClangASTContext::TemplateParameterInfos empty_params;
+
+  // Create the actual function template.
+  clang::FunctionTemplateDecl *func_template =
+      m_ast->CreateFunctionTemplateDecl(record, func, "foo", empty_params);
+
+  EXPECT_EQ(record, func_template->getDeclContext());
+  EXPECT_EQ("foo", func_template->getName());
+  EXPECT_EQ(clang::AccessSpecifier::AS_public, func_template->getAccess());
+}
Index: lldb/source/Symbol/ClangASTContext.cpp
===================================================================
--- lldb/source/Symbol/ClangASTContext.cpp
+++ lldb/source/Symbol/ClangASTContext.cpp
@@ -1359,6 +1359,11 @@
     // TODO: verify which decl context we should put template_param_decls into..
     template_param_decls[i]->setDeclContext(func_decl);
   }
+  // Function templates inside a record need to have an access specifier.
+  // It doesn't matter what access specifier we give the template as LLDB
+  // anyway allows accessing everything inside a record.
+  if (decl_ctx->isRecord())
+    func_tmpl_decl->setAccess(clang::AccessSpecifier::AS_public);
 
   return func_tmpl_decl;
 }
Index: lldb/packages/Python/lldbsuite/test/commands/expression/regression-access-function-template-in-record/TestRegressionAccessFunctionTemplateInRecord.py
===================================================================
--- /dev/null
+++ lldb/packages/Python/lldbsuite/test/commands/expression/regression-access-function-template-in-record/TestRegressionAccessFunctionTemplateInRecord.py
@@ -0,0 +1,4 @@
+from lldbsuite.test import lldbinline
+from lldbsuite.test import decorators
+
+lldbinline.MakeInlineTest(__file__, globals(), [])
Index: lldb/packages/Python/lldbsuite/test/commands/expression/completion-crash2/TestCompletionCrash2.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/commands/expression/completion-crash2/TestCompletionCrash2.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from lldbsuite.test import lldbinline
-from lldbsuite.test import decorators
-
-lldbinline.MakeInlineTest(__file__, globals(), [decorators.skipIf(bugnumber="rdar://53754063")])


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71909.235369.patch
Type: text/x-patch
Size: 4426 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20191226/93729b45/attachment.bin>


More information about the lldb-commits mailing list