TypeChef icon indicating copy to clipboard operation
TypeChef copied to clipboard

Handling of labled statements broken

Open ckaestne opened this issue 11 years ago • 1 comments

Parsing of labeled statements is incorrect (our grammar needs fixing)

We parse labels as separate statements. That is a: b: c(); is parsed as three statements: List(LabeledStatement(a), LabeledStatement(b), FunctionCall(c..)). In the ANSI C grammar this is a single statement LabeledStatement(a, LabeledStatement(b, FunctionCall(c..))). In GCC this is again handled differently, closer to our separate statements: the internal tree representation actually creates an internal block where needed.

Here is the original code block (one statement) from uclibc that illustrates the problem:

if (0)
        jin:{
        if ((a = *++haystack) == c)
          goto crest;
          }
        else
          a = *++haystack;

Corresponding grammar: http://www.lysator.liu.se/c/ANSI-C-grammar-y.html and corresponding parser code in GCC: https://github.com/mirrors/gcc/blob/master/gcc/c/c-parser.c#L4457

Fixing the grammar will require follow up fixes in the data flow analysis and simple changes in the type system.

ckaestne avatar Jun 16 '13 15:06 ckaestne