Incorrect x86 variable offset


The compiler does not generate the correct x86 binary for the following method:
 public unsafe static void WriteChar(byte c, byte color, byte* address)
    byte* address2 = address + 1;
    address = c;
    address2 = color;    // this is the problem statement
The IL generated for this method is:
.method public hidebysig static void  WriteChar(uint8 c, uint8 color, uint8
address) cil managed
  // Code size       13 (0xd)
  .maxstack  2
  .locals init ([0] uint8
  IL_0000:  nop
  IL_0001:  ldarg.2
  IL_0002:  ldc.i4.1
  IL_0003:  conv.i
  IL_0004:  add
  IL_0005:  stloc.0
  IL_0006:  ldarg.2
  IL_0007:  ldarg.0
  IL_0008:  stind.i1
  IL_0009:  ldloc.0
  IL_000a:  ldarg.1
  IL_000b:  stind.i1
  IL_000c:  ret
} // end of method Boot::WriteChar
And finally here's the disassemble code :
.text:00402EC1                 mov     [ebp+var_14], 1
.text:00402ECB                 mov     eax, [ebp+arg_8]
.text:00402ED1                 add     eax, [ebp+var_14]
.text:00402ED7                 mov     [ebp+var_10], eax
.text:00402EDD                 mov     eax, [ebp+arg_8]
.text:00402EE3                 mov     dl, [ebp+arg_0]
.text:00402EE9                 mov     [eax+0], dl
.text:00402EEF                 mov     eax, [ebp+var_C]   ; should be mov eax, [ebp+var_10] ???
.text:00402EF5                 mov     dl, [ebp+arg_4]
.text:00402EFB                 mov     [eax+0], dl
The offset should be var_10 (and not var_C) in my opinion. 
Any suggestions on how to fix this?
Closed Apr 4, 2009 at 3:59 PM by tgiphil
This is caused by a problem with SSA and not a variable offset.

Closing this case.


tgiphil wrote Apr 4, 2009 at 3:19 PM

Seems to be an SSA problem and not an alignment problem.

wrote Apr 4, 2009 at 3:19 PM

wrote Apr 4, 2009 at 3:59 PM

wrote Feb 13, 2013 at 8:45 PM

wrote May 16, 2013 at 2:11 AM