Skip to content

Commit 561234d

Browse files
authored
[lldb][Expression] Remove m_found_function_with_type_info in favour of boolean return (#141774)
I've been skimming this code while investigating a bug around module lookup and this looked like something we could clean up. We don't need to be carrying around state inside of `NameSearchContext` to tell us to look into modules. We can signal this via a boolean return from `LookupFunction`.
1 parent 67d907a commit 561234d

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,8 +1047,6 @@ void ClangExpressionDeclMap::LookupInModulesDeclVendor(
10471047
MaybeRegisterFunctionBody(copied_function);
10481048

10491049
context.AddNamedDecl(copied_function);
1050-
1051-
context.m_found_function_with_type_info = true;
10521050
} else if (auto copied_var = dyn_cast<clang::VarDecl>(copied_decl)) {
10531051
context.AddNamedDecl(copied_var);
10541052
context.m_found_variable = true;
@@ -1217,11 +1215,11 @@ SymbolContextList ClangExpressionDeclMap::SearchFunctionsInSymbolContexts(
12171215
return sc_func_list;
12181216
}
12191217

1220-
void ClangExpressionDeclMap::LookupFunction(
1218+
bool ClangExpressionDeclMap::LookupFunction(
12211219
NameSearchContext &context, lldb::ModuleSP module_sp, ConstString name,
12221220
const CompilerDeclContext &namespace_decl) {
12231221
if (!m_parser_vars)
1224-
return;
1222+
return false;
12251223

12261224
Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
12271225

@@ -1281,6 +1279,8 @@ void ClangExpressionDeclMap::LookupFunction(
12811279
}
12821280
}
12831281

1282+
bool found_function_with_type_info = false;
1283+
12841284
if (sc_list.GetSize()) {
12851285
Symbol *extern_symbol = nullptr;
12861286
Symbol *non_extern_symbol = nullptr;
@@ -1297,7 +1297,7 @@ void ClangExpressionDeclMap::LookupFunction(
12971297
continue;
12981298

12991299
AddOneFunction(context, sym_ctx.function, nullptr);
1300-
context.m_found_function_with_type_info = true;
1300+
found_function_with_type_info = true;
13011301
} else if (sym_ctx.symbol) {
13021302
Symbol *symbol = sym_ctx.symbol;
13031303
if (target && symbol->GetType() == eSymbolTypeReExported) {
@@ -1313,27 +1313,29 @@ void ClangExpressionDeclMap::LookupFunction(
13131313
}
13141314
}
13151315

1316-
if (!context.m_found_function_with_type_info) {
1316+
if (!found_function_with_type_info) {
13171317
for (clang::NamedDecl *decl : decls_from_modules) {
13181318
if (llvm::isa<clang::FunctionDecl>(decl)) {
13191319
clang::NamedDecl *copied_decl =
13201320
llvm::cast_or_null<FunctionDecl>(CopyDecl(decl));
13211321
if (copied_decl) {
13221322
context.AddNamedDecl(copied_decl);
1323-
context.m_found_function_with_type_info = true;
1323+
found_function_with_type_info = true;
13241324
}
13251325
}
13261326
}
13271327
}
13281328

1329-
if (!context.m_found_function_with_type_info) {
1329+
if (!found_function_with_type_info) {
13301330
if (extern_symbol) {
13311331
AddOneFunction(context, nullptr, extern_symbol);
13321332
} else if (non_extern_symbol) {
13331333
AddOneFunction(context, nullptr, non_extern_symbol);
13341334
}
13351335
}
13361336
}
1337+
1338+
return found_function_with_type_info;
13371339
}
13381340

13391341
void ClangExpressionDeclMap::FindExternalVisibleDecls(
@@ -1432,10 +1434,7 @@ void ClangExpressionDeclMap::FindExternalVisibleDecls(
14321434
}
14331435
}
14341436

1435-
LookupFunction(context, module_sp, name, namespace_decl);
1436-
1437-
// Try the modules next.
1438-
if (!context.m_found_function_with_type_info)
1437+
if (!LookupFunction(context, module_sp, name, namespace_decl))
14391438
LookupInModulesDeclVendor(context, name);
14401439

14411440
if (target && !context.m_found_variable && !namespace_decl) {

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,10 @@ class ClangExpressionDeclMap : public ClangASTSource {
481481
///
482482
/// \param[in] namespace_decl
483483
/// If valid and module is non-NULL, the parent namespace.
484-
void LookupFunction(NameSearchContext &context, lldb::ModuleSP module_sp,
484+
///
485+
/// \returns Returns \c true if we successfully found a function
486+
/// and could create a decl with correct type-info for it.
487+
bool LookupFunction(NameSearchContext &context, lldb::ModuleSP module_sp,
485488
ConstString name,
486489
const CompilerDeclContext &namespace_decl);
487490

lldb/source/Plugins/ExpressionParser/Clang/NameSearchContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ struct NameSearchContext {
4040
llvm::SmallSet<CompilerType, 5> m_function_types;
4141

4242
bool m_found_variable = false;
43-
bool m_found_function_with_type_info = false;
4443
bool m_found_local_vars_nsp = false;
4544
bool m_found_type = false;
4645

0 commit comments

Comments
 (0)