Force clang to disable preprocessing

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?

best regards,
Andrey Tarasevich

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