Skip to content

Add error handling to GetChildCompilerTypeAtIndex() #8793

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
merged 2 commits into from
May 23, 2024

Conversation

adrian-prantl
Copy link

@adrian-prantl adrian-prantl commented May 22, 2024

This was prompted by a crash report due to an out-of-bounds access of "fields" in

return get_from_field_info(fields[idx], tuple, true);

which is now wrapped in an error. I don't know how to trigger this
situation from a testcase.

rdar://128284599

This change is a general improvement of the internal API. My motivation
is to use this in the Swift typesystem plugin.

(cherry picked from commit ac1dc05)

 Conflicts:
	lldb/include/lldb/Symbol/TypeSystem.h
@adrian-prantl
Copy link
Author

@swift-ci test

This was prompted by a crash report due to an out-of-bounds access of "fields" in

    return get_from_field_info(fields[idx], tuple, true);

which is now wrapped in an error. I don't know how to trigger this
situation from a testcase.

rdar://128284599
@adrian-prantl
Copy link
Author

@swift-ci test

@adrian-prantl adrian-prantl merged commit 04fb099 into swiftlang:swift/release/6.0 May 23, 2024
3 checks passed
child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset,
child_is_base_class, child_is_deref_of_parent, this, language_flags);
CompilerType child_compiler_type;
if (!child_compiler_type_or_err)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extreme bikeshed, but I'd switch the success case to be first

uint64_t language_flags = 0;

ExecutionContext exe_ctx(GetExecutionContextRef());

child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex(
CompilerType child_compiler_type;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also very inconsequential, but I'd but this closer to the "if" below

return {};
}
if (!num_children_or_err)
return num_children_or_err.takeError();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the log message?

@@ -362,7 +362,7 @@ class TypeSystem : public PluginInterface,
GetVirtualBaseClassAtIndex(lldb::opaque_compiler_type_t type, size_t idx,
uint32_t *bit_offset_ptr) = 0;

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you upstreaming these changes to the generic code?

@@ -53,6 +53,14 @@ using namespace lldb_private;

namespace lldb_private {

std::string toString(const swift::reflection::TypeRef *tr) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize To?

@@ -1220,6 +1227,11 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
language_flags = 0;
return ts->GetRawPointerType();
}
if (idx - 3 >= fields.size())
return llvm::createStringError(llvm::inconvertibleErrorCode(),
llvm::Twine("index") + llvm::Twine(idx) +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need spaces here? Will it print "indexnis out of bounds"?

@@ -1387,7 +1414,7 @@ CompilerType SwiftLanguageRuntimeImpl::GetChildCompilerTypeAtIndex(
// field in the base class.
if (!type_ref) {
child_name = "<base class>";
return {};
return CompilerType();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these "return CompilerType()" different from errors?

@@ -2425,9 +2447,11 @@ constexpr ExecutionContextScope *g_no_exe_ctx = nullptr;
} while (0)

#define VALIDATE_AND_RETURN_EXPECTED(IMPL, REFERENCE, TYPE, EXE_CTX, ARGS, \
FALLBACK_ARGS, DEFAULT) \
FALLBACK_ARGS) \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the equivalent of #8394 to remove the DEFAULT from the #else branch in new line 2500.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants