[Mono-bugs] [Bug 639762] New: gmcs crashes

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Sep 16 07:39:30 EDT 2010


https://bugzilla.novell.com/show_bug.cgi?id=639762

https://bugzilla.novell.com/show_bug.cgi?id=639762#c0


           Summary: gmcs crashes
    Classification: Mono
           Product: Mono: Compilers
           Version: 2.6.x
          Platform: x86-64
        OS/Version: UNIX Other
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: asl.pavel at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Development
           Blocker: Yes


Description of Problem:
crashed while compiling file

Steps to reproduce the problem:
1. try compile this:
using System;
using System.Text;
using System.Collections.Generic;

//{{{ Tokens
public enum ETag : uint
{
    Num = 256,
    Id,
    True,
    False
}

public class Token
{
    private static uint id = 0;
    public uint Tag { private set; get; }
    public uint Id { private set; get; }
    public Token( uint tag )
    {
        Tag = tag;
        Id = id++;
    }
    public override string ToString()
    {
        return String.Format("<ID:{0}|{1}>", Id, Tag);
    }
}

public class NumToken : Token
{
    public int Value { private set; get; }
    public NumToken( int val ) : base( (uint) ETag.Num )
    {
        Value = val;
    }
    public override string ToString()
    {
        return String.Format("<ID:{0}|NUM,{1}>", Id, Value);
    }
}

public class WordToken : Token
{
    public string Lexeme { private set; get; }
    public WordToken( uint tag, string lexeme ) : base( tag )
    {
        Lexeme = lexeme;
    }
    public override string ToString()
    {

        return String.Format("<ID:{0}|WORD,{1},{2}>", Id, (ETag)Tag, Lexeme);
    }

    public static WordToken True = new WordToken( (uint) ETag.True, "true");
    public static WordToken False = new WordToken( (uint) ETag.False, "false");
}
//}}}

public class EEndOfStream : Exception {}

public class Lexer
{
    // helpers
    private static bool isDigit( int c )
    {
        return c > 47 && c < 58;
    }
    private static bool isLetter( int c )
    {
        return ( c > 96 && c < 123 ) ||
               ( c > 64 && c < 91 );
    }

    // current symbol
    private int peek = ' ';
    // init symbol table
    private Dictionary<string,Token> stable = new Dictionary<string,Token>
    {
        { WordToken.True.Lexeme, WordToken.True },
        { WordToken.False.Lexeme, WordToken.False }
    };

    // public fields
    public int Line { private set; get; }

    private static int NextChar(IEnumerator<int> istream)
    {
        if ( istream.MoveNext() )
            return istream.Current;
        throw new EEndOfStream();
    }

    public Token Scan(IEnumerator<int> istream)
    {
        // skeep spaces
        bool loop = true;
        for( ;loop; peek = NextChar(istream) )
        {
            switch (peek)
            {
                case ' ':
                case '\t':
                    break;
                case '\n':
                    Line += 1;
                    break;
                default:
                    loop = false;
                    break;
            }
        }

        // parse numbers
        if ( isDigit(peek) )
        {
            int v = 0;
            do {
                v = v * 10 + ( peek - 48 );
                peek = NextChar(istream);
            } while ( isDigit(peek) );
        }

        Token t;

        // parse lexems
        if ( isLetter(peek) )
        {
            var sb = new StringBuilder();
            do {
                sb.Append((byte) peek);
                peek = NextChar(istream);
            } while ( isLetter(peek) );
            var k = sb.ToString();

            if ( stable.TryGetValue( k, out t ) )
                return t;

            t = new WordToken((uint)ETag.Id, k);
            stable[k] = t;

            return t;
        }

        t = new Token((uint)peek);
        peek = ' ';
        return t;
    }

    public IEnumerable<Token> Tokenize( IEnumerator<int> istream )
    {
        Token t;
        for(;;)
        {
            try
            {
                t = Scan(istream);
            }
            catch ( EEndOfStream e )
            {
                return false;
            }
            yield return t;
        }
    }
}

public static class LexerApp
{
    public static void Main(string[] args)
    {
        if ( args.Length == 0 )
        {
            Console.WriteLine("At least one argument expected");
            return;
        }

        Lexer l = new Lexer();
        foreach ( var t in l.Tokenize( args[0].GetEnumerator() ) )
        {
            Console.Write("{0} ", t);
        }
        Console.WriteLine();
    }
}

Actual Results:
lexer.cs(160,34): warning CS0168: The variable `e' is declared but never used
Internal compiler error at lexer.cs(151,31):: exception caught while emitting
MethodBuilder [<Tokenize>c__Iterator0::MoveNext]

Unhandled Exception: System.ArgumentException: Trying to emit a local from a
different ILGenerator.
  at System.Reflection.Emit.ILGenerator.Emit (OpCode opcode,
System.Reflection.Emit.LocalBuilder local) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.LocalInfo.EmitAssign (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.VariableReference.EmitAssign (Mono.CSharp.EmitContext ec,
Mono.CSharp.Expression source, Boolean leave_copy, Boolean prepare_for_load)
[0x00000] in <filename unknown>:0 
  at Mono.CSharp.Catch.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.TryCatch.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.Block.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename
unknown>:0 
  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.For.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in <filename
unknown>:0 
  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.Block.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename
unknown>:0 
  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.Block.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename
unknown>:0 
  at Mono.CSharp.Iterator.EmitMoveNext (Mono.CSharp.EmitContext ec,
Mono.CSharp.Block original_block) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.IteratorStatement.DoEmit (Mono.CSharp.EmitContext ec)
[0x00000] in <filename unknown>:0 
  at Mono.CSharp.Statement.Emit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.Block.DoEmit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.Block.Emit (Mono.CSharp.EmitContext ec) [0x00000] in <filename
unknown>:0 
  at Mono.CSharp.ExplicitBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.ToplevelBlock.Emit (Mono.CSharp.EmitContext ec) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.MethodData.Emit (Mono.CSharp.DeclSpace parent) [0x00000] in
<filename unknown>:0 
  at Mono.CSharp.MethodOrOperator.Emit () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Method.Emit () [0x00000] in <filename unknown>:0 

Expected Results:
File should be compiled or error reported

How often does this happen? 
always

Additional Information:

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list