Skip to content

Commit

Permalink
JIT: Fix STORE_DYN_BLK morphing (#73844)
Browse files Browse the repository at this point in the history
Make sure to properly call SetIndirExceptionFlags and to properly mark defs (that will otherwise hit asserts in rationalization).
  • Loading branch information
jakobbotsch authored Aug 12, 2022
1 parent 3824cb2 commit c302b7b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7541,6 +7541,8 @@ GenTree* Compiler::gtNewStructVal(ClassLayout* layout, GenTree* addr)
blkNode = gtNewObjNode(layout, addr);
}

blkNode->SetIndirExceptionFlags(this);

return blkNode;
}

Expand Down
8 changes: 6 additions & 2 deletions src/coreclr/jit/morphblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,14 +1550,18 @@ GenTree* Compiler::fgMorphStoreDynBlock(GenTreeStoreDynBlk* tree)
if (size != 0)
{
GenTree* lhs = gtNewBlockVal(tree->Addr(), static_cast<unsigned>(size));
lhs->SetIndirExceptionFlags(this);

GenTree* asg = gtNewAssignNode(lhs, tree->Data());
asg->gtFlags |= (tree->gtFlags & (GTF_ALL_EFFECT | GTF_BLK_VOLATILE | GTF_BLK_UNALIGNED));
INDEBUG(asg->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED);

JITDUMP("MorphStoreDynBlock: transformed STORE_DYN_BLK into ASG(BLK, Data())\n");

GenTree* lclVarTree = fgIsIndirOfAddrOfLocal(lhs);
if (lclVarTree != nullptr)
{
lclVarTree->gtFlags |= GTF_VAR_DEF;
}

return tree->OperIsCopyBlkOp() ? fgMorphCopyBlock(asg) : fgMorphInitBlock(asg);
}
}
Expand Down
35 changes: 35 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_73821/Runtime_73821.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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;

unsafe class Runtime_73821
{
public struct S
{
public int F;
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static S Test1(int val)
{
S s;
int size = sizeof(S);
Unsafe.CopyBlockUnaligned(&s, &val, (uint)size);
return s;
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static int Test2(int val)
{
int val2;
int size = sizeof(int);
Unsafe.CopyBlockUnaligned(&val2, &val, (uint)size);
return val2;
}

static int Main()
{
return Test1(33).F + Test2(67);
}
}
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 c302b7b

Please sign in to comment.