-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[lldb][ObjC][NFC] Use early-return in AppleObjCDeclVendor::FindDecls #164371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Member
|
@llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) ChangesWas browsing through this and the do/while loop (in addition to the local Full diff: https://github.com/llvm/llvm-project/pull/164371.diff 1 Files Affected:
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;
}
|
adrian-prantl
approved these changes
Oct 21, 2025
Lukacma
pushed a commit
to Lukacma/llvm-project
that referenced
this pull request
Oct 29, 2025
…lvm#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.
aokblast
pushed a commit
to aokblast/llvm-project
that referenced
this pull request
Oct 30, 2025
…lvm#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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Was browsing through this and the do/while loop (in addition to the local
retcounter which only ever gets incremented at most once) were hard to reason about imo. This patch removes both in favour of early-returns.