Skip to content

Commit 52d6920

Browse files
authored
Merge pull request #6644 from Michael137/bugfix/namespace-clash-to-5.9
2 parents 417f36c + d209717 commit 52d6920

File tree

15 files changed

+107
-36
lines changed

15 files changed

+107
-36
lines changed

lldb/include/lldb/Symbol/SymbolFile.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,17 @@ class SymbolFile : public PluginInterface {
333333
virtual llvm::Expected<lldb::TypeSystemSP>
334334
GetTypeSystemForLanguage(lldb::LanguageType language) = 0;
335335

336+
/// Finds a namespace of name \ref name and whose parent
337+
/// context is \ref parent_decl_ctx.
338+
///
339+
/// If \code{.cpp} !parent_decl_ctx.IsValid() \endcode
340+
/// then this function will consider all namespaces that
341+
/// match the name. If \ref only_root_namespaces is
342+
/// true, only consider in the search those DIEs that
343+
/// represent top-level namespaces.
336344
virtual CompilerDeclContext
337-
FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx) {
345+
FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx,
346+
bool only_root_namespaces = false) {
338347
return CompilerDeclContext();
339348
}
340349

lldb/include/lldb/Symbol/SymbolFileOnDemand.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ class SymbolFileOnDemand : public lldb_private::SymbolFile {
167167
llvm::Expected<lldb::TypeSystemSP>
168168
GetTypeSystemForLanguage(lldb::LanguageType language) override;
169169

170-
lldb_private::CompilerDeclContext FindNamespace(
171-
lldb_private::ConstString name,
172-
const lldb_private::CompilerDeclContext &parent_decl_ctx) override;
170+
lldb_private::CompilerDeclContext
171+
FindNamespace(lldb_private::ConstString name,
172+
const lldb_private::CompilerDeclContext &parent_decl_ctx,
173+
bool only_root_namespaces) override;
173174

174175
std::vector<std::unique_ptr<lldb_private::CallEdge>>
175176
ParseCallEdgesInFunction(UserID func_id) override;

lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,18 @@ void ClangASTSource::FillNamespaceMap(
700700
if (!symbol_file)
701701
continue;
702702

703-
found_namespace_decl = symbol_file->FindNamespace(name, namespace_decl);
703+
// If namespace_decl is not valid, 'FindNamespace' would look for
704+
// any namespace called 'name' (ignoring parent contexts) and return
705+
// the first one it finds. Thus if we're doing a qualified lookup only
706+
// consider root namespaces. E.g., in an expression ::A::B::Foo, the
707+
// lookup of ::A will result in a qualified lookup. Note, namespace
708+
// disambiguation for function calls are handled separately in
709+
// SearchFunctionsInSymbolContexts.
710+
const bool find_root_namespaces =
711+
context.m_decl_context &&
712+
context.m_decl_context->shouldUseQualifiedLookup();
713+
found_namespace_decl = symbol_file->FindNamespace(
714+
name, namespace_decl, /* only root namespaces */ find_root_namespaces);
704715

705716
if (found_namespace_decl) {
706717
context.m_namespace_map->push_back(

lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ class SymbolFileBreakpad : public SymbolFileCommon {
133133
llvm::inconvertibleErrorCode());
134134
}
135135

136-
CompilerDeclContext
137-
FindNamespace(ConstString name,
138-
const CompilerDeclContext &parent_decl_ctx) override {
136+
CompilerDeclContext FindNamespace(ConstString name,
137+
const CompilerDeclContext &parent_decl_ctx,
138+
bool only_root_namespaces) override {
139139
return CompilerDeclContext();
140140
}
141141

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,12 +2365,19 @@ bool SymbolFileDWARF::ResolveFunction(const DWARFDIE &orig_die,
23652365
}
23662366

23672367
bool SymbolFileDWARF::DIEInDeclContext(const CompilerDeclContext &decl_ctx,
2368-
const DWARFDIE &die) {
2368+
const DWARFDIE &die,
2369+
bool only_root_namespaces) {
23692370
// If we have no parent decl context to match this DIE matches, and if the
23702371
// parent decl context isn't valid, we aren't trying to look for any
23712372
// particular decl context so any die matches.
2372-
if (!decl_ctx.IsValid())
2373+
if (!decl_ctx.IsValid()) {
2374+
// ...But if we are only checking root decl contexts, confirm that the
2375+
// 'die' is a top-level context.
2376+
if (only_root_namespaces)
2377+
return die.GetParent().Tag() == dwarf::DW_TAG_compile_unit;
2378+
23732379
return true;
2380+
}
23742381

23752382
if (die) {
23762383
if (DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU())) {
@@ -2604,7 +2611,8 @@ void SymbolFileDWARF::FindTypes(
26042611

26052612
CompilerDeclContext
26062613
SymbolFileDWARF::FindNamespace(ConstString name,
2607-
const CompilerDeclContext &parent_decl_ctx) {
2614+
const CompilerDeclContext &parent_decl_ctx,
2615+
bool only_root_namespaces) {
26082616
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
26092617
Log *log = GetLog(DWARFLog::Lookups);
26102618

@@ -2620,7 +2628,7 @@ SymbolFileDWARF::FindNamespace(ConstString name,
26202628
return namespace_decl_ctx;
26212629

26222630
m_index->GetNamespaces(name, [&](DWARFDIE die) {
2623-
if (!DIEInDeclContext(parent_decl_ctx, die))
2631+
if (!DIEInDeclContext(parent_decl_ctx, die, only_root_namespaces))
26242632
return true; // The containing decl contexts don't match
26252633

26262634
DWARFASTParser *dwarf_ast = GetDWARFParser(*die.GetCU());

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,10 @@ class SymbolFileDWARF : public lldb_private::SymbolFileCommon,
225225
llvm::Expected<lldb::TypeSystemSP>
226226
GetTypeSystemForLanguage(lldb::LanguageType language) override;
227227

228-
lldb_private::CompilerDeclContext FindNamespace(
229-
lldb_private::ConstString name,
230-
const lldb_private::CompilerDeclContext &parent_decl_ctx) override;
228+
lldb_private::CompilerDeclContext
229+
FindNamespace(lldb_private::ConstString name,
230+
const lldb_private::CompilerDeclContext &parent_decl_ctx,
231+
bool only_root_namespaces) override;
231232

232233
bool GetCompileOption(const char *option, std::string &value,
233234
lldb_private::CompileUnit *cu = nullptr) override;
@@ -300,7 +301,7 @@ class SymbolFileDWARF : public lldb_private::SymbolFileCommon,
300301

301302
static bool
302303
DIEInDeclContext(const lldb_private::CompilerDeclContext &parent_decl_ctx,
303-
const DWARFDIE &die);
304+
const DWARFDIE &die, bool only_root_namespaces = false);
304305

305306
std::vector<std::unique_ptr<lldb_private::CallEdge>>
306307
ParseCallEdgesInFunction(UserID func_id) override;

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,13 +1260,14 @@ void SymbolFileDWARFDebugMap::FindTypes(
12601260
}
12611261

12621262
CompilerDeclContext SymbolFileDWARFDebugMap::FindNamespace(
1263-
lldb_private::ConstString name,
1264-
const CompilerDeclContext &parent_decl_ctx) {
1263+
lldb_private::ConstString name, const CompilerDeclContext &parent_decl_ctx,
1264+
bool only_root_namespaces) {
12651265
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
12661266
CompilerDeclContext matching_namespace;
12671267

12681268
ForEachSymbolFile([&](SymbolFileDWARF *oso_dwarf) -> bool {
1269-
matching_namespace = oso_dwarf->FindNamespace(name, parent_decl_ctx);
1269+
matching_namespace =
1270+
oso_dwarf->FindNamespace(name, parent_decl_ctx, only_root_namespaces);
12701271

12711272
return (bool)matching_namespace;
12721273
});

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,10 @@ class SymbolFileDWARFDebugMap : public lldb_private::SymbolFileCommon {
137137
lldb_private::LanguageSet languages,
138138
llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
139139
lldb_private::TypeMap &types) override;
140-
lldb_private::CompilerDeclContext FindNamespace(
141-
lldb_private::ConstString name,
142-
const lldb_private::CompilerDeclContext &parent_decl_ctx) override;
140+
lldb_private::CompilerDeclContext
141+
FindNamespace(lldb_private::ConstString name,
142+
const lldb_private::CompilerDeclContext &parent_decl_ctx,
143+
bool only_root_namespaces) override;
143144
void GetTypes(lldb_private::SymbolContextScope *sc_scope,
144145
lldb::TypeClass type_mask,
145146
lldb_private::TypeList &type_list) override;

lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,9 +2112,8 @@ void SymbolFileNativePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope,
21122112
TypeClass type_mask,
21132113
lldb_private::TypeList &type_list) {}
21142114

2115-
CompilerDeclContext
2116-
SymbolFileNativePDB::FindNamespace(ConstString name,
2117-
const CompilerDeclContext &parent_decl_ctx) {
2115+
CompilerDeclContext SymbolFileNativePDB::FindNamespace(
2116+
ConstString name, const CompilerDeclContext &parent_decl_ctx, bool) {
21182117
return {};
21192118
}
21202119

lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ class SymbolFileNativePDB : public SymbolFileCommon {
151151
llvm::Expected<lldb::TypeSystemSP>
152152
GetTypeSystemForLanguage(lldb::LanguageType language) override;
153153

154-
CompilerDeclContext
155-
FindNamespace(ConstString name,
156-
const CompilerDeclContext &parent_decl_ctx) override;
154+
CompilerDeclContext FindNamespace(ConstString name,
155+
const CompilerDeclContext &parent_decl_ctx,
156+
bool only_root_namespaces) override;
157157

158158
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
159159

0 commit comments

Comments
 (0)