@@ -959,6 +959,25 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
959959
960960 // Start Main loop!
961961 FuncDecl *drainQueueFuncDecl = SGM.getAsyncMainDrainQueue ();
962+ if (!drainQueueFuncDecl) {
963+ // If it doesn't exist, we can conjure one up instead of crashing
964+ // @available(SwiftStdlib 5.5, *)
965+ // @_silgen_name("swift_task_asyncMainDrainQueue")
966+ // internal func _asyncMainDrainQueue() -> Never
967+ ParameterList *emptyParams = ParameterList::createEmpty (getASTContext ());
968+ drainQueueFuncDecl = FuncDecl::createImplicit (
969+ getASTContext (), StaticSpellingKind::None,
970+ DeclName (
971+ getASTContext (),
972+ DeclBaseName (getASTContext ().getIdentifier (" _asyncMainDrainQueue" )),
973+ /* Arguments*/ emptyParams),
974+ {}, /* async*/ false , /* throws*/ false , {}, emptyParams,
975+ getASTContext ().getNeverType (),
976+ entryPoint.getDecl ()->getModuleContext ());
977+ drainQueueFuncDecl->getAttrs ().add (new (getASTContext ()) SILGenNameAttr (
978+ " swift_task_asyncMainDrainQueue" , /* implicit*/ true ));
979+ }
980+
962981 SILFunction *drainQueueSILFunc = SGM.getFunction (
963982 SILDeclRef (drainQueueFuncDecl, SILDeclRef::Kind::Func), NotForDefinition);
964983 SILValue drainQueueFunc =
0 commit comments