[antlr-interest] Bug in 64bit C backend

Jim Idle jimi at temporal-wave.com
Wed Jul 30 17:44:05 PDT 2008


On Wed, 2008-07-30 at 17:59 -0400, Jason Nielsen wrote:

> Hello,
> 
> I believe there is a bug in the 64 bit version of the C backend runtime since 
> using the 32bit version works as expected (or it could be that I've done 
> something foolish that works in 32 bit mode and not in 64 bit). I've attached a 
> tar.gz with code that illustrates the problem and was as simple as I could make 
> it.  The output is also below for your convenience.


I think you may have just run into a bug that I have fixed today is all.
It is just luck of the draw whether something works or not when memory
corruption is involved so you will likely get different behaviors in 32
and 64 bit mode. But, i am not sure because your code is in error.

However, your code does not guard against errors and so on, and your
main program is trying to print a string that you have already freed in
your translate() function. You need to strdup that return string
otherwise it will be deallocated when you free the nodes and then you
try to print it. This may actaully be your problem,

The problem I fixed today involves thigns going slightly awry when a
syntax error is encountered by a tree parser. Your programs give me (10
times):

gcc -g -O2 -fPIC -m64 main.c translate.c *Lexer.c *Parser.c *Walker.c
-lantlr3c -I /tmp/test
jimi at jimi:/tmp/test$ ./a.out
-Imaginary-(0)  : error 10 : Unexpected node, at offset 0, near <missing
<invalid>> : Missing <invalid> 
-Imaginary-(0)  : error 9 : Extraneous token, at offset 0, near <missing
ID> : Extraneous input - expected <DOWN> ...
-Imaginary-(0)  : error 9 : Extraneous token, at offset 0, near <missing
ID> : Extraneous input - expected <DOWN> ...
-Imaginary-(0)  : error 10 : Missing token, at offset 93, near <missing
ID> : Missing ID 
-Imaginary-(0)  : error 3 : , at offset 0, near UP : cannot match to any
predicted input...
-Imaginary-(0)  : error 3 : , at offset 0, near UP : cannot match to any
predicted input...
Nodes: (VAR_DEF char c) (VAR_DEF int x) (FUNC_DECL (FUNC_HDR void bar
(ARG_DEF int x))) (FUNC_DEF (FUNC_HDR int foo ARG_DEF ARG_DEF) (BLOCK
(VAR_DEF int i) (for = (< i 3) = (BLOCK = =))))

Another issue is that that runtime version causes an erroneous free of
the input string in the in place stream (also fixed today). Try running
it once or download the beat 3 runtime from Fisheye,

Which tends to make me think that perhaps there is something wrong with
your input, or perhaps you have modified the sample grammars? Or perhaps
my current development version has another error. Fix your coding error
and see what you get back then.

Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080730/ec4997bb/attachment-0001.html 


More information about the antlr-interest mailing list