Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum type inference could use improvement #1142

Open
bprg opened this issue May 20, 2018 · 3 comments
Open

Enum type inference could use improvement #1142

bprg opened this issue May 20, 2018 · 3 comments
Labels
C# Decompiler The decompiler engine itself Enhancement Areas for improvement IL Issues about IL view

Comments

@bprg
Copy link

bprg commented May 20, 2018

C#
var value = 0xfffffe0b;

IL
IL_0000: ldc.i4 -501

@siegfriedpammer
Copy link
Member

siegfriedpammer commented May 20, 2018

Why is this invalid? What would you expect? -501 and 0xfffffe0b have the same value, when encoded in binary and ilasm accepts both ldc.i4 -501 and ldc.i4 0xfffffe0b. It seems ildasm always uses hexadecimal notation for values < 0, but that is just a question of formatting the output value.

ldc.i4 -504 is not invalid.

@bprg
Copy link
Author

bprg commented May 20, 2018

You're right, But if added hexadecimal value in comment like dotPeek decompiler is great.

IL_0000: ldc.i4 -501 //0xfffffe0b

@bprg
Copy link
Author

bprg commented May 21, 2018

Another issue with enum.

Code

MyEnum value = MyEnum.Val2;
if (value - MyEnum.Val1 <= 4)
{
   Console.WriteLine(value - MyEnum.Val1);
}

enum MyEnum : uint
{
   Val1 = 0xfffffe0b,
   Val2 = 0xfffffe0f
}

Decompile result

MyEnum myEnum = MyEnum.Val2;
if ((uint)((int)myEnum - -501) <= 4u)
{
   Console.WriteLine((uint)((int)myEnum - -501));
}

@dgrunwald dgrunwald changed the title Invalid IL value Enum type inference could use improvement Jun 2, 2018
@siegfriedpammer siegfriedpammer added C# Decompiler The decompiler engine itself Enhancement Areas for improvement IL Issues about IL view labels Aug 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# Decompiler The decompiler engine itself Enhancement Areas for improvement IL Issues about IL view
Projects
None yet
Development

No branches or pull requests

2 participants