Skip to content

Importer's spilling logic is incomplete in subtle ways #72133

Closed
@SingleAccretion

Description

@SingleAccretion

Reproduction (requires Fody.InlineIL):

Console.WriteLine(Problem(1, 2, 0));

[MethodImpl(MethodImplOptions.NoInlining)]
static int Problem(int a, int b, int c)
{
    IL.Emit.Ldarg(0);
    IL.Emit.Ldarga(0);
    IL.Emit.Ldarg(2);
    IL.Emit.Add();
    IL.Emit.Ldarga(1);
    IL.Emit.Ldobj<StructWithInt>();
    IL.Emit.Stobj<StructWithInt>();

    return IL.Return<int>(); 
}

struct StructWithInt
{
    public int Int;
}

Compile and run.

Expected result: program prints 1.

Actual result: program prints 2.

Cause: the importer doesn't spill a when it appends the stobj:

Importing BB01 (PC=000) of 'RyuJitReproduction.Program:Problem(int,int,int):int'
    [ 0]   0 (0x000) ldarg.0
    [ 1]   1 (0x001) ldarga.s 0
    [ 2]   3 (0x003) ldarg.2
    [ 3]   4 (0x004) add
    [ 2]   5 (0x005) ldarga.s 1
    [ 3]   7 (0x007) ldobj 0200002D
    [ 3]  12 (0x00c) stobj 0200002D

STMT00000 ( 0x000[E-] ... ??? )
               [000010] -A-X-------                         *  ASG       struct (copy)
               [000009] -----------                         +--*  BLK       struct<RyuJitReproduction.Program+StructWithInt, 4>
               [000005] -----------                         |  \--*  ADD       long  
               [000002] -----------                         |     +--*  ADDR      long  
               [000001] -------N---                         |     |  \--*  LCL_VAR   int    V00 arg0         
               [000004] -----------                         |     \--*  CAST      long <- int
               [000003] -----------                         |        \--*  LCL_VAR   int    V02 arg2         
               [000008] n--X-------                         \--*  OBJ       struct<RyuJitReproduction.Program+StructWithInt, 4>
               [000007] -----------                            \--*  ADDR      byref 
               [000006] -------N---                               \--*  LCL_VAR   int    V01 arg1         

    [ 1]  17 (0x011) ret

STMT00001 ( ??? ... ??? )
               [000011] -----------                         *  RETURN    int   
               [000000] -----------                         \--*  LCL_VAR   int    V00 arg0         

Metadata

Metadata

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIbug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions