[Lldb-commits] [lldb] [LLDB] Fix GetIndexOfChildMemberWithName to handle anonymous struct in base classes (PR #158256)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Sep 12 02:50:17 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- lldb/test/API/lang/cpp/type_lookup_anon_base_member/main.cpp lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 43d956a2e..414349a91 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -6714,14 +6714,14 @@ bool TypeSystemClang::FindInAnonRecordFields(const clang::RecordDecl *rd,
uint32_t local_idx = 0;
// We need the visible base count to compute the child index offset
- const clang::CXXRecordDecl *crd =
- llvm::dyn_cast<clang::CXXRecordDecl>(rd);
+ const clang::CXXRecordDecl *crd = llvm::dyn_cast<clang::CXXRecordDecl>(rd);
const uint32_t bases =
TypeSystemClang::GetNumBaseClasses(crd, omit_empty_base_classes);
- // We only treat anonymous record fields as transparent containers for further lookup.
- for (auto it = rd->field_begin(), ie = rd->field_end();
- it != ie; ++it, ++local_idx) {
+ // We only treat anonymous record fields as transparent containers for further
+ // lookup.
+ for (auto it = rd->field_begin(), ie = rd->field_end(); it != ie;
+ ++it, ++local_idx) {
llvm::StringRef fname = it->getName();
const bool is_anon = it->isAnonymousStructOrUnion() || fname.empty();
@@ -6739,7 +6739,8 @@ bool TypeSystemClang::FindInAnonRecordFields(const clang::RecordDecl *rd,
continue;
const auto *inner_rt = it->getType()->castAs<clang::RecordType>();
- const clang::RecordDecl *inner_rd = inner_rt->getOriginalDecl()->getDefinitionOrSelf();
+ const clang::RecordDecl *inner_rd =
+ inner_rt->getOriginalDecl()->getDefinitionOrSelf();
if (!inner_rd)
continue;
@@ -6822,8 +6823,10 @@ size_t TypeSystemClang::GetIndexOfChildMemberWithName(
std::vector<uint32_t> save_indices = child_indexes;
child_indexes.push_back(this_slot);
const auto *rt = field->getType()->castAs<clang::RecordType>();
- const clang::RecordDecl *rd = rt->getOriginalDecl()->getDefinitionOrSelf();
- if (rd && FindInAnonRecordFields(rd, child_indexes, name, omit_empty_base_classes))
+ const clang::RecordDecl *rd =
+ rt->getOriginalDecl()->getDefinitionOrSelf();
+ if (rd && FindInAnonRecordFields(rd, child_indexes, name,
+ omit_empty_base_classes))
return child_indexes.size();
child_indexes = std::move(save_indices);
}
@@ -6837,9 +6840,10 @@ size_t TypeSystemClang::GetIndexOfChildMemberWithName(
}
if (cxx_record_decl) {
- for (const clang::CXXBaseSpecifier &base_spec : cxx_record_decl->bases()) {
- uint32_t base_slot =
- GetIndexForRecordBase(record_decl, &base_spec, omit_empty_base_classes);
+ for (const clang::CXXBaseSpecifier &base_spec :
+ cxx_record_decl->bases()) {
+ uint32_t base_slot = GetIndexForRecordBase(record_decl, &base_spec,
+ omit_empty_base_classes);
if (base_slot == UINT32_MAX)
continue;
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
index 62e6d8314..8a6b36426 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -321,8 +321,7 @@ public:
bool omit_empty_base_classes);
bool FindInAnonRecordFields(const clang::RecordDecl *rd,
- std::vector<uint32_t> &path,
- llvm::StringRef name,
+ std::vector<uint32_t> &path, llvm::StringRef name,
bool omit_empty_base_classes);
/// Synthesize a clang::Module and return its ID or a default-constructed ID.
``````````
</details>
https://github.com/llvm/llvm-project/pull/158256
More information about the lldb-commits
mailing list