(Re)Enable NativeVarargs for CoreCLR (#18373)
authorJarret Shook <jashoo@microsoft.com>
Mon, 11 Jun 2018 18:28:26 +0000 (11:28 -0700)
committerGitHub <noreply@github.com>
Mon, 11 Jun 2018 18:28:26 +0000 (11:28 -0700)
* Enable NativeVarargs for CoreCLR

This will allow coreclr run programs which have native varargs.
It also re-enables the ArgIterator type for managed to managed native
vararg calls. This will allow the use of the __arglist keyword.

Limitations:

NYI statements have been added for all Unix Targets.

With this change __arglist (native varargs) will be supported, but not
yet tested on:

Amd64 Windows
x86 Windows
Arm32 Windows
Arm64 Windows

This change does not re-enable native vararg tests. This will be done
in a separate change.

src/System.Private.CoreLib/src/System/ArgIterator.cs
src/jit/lclvars.cpp
src/jit/morph.cpp
src/vm/jitinterface.cpp
tests/arm/Tests.lst
tests/arm64/Tests.lst
tests/issues.targets

index 67e549c..7a4131e 100644 (file)
@@ -27,7 +27,7 @@ namespace System
         private IntPtr ArgPtr;                  // Pointer to remaining args.
         private int RemainingArgs;           // # of remaining args.
 
-#if VARARGS_ENABLED //The JIT doesn't support Varargs calling convention.
+#if PLATFORM_WINDOWS // Native Varargs are not supported on Unix
         [MethodImplAttribute(MethodImplOptions.InternalCall)]
         private extern ArgIterator(IntPtr arglist);
 
@@ -132,7 +132,7 @@ namespace System
         {
             throw new NotSupportedException(SR.NotSupported_NYI);
         }
-#else
+#else 
         public ArgIterator(RuntimeArgumentHandle arglist)
         {
             throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator); // https://github.com/dotnet/coreclr/issues/9204
@@ -180,6 +180,6 @@ namespace System
         {
             throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator); // https://github.com/dotnet/coreclr/issues/9204
         }
-#endif //VARARGS_ENABLED
+#endif // PLATFORM_WINDOWS
     }
 }
index 19dadfc..1a18700 100644 (file)
@@ -598,6 +598,18 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo)
                 isHfaArg = varTypeIsFloating(hfaType);
             }
         }
+        else if (info.compIsVarArgs)
+        {
+#ifdef _TARGET_UNIX_
+            // Currently native varargs is not implemented on non windows targets.
+            //
+            // Note that some targets like Arm64 Unix should not need much work as
+            // the ABI is the same. While other targets may only need small changes
+            // such as amd64 Unix, which just expects RAX to pass numFPArguments.
+            NYI("InitUserArgs for Vararg callee is not yet implemented on non Windows targets.");
+#endif
+        }
+
         if (isHfaArg)
         {
             // We have an HFA argument, so from here on out treat the type as a float or double.
index 37bc2f3..c4d6bee 100644 (file)
@@ -2737,10 +2737,19 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)
     unsigned nonRegPassedStructSlots = 0;
     bool     reMorphing              = call->AreArgsComplete();
     bool     callHasRetBuffArg       = call->HasRetBufArg();
+    bool     callIsVararg            = call->IsVarargs();
 
-#ifndef _TARGET_X86_ // i.e. _TARGET_AMD64_ or _TARGET_ARM_
-    bool callIsVararg = call->IsVarargs();
-#endif
+#ifdef _TARGET_UNIX_
+    if (callIsVararg)
+    {
+        // Currently native varargs is not implemented on non windows targets.
+        //
+        // Note that some targets like Arm64 Unix should not need much work as
+        // the ABI is the same. While other targets may only need small changes
+        // such as amd64 Unix, which just expects RAX to pass numFPArguments.
+        NYI("Morphing Vararg call not yet implemented on non Windows targets.");
+    }
+#endif // _TARGET_UNIX_
 
 #ifdef UNIX_AMD64_ABI
     // If fgMakeOutgoingStructArgCopy is called and copies are generated, hasStackArgCopy is set
