diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 3cf41984ec1970..8f0484582550a4 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -2987,6 +2987,18 @@ void CodeGen::genFnPrologCalleeRegArgs(regNumber xtraReg, bool* pXtraRegClobbere } } +#ifdef SWIFT_SUPPORT + // The Swift self parameter is passed in a callee save register and is + // not part of the arg register order that this function relies on to + // handle conflicts. For this reason we always mark it as DNER and + // handle it outside the normal register arguments. + // TODO-CQ: Fix this. + if (varNum == compiler->lvaSwiftSelfArg) + { + continue; + } +#endif + var_types regType = compiler->mangleVarArgsType(varDsc->TypeGet()); // Change regType to the HFA type when we have a HFA argument if (varDsc->lvIsHfaRegArg()) @@ -6131,6 +6143,14 @@ void CodeGen::genFnProlog() intRegState.rsCalleeRegArgMaskLiveIn &= ~RBM_SECRET_STUB_PARAM; } +#ifdef SWIFT_SUPPORT + if ((compiler->lvaSwiftSelfArg != BAD_VAR_NUM) && ((intRegState.rsCalleeRegArgMaskLiveIn & RBM_SWIFT_SELF) != 0)) + { + GetEmitter()->emitIns_S_R(ins_Store(TYP_I_IMPL), EA_PTRSIZE, REG_SWIFT_SELF, compiler->lvaSwiftSelfArg, 0); + intRegState.rsCalleeRegArgMaskLiveIn &= ~RBM_SWIFT_SELF; + } +#endif + // // Zero out the frame as needed // diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index afb8cb2df3b577..7e8a99087a8337 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -10529,6 +10529,7 @@ HelperCallProperties Compiler::s_helperCallProperties; // Return Value: // true - tree kills GC refs on callee save registers // false - tree doesn't affect GC refs on callee save registers +// bool Compiler::killGCRefs(GenTree* tree) { if (tree->IsCall()) @@ -10825,6 +10826,10 @@ void Compiler::EnregisterStats::RecordLocal(const LclVarDsc* varDsc) m_simdUserForcesDep++; break; + case DoNotEnregisterReason::NonStandardParameter: + m_nonStandardParameter++; + break; + default: unreached(); break; @@ -10952,6 +10957,7 @@ void Compiler::EnregisterStats::Dump(FILE* fout) const PRINT_STATS(m_returnSpCheck, notEnreg); PRINT_STATS(m_callSpCheck, notEnreg); PRINT_STATS(m_simdUserForcesDep, notEnreg); + PRINT_STATS(m_nonStandardParameter, notEnreg); fprintf(fout, "\nAddr exposed details:\n"); if (m_addrExposed == 0) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 2760347c612569..a564bfe5d7773c 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -456,13 +456,14 @@ enum class DoNotEnregisterReason #endif LclAddrNode, // the local is accessed with LCL_ADDR_VAR/FLD. CastTakesAddr, - StoreBlkSrc, // the local is used as STORE_BLK source. - SwizzleArg, // the local is passed using LCL_FLD as another type. - BlockOpRet, // the struct is returned and it promoted or there is a cast. - ReturnSpCheck, // the local is used to do SP check on return from function - CallSpCheck, // the local is used to do SP check on every call - SimdUserForcesDep, // a promoted struct was used by a SIMD/HWI node; it must be dependently promoted - HiddenBufferStructArg // the argument is a hidden return buffer passed to a method. + StoreBlkSrc, // the local is used as STORE_BLK source. + SwizzleArg, // the local is passed using LCL_FLD as another type. + BlockOpRet, // the struct is returned and it promoted or there is a cast. + ReturnSpCheck, // the local is used to do SP check on return from function + CallSpCheck, // the local is used to do SP check on every call + SimdUserForcesDep, // a promoted struct was used by a SIMD/HWI node; it must be dependently promoted + HiddenBufferStructArg, // the argument is a hidden return buffer passed to a method. + NonStandardParameter, // local is a parameter that is passed in a register unhandled by genFnPrologCalleeRegArgs }; enum class AddressExposedReason @@ -489,7 +490,6 @@ class LclVarDsc // The constructor. Most things can just be zero'ed. // // Initialize the ArgRegs to REG_STK. - // Morph will update if this local is passed in a register. LclVarDsc() : _lvArgReg(REG_STK) #if FEATURE_MULTIREG_ARGS @@ -3860,6 +3860,10 @@ class Compiler // where it is used to detect tail-call chains. unsigned lvaRetAddrVar; +#ifdef SWIFT_SUPPORT + unsigned lvaSwiftSelfArg; +#endif + #if defined(DEBUG) && defined(TARGET_XARCH) unsigned lvaReturnSpCheck; // Stores SP to confirm it is not corrupted on return. @@ -3982,6 +3986,8 @@ class Compiler CORINFO_ARG_LIST_HANDLE varList, CORINFO_SIG_INFO* varSig); + bool lvaInitSpecialSwiftParam(InitVarDscInfo* varDscInfo, CorInfoType type, CORINFO_CLASS_HANDLE typeHnd); + var_types lvaGetActualType(unsigned lclNum); var_types lvaGetRealType(unsigned lclNum); @@ -7984,6 +7990,7 @@ class Compiler public: regNumber raUpdateRegStateForArg(RegState* regState, LclVarDsc* argDsc); + void raCheckValidIntParamReg(LclVarDsc* dsc, regNumber inArgReg); void raMarkStkVars(); @@ -10636,6 +10643,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX unsigned m_returnSpCheck; unsigned m_callSpCheck; unsigned m_simdUserForcesDep; + unsigned m_nonStandardParameter; unsigned m_liveInOutHndlr; unsigned m_depField; unsigned m_noRegVars; diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index f2e47ae2ddac44..a26510e05abbe3 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -69,6 +69,10 @@ void Compiler::lvaInit() lvaMonAcquired = BAD_VAR_NUM; lvaRetAddrVar = BAD_VAR_NUM; +#ifdef SWIFT_SUPPORT + lvaSwiftSelfArg = BAD_VAR_NUM; +#endif + lvaInlineeReturnSpillTemp = BAD_VAR_NUM; gsShadowVarInfo = nullptr; @@ -622,6 +626,17 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo, unsigned skipArgs, un lvaSetClass(varDscInfo->varNum, clsHnd); } + // The final home for this incoming parameter might be our local stack frame. + varDsc->lvOnFrame = true; + +#ifdef SWIFT_SUPPORT + if ((info.compCallConv == CorInfoCallConvExtension::Swift) && + lvaInitSpecialSwiftParam(varDscInfo, strip(corInfoType), typeHnd)) + { + continue; + } +#endif + // For ARM, ARM64, LOONGARCH64, RISCV64 and AMD64 varargs, all arguments go in integer registers var_types argType = mangleVarArgsType(varDsc->TypeGet()); @@ -821,10 +836,6 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo, unsigned skipArgs, un } #endif // UNIX_AMD64_ABI - // The final home for this incoming register might be our local stack frame. - // For System V platforms the final home will always be on the local stack frame. - varDsc->lvOnFrame = true; - bool canPassArgInRegisters = false; #if defined(UNIX_AMD64_ABI) @@ -1301,6 +1312,48 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo, unsigned skipArgs, un #endif // TARGET_ARM } +#ifdef SWIFT_SUPPORT +//----------------------------------------------------------------------------- +// lvaInitSpecialSwiftParam: +// If the parameter is a special Swift parameter then initialize it and return true. +// +// Parameters: +// varDsc - LclVarDsc* for the parameter +// type - Type of the parameter +// typeHnd - Class handle for the type of the parameter +// +// Remarks: +// Handles SwiftSelf. +// +bool Compiler::lvaInitSpecialSwiftParam(InitVarDscInfo* varDscInfo, CorInfoType type, CORINFO_CLASS_HANDLE typeHnd) +{ + if (type != CORINFO_TYPE_VALUECLASS) + { + return false; + } + + if (!info.compCompHnd->isIntrinsicType(typeHnd)) + { + return false; + } + + const char* namespaceName; + const char* className = info.compCompHnd->getClassNameFromMetadata(typeHnd, &namespaceName); + if ((strcmp(className, "SwiftSelf") == 0) && (strcmp(namespaceName, "System.Runtime.InteropServices.Swift") == 0)) + { + LclVarDsc* varDsc = varDscInfo->varDsc; + varDsc->SetArgReg(REG_SWIFT_SELF); + varDsc->SetOtherArgReg(REG_NA); + varDsc->lvIsRegArg = true; + lvaSwiftSelfArg = varDscInfo->varNum; + lvaSetVarDoNotEnregister(lvaSwiftSelfArg DEBUGARG(DoNotEnregisterReason::NonStandardParameter)); + return true; + } + + return false; +} +#endif + /*****************************************************************************/ void Compiler::lvaInitGenericsCtxt(InitVarDscInfo* varDscInfo) { @@ -2752,6 +2805,10 @@ void Compiler::lvaSetVarDoNotEnregister(unsigned varNum DEBUGARG(DoNotEnregister JITDUMP("Promoted struct used by a SIMD/HWI node\n"); break; + case DoNotEnregisterReason::NonStandardParameter: + JITDUMP("Non-standard parameter\n"); + break; + default: unreached(); break; diff --git a/src/coreclr/jit/lsrabuild.cpp b/src/coreclr/jit/lsrabuild.cpp index 8fd31c072ffed3..0d4c8b9a26612c 100644 --- a/src/coreclr/jit/lsrabuild.cpp +++ b/src/coreclr/jit/lsrabuild.cpp @@ -2126,14 +2126,14 @@ void LinearScan::UpdateRegStateForStructArg(LclVarDsc* argDsc) if ((argDsc->GetArgReg() != REG_STK) && (argDsc->GetArgReg() != REG_NA)) { - if (genRegMask(argDsc->GetArgReg()) & (RBM_ALLFLOAT)) + if ((genRegMask(argDsc->GetArgReg()) & RBM_ALLFLOAT) != RBM_NONE) { - assert(genRegMask(argDsc->GetArgReg()) & (RBM_FLTARG_REGS)); + assert((genRegMask(argDsc->GetArgReg()) & RBM_FLTARG_REGS) != RBM_NONE); floatRegState->rsCalleeRegArgMaskLiveIn |= genRegMask(argDsc->GetArgReg()); } else { - assert(genRegMask(argDsc->GetArgReg()) & (RBM_ARG_REGS)); + compiler->raCheckValidIntParamReg(argDsc, argDsc->GetArgReg()); intRegState->rsCalleeRegArgMaskLiveIn |= genRegMask(argDsc->GetArgReg()); } } @@ -2147,7 +2147,7 @@ void LinearScan::UpdateRegStateForStructArg(LclVarDsc* argDsc) } else { - assert(genRegMask(argDsc->GetOtherArgReg()) & (RBM_ARG_REGS)); + compiler->raCheckValidIntParamReg(argDsc, argDsc->GetOtherArgReg()); intRegState->rsCalleeRegArgMaskLiveIn |= genRegMask(argDsc->GetOtherArgReg()); } } diff --git a/src/coreclr/jit/regalloc.cpp b/src/coreclr/jit/regalloc.cpp index 211452f0076b35..5c44f2dbd95a4f 100644 --- a/src/coreclr/jit/regalloc.cpp +++ b/src/coreclr/jit/regalloc.cpp @@ -104,23 +104,11 @@ regNumber Compiler::raUpdateRegStateForArg(RegState* regState, LclVarDsc* argDsc if (regState->rsIsFloat) { - noway_assert(inArgMask & RBM_FLTARG_REGS); + assert(inArgMask & RBM_FLTARG_REGS); } - else // regState is for the integer registers + else { - // This might be the fixed return buffer register argument (on ARM64) - // We check and allow inArgReg to be theFixedRetBuffReg - if (hasFixedRetBuffReg() && (inArgReg == theFixedRetBuffReg())) - { - // We should have a TYP_BYREF or TYP_I_IMPL arg and not a TYP_STRUCT arg - noway_assert(argDsc->lvType == TYP_BYREF || argDsc->lvType == TYP_I_IMPL); - // We should have recorded the variable number for the return buffer arg - noway_assert(info.compRetBuffArg != BAD_VAR_NUM); - } - else // we have a regular arg - { - noway_assert(inArgMask & RBM_ARG_REGS); - } + raCheckValidIntParamReg(argDsc, inArgReg); } regState->rsCalleeRegArgMaskLiveIn |= inArgMask; @@ -181,6 +169,42 @@ regNumber Compiler::raUpdateRegStateForArg(RegState* regState, LclVarDsc* argDsc return inArgReg; } +//------------------------------------------------------------------------ +// raCheckValidIntParamReg: +// Check that an integer parameter's register information matches what we +// expect. +// +// Parameters: +// argDsc - LclVarDsc* for the parameter +// inArgReg - Register used by the parameter +// +void Compiler::raCheckValidIntParamReg(LclVarDsc* argDsc, regNumber inArgReg) +{ +#ifdef DEBUG + // This might be the fixed return buffer register argument (on ARM64) + // We check and allow inArgReg to be theFixedRetBuffReg + if (hasFixedRetBuffReg() && (inArgReg == theFixedRetBuffReg())) + { + // We should have a TYP_BYREF or TYP_I_IMPL arg and not a TYP_STRUCT arg + assert(argDsc->lvType == TYP_BYREF || argDsc->lvType == TYP_I_IMPL); + // We should have recorded the variable number for the return buffer arg + assert(info.compRetBuffArg != BAD_VAR_NUM); + } +#ifdef SWIFT_SUPPORT + else if ((info.compCallConv == CorInfoCallConvExtension::Swift) && (inArgReg == REG_SWIFT_SELF)) + { + assert((lvaSwiftSelfArg != BAD_VAR_NUM) && + ((argDsc == lvaGetDesc(lvaSwiftSelfArg)) || + (argDsc->lvIsStructField && argDsc->lvParentLcl == lvaSwiftSelfArg))); + } +#endif + else // we have a regular arg + { + assert((genRegMask(inArgReg) & RBM_ARG_REGS) != RBM_NONE); + } +#endif +} + //------------------------------------------------------------------------ // rpMustCreateEBPFrame: // Returns true when we must create an EBP frame diff --git a/src/coreclr/jit/scopeinfo.cpp b/src/coreclr/jit/scopeinfo.cpp index 01238efcfcbd0c..4b736859d69bea 100644 --- a/src/coreclr/jit/scopeinfo.cpp +++ b/src/coreclr/jit/scopeinfo.cpp @@ -1721,8 +1721,6 @@ void CodeGen::psiBegProlog() regNumber otherRegNum = REG_NA; for (unsigned nCnt = 0; nCnt < structDesc.eightByteCount; nCnt++) { - var_types regType = TYP_UNDEF; - if (nCnt == 0) { regNum = lclVarDsc->GetArgReg(); @@ -1735,12 +1733,6 @@ void CodeGen::psiBegProlog() { assert(false && "Invalid eightbyte number."); } - - regType = compiler->GetEightByteType(structDesc, nCnt); -#ifdef DEBUG - regType = compiler->mangleVarArgsType(regType); - assert(genMapRegNumToRegArgNum((nCnt == 0 ? regNum : otherRegNum), regType) != (unsigned)-1); -#endif // DEBUG } varLocation.storeVariableInRegisters(regNum, otherRegNum); @@ -1789,7 +1781,6 @@ void CodeGen::psiBegProlog() regType = lclVarDsc->GetHfaType(); } #endif // defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64) - assert(genMapRegNumToRegArgNum(lclVarDsc->GetArgReg(), regType) != (unsigned)-1); #endif // DEBUG varLocation.storeVariableInRegisters(lclVarDsc->GetArgReg(), REG_NA); } diff --git a/src/coreclr/jit/targetamd64.h b/src/coreclr/jit/targetamd64.h index 4a7033732e7a13..8a349f5ab1aac6 100644 --- a/src/coreclr/jit/targetamd64.h +++ b/src/coreclr/jit/targetamd64.h @@ -568,6 +568,7 @@ #define REG_SWIFT_ERROR REG_R12 #define RBM_SWIFT_ERROR RBM_R12 #define REG_SWIFT_SELF REG_R13 + #define RBM_SWIFT_SELF RBM_R13 #define REG_SWIFT_INTRET_ORDER REG_RAX,REG_RDX,REG_RCX,REG_R8 #define REG_SWIFT_FLOATRET_ORDER REG_XMM0,REG_XMM1,REG_XMM2,REG_XMM3 diff --git a/src/coreclr/jit/targetarm64.h b/src/coreclr/jit/targetarm64.h index 4a99ca2a79f989..427b76cfb9ea3d 100644 --- a/src/coreclr/jit/targetarm64.h +++ b/src/coreclr/jit/targetarm64.h @@ -382,6 +382,7 @@ #define REG_SWIFT_ERROR REG_R21 #define RBM_SWIFT_ERROR RBM_R21 #define REG_SWIFT_SELF REG_R20 + #define RBM_SWIFT_SELF RBM_R20 #define REG_SWIFT_INTRET_ORDER REG_R0,REG_R1,REG_R2,REG_R3 #define REG_SWIFT_FLOATRET_ORDER REG_V0,REG_V1,REG_V2,REG_V3 diff --git a/src/tests/Interop/CMakeLists.txt b/src/tests/Interop/CMakeLists.txt index 248f1cad12eb60..070b4e562eb433 100644 --- a/src/tests/Interop/CMakeLists.txt +++ b/src/tests/Interop/CMakeLists.txt @@ -107,4 +107,5 @@ if(CLR_CMAKE_TARGET_APPLE) add_subdirectory(Swift/SwiftInvalidCallConv) add_subdirectory(Swift/SwiftAbiStress) add_subdirectory(Swift/SwiftRetAbiStress) + add_subdirectory(Swift/SwiftCallbackAbiStress) endif() diff --git a/src/tests/Interop/Swift/SwiftAbiStress/SwiftAbiStress.cs b/src/tests/Interop/Swift/SwiftAbiStress/SwiftAbiStress.cs index 7e23c8d290d75e..9fab793b6e2c97 100644 --- a/src/tests/Interop/Swift/SwiftAbiStress/SwiftAbiStress.cs +++ b/src/tests/Interop/Swift/SwiftAbiStress/SwiftAbiStress.cs @@ -1,3 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/src/tests/Interop/Swift/SwiftAbiStress/SwiftAbiStress.swift b/src/tests/Interop/Swift/SwiftAbiStress/SwiftAbiStress.swift index 91e4fd03683afa..081cee59937072 100644 --- a/src/tests/Interop/Swift/SwiftAbiStress/SwiftAbiStress.swift +++ b/src/tests/Interop/Swift/SwiftAbiStress/SwiftAbiStress.swift @@ -1,3 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + import Foundation struct HasherFNV1a { diff --git a/src/tests/Interop/Swift/SwiftCallbackAbiStress/CMakeLists.txt b/src/tests/Interop/Swift/SwiftCallbackAbiStress/CMakeLists.txt new file mode 100644 index 00000000000000..283ea0eb65430d --- /dev/null +++ b/src/tests/Interop/Swift/SwiftCallbackAbiStress/CMakeLists.txt @@ -0,0 +1,21 @@ +project(SwiftCallbackAbiStress) +include ("${CLR_INTEROP_TEST_ROOT}/Interop.cmake") + +set(SOURCE SwiftCallbackAbiStress) + +if (NOT SWIFT_COMPILER_TARGET AND CLR_CMAKE_TARGET_OSX) + set(SWIFT_PLATFORM "macosx") + set(SWIFT_PLATFORM_SUFFIX "") + set(SWIFT_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET}) + set(SWIFT_COMPILER_TARGET "${CMAKE_OSX_ARCHITECTURES}-apple-${SWIFT_PLATFORM}${SWIFT_DEPLOYMENT_TARGET}${SWIFT_PLATFORM_SUFFIX}") +endif() + +add_custom_target(${SOURCE} ALL + COMMAND xcrun swiftc -target ${SWIFT_COMPILER_TARGET} -emit-library ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE}.swift -o ${CMAKE_CURRENT_BINARY_DIR}/lib${SOURCE}.dylib + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE}.swift + COMMENT "Generating ${SOURCE} library" +) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${SOURCE}.dylib + DESTINATION bin +) diff --git a/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.cs b/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.cs new file mode 100644 index 00000000000000..8dc301f171006a --- /dev/null +++ b/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.cs @@ -0,0 +1,485 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#pragma warning disable CS8500 + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.ExceptionServices; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.Swift; +using Xunit; + +public unsafe class SwiftCallbackAbiStress +{ + private const string SwiftLib = "libSwiftCallbackAbiStress.dylib"; + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func01fs5UInt8VAEs5Int16V_s5Int32Vs6UInt64Vs6UInt16Vs5Int64VSds6UInt32VAMSiAKtXE_tF")] + private static extern byte SwiftCallbackFunc0(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static byte SwiftCallbackFunc0Callback(short a0, int a1, ulong a2, ushort a3, long a4, double a5, uint a6, ushort a7, nint a8, ulong a9, SwiftSelf self) + { + try + { + Assert.Equal((short)-17813, a0); + Assert.Equal((int)318006528, a1); + Assert.Equal((ulong)1195162122024233590, a2); + Assert.Equal((ushort)60467, a3); + Assert.Equal((long)4587464142261794085, a4); + Assert.Equal((double)2686980744237725, a5); + Assert.Equal((uint)331986645, a6); + Assert.Equal((ushort)56299, a7); + Assert.Equal((nint)unchecked((nint)6785053689615432643), a8); + Assert.Equal((ulong)6358078381523084952, a9); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 254; + } + + [Fact] + public static void TestSwiftCallbackFunc0() + { + Console.Write("Running SwiftCallbackFunc0: "); + ExceptionDispatchInfo ex = null; + byte val = SwiftCallbackFunc0(&SwiftCallbackFunc0Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((byte)254, val); + Console.WriteLine("OK"); + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func11fS2ds4Int8V_s5Int16VSfs5Int64VtXE_tF")] + private static extern double SwiftCallbackFunc1(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static double SwiftCallbackFunc1Callback(sbyte a0, short a1, float a2, long a3, SwiftSelf self) + { + try + { + Assert.Equal((sbyte)-117, a0); + Assert.Equal((short)24667, a1); + Assert.Equal((float)7203656, a2); + Assert.Equal((long)2859275717293113701, a3); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 1815003852073252; + } + + [Fact] + public static void TestSwiftCallbackFunc1() + { + Console.Write("Running SwiftCallbackFunc1: "); + ExceptionDispatchInfo ex = null; + double val = SwiftCallbackFunc1(&SwiftCallbackFunc1Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((double)1815003852073252, val); + Console.WriteLine("OK"); + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func21fs5UInt8VAEs4Int8V_s6UInt32VSfSuAegIs6UInt64Vs5Int64Vs5Int16Vs5Int32VAOSiSutXE_tF")] + private static extern byte SwiftCallbackFunc2(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static byte SwiftCallbackFunc2Callback(sbyte a0, uint a1, float a2, nuint a3, byte a4, sbyte a5, uint a6, ulong a7, long a8, short a9, int a10, short a11, nint a12, nuint a13, SwiftSelf self) + { + try + { + Assert.Equal((sbyte)93, a0); + Assert.Equal((uint)571731946, a1); + Assert.Equal((float)1958727, a2); + Assert.Equal((nuint)unchecked((nuint)3919017851053326963), a3); + Assert.Equal((byte)156, a4); + Assert.Equal((sbyte)-17, a5); + Assert.Equal((uint)747962023, a6); + Assert.Equal((ulong)1104840539654964163, a7); + Assert.Equal((long)5642679323997486487, a8); + Assert.Equal((short)29557, a9); + Assert.Equal((int)660273506, a10); + Assert.Equal((short)-14877, a11); + Assert.Equal((nint)unchecked((nint)3546952189496193868), a12); + Assert.Equal((nuint)unchecked((nuint)3599444831393612282), a13); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 141; + } + + [Fact] + public static void TestSwiftCallbackFunc2() + { + Console.Write("Running SwiftCallbackFunc2: "); + ExceptionDispatchInfo ex = null; + byte val = SwiftCallbackFunc2(&SwiftCallbackFunc2Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((byte)141, val); + Console.WriteLine("OK"); + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func31fS2dSi_s5UInt8Vs4Int8Vs5Int64VAGs6UInt16VS2uSiSfAKs6UInt32VSiAEs5Int16Vs5Int32VAKSuAgESdSiAmGtXE_tF")] + private static extern double SwiftCallbackFunc3(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static double SwiftCallbackFunc3Callback(nint a0, byte a1, sbyte a2, long a3, sbyte a4, ushort a5, nuint a6, nuint a7, nint a8, float a9, ushort a10, uint a11, nint a12, byte a13, short a14, int a15, ushort a16, nuint a17, sbyte a18, byte a19, double a20, nint a21, uint a22, sbyte a23, SwiftSelf self) + { + try + { + Assert.Equal((nint)unchecked((nint)5610153900386943274), a0); + Assert.Equal((byte)236, a1); + Assert.Equal((sbyte)-6, a2); + Assert.Equal((long)3316874161259890183, a3); + Assert.Equal((sbyte)-53, a4); + Assert.Equal((ushort)37580, a5); + Assert.Equal((nuint)unchecked((nuint)1683057726956349710), a6); + Assert.Equal((nuint)unchecked((nuint)415152378126297632), a7); + Assert.Equal((nint)unchecked((nint)2870393941738319551), a8); + Assert.Equal((float)1652893, a9); + Assert.Equal((ushort)16825, a10); + Assert.Equal((uint)419224712, a11); + Assert.Equal((nint)unchecked((nint)7680849977572141563), a12); + Assert.Equal((byte)200, a13); + Assert.Equal((short)22892, a14); + Assert.Equal((int)2118994921, a15); + Assert.Equal((ushort)44276, a16); + Assert.Equal((nuint)unchecked((nuint)4006990310546323213), a17); + Assert.Equal((sbyte)-39, a18); + Assert.Equal((byte)67, a19); + Assert.Equal((double)3008014901411425, a20); + Assert.Equal((nint)unchecked((nint)7039812168807528075), a21); + Assert.Equal((uint)1057070707, a22); + Assert.Equal((sbyte)103, a23); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 171601370856717; + } + + [Fact] + public static void TestSwiftCallbackFunc3() + { + Console.Write("Running SwiftCallbackFunc3: "); + ExceptionDispatchInfo ex = null; + double val = SwiftCallbackFunc3(&SwiftCallbackFunc3Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((double)171601370856717, val); + Console.WriteLine("OK"); + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func41fs5Int64VAEs6UInt16V_Sfs5Int32VAGs4Int8VSfs6UInt64Vs5Int16VSdA2kISiAi2eiMs6UInt32VAMs5UInt8VAISuAKtXE_tF")] + private static extern long SwiftCallbackFunc4(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static long SwiftCallbackFunc4Callback(ushort a0, float a1, int a2, ushort a3, sbyte a4, float a5, ulong a6, short a7, double a8, sbyte a9, sbyte a10, int a11, nint a12, int a13, long a14, long a15, int a16, ulong a17, uint a18, ulong a19, byte a20, int a21, nuint a22, sbyte a23, SwiftSelf self) + { + try + { + Assert.Equal((ushort)64787, a0); + Assert.Equal((float)1472942, a1); + Assert.Equal((int)2042281537, a2); + Assert.Equal((ushort)18667, a3); + Assert.Equal((sbyte)-102, a4); + Assert.Equal((float)1768897, a5); + Assert.Equal((ulong)8888237425788084647, a6); + Assert.Equal((short)20853, a7); + Assert.Equal((double)3454973030441503, a8); + Assert.Equal((sbyte)-46, a9); + Assert.Equal((sbyte)-63, a10); + Assert.Equal((int)366699691, a11); + Assert.Equal((nint)unchecked((nint)4641984012938514811), a12); + Assert.Equal((int)1691113876, a13); + Assert.Equal((long)6912906265890433291, a14); + Assert.Equal((long)6701017449244003958, a15); + Assert.Equal((int)568887433, a16); + Assert.Equal((ulong)9099941242643212987, a17); + Assert.Equal((uint)1380054056, a18); + Assert.Equal((ulong)595836183051442276, a19); + Assert.Equal((byte)174, a20); + Assert.Equal((int)1047364523, a21); + Assert.Equal((nuint)unchecked((nuint)1417646176372805029), a22); + Assert.Equal((sbyte)-35, a23); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 3100893724073759448; + } + + [Fact] + public static void TestSwiftCallbackFunc4() + { + Console.Write("Running SwiftCallbackFunc4: "); + ExceptionDispatchInfo ex = null; + long val = SwiftCallbackFunc4(&SwiftCallbackFunc4Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((long)3100893724073759448, val); + Console.WriteLine("OK"); + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func51fS2is4Int8V_s5UInt8VSis6UInt64VAIs5Int64Vs5Int16VAmKs6UInt16VAgOSfAIs5Int32VtXE_tF")] + private static extern nint SwiftCallbackFunc5(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static nint SwiftCallbackFunc5Callback(sbyte a0, byte a1, nint a2, ulong a3, ulong a4, long a5, short a6, short a7, long a8, ushort a9, byte a10, ushort a11, float a12, ulong a13, int a14, SwiftSelf self) + { + try + { + Assert.Equal((sbyte)-86, a0); + Assert.Equal((byte)201, a1); + Assert.Equal((nint)unchecked((nint)3436765034579128495), a2); + Assert.Equal((ulong)6305137336506323506, a3); + Assert.Equal((ulong)6280137078630028944, a4); + Assert.Equal((long)6252650621827449809, a5); + Assert.Equal((short)306, a6); + Assert.Equal((short)-27739, a7); + Assert.Equal((long)8386588676727568762, a8); + Assert.Equal((ushort)24144, a9); + Assert.Equal((byte)230, a10); + Assert.Equal((ushort)59907, a11); + Assert.Equal((float)1791462, a12); + Assert.Equal((ulong)8271399067416599310, a13); + Assert.Equal((int)1699875267, a14); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return unchecked((nint)5224035852455624489); + } + + [Fact] + public static void TestSwiftCallbackFunc5() + { + Console.Write("Running SwiftCallbackFunc5: "); + ExceptionDispatchInfo ex = null; + nint val = SwiftCallbackFunc5(&SwiftCallbackFunc5Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nint)unchecked((nint)5224035852455624489), val); + Console.WriteLine("OK"); + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func61fs5Int64VAEs6UInt32V_Sfs5UInt8Vs5Int32VAGs6UInt64VAKs4Int8VS2is5Int16VSiAg2meGs6UInt16VtXE_tF")] + private static extern long SwiftCallbackFunc6(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static long SwiftCallbackFunc6Callback(uint a0, float a1, byte a2, int a3, uint a4, ulong a5, int a6, sbyte a7, nint a8, nint a9, short a10, nint a11, uint a12, ulong a13, ulong a14, long a15, uint a16, ushort a17, SwiftSelf self) + { + try + { + Assert.Equal((uint)743741783, a0); + Assert.Equal((float)3321238, a1); + Assert.Equal((byte)51, a2); + Assert.Equal((int)1315779092, a3); + Assert.Equal((uint)1375736443, a4); + Assert.Equal((ulong)7022244764256789748, a5); + Assert.Equal((int)156967479, a6); + Assert.Equal((sbyte)-120, a7); + Assert.Equal((nint)unchecked((nint)3560129042279209151), a8); + Assert.Equal((nint)unchecked((nint)9064213378356024089), a9); + Assert.Equal((short)7947, a10); + Assert.Equal((nint)unchecked((nint)8756231901741598476), a11); + Assert.Equal((uint)56423704, a12); + Assert.Equal((ulong)6962175160124965670, a13); + Assert.Equal((ulong)2935089705514798822, a14); + Assert.Equal((long)1348139258363155351, a15); + Assert.Equal((uint)1754662893, a16); + Assert.Equal((ushort)35528, a17); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 2428870998079250366; + } + + [Fact] + public static void TestSwiftCallbackFunc6() + { + Console.Write("Running SwiftCallbackFunc6: "); + ExceptionDispatchInfo ex = null; + long val = SwiftCallbackFunc6(&SwiftCallbackFunc6Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((long)2428870998079250366, val); + Console.WriteLine("OK"); + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func71fS2is5UInt8V_s5Int16VSus6UInt32Vs4Int8VAkESfSiAiESfs5Int64VSdAKSiAgMS2dtXE_tF")] + private static extern nint SwiftCallbackFunc7(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static nint SwiftCallbackFunc7Callback(byte a0, short a1, nuint a2, uint a3, sbyte a4, sbyte a5, byte a6, float a7, nint a8, uint a9, byte a10, float a11, long a12, double a13, sbyte a14, nint a15, short a16, long a17, double a18, double a19, SwiftSelf self) + { + try + { + Assert.Equal((byte)134, a0); + Assert.Equal((short)-32369, a1); + Assert.Equal((nuint)unchecked((nuint)8380717554783122608), a2); + Assert.Equal((uint)1860099027, a3); + Assert.Equal((sbyte)-6, a4); + Assert.Equal((sbyte)86, a5); + Assert.Equal((byte)32, a6); + Assert.Equal((float)1160734, a7); + Assert.Equal((nint)unchecked((nint)6413974004534568863), a8); + Assert.Equal((uint)835905835, a9); + Assert.Equal((byte)1, a10); + Assert.Equal((float)7455267, a11); + Assert.Equal((long)6652417171359975799, a12); + Assert.Equal((double)3767979765576223, a13); + Assert.Equal((sbyte)-92, a14); + Assert.Equal((nint)unchecked((nint)2188807859088864320), a15); + Assert.Equal((short)22602, a16); + Assert.Equal((long)6695605905030342661, a17); + Assert.Equal((double)3516012226643358, a18); + Assert.Equal((double)1125481383704537, a19); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return unchecked((nint)4420963390330795075); + } + + [Fact] + public static void TestSwiftCallbackFunc7() + { + Console.Write("Running SwiftCallbackFunc7: "); + ExceptionDispatchInfo ex = null; + nint val = SwiftCallbackFunc7(&SwiftCallbackFunc7Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nint)unchecked((nint)4420963390330795075), val); + Console.WriteLine("OK"); + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func81fs4Int8VAESd_Sds6UInt64Vs6UInt16VSds6UInt32VAiEs5UInt8Vs5Int16VAGSfAItXE_tF")] + private static extern sbyte SwiftCallbackFunc8(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static sbyte SwiftCallbackFunc8Callback(double a0, double a1, ulong a2, ushort a3, double a4, uint a5, ushort a6, sbyte a7, byte a8, short a9, ulong a10, float a11, ushort a12, SwiftSelf self) + { + try + { + Assert.Equal((double)378554201505534, a0); + Assert.Equal((double)1650526878176435, a1); + Assert.Equal((ulong)7125767448027274022, a2); + Assert.Equal((ushort)19812, a3); + Assert.Equal((double)1173178493312463, a4); + Assert.Equal((uint)416842395, a5); + Assert.Equal((ushort)46360, a6); + Assert.Equal((sbyte)-60, a7); + Assert.Equal((byte)107, a8); + Assert.Equal((short)-2849, a9); + Assert.Equal((ulong)3245727696885859461, a10); + Assert.Equal((float)3340085, a11); + Assert.Equal((ushort)24776, a12); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 30; + } + + [Fact] + public static void TestSwiftCallbackFunc8() + { + Console.Write("Running SwiftCallbackFunc8: "); + ExceptionDispatchInfo ex = null; + sbyte val = SwiftCallbackFunc8(&SwiftCallbackFunc8Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((sbyte)30, val); + Console.WriteLine("OK"); + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func91fS2ds5Int16V_SiAEs5UInt8Vs6UInt32Vs5Int64Vs6UInt64Vs6UInt16VAOs4Int8VAkgqKSfAQtXE_tF")] + private static extern double SwiftCallbackFunc9(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static double SwiftCallbackFunc9Callback(short a0, nint a1, short a2, byte a3, uint a4, long a5, ulong a6, ushort a7, ushort a8, sbyte a9, long a10, byte a11, sbyte a12, long a13, float a14, sbyte a15, SwiftSelf self) + { + try + { + Assert.Equal((short)4555, a0); + Assert.Equal((nint)unchecked((nint)4720638462358523954), a1); + Assert.Equal((short)30631, a2); + Assert.Equal((byte)123, a3); + Assert.Equal((uint)2112687301, a4); + Assert.Equal((long)1804058604961822948, a5); + Assert.Equal((ulong)8772179036715198777, a6); + Assert.Equal((ushort)54948, a7); + Assert.Equal((ushort)29928, a8); + Assert.Equal((sbyte)-36, a9); + Assert.Equal((long)7573525757641791389, a10); + Assert.Equal((byte)239, a11); + Assert.Equal((sbyte)-71, a12); + Assert.Equal((long)7143939705627605769, a13); + Assert.Equal((float)2647713, a14); + Assert.Equal((sbyte)-7, a15); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 3088996708692961; + } + + [Fact] + public static void TestSwiftCallbackFunc9() + { + Console.Write("Running SwiftCallbackFunc9: "); + ExceptionDispatchInfo ex = null; + double val = SwiftCallbackFunc9(&SwiftCallbackFunc9Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((double)3088996708692961, val); + Console.WriteLine("OK"); + } + +} diff --git a/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.csproj b/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.csproj new file mode 100644 index 00000000000000..a57cd84cf8842c --- /dev/null +++ b/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.csproj @@ -0,0 +1,16 @@ + + + + true + true + + true + + + + + + + + + diff --git a/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.swift b/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.swift new file mode 100644 index 00000000000000..aeb63ee8c72864 --- /dev/null +++ b/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.swift @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +import Foundation + +public func swiftCallbackFunc0(f: (Int16, Int32, UInt64, UInt16, Int64, Double, UInt32, UInt16, Int, UInt64) -> UInt8) -> UInt8 { + return f(-17813, 318006528, 1195162122024233590, 60467, 4587464142261794085, 2686980744237725, 331986645, 56299, 6785053689615432643, 6358078381523084952) +} + +public func swiftCallbackFunc1(f: (Int8, Int16, Float, Int64) -> Double) -> Double { + return f(-117, 24667, 7203656, 2859275717293113701) +} + +public func swiftCallbackFunc2(f: (Int8, UInt32, Float, UInt, UInt8, Int8, UInt32, UInt64, Int64, Int16, Int32, Int16, Int, UInt) -> UInt8) -> UInt8 { + return f(93, 571731946, 1958727, 3919017851053326963, 156, -17, 747962023, 1104840539654964163, 5642679323997486487, 29557, 660273506, -14877, 3546952189496193868, 3599444831393612282) +} + +public func swiftCallbackFunc3(f: (Int, UInt8, Int8, Int64, Int8, UInt16, UInt, UInt, Int, Float, UInt16, UInt32, Int, UInt8, Int16, Int32, UInt16, UInt, Int8, UInt8, Double, Int, UInt32, Int8) -> Double) -> Double { + return f(5610153900386943274, 236, -6, 3316874161259890183, -53, 37580, 1683057726956349710, 415152378126297632, 2870393941738319551, 1652893, 16825, 419224712, 7680849977572141563, 200, 22892, 2118994921, 44276, 4006990310546323213, -39, 67, 3008014901411425, 7039812168807528075, 1057070707, 103) +} + +public func swiftCallbackFunc4(f: (UInt16, Float, Int32, UInt16, Int8, Float, UInt64, Int16, Double, Int8, Int8, Int32, Int, Int32, Int64, Int64, Int32, UInt64, UInt32, UInt64, UInt8, Int32, UInt, Int8) -> Int64) -> Int64 { + return f(64787, 1472942, 2042281537, 18667, -102, 1768897, 8888237425788084647, 20853, 3454973030441503, -46, -63, 366699691, 4641984012938514811, 1691113876, 6912906265890433291, 6701017449244003958, 568887433, 9099941242643212987, 1380054056, 595836183051442276, 174, 1047364523, 1417646176372805029, -35) +} + +public func swiftCallbackFunc5(f: (Int8, UInt8, Int, UInt64, UInt64, Int64, Int16, Int16, Int64, UInt16, UInt8, UInt16, Float, UInt64, Int32) -> Int) -> Int { + return f(-86, 201, 3436765034579128495, 6305137336506323506, 6280137078630028944, 6252650621827449809, 306, -27739, 8386588676727568762, 24144, 230, 59907, 1791462, 8271399067416599310, 1699875267) +} + +public func swiftCallbackFunc6(f: (UInt32, Float, UInt8, Int32, UInt32, UInt64, Int32, Int8, Int, Int, Int16, Int, UInt32, UInt64, UInt64, Int64, UInt32, UInt16) -> Int64) -> Int64 { + return f(743741783, 3321238, 51, 1315779092, 1375736443, 7022244764256789748, 156967479, -120, 3560129042279209151, 9064213378356024089, 7947, 8756231901741598476, 56423704, 6962175160124965670, 2935089705514798822, 1348139258363155351, 1754662893, 35528) +} + +public func swiftCallbackFunc7(f: (UInt8, Int16, UInt, UInt32, Int8, Int8, UInt8, Float, Int, UInt32, UInt8, Float, Int64, Double, Int8, Int, Int16, Int64, Double, Double) -> Int) -> Int { + return f(134, -32369, 8380717554783122608, 1860099027, -6, 86, 32, 1160734, 6413974004534568863, 835905835, 1, 7455267, 6652417171359975799, 3767979765576223, -92, 2188807859088864320, 22602, 6695605905030342661, 3516012226643358, 1125481383704537) +} + +public func swiftCallbackFunc8(f: (Double, Double, UInt64, UInt16, Double, UInt32, UInt16, Int8, UInt8, Int16, UInt64, Float, UInt16) -> Int8) -> Int8 { + return f(378554201505534, 1650526878176435, 7125767448027274022, 19812, 1173178493312463, 416842395, 46360, -60, 107, -2849, 3245727696885859461, 3340085, 24776) +} + +public func swiftCallbackFunc9(f: (Int16, Int, Int16, UInt8, UInt32, Int64, UInt64, UInt16, UInt16, Int8, Int64, UInt8, Int8, Int64, Float, Int8) -> Double) -> Double { + return f(4555, 4720638462358523954, 30631, 123, 2112687301, 1804058604961822948, 8772179036715198777, 54948, 29928, -36, 7573525757641791389, 239, -71, 7143939705627605769, 2647713, -7) +} + diff --git a/src/tests/Interop/Swift/SwiftRetAbiStress/SwiftRetAbiStress.cs b/src/tests/Interop/Swift/SwiftRetAbiStress/SwiftRetAbiStress.cs index bbe4b8858d39cb..f3bdd60660b7eb 100644 --- a/src/tests/Interop/Swift/SwiftRetAbiStress/SwiftRetAbiStress.cs +++ b/src/tests/Interop/Swift/SwiftRetAbiStress/SwiftRetAbiStress.cs @@ -1,3 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/src/tests/Interop/Swift/SwiftRetAbiStress/SwiftRetAbiStress.swift b/src/tests/Interop/Swift/SwiftRetAbiStress/SwiftRetAbiStress.swift index 2373b510687567..7667f605bbf6dd 100644 --- a/src/tests/Interop/Swift/SwiftRetAbiStress/SwiftRetAbiStress.swift +++ b/src/tests/Interop/Swift/SwiftRetAbiStress/SwiftRetAbiStress.swift @@ -1,3 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + import Foundation @frozen diff --git a/src/tests/issues.targets b/src/tests/issues.targets index 01b2f9aab129d4..958ef8573bdac8 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -1879,6 +1879,9 @@ https://github.com/dotnet/runtime/issues/93631: Swift frozen struct support is not implemented on Mono yet + + https://github.com/dotnet/runtime/issues/93631: Swift reverse pinvokes are not implemented on Mono yet +