Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Fix ADDR(IND(tree))=>tree transformation in morph. #27108

Merged
merged 1 commit into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13188,6 +13188,14 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac)
// Perform the transform ADDR(IND(...)) == (...).
GenTree* addr = op1->gtOp.gtOp1;

// If tree has a zero field sequence annotation, update the annotation
// on addr node.
FieldSeqNode* zeroFieldSeq = nullptr;
if (GetZeroOffsetFieldMap()->Lookup(tree, &zeroFieldSeq))
{
fgAddFieldSeqForZeroOffset(addr, zeroFieldSeq);
}

noway_assert(varTypeIsGC(addr->gtType) || addr->gtType == TYP_I_IMPL);

DEBUG_DESTROY_NODE(op1);
Expand Down
53 changes: 53 additions & 0 deletions tests/src/JIT/Regression/JitBlue/GitHub_99999/GitHub_99999.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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.Runtime.CompilerServices;

struct S
{
public Program p;
public int i;
}

struct T
{
public S s;
}

class Program
{
public T t;
public T t1;

[MethodImpl(MethodImplOptions.NoInlining)]
int Test()
{
// The bug was that a field sequence annotation was lost
// when morph was transforming ADDR(IND(tree)) into tree
// when processing this.t.s.p.
if (this.t.s.p == this.t1.s.p)
{
return 0;
}
this.t1.s = this.t.s;
int result = Helper(this.t.s);
return result;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static int Helper(S s)
{
return s.i;
}

static int Main()
{
Program p = new Program();
p.t.s.i = 100;
p.t.s.p = p;

return p.Test();
}
}
12 changes: 12 additions & 0 deletions tests/src/JIT/Regression/JitBlue/GitHub_99999/GitHub_99999.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>