@@ -913,10 +913,21 @@ void CoroCloner::create() {
913
913
Shape.FrameSize , Shape.FrameAlign );
914
914
break ;
915
915
case coro::ABI::Async: {
916
+ auto *ActiveAsyncSuspend = cast<CoroSuspendAsyncInst>(ActiveSuspend);
916
917
if (OrigF.hasParamAttribute (Shape.AsyncLowering .ContextArgNo ,
917
918
Attribute::SwiftAsync)) {
918
- addAsyncContextAttrs (NewAttrs, Context, Shape.AsyncLowering .ContextArgNo );
919
+ uint32_t ArgAttributeIndices =
920
+ ActiveAsyncSuspend->getStorageArgumentIndex ();
921
+ auto ContextArgIndex = ArgAttributeIndices & 0xff ;
922
+ addAsyncContextAttrs (NewAttrs, Context, ContextArgIndex);
923
+
924
+ // `swiftasync` must preceed `swiftself` so 0 is not a valid index for
925
+ // `swiftself`.
926
+ auto SwiftSelfIndex = ArgAttributeIndices >> 8 ;
927
+ if (SwiftSelfIndex)
928
+ addSwiftSelfAttrs (NewAttrs, Context, SwiftSelfIndex);
919
929
}
930
+
920
931
// Transfer the original function's attributes.
921
932
auto FnAttrs = OrigF.getAttributes ().getFnAttributes ();
922
933
NewAttrs =
@@ -956,24 +967,9 @@ void CoroCloner::create() {
956
967
// followed by a return.
957
968
// Don't change returns to unreachable because that will trip up the verifier.
958
969
// These returns should be unreachable from the clone.
959
- case coro::ABI::Async: {
960
- auto *ActiveAsyncSuspend = cast<CoroSuspendAsyncInst>(ActiveSuspend);
961
- if (OrigF.hasParamAttribute (Shape.AsyncLowering .ContextArgNo ,
962
- Attribute::SwiftAsync)) {
963
- uint32_t ArgAttributeIndices =
964
- ActiveAsyncSuspend->getStorageArgumentIndex ();
965
- auto ContextArgIndex = ArgAttributeIndices & 0xff ;
966
- addAsyncContextAttrs (NewAttrs, Context, ContextArgIndex);
967
-
968
- // `swiftasync` must preceed `swiftself` so 0 is not a valid index for
969
- // `swiftself`.
970
- auto SwiftSelfIndex = ArgAttributeIndices >> 8 ;
971
- if (SwiftSelfIndex)
972
- addSwiftSelfAttrs (NewAttrs, Context, SwiftSelfIndex);
973
- }
970
+ case coro::ABI::Async:
974
971
break ;
975
972
}
976
- }
977
973
978
974
NewF->setAttributes (NewAttrs);
979
975
NewF->setCallingConv (Shape.getResumeFunctionCC ());
0 commit comments