Skip to content

CopyPropagation.DoPropagate shouldn't reuse the ILRange from copiedExpr? #1873

Description

@yyjdelete

Seems the current version can not properly handle line info for the below code. Not sure it only happen for DoPropagate or also for other usage of ILInstruction.Clone() in ILSpy.

        static int i;

        private static void XXX()
        {
            ref var i2 = ref i;
            if (i == 0)
            {
                i2++;
                i2 += 2;
            }
            else
            {
                i2--;
                i2 -= 2;
            }
        }
.method private hidebysig static 
	void XXX () cil managed 
{
	// Method begins at RVA 0x20b0
	// Code size 50 (0x32)
	.maxstack 3
	.locals init (
		[0] int32& i2,
		[1] bool
	)

	// (no C# code)
	IL_0000: nop
	// i -= 2;
	IL_0001: ldsflda int32 ConsoleApp8.Program::i
	// (no C# code)
	IL_0006: stloc.0
	// if (i == 0)
	IL_0007: ldsfld int32 ConsoleApp8.Program::i
	IL_000c: ldc.i4.0
	IL_000d: ceq
	IL_000f: stloc.1
	IL_0010: ldloc.1
	// (no C# code)
	IL_0011: brfalse.s IL_0023

	IL_0013: nop
	IL_0014: ldloc.0
	IL_0015: ldloc.0
	IL_0016: ldind.i4
	IL_0017: ldc.i4.1
	IL_0018: add
	IL_0019: stind.i4
	IL_001a: ldloc.0
	IL_001b: ldloc.0
	IL_001c: ldind.i4
	IL_001d: ldc.i4.2
	IL_001e: add
	IL_001f: stind.i4
	IL_0020: nop
	// }
	IL_0021: br.s IL_0031

	// (no C# code)
	IL_0023: nop
	IL_0024: ldloc.0
	IL_0025: ldloc.0
	IL_0026: ldind.i4
	IL_0027: ldc.i4.1
	IL_0028: sub
	IL_0029: stind.i4
	IL_002a: ldloc.0
	IL_002b: ldloc.0
	IL_002c: ldind.i4
	IL_002d: ldc.i4.2
	IL_002e: sub
	IL_002f: stind.i4
	IL_0030: nop

	IL_0031: ret
} // end of method Program::XXX

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions