[cfe-dev] usage of clang in an university project

Nuno Lopes nunoplopes at sapo.pt
Sun Oct 7 11:29:00 PDT 2007

Thank you for your fast answer.
Today I was reading the clang code and I'm now trying to implement an 
ASTConsumer, as I'll have to do a little more analysis that just checking 
function calls. I also need to know when a particular variable used in the 
function call is initialized or not as well as if it is not initialized by 
the function call (through a pointer) whether it is used afterwards or not. 
I still didn't know if this will be simple enough to do, but I'll try..

For now, I have just more two questions:
 - is it possible to disable clang warnings and output just the warnings 
I'll be generating? (I added a -parse-ast-sirs opt for me)
 - can clang ignore parsing errors? e.g. if it can't find an header.h file 
can it continue even if a function is called without being declared. This is 
especially useful in my case because I'll be parsing the PHP sources (in C) 
and I don't have all the external libraries that some PHP extensions rely 
on, but I still would like to be able to analyse those extensions, though.

BTW, in attach you'll find a backtrace I got when doing executing 
'clang -parse-ast-*'. It happens when I parse a PHP source file and when not 
all include (-I) paths are specified. I took a quick look at those 
functions, but I couldn't fix the bug myself.


----- Original Message ----- 
From: "Chris Lattner" <clattner at apple.com>
To: "Nuno Lopes" <nunoplopes at sapo.pt>
Cc: <cfe-dev at cs.uiuc.edu>
Sent: Saturday, October 06, 2007 7:27 PM
Subject: Re: [cfe-dev] usage of clang in an university project

> On Oct 6, 2007, at 11:06 AM, Nuno Lopes wrote:
>> I was assigned a project for the security class in the university that
>> consists in doing some analisys of varargs function calls (C only).
>> Basically I need some form of an AST of a C file and a way to  transverse 
>> it.
> Sure, clang can do that very easily.
>> Do you think that clang is the best tool for the job? (btw, it has  to be
>> delivered in mid-December). I already took a look to other  projects, 
>> like
>> ANTLR, GCCXML, a flex+bison grammar I found on the web, and even  the 
>> dump of
>> gcc -fdump-translation-unit, but noone seems to be appropriate  (they 
>> have a
>> big learning curve or they don't work well enough).
>> So if you think that clang might do the job, can you please give me  some
>> pointers to how to get started?
> The easiest thing to do is to get clang and build it.  Then run the - 
> parse-ast-print option.  The code for this is implemented in the 
> clang/AST/StmtPrinter.cpp file.  That will give you an overview of  using 
> the AST for something simple.
> For you, you don't want to process all nodes, just calls.  Given a  Stmt 
> for a function body, to walk the AST, you should be able to do  something 
> like this:
> void WalkAST(Stmt *S) {
>   if (S == 0) return;
>   if (CallExpr *Call = dyn_cast<CallExpr>(S)) {
>     // Look at this call.
>   }
>   for (Stmt::child_iterator I = S->child_begin(), E = S->child_end (); I 
> != E; ++I)
>     WalkAST(*I);
> }
> -Chris 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: clang-bt.txt
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20071007/0aea8cfb/attachment.txt>

More information about the cfe-dev mailing list