[Mono-devel-list] mcs generates incorrect IL-code using declarations after goto
Simon Ask Ulsnes
simon at ulsnes.dk
Wed Jun 30 12:50:17 EDT 2004
Hi,
> The following simple program compiles using mcs but doesn't run, using
> csc this program works with .net and mono.
>
> public class Test{
> public static void Main(){
> goto end;
> int a;
> end:
> System.Console.WriteLine("end");
> }
> }
>
> mcs output:
> Test.cs(4) warning CS0162: Unreachable code detected
> Compilation succeeded - 1 warning(s)
>
>
> Execution:
>
> Expected result:
> end
>
> Actual result:
> ** ERROR **: Invalid IL code at IL0000 in C:Main (): IL_0000:
> br IL_ffffffff
Why the heck would anybody want to do that? But anyway, it only happens
if you have actualy unreachable code. If you do a conditional goto like
the following:
bool b = true;
if (b)
{
goto end;
}
else
{
int a = 56;
Console.WriteLine(a);
}
end:
Console.WriteLine("end");
it runs fine and error-less.
I guess Mono places the unreachable code in a wrong place (while it
should actually just delete it from the assembly generated).
Yours,
Simon
More information about the Mono-devel-list
mailing list