[cfe-dev] Clang AST bug?

Richard Smith metafoo at gmail.com
Sun Feb 2 13:38:31 PST 2014


On Sun Feb 02 2014 at 12:02:19 PM, Saoni Mukherjee <
sayani.mookherjee at gmail.com> wrote:

> I am aware of this option. However I have developed a program ( a parser )
> based on the output of clang -cc1 -ast-print that I used to get. Here is an
> excerpt of how it used to look like:
>
> typedef __int128 __int128_t;
> typedef unsigned __int128 __uint128_t;
> typedef __va_list_tag __builtin_va_list[1];
> float my_islower(float x) (CompoundStmt 0x5c79920 <islower.c:1:27,
> line:8:1>
>   (DeclStmt 0x5c4e2d8 <line:2:3, col:10>
>     (0x5c4e280 "float y"))
>   (IfStmt 0x5c79890 <line:3:3, line:6:9>
>     (<<<NULL>>>)
>     (BinaryOperator 0x5c4e368 <line:3:7, col:11> 'int' '>'
>       (ImplicitCastExpr 0x5c4e338 <col:7> 'float' <LValueToRValue>
>         (DeclRefExpr 0x5c4e2f0 <col:7> 'float' lvalue ParmVar 0x5c4e100
> 'x' 'float'))
>       (ImplicitCastExpr 0x5c4e350 <col:11> 'float' <IntegralToFloating>
>         (IntegerLiteral 0x5c4e318 <col:11> 'int' 0)))
>
> Can you please suggest how to get this syntax? Clearly, it is important
> for me (or my program) to get a similar syntax of the AST output.
>

This weird mix of pretty-printed source code and AST dump was basically a
bug. We no longer have any way to produce that output.

However, our -ast-dump output is pretty similar to the output above (except
that we use ASCII art to represent the nesting within statements instead of
something approximating s-expressions). Neither the old format nor the new
one is intended to be machine-readable, but if you want to keep parsing it,
it should be straightforward to extend a parser for the s-expression-like
language to parse our -ast-dump output.


> On Sun, Feb 2, 2014 at 2:35 PM, Dmitri Gribenko <gribozavr at gmail.com>wrote:
>
> On Sun, Feb 2, 2014 at 6:25 PM, Saoni Mukherjee
> <sayani.mookherjee at gmail.com> wrote:
> > I have installed Clang using the description mentioned on the website.
> All
> > seemed okay. Now when I try to generate the AST from a C source file, I
> get
> > the source code back. In other words, if I enter
> > clang -cc1 -ast-print <file>.c
>
> Hello Saoni,
>
> Please try 'clang -cc1 -ast-dump'.
>
> Dmitri
>
> --
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140202/7f4081da/attachment.html>


More information about the cfe-dev mailing list