ILSpy icon indicating copy to clipboard operation
ILSpy copied to clipboard

Unnecessary uint casts/conversions for certain bitwise operations in ILSpy 6.2p2

Open lbmaian opened this issue 5 years ago • 0 comments

This seems to be a regression from the fixes for #1796

I've found two cases where uint casts and constant conversions to unsigned are unnecessary. Possibly also applies to other unsigned integral types.

Input code

Decompiler settings reset to default.

Source as entered in LINQPad 5:

int Foo(int x)
{
	if ((x & 0x10) != 0)
		return 1;
	return 0;
}

byte Bar(int x)
{
	return (byte)(x & 0x10);
}

Assembly: query_jsdiku.zip

Erroneous output

Actual output:

private int Foo(int x)
{
	if (((uint)x & 0x10u) != 0)
	{
		return 1;
	}
	return 0;
}

private byte Bar(int x)
{
	return (byte)((uint)x & 0x10u);
}

Expected output (as decompiled by ILSpy 6.1):

private int Foo(int x)
{
	if ((x & 0x10) != 0)
	{
		return 1;
	}
	return 0;
}

private byte Bar(int x)
{
	return (byte)(x & 0x10);
}

Details

  • Product in use: ILSpy
  • Version in use: 6.2.0.6118-preview2

lbmaian avatar Sep 19 '20 20:09 lbmaian