@@ -1469,6 +1469,7 @@ class IRGenSILFunction :
14691469 void visitCondBranchInst (CondBranchInst *i);
14701470 void visitReturnInst (ReturnInst *i);
14711471 void visitThrowInst (ThrowInst *i);
1472+ void visitThrowAddrInst (ThrowAddrInst *i);
14721473 void visitUnwindInst (UnwindInst *i);
14731474 void visitYieldInst (YieldInst *i);
14741475 void visitSwitchValueInst (SwitchValueInst *i);
@@ -4251,23 +4252,34 @@ void IRGenSILFunction::visitReturnInst(swift::ReturnInst *i) {
42514252void IRGenSILFunction::visitThrowInst (swift::ThrowInst *i) {
42524253 SILFunctionConventions conv (CurSILFn->getLoweredFunctionType (),
42534254 getSILModule ());
4255+ assert (!conv.hasIndirectSILErrorResults ());
4256+
42544257 if (!isAsync ()) {
42554258 if (conv.isTypedError ()) {
42564259 llvm::Constant *flag = llvm::ConstantInt::get (IGM.IntPtrTy , 1 );
42574260 flag = llvm::ConstantExpr::getIntToPtr (flag, IGM.Int8PtrTy );
4258- if (!conv.hasIndirectSILErrorResults ()) {
4259- Explosion errorResult = getLoweredExplosion (i->getOperand ());
4260- auto &ti = cast<LoadableTypeInfo>(IGM.getTypeInfo (conv.getSILErrorType (
4261- IGM.getMaximalTypeExpansionContext ())));
4262- ti.initialize (*this , errorResult, getCallerTypedErrorResultSlot (), false );
4263- }
4261+ Explosion errorResult = getLoweredExplosion (i->getOperand ());
4262+ auto &ti = cast<LoadableTypeInfo>(IGM.getTypeInfo (conv.getSILErrorType (
4263+ IGM.getMaximalTypeExpansionContext ())));
4264+ ti.initialize (*this , errorResult, getCallerTypedErrorResultSlot (), false );
4265+
42644266 Builder.CreateStore (flag, getCallerErrorResultSlot ());
42654267 } else {
42664268 Explosion errorResult = getLoweredExplosion (i->getOperand ());
42674269 Builder.CreateStore (errorResult.claimNext (), getCallerErrorResultSlot ());
42684270 }
4269- // Async functions just return to the continuation.
4270- } else if (isAsync ()) {
4271+
4272+ // Create a normal return, but leaving the return value undefined.
4273+ auto fnTy = CurFn->getFunctionType ();
4274+ auto retTy = fnTy->getReturnType ();
4275+ if (retTy->isVoidTy ()) {
4276+ Builder.CreateRetVoid ();
4277+ } else {
4278+ Builder.CreateRet (llvm::UndefValue::get (retTy));
4279+ }
4280+
4281+ // Async functions just return to the continuation.
4282+ } else {
42714283 // Store the exception to the error slot.
42724284 auto exn = getLoweredExplosion (i->getOperand ());
42734285
@@ -4276,13 +4288,9 @@ void IRGenSILFunction::visitThrowInst(swift::ThrowInst *i) {
42764288 conv.getSILResultType (IGM.getMaximalTypeExpansionContext ()));
42774289
42784290 if (conv.isTypedError ()) {
4279- if (conv.hasIndirectSILErrorResults ()) {
4280- (void )exn.claimAll ();
4281- } else {
4282- auto &ti = cast<LoadableTypeInfo>(IGM.getTypeInfo (conv.getSILErrorType (
4283- IGM.getMaximalTypeExpansionContext ())));
4284- ti.initialize (*this , exn, getCallerTypedErrorResultSlot (), false );
4285- }
4291+ auto &ti = cast<LoadableTypeInfo>(IGM.getTypeInfo (conv.getSILErrorType (
4292+ IGM.getMaximalTypeExpansionContext ())));
4293+ ti.initialize (*this , exn, getCallerTypedErrorResultSlot (), false );
42864294 llvm::Constant *flag = llvm::ConstantInt::get (IGM.IntPtrTy , 1 );
42874295 flag = llvm::ConstantExpr::getIntToPtr (flag, IGM.Int8PtrTy );
42884296 assert (exn.empty () && " Unclaimed typed error results" );
@@ -4293,16 +4301,44 @@ void IRGenSILFunction::visitThrowInst(swift::ThrowInst *i) {
42934301 Explosion empty;
42944302 emitAsyncReturn (*this , layout, funcResultType,
42954303 i->getFunction ()->getLoweredFunctionType (), empty, exn);
4296- return ;
42974304 }
4305+ }
42984306
4299- // Create a normal return, but leaving the return value undefined.
4300- auto fnTy = CurFn->getFunctionType ();
4301- auto retTy = fnTy->getReturnType ();
4302- if (retTy->isVoidTy ()) {
4303- Builder.CreateRetVoid ();
4307+ void IRGenSILFunction::visitThrowAddrInst (swift::ThrowAddrInst *i) {
4308+ SILFunctionConventions conv (CurSILFn->getLoweredFunctionType (),
4309+ getSILModule ());
4310+ assert (conv.isTypedError ());
4311+ assert (conv.hasIndirectSILErrorResults ());
4312+
4313+ if (!isAsync ()) {
4314+ llvm::Constant *flag = llvm::ConstantInt::get (IGM.IntPtrTy , 1 );
4315+ flag = llvm::ConstantExpr::getIntToPtr (flag, IGM.Int8PtrTy );
4316+ Builder.CreateStore (flag, getCallerErrorResultSlot ());
4317+
4318+ // Create a normal return, but leaving the return value undefined.
4319+ auto fnTy = CurFn->getFunctionType ();
4320+ auto retTy = fnTy->getReturnType ();
4321+ if (retTy->isVoidTy ()) {
4322+ Builder.CreateRetVoid ();
4323+ } else {
4324+ Builder.CreateRet (llvm::UndefValue::get (retTy));
4325+ }
4326+
4327+ // Async functions just return to the continuation.
43044328 } else {
4305- Builder.CreateRet (llvm::UndefValue::get (retTy));
4329+ auto layout = getAsyncContextLayout (*this );
4330+ auto funcResultType = CurSILFn->mapTypeIntoContext (
4331+ conv.getSILResultType (IGM.getMaximalTypeExpansionContext ()));
4332+
4333+ llvm::Constant *flag = llvm::ConstantInt::get (IGM.IntPtrTy , 1 );
4334+ flag = llvm::ConstantExpr::getIntToPtr (flag, IGM.Int8PtrTy );
4335+
4336+ Explosion exn;
4337+ exn.add (flag);
4338+
4339+ Explosion empty;
4340+ emitAsyncReturn (*this , layout, funcResultType,
4341+ i->getFunction ()->getLoweredFunctionType (), empty, exn);
43064342 }
43074343}
43084344
0 commit comments