Skip to content

Commit eccbcf9

Browse files
committed
[lldb] Fix TestClangASTContext.TestFunctionTemplateInRecordConstruction in Debug builds
Summary: In Debug builds we call VerifyDecl in ClangASTContext::CreateFunctionDeclaration which in turn calls `getAccess` on the created FunctionDecl. As we passed in a RecordDecl as the DeclContext for the FunctionDecl, we end up hitting the assert in `getAccess` that checks that we never have a Decl inside a Record without a valid AccessSpecifier. FunctionDecls are never in RecordDecls (that would be a CXXMethodDecl) so setting a access specifier would not be the correct way to fix this. Instead this patch does the same thing that DWARFASTParserClang::ParseSubroutine is doing: We pass in the FunctionDecl with the TranslationUnit as the DeclContext. That's not ideal but it is how we currently do it when creating our debug info AST, so the unit test should do the same. Reviewers: shafik Reviewed By: shafik Subscribers: aprantl, JDevlieghere, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D72359
1 parent d0e243f commit eccbcf9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lldb/unittests/Symbol/TestTypeSystemClang.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ TEST_F(TestTypeSystemClang, TestFunctionTemplateInRecordConstruction) {
498498
// Tests creating a function template inside a record.
499499

500500
CompilerType int_type = m_ast->GetBasicType(lldb::eBasicTypeInt);
501+
clang::TranslationUnitDecl *TU = m_ast->GetTranslationUnitDecl();
501502

502503
// Create a record we can put the function template int.
503504
CompilerType record_type =
@@ -507,8 +508,11 @@ TEST_F(TestTypeSystemClang, TestFunctionTemplateInRecordConstruction) {
507508
// Prepare the declarations/types we need for the template.
508509
CompilerType clang_type =
509510
m_ast->CreateFunctionType(int_type, nullptr, 0U, false, 0U);
511+
// We create the FunctionDecl for the template in the TU DeclContext because:
512+
// 1. FunctionDecls can't be in a Record (only CXXMethodDecls can).
513+
// 2. It is mirroring the behavior of DWARFASTParserClang::ParseSubroutine.
510514
FunctionDecl *func =
511-
m_ast->CreateFunctionDeclaration(record, "foo", clang_type, 0, false);
515+
m_ast->CreateFunctionDeclaration(TU, "foo", clang_type, 0, false);
512516
TypeSystemClang::TemplateParameterInfos empty_params;
513517

514518
// Create the actual function template.

0 commit comments

Comments
 (0)