Clang AST bug?

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 .c

Instead of getting an AST, I get back the source code of the .c

Is it a bug or I am doing something silly?

Thanks!

Saoni

Hello Saoni,

Please try 'clang -cc1 -ast-dump'.

Dmitri

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>
(<<>>)
(BinaryOperator 0x5c4e368 <line:3:7, col:11> ‘int’ ‘>’
(ImplicitCastExpr 0x5c4e338 col:7 ‘float’
(DeclRefExpr 0x5c4e2f0 col:7 ‘float’ lvalue ParmVar 0x5c4e100 ‘x’ ‘float’))
(ImplicitCastExpr 0x5c4e350 col:11 ‘float’
(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.

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>
(<<>>)
(BinaryOperator 0x5c4e368 <line:3:7, col:11> ‘int’ ‘>’
(ImplicitCastExpr 0x5c4e338 col:7 ‘float’
(DeclRefExpr 0x5c4e2f0 col:7 ‘float’ lvalue ParmVar 0x5c4e100 ‘x’ ‘float’))
(ImplicitCastExpr 0x5c4e350 col:11 ‘float’
(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.