mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The operands to the original apply are cast via an ownership forwarding instruction to the appropriate type for the rewritten apply. ``` %converted = convert_function %original to $(NewTy) -> () apply %converted(%operand) ``` -> ``` %cast = cast %operand to $OriginalTy apply %original(%cast) ``` Previously, when an original operand is owned but the new apply does not consume that operand, the newly added cast would consume the original operand (an owned value)--something the original code being replaced did not do. ``` %converted = convert_function %original to $(NewTy) -> () apply %converted(%operand : @guaranteed) // %operand remains available ``` -> ``` %cast = cast %operand to $OriginalTy // consumes %operand! apply %original(%cast : @guaranteed) // %operand is not available! ``` This is incorrect for the complementary reasons that the result of the cast is leaked and any uses of the original operand subsequent to the new apply are uses-after-consume. Here, this is fixed by borrowing the original operand before casting in this case. rdar://142570727
68 KiB
68 KiB