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

bitfiddling decompilation problem #1922

Closed
tamlin-mike opened this issue Jan 30, 2020 · 1 comment
Closed

bitfiddling decompilation problem #1922

tamlin-mike opened this issue Jan 30, 2020 · 1 comment

Comments

@tamlin-mike
Copy link

Expected fnFails to produce the same decompiled code as fnWorks. Only difference is the size of the constants, i.e. ldc.i4+conv.i8 vs ldc.i8.

Not sure what produces an IL i8 less than 2^31 (I tried marking a constant with 'L' suffix, but the compiler seemingly disregarded that), but that makes ilspy fail to include the required argument casts to long.

.method public hidebysig static int64 fnWorks (int32 x, int32 y) cil managed 
{
  .maxstack 8

  ldarg.1
  conv.i8
  ldc.i4 16777215
  conv.i8
  and
  ldc.i4.s 24
  shl
  ldarg.0
  conv.i8
  ldc.i4 16777215
  conv.i8
  and
  or
  ret
}
decompiled OK: return (((long)y & 16777215L) << 24) | ((long)x & 16777215L);


.method public hidebysig static int64 fnFails (int32 x, int32 y) cil managed 
{
  .maxstack 8

  ldarg.1
  conv.i8
  ldc.i8 16777215
  and
  ldc.i4.s 24
  shl
  ldarg.0
  conv.i8
  ldc.i8 16777215
  and
  or
  ret
}
decompiled bad: return ((y & 0xFFFFFF) << 24) | (x & 0xFFFFFF);

Another minor detail here, is that the failing case properly recognize that the constants are of form 2^n-1 and turns them into hex, but the working case (probably due to the conv.i8) does not.

@dgrunwald
Copy link
Member

Fixed in ad5ba92.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants