-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
[SILGen] Fix a crash when a closure is converted to a pointer to a function returning a non-trivial C++ type #73561
base: main
Are you sure you want to change the base?
Conversation
function returning a non-trivial C++ type rdar://124501345
@swift-ci please test |
@swift-ci please test |
@swift-ci please test macOS |
assert((SGF.F.getRepresentation() == | ||
SILFunctionType::Representation::CFunctionPointer || | ||
objcFnTy->getNumIndirectFormalResults() == 0) && | ||
"Objective-C methods cannot have indirect results"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assertion is just wrong now that we're importing types that are formally treated as indirect in SIL. The test case here is just an ObjC++ method that returns a non-trivial C++ type, or even an ObjC method that returns a struct that contains a __weak
reference (although we may not support that properly). We should just remove this assertion. Please check whether that test case passes without any other changes.
for (auto result : substConv.getResults()) { | ||
if (!substConv.isSILIndirect(result)) { | ||
continue; | ||
if (F.getRepresentation() == |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition should not be looking at function type representations and should instead be looking at, I guess, whether there's a direct/indirect mismatch in the result.
if (substConv.hasIndirectSILResults()) { | ||
assert(substTy->getNumResults() == 1); | ||
result = args[0]; | ||
if (F.getRepresentation() != SILFunctionType::Representation::CFunctionPointer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here as above. This should be based intelligently on looking at the differences between the result types and whether they're returned directly, not the function type representation.
Pass the thunk's result address parameter to the closure when the thunk is for a C function.
Also, fix the predicate function passed to
emitEntryPointIndirectReturn
. The predicate should return true only when the result is returned directly at the SIL level but indirectly at the IR level.rdar://124501345