-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[embedded] Fix miscompile in IRGen in offset computation of Builtin.destroyArray #73130
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
[embedded] Fix miscompile in IRGen in offset computation of Builtin.destroyArray #73130
Conversation
@swift-ci please test |
Out of curiosity: why do we need to do something different in embedded swift for destroyArray? Can't we just use the typeinfo's destroyArray? |
adding @aschwaighofer as reviewer |
Don't we have the same problem with the other array builtins, like copyArray? |
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.
lgtm
That would emit a call to a runtime function ( |
It probably deserves a comment/explainer in the source code :) |
Added comments, applied the fix to the init/take/assign builtins too (@eeckstein you're right we needed it there too), added a testcase. |
@swift-ci please test |
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.
thanks! lgtm
In Embedded Swift, IRGen emits the loop to destroy values in the array directly. Turns out that the GEP we use to index into the individual elements of the array's storage is using the value's size and not the stride in some cases, concretely in cases where the type is an enum with payloads. E.g. this
ends up being represented as this type in LLVM IR:
...on which GEP will not do the right thing we want (stride). Let's compute the offset directly via ptrtoint, add, inttoptr.
Will add tests, but wanted to check that this is the right approach first.
rdar://126386301