Intermediate Language troubles (Advanced Question)

M

Mark Ingram

Hi, I am trying to track down a very odd bug that only occurs when it is
built on one machine. I try to calculate the width of a piece of string
(needed to calculate the width of a button). On one PC upto 2 letters
are missed from the text string, however on the other PC it works just
fine. I have ILDASM'd the function in question and wondered if anyone
could tell me why the last but one line is "L_0066: ldloc.0"" instead
of "IL_0066: ldloc.0"??

If that isn't the issue, does anyone have any ideas as to why the two
compilers would generate code sufficiently different to cause a bug?
(It definately works 100% on my PC, but causes the bug if built on a
different PC with Visual C# Express on)



VISUAL C# EXPRESS



.method public hidebysig instance int32
CalculateRequiredWidth() cil managed
{
// Code size 104 (0x68)
.maxstack 6
.locals init (int32 V_0,
class [System.Drawing]System.Drawing.Graphics V_1,
class [System.Drawing]System.Drawing.StringFormat V_2,
valuetype [System.Drawing]System.Drawing.SizeF V_3,
valuetype
[System.Windows.Forms]System.Windows.Forms.Padding V_4)
IL_0000: ldc.i4.m1
IL_0001: stloc.0
IL_0002: ldarg.0
IL_0003: call instance class
[System.Drawing]System.Drawing.Graphics
[System.Windows.Forms]System.Windows.Forms.Control::CreateGraphics()
IL_0008: stloc.1
.try
{
IL_0009: ldarg.0
IL_000a: call instance class
[System.Drawing]System.Drawing.StringFormat
Softease.Podium.Controls.GroupBoxMinimisedToolStrip::GetStringFormatFromTitleButton()
IL_000f: stloc.2
IL_0010: ldloc.1
IL_0011: ldarg.0
IL_0012: ldfld class
Softease.Podium.Controls.MinimisedToolStripTitleButton
Softease.Podium.Controls.GroupBoxMinimisedToolStrip::titleButton
IL_0017: callvirt instance string
[System.Windows.Forms]System.Windows.Forms.Control::get_Text()
IL_001c: ldarg.0
IL_001d: ldfld class
Softease.Podium.Controls.MinimisedToolStripTitleButton
Softease.Podium.Controls.GroupBoxMinimisedToolStrip::titleButton
IL_0022: callvirt instance class
[System.Drawing]System.Drawing.Font
[System.Windows.Forms]System.Windows.Forms.Control::get_Font()
IL_0027: ldc.i4.0
IL_0028: ldc.i4.0
IL_0029: newobj instance void
[System.Drawing]System.Drawing.Point::.ctor(int32,

int32)
IL_002e: call valuetype
[System.Drawing]System.Drawing.PointF
[System.Drawing]System.Drawing.Point::blush:p_Implicit(valuetype
[System.Drawing]System.Drawing.Point)
IL_0033: ldloc.2
IL_0034: callvirt instance valuetype
[System.Drawing]System.Drawing.SizeF
[System.Drawing]System.Drawing.Graphics::MeasureString(string,


class [System.Drawing]System.Drawing.Font,


valuetype [System.Drawing]System.Drawing.PointF,


class [System.Drawing]System.Drawing.StringFormat)
IL_0039: stloc.3
IL_003a: ldloca.s V_3
IL_003c: call instance float32
[System.Drawing]System.Drawing.SizeF::get_Width()
IL_0041: conv.i4
IL_0042: ldc.i4.6
IL_0043: add
IL_0044: ldarg.0
IL_0045: ldfld class
Softease.Podium.Controls.MinimisedToolStripTitleButton
Softease.Podium.Controls.GroupBoxMinimisedToolStrip::titleButton
IL_004a: callvirt instance valuetype
[System.Windows.Forms]System.Windows.Forms.Padding
[System.Windows.Forms]System.Windows.Forms.Control::get_Margin()
IL_004f: stloc.s V_4
IL_0051: ldloca.s V_4
IL_0053: call instance int32
[System.Windows.Forms]System.Windows.Forms.Padding::get_Horizontal()
IL_0058: add
IL_0059: stloc.0
IL_005a: leave.s IL_0066

} // end .try
finally
{
IL_005c: ldloc.1
IL_005d: brfalse.s IL_0065

IL_005f: ldloc.1
IL_0060: callvirt instance void
[mscorlib]System.IDisposable::Dispose()
IL_0065: endfinally
} // end handler
L_0066: ldloc.0
IL_0067: ret
} // end of method GroupBoxMinimisedToolStrip::CalculateRequiredWidth



VISUAL STUDIO 2005



.method public hidebysig instance int32
CalculateRequiredWidth() cil managed
{
// Code size 104 (0x68)
.maxstack 6
.locals init ([0] int32 width,
[1] class [System.Drawing]System.Drawing.Graphics gfx,
[2] class [System.Drawing]System.Drawing.StringFormat format,
[3] valuetype [System.Drawing]System.Drawing.SizeF titleSize,
[4] valuetype
[System.Windows.Forms]System.Windows.Forms.Padding CS$0$0000)
IL_0000: ldc.i4.m1
IL_0001: stloc.0
IL_0002: ldarg.0
IL_0003: call instance class
[System.Drawing]System.Drawing.Graphics
[System.Windows.Forms]System.Windows.Forms.Control::CreateGraphics()
IL_0008: stloc.1
.try
{
IL_0009: ldarg.0
IL_000a: call instance class
[System.Drawing]System.Drawing.StringFormat
Softease.Podium.Controls.GroupBoxMinimisedToolStrip::GetStringFormatFromTitleButton()
IL_000f: stloc.2
IL_0010: ldloc.1
IL_0011: ldarg.0
IL_0012: ldfld class
Softease.Podium.Controls.MinimisedToolStripTitleButton
Softease.Podium.Controls.GroupBoxMinimisedToolStrip::titleButton
IL_0017: callvirt instance string
[System.Windows.Forms]System.Windows.Forms.Control::get_Text()
IL_001c: ldarg.0
IL_001d: ldfld class
Softease.Podium.Controls.MinimisedToolStripTitleButton
Softease.Podium.Controls.GroupBoxMinimisedToolStrip::titleButton
IL_0022: callvirt instance class
[System.Drawing]System.Drawing.Font
[System.Windows.Forms]System.Windows.Forms.Control::get_Font()
IL_0027: ldc.i4.0
IL_0028: ldc.i4.0
IL_0029: newobj instance void
[System.Drawing]System.Drawing.Point::.ctor(int32,

int32)
IL_002e: call valuetype
[System.Drawing]System.Drawing.PointF
[System.Drawing]System.Drawing.Point::blush:p_Implicit(valuetype
[System.Drawing]System.Drawing.Point)
IL_0033: ldloc.2
IL_0034: callvirt instance valuetype
[System.Drawing]System.Drawing.SizeF
[System.Drawing]System.Drawing.Graphics::MeasureString(string,


class [System.Drawing]System.Drawing.Font,


valuetype [System.Drawing]System.Drawing.PointF,


class [System.Drawing]System.Drawing.StringFormat)
IL_0039: stloc.3
IL_003a: ldloca.s titleSize
IL_003c: call instance float32
[System.Drawing]System.Drawing.SizeF::get_Width()
IL_0041: conv.i4
IL_0042: ldc.i4.6
IL_0043: add
IL_0044: ldarg.0
IL_0045: ldfld class
Softease.Podium.Controls.MinimisedToolStripTitleButton
Softease.Podium.Controls.GroupBoxMinimisedToolStrip::titleButton
IL_004a: callvirt instance valuetype
[System.Windows.Forms]System.Windows.Forms.Padding
[System.Windows.Forms]System.Windows.Forms.Control::get_Margin()
IL_004f: stloc.s CS$0$0000
IL_0051: ldloca.s CS$0$0000
IL_0053: call instance int32
[System.Windows.Forms]System.Windows.Forms.Padding::get_Horizontal()
IL_0058: add
IL_0059: stloc.0
IL_005a: leave.s IL_0066

} // end .try
finally
{
IL_005c: ldloc.1
IL_005d: brfalse.s IL_0065

IL_005f: ldloc.1
IL_0060: callvirt instance void
[mscorlib]System.IDisposable::Dispose()
IL_0065: endfinally
} // end handler
IL_0066: ldloc.0
IL_0067: ret
} // end of method GroupBoxMinimisedToolStrip::CalculateRequiredWidth
 
M

Mark Ingram

OK, after a quick test with VS 2005 on the other PC, it turns out the IL
code is exactly the same. So how come on one machine I get local
variables called V_1, V_2 etc, and on the other machine i get the actual
variable names? What could be causing the differences between the two
sets of intermediate code?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top