Skip to content

Commit aaf9c4e

Browse files
[lldb] Upgrade CompilerType::GetIndexOfFieldWithName to return llvm::Expected
1 parent b9ce185 commit aaf9c4e

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

lldb/include/lldb/Symbol/CompilerType.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,12 @@ class CompilerType {
433433

434434
CompilerDecl GetStaticFieldWithName(llvm::StringRef name) const;
435435

436-
uint32_t GetIndexOfFieldWithName(const char *name,
437-
CompilerType *field_compiler_type = nullptr,
438-
uint64_t *bit_offset_ptr = nullptr,
439-
uint32_t *bitfield_bit_size_ptr = nullptr,
440-
bool *is_bitfield_ptr = nullptr) const;
436+
llvm::Expected<uint32_t>
437+
GetIndexOfFieldWithName(const char *name,
438+
CompilerType *field_compiler_type = nullptr,
439+
uint64_t *bit_offset_ptr = nullptr,
440+
uint32_t *bitfield_bit_size_ptr = nullptr,
441+
bool *is_bitfield_ptr = nullptr) const;
441442

442443
llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex(
443444
ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,

lldb/source/Symbol/CompilerType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ CompilerDecl CompilerType::GetStaticFieldWithName(llvm::StringRef name) const {
893893
return CompilerDecl();
894894
}
895895

896-
uint32_t CompilerType::GetIndexOfFieldWithName(
896+
llvm::Expected<uint32_t> CompilerType::GetIndexOfFieldWithName(
897897
const char *name, CompilerType *field_compiler_type_ptr,
898898
uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr,
899899
bool *is_bitfield_ptr) const {
@@ -909,7 +909,7 @@ uint32_t CompilerType::GetIndexOfFieldWithName(
909909
return index;
910910
}
911911
}
912-
return UINT32_MAX;
912+
return llvm::createStringError("Invalid name: Cannot find index");
913913
}
914914

915915
llvm::Expected<CompilerType> CompilerType::GetChildCompilerTypeAtIndex(

lldb/unittests/Platform/PlatformSiginfoTest.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ class PlatformSiginfoTest : public ::testing::Test {
6060
uint64_t total_offset = 0;
6161
for (auto field_name : llvm::split(path, '.')) {
6262
uint64_t bit_offset;
63-
ASSERT_NE(field_type.GetIndexOfFieldWithName(field_name.str().c_str(),
64-
&field_type, &bit_offset),
65-
UINT32_MAX);
63+
ASSERT(llvm::expectedToOptional(
64+
field_type.GetIndexOfFieldWithName(field_name.str().c_str(),
65+
&field_type, &bit_offset))
66+
.has_value());
6667
total_offset += bit_offset;
6768
}
6869

0 commit comments

Comments
 (0)