Skip to content

Commit

Permalink
Don't create mismatched block copies in cpblk import (#71160)
Browse files Browse the repository at this point in the history
* Don't create questionable IR in "cpblk" import

* Add a test
  • Loading branch information
SingleAccretion authored Jul 27, 2022
1 parent f90028c commit 4f54504
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17330,25 +17330,18 @@ void Compiler::impImportBlockCode(BasicBlock* block)
op2 = impPopStack().val; // Src addr
op1 = impPopStack().val; // Dst addr

if (op2->OperGet() == GT_ADDR)
{
op2 = op2->AsOp()->gtOp1;
}
else
{
op2 = gtNewOperNode(GT_IND, TYP_STRUCT, op2);
}

if (op3->IsCnsIntOrI())
{
size = (unsigned)op3->AsIntConCommon()->IconValue();
op1 = new (this, GT_BLK) GenTreeBlk(GT_BLK, TYP_STRUCT, op1, typGetBlkLayout(size));
op1 = gtNewBlkOpNode(op1, op2, (prefixFlags & PREFIX_VOLATILE) != 0, true);
size = static_cast<unsigned>(op3->AsIntConCommon()->IconValue());

op1 = gtNewBlockVal(op1, size);
op2 = gtNewBlockVal(op2, size);
op1 = gtNewBlkOpNode(op1, op2, (prefixFlags & PREFIX_VOLATILE) != 0, /* isCopyBlock */ true);
}
else
{
op1 = new (this, GT_STORE_DYN_BLK) GenTreeStoreDynBlk(op1, op2, op3);
size = 0;
op2 = gtNewOperNode(GT_IND, TYP_STRUCT, op2);
op1 = new (this, GT_STORE_DYN_BLK) GenTreeStoreDynBlk(op1, op2, op3);

if ((prefixFlags & PREFIX_VOLATILE) != 0)
{
Expand Down
22 changes: 22 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_71156/Runtime_71156.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;

public unsafe class Runtime_71156
{
public static int Main()
{
return Problem() ? 101 : 100;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool Problem()
{
float a;
var b = 0xFF000000;
Unsafe.CopyBlock(&a, &b, 4);

return *(uint*)&a != 0xFF000000u;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit 4f54504

Please sign in to comment.