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

Consider constructor type when lifting decimal constants #2953

Merged
merged 3 commits into from
Apr 9, 2023

Conversation

ElektroKill
Copy link
Contributor

@ElektroKill ElektroKill commented Apr 6, 2023

Link to issue(s) this covers:
Fixes #2949

Problem

ILSpy did not use the proper decimal constructor when transforming the LdcI4 instruction into a LdcDecimal instruction. Furthermore, the constructors with parameter type long and ulong were not supported at all as the pattern did not account for LdcI8.

Code to reproduce the missing constructor issue:

public static decimal LongToDecimal() {
	return (decimal)long.MaxValue;
}

public static decimal ULongToDecimal() {
	return (decimal)ulong.MaxValue;
}

Solution

  • Ensure the correct decimal constructor is used when creating LdcDecimal instructions.
  • Add support for the two aforementioned previously unsupported constructors.

@siegfriedpammer
Copy link
Member

Would be nice if you could add the example code as test cases somewhere... Thanks!

@ElektroKill
Copy link
Contributor Author

Would be nice if you could add the example code as test cases somewhere... Thanks!

I went with extending the correctness test for decimal since ILSpy will always decompile decimal constants using the raw value and will not introduce special constants like uint.MaxValue so a pretty test would not have been ideal.

@siegfriedpammer siegfriedpammer merged commit fcb9b0e into icsharpcode:master Apr 9, 2023
@siegfriedpammer
Copy link
Member

Thank you very much for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

decompilation of large uint constants cast to decimal is incorrect
2 participants