summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
authorRaphael Isemann <teemperor@gmail.com>2020-01-02 14:46:39 +0100
committerRaphael Isemann <teemperor@gmail.com>2020-01-02 14:47:04 +0100
commit7ead00872929a994ac40fc2c99fce15968e2c5a6 (patch)
treea5a52a72d985b676793b20158c3e1cc811a79f3b /lldb
parent136f34fed661869ebb0082d32f7b5399baca204c (diff)
downloadbcm5719-llvm-7ead00872929a994ac40fc2c99fce15968e2c5a6.tar.gz
bcm5719-llvm-7ead00872929a994ac40fc2c99fce15968e2c5a6.zip
[lldb] Fix crash in AccessDeclContextSanity when copying FunctionTemplateDecl inside a record.
Summary: We currently don't set access specifiers for function template declarations. This seems to be fine as long as the function template is not declared inside any record in which case Clang asserts with the following once we try to query it's access: ``` Assertion failed: (Access != AS_none && "Access specifier is AS_none inside a record decl"), function AccessDeclContextSanity, ``` This patch just marks these function template declarations as public to make Clang happy. Reviewers: shafik, teemperor Reviewed By: teemperor Subscribers: JDevlieghere, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D71909
Diffstat (limited to 'lldb')
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/expression/completion-crash2/TestCompletionCrash2.py4
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/expression/regression-access-function-template-in-record/TestRegressionAccessFunctionTemplateInRecord.py4
-rw-r--r--lldb/packages/Python/lldbsuite/test/commands/expression/regression-access-function-template-in-record/main.cpp (renamed from lldb/packages/Python/lldbsuite/test/commands/expression/completion-crash2/main.cpp)0
-rw-r--r--lldb/source/Symbol/ClangASTContext.cpp5
-rw-r--r--lldb/unittests/Symbol/TestClangASTContext.cpp49
5 files changed, 58 insertions, 4 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/commands/expression/completion-crash2/TestCompletionCrash2.py b/lldb/packages/Python/lldbsuite/test/commands/expression/completion-crash2/TestCompletionCrash2.py
deleted file mode 100644
index 922347aa781..00000000000
--- a/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")])
diff --git a/lldb/packages/Python/lldbsuite/test/commands/expression/regression-access-function-template-in-record/TestRegressionAccessFunctionTemplateInRecord.py b/lldb/packages/Python/lldbsuite/test/commands/expression/regression-access-function-template-in-record/TestRegressionAccessFunctionTemplateInRecord.py
new file mode 100644
index 00000000000..f08c0dcbda9
--- /dev/null
+++ b/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(), [])
diff --git a/lldb/packages/Python/lldbsuite/test/commands/expression/completion-crash2/main.cpp b/lldb/packages/Python/lldbsuite/test/commands/expression/regression-access-function-template-in-record/main.cpp
index 02f15c295c2..02f15c295c2 100644
--- a/lldb/packages/Python/lldbsuite/test/commands/expression/completion-crash2/main.cpp
+++ b/lldb/packages/Python/lldbsuite/test/commands/expression/regression-access-function-template-in-record/main.cpp
diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp
index 4cf70fa9c1c..99299c3c6c4 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -1340,6 +1340,11 @@ clang::FunctionTemplateDecl *ClangASTContext::CreateFunctionTemplateDecl(
// 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;
}
diff --git a/lldb/unittests/Symbol/TestClangASTContext.cpp b/lldb/unittests/Symbol/TestClangASTContext.cpp
index 2cbd94982aa..cea3a2912e3 100644
--- a/lldb/unittests/Symbol/TestClangASTContext.cpp
+++ b/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 @@ TEST_F(TestClangASTContext, TestGetTypeClassNested) {
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());
+}
OpenPOWER on IntegriCloud