index ff8a89d..0a921e5 100644 (file)
@@ -489,12 +489,14 @@ CEEInfo::ConvToJitSig(
         IfFailThrow(sig.GetCallingConvInfo(&data));
         sigRet->callConv = (CorInfoCallConv) data;
 
+#ifdef PLATFORM_UNIX
         if ((isCallConv(sigRet->callConv, IMAGE_CEE_CS_CALLCONV_VARARG)) ||
             (isCallConv(sigRet->callConv, IMAGE_CEE_CS_CALLCONV_NATIVEVARARG)))
         {
             // This signature corresponds to a method that uses varargs, which are not supported.
              COMPlusThrow(kInvalidProgramException, IDS_EE_VARARG_NOT_SUPPORTED);
         }
+#endif // PLATFORM_UNIX
 
         // Skip number of type arguments
         if (sigRet->callConv & IMAGE_CEE_CS_CALLCONV_GENERIC)
index 148d63b..9633cf6 100644 (file)
@@ -48428,14 +48428,6 @@ MaxAllowedDurationSeconds=600
 Categories=EXPECTED_PASS;Pri1
 HostStyle=0
 
-[varargsupport_r.cmd_6076]
-RelativePath=baseservices\varargs\varargsupport_r\varargsupport_r.cmd
-WorkingDir=baseservices\varargs\varargsupport_r
-Expected=0
-MaxAllowedDurationSeconds=600
-Categories=EXPECTED_PASS
-HostStyle=0
-
 [_il_relcatchfault_tail.cmd_6077]
 RelativePath=JIT\Methodical\Invoke\SEH\_il_relcatchfault_tail\_il_relcatchfault_tail.cmd
 WorkingDir=JIT\Methodical\Invoke\SEH\_il_relcatchfault_tail
@@ -74412,14 +74404,6 @@ MaxAllowedDurationSeconds=600
 Categories=EXPECTED_PASS
 HostStyle=0
 
-[varargsupport.cmd_9339]
-RelativePath=baseservices\varargs\varargsupport\varargsupport.cmd
-WorkingDir=baseservices\varargs\varargsupport
-Expected=0
-MaxAllowedDurationSeconds=600
-Categories=EXPECTED_PASS
-HostStyle=0
-
 [uint8_d.cmd_9340]
 RelativePath=JIT\Directed\shift\uint8_d\uint8_d.cmd
 WorkingDir=JIT\Directed\shift\uint8_d
index 574fb25..8c8fd8e 100644 (file)
@@ -4612,22 +4612,6 @@ MaxAllowedDurationSeconds=600
 Categories=EXPECTED_PASS;Pri1
 HostStyle=0
 
-[varargsupport.cmd_576]
-RelativePath=baseservices\varargs\varargsupport\varargsupport.cmd
-WorkingDir=baseservices\varargs\varargsupport
-Expected=0
-MaxAllowedDurationSeconds=600
-Categories=EXPECTED_PASS
-HostStyle=0
-
-[varargsupport_r.cmd_577]
-RelativePath=baseservices\varargs\varargsupport_r\varargsupport_r.cmd
-WorkingDir=baseservices\varargs\varargsupport_r
-Expected=0
-MaxAllowedDurationSeconds=600
-Categories=EXPECTED_PASS
-HostStyle=0
-
 [Co9600Ctor.cmd_578]
 RelativePath=CoreMangLib\components\stopwatch\Co9600Ctor\Co9600Ctor.cmd
 WorkingDir=CoreMangLib\components\stopwatch\Co9600Ctor
index aed787d..1772f8c 100644 (file)
         <ExcludeList Include="$(XunitTestBinBase)\JIT\Regression\JitBlue\GitHub_18056\Bool_And_Op_cs_do\Bool_And_Op_cs_do.cmd">
             <Issue>18056</Issue>
         </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\baseservices\varargs\varargsupport\varargsupport.cmd">
+            <Issue>Varargs supported on this platform</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)\baseservices\varargs\varargsupport_r\varargsupport_r.cmd">
+            <Issue>Varargs supported on this platform</Issue>
+        </ExcludeList>
     </ItemGroup>
 
     <!-- The following are x86 failures -->