Author: Raphael Isemann
Date: 2020-01-10T21:34:07+01:00
New Revision: 9e13cff44d6b8b9c9c8420870132931c218707cb

URL: 
https://github.com/llvm/llvm-project/commit/9e13cff44d6b8b9c9c8420870132931c218707cb
DIFF: 
https://github.com/llvm/llvm-project/commit/9e13cff44d6b8b9c9c8420870132931c218707cb.diff

LOG: [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

Added: 
    

Modified: 
    lldb/unittests/Symbol/TestClangASTContext.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/unittests/Symbol/TestClangASTContext.cpp 
b/lldb/unittests/Symbol/TestClangASTContext.cpp
index 547ca312283f..99ef3ed5bef9 100644
--- a/lldb/unittests/Symbol/TestClangASTContext.cpp
+++ b/lldb/unittests/Symbol/TestClangASTContext.cpp
@@ -498,6 +498,7 @@ TEST_F(TestClangASTContext, 
TestFunctionTemplateInRecordConstruction) {
   // Tests creating a function template inside a record.
 
   CompilerType int_type = m_ast->GetBasicType(lldb::eBasicTypeInt);
+  clang::TranslationUnitDecl *TU = m_ast->GetTranslationUnitDecl();
 
   // Create a record we can put the function template int.
   CompilerType record_type =
@@ -507,8 +508,11 @@ TEST_F(TestClangASTContext, 
TestFunctionTemplateInRecordConstruction) {
   // Prepare the declarations/types we need for the template.
   CompilerType clang_type =
       m_ast->CreateFunctionType(int_type, nullptr, 0U, false, 0U);
+  // We create the FunctionDecl for the template in the TU DeclContext because:
+  // 1. FunctionDecls can't be in a Record (only CXXMethodDecls can).
+  // 2. It is mirroring the behavior of DWARFASTParserClang::ParseSubroutine.
   FunctionDecl *func =
-      m_ast->CreateFunctionDeclaration(record, "foo", clang_type, 0, false);
+      m_ast->CreateFunctionDeclaration(TU, "foo", clang_type, 0, false);
   ClangASTContext::TemplateParameterInfos empty_params;
 
   // Create the actual function template.


        
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to