[cfe-dev] Force clang to disable preprocessing

Chad Rosier mcrosier at apple.com
Mon Aug 15 11:34:29 PDT 2011


On Aug 14, 2011, at 4:25 PM, Andrey Tarasevich wrote:

> Hello!
> 
> Currently I'm parsing Linux kernel source code and want to do some source code manipulations. I wanted to use clang for this, but in order to build AST clang should first preprocess source code and this causes clang to produce corrupted code in many cases, since kernel has lots of magic and not trivial behaviour.
> Is it possible to force clang disable preprocessing and make it think, that source code is sane and thus build complete AST without macro and includes expansion? I do understand, that this is not how compiler suppose to work, but maybe there are any workarounds?

You could look into using the -x option, which is used to explicitly define the language of the input file.  For example, 'clang -x cpp-output test.c', would treat test.c as if it had already been preprocessed.  Of course if the input file hasn't actually been preprocessed you should expect problems.

 Chad

> best regards,
> Andrey Tarasevich
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list