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

StackBefore == null #12

Closed
DmitryFriesen opened this issue Feb 19, 2011 · 7 comments
Closed

StackBefore == null #12

DmitryFriesen opened this issue Feb 19, 2011 · 7 comments

Comments

@DmitryFriesen
Copy link

Ln 207 if (branchTarget.StackBefore.Count != newStack.Count) // is true

Ln 233 int popCount = byteCode.PopCount ?? byteCode.StackBefore.Count; // StackBefore == null

Ln 384 int popCount = byteCode.PopCount ?? byteCode.StackBefore.Count; // StackBefore == null

@DmitryFriesen
Copy link
Author

in file ICSharpCode.Decompiler\ILAst\ILAstBuilder.cs

@dsrbecky
Copy link
Member

What do you mean? Do you know how to trigger thouse?

The first one would mean inconsisten stack - that is quite forbiden in CLR. So it would mean that there is a bug in the analysis.

The second/third would mean that there is unreachable IL code - that is probably allowed, but again, it more likely means there is some scenario I did not htink of.

@dsrbecky
Copy link
Member

Oh, I see the other bug report now...

@DmitryFriesen
Copy link
Author

ILSpy_0.1.0.325_Source

IL_00e9: ldloc.1
IL_00ea: stloc.s 4
IL_00ec: ldloc.s 4
IL_00ee: brfalse.s IL_010a
IL_00f0: ldstr "-"
IL_00f5: ldloc.2
IL_00f6: callvirt instance string [mscorlib]System.Text.StringBuilder::ToString()
IL_00fb: callvirt instance string string::Trim()
IL_0100: call string string::Concat(string, string)
IL_0105: stloc.3
IL_0106: br.s IL_011a
IL_0108: br.s IL_0119   <----- Ln 235: byteCode.StackBefore == null 
IL_010a: nop
IL_010b: ldloc.2
IL_010c: callvirt instance string [mscorlib]System.Text.StringBuilder::ToString()
IL_0111: callvirt instance string string::Trim()
IL_0116: stloc.3
IL_0117: br.s IL_011a
IL_0119: nop
IL_011a: ldloc.3
IL_011b: ret

@dsrbecky
Copy link
Member

I do not see anything that would branch to IL_0108. Is there some branch to that location somewhere else? Or is the code really just plainly unreachable? Does that come from the C# compiler?

@DmitryFriesen
Copy link
Author

    IL_0000: nop
    IL_0001: ldarg.0
    IL_0002: ldfld class [mscorlib]System.Collections.Generic.Dictionary`2<string, class RaceClient.clsRunningClock> class RaceClient.clsRaceClient::mRunningClocks
    IL_0007: ldarg.1
    IL_0008: callvirt instance bool [mscorlib]System.Collections.Generic.Dictionary`2<string, RaceClient.clsRunningClock>::ContainsKey(!0)
    IL_000d: ldc.i4.0
    IL_000e: ceq
    IL_0010: stloc.1
    IL_0011: ldloc.1
    IL_0012: brfalse.s IL_001c
    IL_0014: ldstr ""
    IL_0019: stloc.0
    IL_001a: br.s IL_0053
    IL_001c: ldarg.0
    IL_001d: ldfld class [mscorlib]System.Collections.Generic.Dictionary`2<string, class RaceClient.clsRunningClock> class RaceClient.clsRaceClient::mRunningClocks
    IL_0022: ldarg.1
    IL_0023: callvirt instance !1 [mscorlib]System.Collections.Generic.Dictionary`2<string, RaceClient.clsRunningClock>::get_Item(!0)
    IL_0028: ldnull
    IL_0029: ceq
    IL_002b: ldc.i4.0
    IL_002c: ceq
    IL_002e: stloc.1
    IL_002f: ldloc.1
    IL_0030: brfalse.s IL_0049
    IL_0032: ldarg.0
    IL_0033: ldfld class [mscorlib]System.Collections.Generic.Dictionary`2<string, class RaceClient.clsRunningClock> class RaceClient.clsRaceClient::mRunningClocks
    IL_0038: ldarg.1
    IL_0039: callvirt instance !1 [mscorlib]System.Collections.Generic.Dictionary`2<string, RaceClient.clsRunningClock>::get_Item(!0)
    IL_003e: ldarg.2
    IL_003f: callvirt instance string RaceClient.clsRunningClock::get_ClockString(int32)
    IL_0044: stloc.0
    IL_0045: br.s IL_0053
    IL_0047: br.s IL_0052    <---- byteCode.StackBefore == null
    IL_0049: nop
    IL_004a: ldstr ""
    IL_004f: stloc.0
    IL_0050: br.s IL_0053
    IL_0052: nop
    IL_0053: ldloc.0
    IL_0054: ret

This is the real code and Reflector shows:
public string get_GetClock(string ClockId, [Optional, DefaultParameterValue(0)] int TimeBase)
{
if (this.mRunningClocks.ContainsKey(ClockId) && (this.mRunningClocks[ClockId] != null))
{
return this.mRunningClocks[ClockId].get_ClockString(TimeBase);
}
return "";
}

@dsrbecky
Copy link
Member

Should be fixed in adfc7fc

Please try it.

I did not address if (branchTarget.StackBefore.Count != newStack.Count) // is true
If you can reproduce it, please open new bug report

pgourlain pushed a commit to pgourlain/ILSpy that referenced this issue Apr 15, 2014
Add newline between members and between using block and namespace
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2020
This issue was closed.
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