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

Instruction.Operand contains invalid branch instruction. #42

Closed
mehfuzh opened this issue Oct 8, 2010 · 4 comments
Closed

Instruction.Operand contains invalid branch instruction. #42

mehfuzh opened this issue Oct 8, 2010 · 4 comments
Labels

Comments

@mehfuzh
Copy link

mehfuzh commented Oct 8, 2010

Hi Evain,

I decompiled a switch statement that follows:
switch (arg)
{
case 0:
{
return 2;
}
case 1:
{
return 4;
}
default:
{
return 0;
}
}

The result IL contains :
{IL_0004: switch IL_0013,IL_0018}

Followed by :
{IL_0011: br.s IL_001d}
{IL_0013: nop}

Now, instruction.Operand contains nop which is valid but not expected as it should contain the value from IL_0011 which is the switch branch needed to create proper control flow graph.

In this case, is it possible to send the desired OpCode through instruction.Operand ? So that implementer does not have to do an extra simulation on top it.

Regards,
Mehfuz

@jbevain
Copy link
Owner

jbevain commented Oct 8, 2010

Sorry but I don't understand what you think the problem is. Please write the complete IL of the method, and what you think is wrong in which instruction.

@mehfuzh
Copy link
Author

mehfuzh commented Oct 8, 2010

Hi Evain,
Here goes the full IL
[0]: {IL_0000: nop}
[1]: {IL_0001: ldarg.1}
[2]: {IL_0002: stloc.1}
[3]: {IL_0003: ldloc.1}
[4]: {IL_0004: switch IL_0013,IL_0018}
[5]: {IL_0011: br.s IL_001d}
[6]: {IL_0013: nop}
[7]: {IL_0014: ldc.i4.2}
[8]: {IL_0015: stloc.0}
[9]: {IL_0016: br.s IL_0022}
[10]: {IL_0018: nop}
[11]: {IL_0019: ldc.i4.4}
[12]: {IL_001a: stloc.0}
[13]: {IL_001b: br.s IL_0022}
[14]: {IL_001d: nop}
[15]: {IL_001e: ldc.i4.0}
[16]: {IL_001f: stloc.0}
[17]: {IL_0020: br.s IL_0022}
[18]: {IL_0022: ldloc.0}
[19]: {IL_0023: ret}

Now, when i am at IL_0004 and I call instruction.Operand contains array of OpCodes.Nop, instead of the branch instructions br.s IL_001d and br.s IL_0022 needed to create control flow for switch. As IL_0013 points to nop , it is literally valid but invalid in case of processing branch. For switch statement with return , MSIL generates an extra nop instruction. I was thinking if instruction.Operand call can return instructions for IL_0011 and IL_0016 instead of IL_0013 and IL_0018 respectively.

@jbevain
Copy link
Owner

jbevain commented Oct 8, 2010

Sorry but you're wrong here. The switch is properly constructed and contains the appropriate instructions. It doesn't make any sense for the operands to contain something else than the actual jump points in the jump table.

And it's invalid in no case at all, if you want to build a CFG for a switch statement, you have to create basic blocks starting at each jump points of the switch and starting at its next instruction. Closing.

@mehfuzh
Copy link
Author

mehfuzh commented Oct 8, 2010

Thanks for the clarification, much appreciated.

sbomer pushed a commit to sbomer/cecil that referenced this issue Dec 21, 2022
…012.1 (jbevain#42)

Microsoft.DotNet.Arcade.Sdk
 From Version 8.0.0-beta.22473.1 -> To Version 8.0.0-beta.22512.1
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants