[Lldb-commits] [lldb] [lldb][ObjC][NFC] Use early-return in AppleObjCDeclVendor::FindDecls (PR #164371)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 21 00:46:44 PDT 2025
https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/164371
Was browsing through this and the do/while loop (in addition to the local `ret` counter which only ever gets incremented at most once) were hard to reason about imo. This patch removes both in favour of early-returns.
>From 9c99e6752333d42abc542f7622542ff8cd877a5a Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Tue, 21 Oct 2025 08:45:05 +0100
Subject: [PATCH] [lldb][ObjC][NFC] Use early-return in
AppleObjCDeclVendor::FindDecls
Was browsing through this and the do/while loop (in addition to the
local `ret` counter which only ever gets incremented at most once) were
hard to reason about imo. This patch removes both in favour of
early-returns.
---
.../AppleObjCRuntime/AppleObjCDeclVendor.cpp | 120 ++++++++----------
1 file changed, 56 insertions(+), 64 deletions(-)
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
index d6d2df27c5e74..a707a9f239dd3 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp
@@ -537,83 +537,75 @@ uint32_t AppleObjCDeclVendor::FindDecls(ConstString name, bool append,
if (!append)
decls.clear();
- uint32_t ret = 0;
+ // See if the type is already in our ASTContext.
- do {
- // See if the type is already in our ASTContext.
-
- clang::ASTContext &ast_ctx = m_ast_ctx->getASTContext();
-
- clang::IdentifierInfo &identifier_info =
- ast_ctx.Idents.get(name.GetStringRef());
- clang::DeclarationName decl_name =
- ast_ctx.DeclarationNames.getIdentifier(&identifier_info);
-
- clang::DeclContext::lookup_result lookup_result =
- ast_ctx.getTranslationUnitDecl()->lookup(decl_name);
-
- if (!lookup_result.empty()) {
- if (clang::ObjCInterfaceDecl *result_iface_decl =
- llvm::dyn_cast<clang::ObjCInterfaceDecl>(*lookup_result.begin())) {
- if (log) {
- clang::QualType result_iface_type =
- ast_ctx.getObjCInterfaceType(result_iface_decl);
-
- uint64_t isa_value = LLDB_INVALID_ADDRESS;
- if (std::optional<ClangASTMetadata> metadata =
- m_ast_ctx->GetMetadata(result_iface_decl))
- isa_value = metadata->GetISAPtr();
-
- LLDB_LOGF(log,
- "AOCTV::FT Found %s (isa 0x%" PRIx64 ") in the ASTContext",
- result_iface_type.getAsString().data(), isa_value);
- }
+ clang::ASTContext &ast_ctx = m_ast_ctx->getASTContext();
- decls.push_back(m_ast_ctx->GetCompilerDecl(result_iface_decl));
- ret++;
- break;
- } else {
- LLDB_LOGF(log, "AOCTV::FT There's something in the ASTContext, but "
- "it's not something we know about");
- break;
+ clang::IdentifierInfo &identifier_info =
+ ast_ctx.Idents.get(name.GetStringRef());
+ clang::DeclarationName decl_name =
+ ast_ctx.DeclarationNames.getIdentifier(&identifier_info);
+
+ clang::DeclContext::lookup_result lookup_result =
+ ast_ctx.getTranslationUnitDecl()->lookup(decl_name);
+
+ if (!lookup_result.empty()) {
+ if (clang::ObjCInterfaceDecl *result_iface_decl =
+ llvm::dyn_cast<clang::ObjCInterfaceDecl>(*lookup_result.begin())) {
+ if (log) {
+ clang::QualType result_iface_type =
+ ast_ctx.getObjCInterfaceType(result_iface_decl);
+
+ uint64_t isa_value = LLDB_INVALID_ADDRESS;
+ if (std::optional<ClangASTMetadata> metadata =
+ m_ast_ctx->GetMetadata(result_iface_decl))
+ isa_value = metadata->GetISAPtr();
+
+ LLDB_LOGF(log,
+ "AOCTV::FT Found %s (isa 0x%" PRIx64 ") in the ASTContext",
+ result_iface_type.getAsString().data(), isa_value);
}
- } else if (log) {
- LLDB_LOGF(log, "AOCTV::FT Couldn't find %s in the ASTContext",
- name.AsCString());
+
+ decls.push_back(m_ast_ctx->GetCompilerDecl(result_iface_decl));
+ return 1;
}
- // It's not. If it exists, we have to put it into our ASTContext.
+ LLDB_LOGF(log, "AOCTV::FT There's something in the ASTContext, but "
+ "it's not something we know about");
+ return 0;
+ }
- ObjCLanguageRuntime::ObjCISA isa = m_runtime.GetISA(name);
+ LLDB_LOGF(log, "AOCTV::FT Couldn't find %s in the ASTContext",
+ name.AsCString());
- if (!isa) {
- LLDB_LOGF(log, "AOCTV::FT Couldn't find the isa");
+ // It's not. If it exists, we have to put it into our ASTContext.
- break;
- }
+ ObjCLanguageRuntime::ObjCISA isa = m_runtime.GetISA(name);
- clang::ObjCInterfaceDecl *iface_decl = GetDeclForISA(isa);
+ if (!isa) {
+ LLDB_LOGF(log, "AOCTV::FT Couldn't find the isa");
- if (!iface_decl) {
- LLDB_LOGF(log,
- "AOCTV::FT Couldn't get the Objective-C interface for "
- "isa 0x%" PRIx64,
- (uint64_t)isa);
+ return 0;
+ }
- break;
- }
+ clang::ObjCInterfaceDecl *iface_decl = GetDeclForISA(isa);
- if (log) {
- clang::QualType new_iface_type = ast_ctx.getObjCInterfaceType(iface_decl);
+ if (!iface_decl) {
+ LLDB_LOGF(log,
+ "AOCTV::FT Couldn't get the Objective-C interface for "
+ "isa 0x%" PRIx64,
+ (uint64_t)isa);
- LLDB_LOG(log, "AOCTV::FT Created {0} (isa 0x{1:x})",
- new_iface_type.getAsString(), (uint64_t)isa);
- }
+ return 0;
+ }
- decls.push_back(m_ast_ctx->GetCompilerDecl(iface_decl));
- ret++;
- break;
- } while (false);
+ if (log) {
+ clang::QualType new_iface_type = ast_ctx.getObjCInterfaceType(iface_decl);
+
+ LLDB_LOG(log, "AOCTV::FT Created {0} (isa 0x{1:x})",
+ new_iface_type.getAsString(), (uint64_t)isa);
+ }
- return ret;
+ decls.push_back(m_ast_ctx->GetCompilerDecl(iface_decl));
+ return 1;
}
More information about the lldb-commits
mailing list