Skip to content

5.9: [IRGen] Cast dynamic alloca to appropriate type. #66086

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

Conversation

nate-chandler
Copy link
Contributor

Description: Stop emitting invalid LLVM IR when emitting pack metadata, witness tables, and values when stack allocating packs in async and coroutine code.

To allocate stack space for these packs, emitDynamicAlloca is called from GenPack. The calling code expects the type of the returned llvm::Value * to be Metadata **/WitnessTable **. In synchronous contexts, the value was indeed typed thus. In asychronous contexts, however, it was typed i8 **. Fix the callee to fulfill the callers' expectations by bit casting the value returned from emitDynamicAlloca to the type indicated by the caller.
Risk: Low. There are only 9 callers of that function and of them the only callers (of which there are 3) that will see a change in behavior are in GenPack. For the remaining 6, this change is NFC because no bitcast is inserted when the source (i8 *) and destination types are the same, and those all request i8 *.
Scope: Narrow. Only affects variadic generic IR generation, and only changes its behavior in async and coroutine contexts.
Original PR: #66014
Reviewed By: Slava Pestov ( @slavapestov )
Testing: Added test case that previously triggered assertion failure.
Resolves: rdar://109540863

Fix the type of the `alloca` created by `GenPack`'s for type metadata
and witness tables by fixing its callee, `emitDynamicAlloca` to always
return a `StackAddress` whose `Address`' type is the one specified by
the caller.

rdar://109540863
@nate-chandler nate-chandler requested a review from a team as a code owner May 23, 2023 18:08
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler merged commit caf8097 into swiftlang:release/5.9 May 24, 2023
@nate-chandler nate-chandler deleted the cherrypick/release/5.9/rdar109540863 branch May 24, 2023 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants