@@ -577,16 +577,13 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
577
577
AtomicBoolSize = Size (ClangASTContext->getTypeSize (atomicBoolTy));
578
578
AtomicBoolAlign = Alignment (ClangASTContext->getTypeSize (atomicBoolTy));
579
579
}
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
585
584
// 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 =
590
587
clang::CodeGen::swiftcall::isSwiftErrorLoweredInRegister (
591
588
ClangCodeGen->CGM ()) || TargetInfo.OutputObjectFormat == llvm::Triple::Wasm;
592
589
@@ -889,7 +886,8 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
889
886
RuntimeAvailability availability,
890
887
llvm::ArrayRef<llvm::Type*> retTypes,
891
888
llvm::ArrayRef<llvm::Type*> argTypes,
892
- ArrayRef<Attribute::AttrKind> attrs) {
889
+ ArrayRef<Attribute::AttrKind> attrs,
890
+ IRGenModule *IGM) {
893
891
894
892
if (cache)
895
893
return cache;
@@ -966,14 +964,17 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
966
964
// Add swiftself and swifterror attributes only when swift_willThrow
967
965
// swift_willThrow is defined in RuntimeFunctions.def, but due to the
968
966
// 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` .
971
969
// 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
973
971
// callee and caller signature. So we need to add them correctly.
974
972
if (functionName == " swift_willThrow" ) {
973
+ assert (IGM && " IGM is required for swift_willThrow." );
975
974
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
+ }
977
978
}
978
979
}
979
980
@@ -1018,7 +1019,7 @@ void IRGenModule::registerRuntimeEffect(ArrayRef<RuntimeEffect> effect,
1018
1019
registerRuntimeEffect (EFFECT, #NAME); \
1019
1020
return getRuntimeFn (Module, ID##Fn, #NAME, CC, \
1020
1021
AVAILABILITY (this ->Context ), \
1021
- RETURNS, ARGS, ATTRS); \
1022
+ RETURNS, ARGS, ATTRS, this ); \
1022
1023
}
1023
1024
1024
1025
#include " swift/Runtime/RuntimeFunctions.def"
0 commit comments