Lowering: Atomic ops can produce a value (dotnet/coreclr#19173)
authorCarol Eidt <carol.eidt@microsoft.com>
Fri, 27 Jul 2018 23:19:48 +0000 (16:19 -0700)
committerGitHub <noreply@github.com>
Fri, 27 Jul 2018 23:19:48 +0000 (16:19 -0700)
* Lowering: Atomic ops can produce a value

dotnet/coreclr#18887 changed OperIsStore to include the atomic functions, but `Lowering::LowerArg()` and `Lowering::CheckCallArg()` assume that stores do not produce a value, so it doesn't correctly set the argument register (or build a `PUTARG_REG`) for the case where the result of an atomic op is passed to a call.
Fix this and add additional asserts.

Fix dotnet/coreclr#19171

Commit migrated from https://github.com/dotnet/coreclr/commit/8b126cf6d62790a70ea15b6c4a35d8de3ddfd795

src/coreclr/src/jit/lower.cpp
src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_19171/GitHub_19171.cs [new file with mode: 0644]
src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_19171/GitHub_19171.csproj [new file with mode: 0644]

index 1c4cc1a..8b12296 100644 (file)
@@ -1288,8 +1288,11 @@ void Lowering::LowerArg(GenTreeCall* call, GenTree** ppArg)
     // Assignments/stores at this level are not really placing an argument.
     // They are setting up temporary locals that will later be placed into
     // outgoing regs or stack.
-    if (arg->OperIsStore() || arg->IsArgPlaceHolderNode() || arg->IsNothingNode() || arg->OperIsCopyBlkOp())
+    // Note that atomic ops may be stores and still produce a value.
+    if (!arg->IsValue())
     {
+        assert((arg->OperIsStore() && !arg->IsValue()) || arg->IsArgPlaceHolderNode() || arg->IsNothingNode() ||
+               arg->OperIsCopyBlkOp());
         return;
     }
 
@@ -5297,8 +5300,10 @@ void Lowering::DoPhase()
 //
 void Lowering::CheckCallArg(GenTree* arg)
 {
-    if (arg->OperIsStore() || arg->IsArgPlaceHolderNode() || arg->IsNothingNode() || arg->OperIsCopyBlkOp())
+    if (!arg->IsValue() && !arg->OperIsPutArgStk())
     {
+        assert((arg->OperIsStore() && !arg->IsValue()) || arg->IsArgPlaceHolderNode() || arg->IsNothingNode() ||
+               arg->OperIsCopyBlkOp());
         return;
     }
 
diff --git a/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_19171/GitHub_19171.cs b/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_19171/GitHub_19171.cs
new file mode 100644 (file)
index 0000000..71aeb8d
--- /dev/null
@@ -0,0 +1,37 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+
+using System;
+using System.Threading;
+using System.Runtime.CompilerServices;
+public class GitHub_19171
+{
+    public static long g_static = -1;
+    public static int returnVal = 100;
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    static bool checkResult(long result)
+    {
+        return(result == g_static);
+    }
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    public static void Function(long value)
+    {
+        g_static = value;
+
+        if (!checkResult(Interlocked.Read(ref g_static)))
+        {
+            returnVal = -1;
+        }
+    }
+    public static int Main()
+    {
+        Function(7);
+        Function(11);
+        Function(0x123456789abcdefL);
+        return returnVal;
+    }
+}
diff --git a/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_19171/GitHub_19171.csproj b/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_19171/GitHub_19171.csproj
new file mode 100644 (file)
index 0000000..03a6a1e
--- /dev/null
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <AssemblyName>$(MSBuildProjectName)</AssemblyName>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{ADEEA3D1-B67B-456E-8F2B-6DCCACC2D34C}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <CLRTestPriority>1</CLRTestPriority>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "></PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <PropertyGroup>
+    <DebugType>Full</DebugType>
+    <Optimize>True</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="$(MSBuildProjectName).cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
+</Project>