@@ -572,7 +572,15 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
572572 C_CC = getOptions ().PlatformCCallingConvention ;
573573 // TODO: use "tinycc" on platforms that support it
574574 DefaultCC = SWIFT_DEFAULT_LLVM_CC;
575- SwiftCC = llvm::CallingConv::Swift;
575+
576+ bool isSwiftCCSupported =
577+ clangASTContext.getTargetInfo ().checkCallingConvention (clang::CC_Swift)
578+ == clang::TargetInfo::CCCR_OK;
579+ if (isSwiftCCSupported) {
580+ SwiftCC = llvm::CallingConv::Swift;
581+ } else {
582+ SwiftCC = DefaultCC;
583+ }
576584
577585 bool isAsyncCCSupported =
578586 clangASTContext.getTargetInfo ().checkCallingConvention (clang::CC_SwiftAsync)
@@ -601,15 +609,22 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
601609 AtomicBoolSize = Size (ClangASTContext->getTypeSize (atomicBoolTy));
602610 AtomicBoolAlign = Alignment (ClangASTContext->getTypeSize (atomicBoolTy));
603611 }
604- // On WebAssembly, tail optional arguments are not allowed because Wasm requires
605- // callee and caller signature to be the same. So LLVM adds dummy arguments for
606- // `swiftself` and `swifterror`. If there is `swiftself` but is no `swifterror` in
607- // a swiftcc function or invocation, then LLVM adds dummy `swifterror` parameter or
608- // argument. To count up how many dummy arguments should be added, we need to mark
609- // it as `swifterror` even though it's not in register.
610- ShouldUseSwiftError =
611- clang::CodeGen::swiftcall::isSwiftErrorLoweredInRegister (
612- ClangCodeGen->CGM ()) || TargetInfo.OutputObjectFormat == llvm::Triple::Wasm;
612+ if (TargetInfo.OutputObjectFormat == llvm::Triple::Wasm) {
613+ // On WebAssembly, tail optional arguments are not allowed because Wasm
614+ // requires callee and caller signature to be the same. So LLVM adds dummy
615+ // arguments for `swiftself` and `swifterror`. If there is `swiftself` but
616+ // is no `swifterror` in a swiftcc function or invocation, then LLVM adds
617+ // dummy `swifterror` parameter or argument. To count up how many dummy
618+ // arguments should be added, we need to mark it as `swifterror` even though
619+ // it's not in register.
620+ ShouldUseSwiftError = true ;
621+ } else if (!isSwiftCCSupported) {
622+ ShouldUseSwiftError = false ;
623+ } else {
624+ ShouldUseSwiftError =
625+ clang::CodeGen::swiftcall::isSwiftErrorLoweredInRegister (
626+ ClangCodeGen->CGM ());
627+ }
613628
614629#ifndef NDEBUG
615630 sanityCheckStdlib (*this );
0 commit comments