-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[IRGen] Fix a bug where an argument wasn't annotated with sret #71459
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
12bbc11
[IRGen] Fix a bug where an argument wasn't annotated with sret
ahatanaka e2081b9
Pass target triple
ahatanaka b65aaf8
Make sure the sret type matches the type of the pointee type.
ahatanaka 6a83363
Fix tests
ahatanaka 9ddee0f
Call arrangeCXXStructorDeclaration to arrange constructor signatures
ahatanaka d444a75
Compute the return type of c++ constructors without calling arrangeCX…
ahatanaka a87806b
Fix sret type in test case
ahatanaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is not the ABI for C++ constructors on Apple ARM64; they return
this
. We can ignore that result, and technically the call will probably succeed as avoid
call, but we should really arrange the function type correctly. Can we just use Clang as a library to arrange the constructor signature?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.
There's
CodeGenTypes::arrangeCXXStructorDeclaration
, but that function isn't available in a header file swift has access to.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.
I tried adding public function
arrangeCXXStructorDeclaration
toCodeGenABITypes.h
so that it can be called to arrange the constructor signature. But that's causing an assertion to fail inexternalizeArguments
:https://github.com/apple/swift/blob/main/lib/IRGen/GenCall.cpp#L4019
The cast fails because
AddressOnlyCXXClangRecordTypeInfo
is returned instead of aLoadableTypeInfo
. The following function returnsAddressOnlyCXXClangRecordTypeInfo
:https://github.com/apple/swift/blob/6dccf3d6679f442cafa9021de50cf677ac727b53/lib/IRGen/GenStruct.cpp#L1334
The type in question is
StructWithCopyConstructorAndValue
intest/Interop/Cxx/class/type-classification-non-trivial.swift
and the assertion fails when the argument is passed to the constructor ofStructWithCopyConstructorAndSubobjectCopyConstructorAndValue
:https://github.com/apple/swift/blob/6dccf3d6679f442cafa9021de50cf677ac727b53/test/Interop/Cxx/class/type-classification-non-trivial.swift#L29
I don't see the assertion fail if I revert the changes and stop using
arrangeCXXStructorDeclaration
. The difference is thatarrangeCXXStructorDeclaration
returnsABIArgInfo::Indirect
for the argument whereas the previous approach (which passes a pointer type toarrangeFreeFunctionCall
as the parameter type) returnedABIArgInfo::Direct
.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.
It looks like
AddressOnlyCXXClangRecordTypeInfo
has methods likeinitializeWithCopy
, which can possibly be used to initialize the temporary.Uh oh!
There was an error while loading. Please reload this page.
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.
That would introduce an extra copy of a non-trivial type, which we generally don't want to do in IRGen as part of making a call.
In this case, SIL type lowering already recognized that the type has to be passed indirectly as a parameter or return value and encoded that using an indirect SIL convention. You should be able to assert that indirect SIL parameters and results correspond to
ABIArgInfo::Indirect
in the ClangFunctionInfo
. (The reverse isn't always true.)