[Lldb-commits] [lldb] r348941 - [ast] CreateParameterDeclaration should use an appropriate DeclContext.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Wed Dec 12 09:17:53 PST 2018


Author: zturner
Date: Wed Dec 12 09:17:53 2018
New Revision: 348941

URL: http://llvm.org/viewvc/llvm-project?rev=348941&view=rev
Log:
[ast] CreateParameterDeclaration should use an appropriate DeclContext.

Previously CreateParameterDeclaration was always using the translation
unit DeclContext.  We would later go and add parameters to the
FunctionDecl, but internally clang makes a copy when you do this, and
we'd end up with ParmVarDecl's at the global scope as well as in the
function scope.

This fixes the issue.  It's hard to say whether this will introduce
a behavioral change in name lookup, but I know there have been several
hacks introduced in previous years to deal with collisions between
various types of variables, so there's a chance that this patch could
obviate one of those hacks.

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

Modified:
    lldb/trunk/include/lldb/Symbol/ClangASTContext.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
    lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
    lldb/trunk/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
    lldb/trunk/source/Symbol/ClangASTContext.cpp

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=348941&r1=348940&r2=348941&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Wed Dec 12 09:17:53 2018
@@ -401,7 +401,8 @@ public:
                                                type_quals, cc);
   }
 
-  clang::ParmVarDecl *CreateParameterDeclaration(const char *name,
+  clang::ParmVarDecl *CreateParameterDeclaration(clang::DeclContext *decl_ctx,
+                                                 const char *name,
                                                  const CompilerType &param_type,
                                                  int storage);
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp?rev=348941&r1=348940&r2=348941&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp Wed Dec 12 09:17:53 2018
@@ -3407,8 +3407,9 @@ size_t DWARFASTParserClang::ParseChildPa
             function_param_types.push_back(type->GetForwardCompilerType());
 
             clang::ParmVarDecl *param_var_decl =
-                m_ast.CreateParameterDeclaration(
-                    name, type->GetForwardCompilerType(), storage);
+                m_ast.CreateParameterDeclaration(containing_decl_ctx, name,
+                                                 type->GetForwardCompilerType(),
+                                                 storage);
             assert(param_var_decl);
             function_param_decls.push_back(param_var_decl);
 

Modified: lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp?rev=348941&r1=348940&r2=348941&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp Wed Dec 12 09:17:53 2018
@@ -635,8 +635,8 @@ lldb::FunctionSP SymbolFileNativePDB::Cr
     PdbCompilandSymId param_uid(func_id.modi, record_offset);
     TypeSP type_sp = GetOrCreateType(param_type);
     clang::ParmVarDecl *param = m_clang->CreateParameterDeclaration(
-        param_name.str().c_str(), type_sp->GetForwardCompilerType(),
-        clang::SC_None);
+        function_decl, param_name.str().c_str(),
+        type_sp->GetForwardCompilerType(), clang::SC_None);
     lldbassert(m_uid_to_decl.count(toOpaqueUid(param_uid)) == 0);
 
     m_uid_to_decl[toOpaqueUid(param_uid)] = param;

Modified: lldb/trunk/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp?rev=348941&r1=348940&r2=348941&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp Wed Dec 12 09:17:53 2018
@@ -932,7 +932,8 @@ PDBASTParser::GetDeclForSymbol(const llv
             continue;
 
           clang::ParmVarDecl *param = m_ast.CreateParameterDeclaration(
-              nullptr, arg_type->GetForwardCompilerType(), clang::SC_None);
+              decl, nullptr, arg_type->GetForwardCompilerType(),
+              clang::SC_None);
           if (param)
             params.push_back(param);
         }

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=348941&r1=348940&r2=348941&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Wed Dec 12 09:17:53 2018
@@ -2214,11 +2214,11 @@ CompilerType ClangASTContext::CreateFunc
 }
 
 ParmVarDecl *ClangASTContext::CreateParameterDeclaration(
-    const char *name, const CompilerType &param_type, int storage) {
+    clang::DeclContext *decl_ctx, const char *name,
+    const CompilerType &param_type, int storage) {
   ASTContext *ast = getASTContext();
   assert(ast != nullptr);
-  return ParmVarDecl::Create(*ast, ast->getTranslationUnitDecl(),
-                             SourceLocation(), SourceLocation(),
+  return ParmVarDecl::Create(*ast, decl_ctx, SourceLocation(), SourceLocation(),
                              name && name[0] ? &ast->Idents.get(name) : nullptr,
                              ClangUtil::GetQualType(param_type), nullptr,
                              (clang::StorageClass)storage, nullptr);




More information about the lldb-commits mailing list