@@ -577,16 +577,13 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
577577 AtomicBoolSize = Size (ClangASTContext->getTypeSize (atomicBoolTy));
578578 AtomicBoolAlign = Alignment (ClangASTContext->getTypeSize (atomicBoolTy));
579579 }
580-
581- // On WebAssembly, tail optional arguments are not allowed because wasm requires
582- // callee and caller signature should be same. So LLVM adds dummy arguments for
583- // swiftself and swifterror. If there is swiftself but there isn't swifterror in
584- // a swiftcc function or invocation, then LLVM adds dummy swifterror parameter or
580+ // On WebAssembly, tail optional arguments are not allowed because Wasm requires
581+ // callee and caller signature to be the same. So LLVM adds dummy arguments for
582+ // `swiftself` and `swifterror`. If there is `swiftself` but is no `swifterror` in
583+ // a swiftcc function or invocation, then LLVM adds dummy `swifterror` parameter or
585584 // argument. To count up how many dummy arguments should be added, we need to mark
586- // it as swifterror even though it's not in register.
587- //
588- // TODO: Before sending patch, please rename `IsSwiftErrorInRegister` to `ShouldUseSwiftError`
589- IsSwiftErrorInRegister =
585+ // it as `swifterror` even though it's not in register.
586+ ShouldUseSwiftError =
590587 clang::CodeGen::swiftcall::isSwiftErrorLoweredInRegister (
591588 ClangCodeGen->CGM ()) || TargetInfo.OutputObjectFormat == llvm::Triple::Wasm;
592589
@@ -889,7 +886,8 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
889886 RuntimeAvailability availability,
890887 llvm::ArrayRef<llvm::Type*> retTypes,
891888 llvm::ArrayRef<llvm::Type*> argTypes,
892- ArrayRef<Attribute::AttrKind> attrs) {
889+ ArrayRef<Attribute::AttrKind> attrs,
890+ IRGenModule *IGM) {
893891
894892 if (cache)
895893 return cache;
@@ -966,14 +964,17 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
966964 // Add swiftself and swifterror attributes only when swift_willThrow
967965 // swift_willThrow is defined in RuntimeFunctions.def, but due to the
968966 // DSL limitation, arguments attributes are not set.
969- // On the other hand, caller of swift_willThrow assumes that it's attributed
970- // with swiftself and swifterror.
967+ // On the other hand, caller of ` swift_willThrow` assumes that it's attributed
968+ // with ` swiftself` and ` swifterror` .
971969 // This mismatch of attributes would be issue when lowering to WebAssembly.
972- // While lowering, LLVM count up how many dummy params are necssary to match
970+ // While lowering, LLVM counts how many dummy params are necessary to match
973971 // callee and caller signature. So we need to add them correctly.
974972 if (functionName == " swift_willThrow" ) {
973+ assert (IGM && " IGM is required for swift_willThrow." );
975974 fn->addParamAttr (0 , Attribute::AttrKind::SwiftSelf);
976- fn->addParamAttr (1 , Attribute::AttrKind::SwiftError);
975+ if (IGM->ShouldUseSwiftError ) {
976+ fn->addParamAttr (1 , Attribute::AttrKind::SwiftError);
977+ }
977978 }
978979 }
979980
@@ -1018,7 +1019,7 @@ void IRGenModule::registerRuntimeEffect(ArrayRef<RuntimeEffect> effect,
10181019 registerRuntimeEffect (EFFECT, #NAME); \
10191020 return getRuntimeFn (Module, ID##Fn, #NAME, CC, \
10201021 AVAILABILITY (this ->Context ), \
1021- RETURNS, ARGS, ATTRS); \
1022+ RETURNS, ARGS, ATTRS, this ); \
10221023 }
10231024
10241025#include " swift/Runtime/RuntimeFunctions.def"
0 commit comments