[ast] CreateParameterDeclaration should use an appropriate DeclContext.
authorZachary Turner <zturner@google.com>
Wed, 12 Dec 2018 17:17:53 +0000 (17:17 +0000)
committerZachary Turner <zturner@google.com>
Wed, 12 Dec 2018 17:17:53 +0000 (17:17 +0000)
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

llvm-svn: 348941

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

index ec2e2b4e65a59360a8047efc0f3c85500494f5a4..9302ddc437e842081bd37ef416a0d237e4ce5e7e 100644 (file)
@@ -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);
 
index 9981aec5a2931beeb743285f915013425199e685..af3c3b4b4107bfe4cd0e9e444d7631e3e612c8e9 100644 (file)
@@ -3407,8 +3407,9 @@ size_t DWARFASTParserClang::ParseChildParameters(
             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);
 
index e521c928ef99877cb174db5e7409794849fcc56b..898b43073bb8f34e64619d7b9f817cedfd54002a 100644 (file)
@@ -635,8 +635,8 @@ lldb::FunctionSP SymbolFileNativePDB::CreateFunction(PdbCompilandSymId func_id,
     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;
index 2c7a1a045d5f76eb1c806cc83cd31a61ac769519..37757578bdb8e5ec7721a1b6d9c1e3c926f64447 100644 (file)
@@ -932,7 +932,8 @@ PDBASTParser::GetDeclForSymbol(const llvm::pdb::PDBSymbol &symbol) {
             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);
         }
index f13631076b41c6fafe9322a5defbf8fe5114a456..7dd8aecc7338493456b1d1a386e0c3d520b55b8a 100644 (file)
@@ -2214,11 +2214,11 @@ CompilerType ClangASTContext::CreateFunctionType(
 }
 
 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);