Skip to content

JIT: Invalid result computed with modulo operation #71600

Closed

Description

@jakobbotsch
// Generated by Fuzzlyn v1.5 on 2022-07-03 14:40:52
// Run on Arm64 MacOS
// Seed: 5960657379714964908
// Reduced from 328.5 KiB to 0.8 KiB in 00:02:08
// Debug: Outputs 0
// Release: Outputs 1
public struct S0
{
    public long F0;
    public long F1;
    public S0(long f1): this()
    {
        F1 = f1;
    }
}

public struct S1
{
    public uint F1;
    public ushort F2;
    public S0 F4;
    public S1(ulong f5): this()
    {
    }

    public long M82(ref short[] arg0)
    {
        Program.s_13 = this.F1++;
        S1 var1 = new S1(0);
        return Program.s_39[0].F1;
    }
}

public class Program
{
    public static uint s_13;
    public static short[] s_28;
    public static S0[] s_39;
    public static void Main()
    {
        S0[] vr2 = new S0[]{new S0(-1)};
        s_39 = vr2;
        S1 vr3 = default(S1);
        M80(vr3);
    }

    public static void M80(S1 arg0)
    {
        arg0.F2 += (ushort)(arg0.F1 % (uint)arg0.M82(ref s_28));
        System.Console.WriteLine(arg0.F2);
    }
}

Activity

  1. ghost added
    area-CodeGen-coreclr
    on Jul 3, 2022
  2. ghost added
    untriaged
    on Jul 3, 2022
  3. jakobbotsch commented on Jul 4, 2022

    @jakobbotsch
    MemberAuthor

    The mod transform reorders the read of arg0.F1 and the function call arg0.M82(...):

    fgMorphTree (before 17):
                   [000024] --CXG------                         ▌  UMOD      int   
                   [000011] -----------                         ├──▌  LCL_FLD   int    V00 arg0         [+0]
                   [000023] --CXG------                         └──▌  CAST      int <- uint <- long
                   [000015] --CXG------                            └──▌  CALL      long   S1.M82
                   [000013] ----------- this                          ├──▌  LCL_VAR_ADDR byref  V00 arg0         
                   [000014] H---------- arg1                          └──▌  CNS_INT(h) long   0x1bdae801f10 static Fseq[s_28]
    
    ...
    
    fgMorphTree (after 17):
                   [000047] -ACXG+-----                         ▌  COMMA     int   
                   [000041] -ACXG+-----                         ├──▌  ASG       int   
                   [000040] D----+-N---                         │  ├──▌  LCL_VAR   int    V05 tmp4         
                   [000023] --CXG+-----                         │  └──▌  CAST      int <- uint <- long
                   [000015] --CXG+-----                         │     └──▌  CALL      long   S1.M82
                   [000013] -----+----- this in x0              │        ├──▌  LCL_VAR   byref  V00 arg0         
                   [000014] H----+----- arg1 in x1              │        └──▌  CNS_INT(h) long   0x1bdae801f10 static Fseq[s_28]
                   [000046] ---XG+-----                         └──▌  SUB       int   
                   [000048] n---G+-----                            ├──▌  IND       int   
                   [000011] -----+-----                            │  └──▌  LCL_VAR   byref  V00 arg0         
                   [000045] ---XG+-----                            └──▌  MUL       int   
                   [000024] ---XG+-----                               ├──▌  UDIV      int   
                   [000049] n---G+-----                               │  ├──▌  IND       int   
                   [000043] -----+-----                               │  │  └──▌  LCL_VAR   byref  V00 arg0         
                   [000044] -----+-----                               │  └──▌  LCL_VAR   int    V05 tmp4         
                   [000042] -----+-----                               └──▌  LCL_VAR   int    V05 tmp4         

    This is probably exposed by recent local morph changes causing us to forward sub the access of arg0.F1.

  4. ghost added
    in-pr
    on Jul 4, 2022
  5. added this to the 7.0.0 milestone on Jul 4, 2022
  6. self-assigned this
    on Jul 4, 2022
  7. ghost removed
    untriaged
    on Jul 4, 2022
  8. ghost removed
    in-pr
    on Jul 6, 2022
  9. ghost locked as resolved and limited conversation to collaborators on Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions