https://github.com/charles-zablit created https://github.com/llvm/llvm-project/pull/135963
This patch updates the `CompilerType::GetIndexOfFieldWithName` API to use `llvm::Expected` if no index is found instead of `UINT32_MAX`. >From aaf9c4ec3e68d78d963cdac3d3f08dc207d49cad Mon Sep 17 00:00:00 2001 From: Charles Zablit <zablitchar...@gmail.com> Date: Wed, 16 Apr 2025 11:28:54 +0100 Subject: [PATCH] [lldb] Upgrade CompilerType::GetIndexOfFieldWithName to return llvm::Expected --- lldb/include/lldb/Symbol/CompilerType.h | 11 ++++++----- lldb/source/Symbol/CompilerType.cpp | 4 ++-- lldb/unittests/Platform/PlatformSiginfoTest.cpp | 7 ++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lldb/include/lldb/Symbol/CompilerType.h b/lldb/include/lldb/Symbol/CompilerType.h index 41a1676dabd76..79998922cfc93 100644 --- a/lldb/include/lldb/Symbol/CompilerType.h +++ b/lldb/include/lldb/Symbol/CompilerType.h @@ -433,11 +433,12 @@ class CompilerType { CompilerDecl GetStaticFieldWithName(llvm::StringRef name) const; - uint32_t GetIndexOfFieldWithName(const char *name, - CompilerType *field_compiler_type = nullptr, - uint64_t *bit_offset_ptr = nullptr, - uint32_t *bitfield_bit_size_ptr = nullptr, - bool *is_bitfield_ptr = nullptr) const; + llvm::Expected<uint32_t> + GetIndexOfFieldWithName(const char *name, + CompilerType *field_compiler_type = nullptr, + uint64_t *bit_offset_ptr = nullptr, + uint32_t *bitfield_bit_size_ptr = nullptr, + bool *is_bitfield_ptr = nullptr) const; llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex( ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers, diff --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp index 22fdd24fc7cd5..0a36b390a645c 100644 --- a/lldb/source/Symbol/CompilerType.cpp +++ b/lldb/source/Symbol/CompilerType.cpp @@ -893,7 +893,7 @@ CompilerDecl CompilerType::GetStaticFieldWithName(llvm::StringRef name) const { return CompilerDecl(); } -uint32_t CompilerType::GetIndexOfFieldWithName( +llvm::Expected<uint32_t> CompilerType::GetIndexOfFieldWithName( const char *name, CompilerType *field_compiler_type_ptr, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) const { @@ -909,7 +909,7 @@ uint32_t CompilerType::GetIndexOfFieldWithName( return index; } } - return UINT32_MAX; + return llvm::createStringError("Invalid name: Cannot find index"); } llvm::Expected<CompilerType> CompilerType::GetChildCompilerTypeAtIndex( diff --git a/lldb/unittests/Platform/PlatformSiginfoTest.cpp b/lldb/unittests/Platform/PlatformSiginfoTest.cpp index 4b2c93a68a94a..e48d8ea667ad8 100644 --- a/lldb/unittests/Platform/PlatformSiginfoTest.cpp +++ b/lldb/unittests/Platform/PlatformSiginfoTest.cpp @@ -60,9 +60,10 @@ class PlatformSiginfoTest : public ::testing::Test { uint64_t total_offset = 0; for (auto field_name : llvm::split(path, '.')) { uint64_t bit_offset; - ASSERT_NE(field_type.GetIndexOfFieldWithName(field_name.str().c_str(), - &field_type, &bit_offset), - UINT32_MAX); + ASSERT(llvm::expectedToOptional( + field_type.GetIndexOfFieldWithName(field_name.str().c_str(), + &field_type, &bit_offset)) + .has_value()); total_offset += bit_offset; } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits