<div dir="ltr">Hi Justin,<div><br></div><div>Thank you very much, it worked!</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-01-25 22:08 GMT+00:00 Justin Bogner <span dir="ltr"><<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Mikhail Ramalho via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> writes:<br>
> Hi all,<br>
><br>
> I'm working on a project to use clang as a frontend to a model checking<br>
> tool.<br>
><br>
> It's almost done but I'm now facing a problem that I couldn't find a<br>
> solution: How to force the preprocessor to run in already preprocessed<br>
> files?<br>
><br>
> For example, something as simples as:<br>
><br>
> int main(void)<br>
> {<br>
> int a = x();<br>
> }<br>
><br>
> When using clangTool to generate the AST, it works fine if add something<br>
> like -Dx=x1. The generated AST looks like:<br>
><br>
> FunctionDecl 0x3a8c290 </home/mramalho/main.c:2:1, line:5:1> line:2:5 main<br>
> 'int (void)'<br>
> `-CompoundStmt 0x3a8c5c0 <line:3:1, line:5:1><br>
> `-DeclStmt 0x3a8c5a8 <line:4:3, col:14><br>
> `-VarDecl 0x3a8c3b8 <col:3, col:13> col:7 a 'int' cinit<br>
> `-CallExpr 0x3a8c580 <<command line>:6:11,<br>
> /home/mramalho/main.c:4:13> 'int'<br>
> `-ImplicitCastExpr 0x3a8c568 <<command line>:6:11> 'int (*)()'<br>
> <FunctionToPointerDecay><br>
</span>> * `-DeclRefExpr 0x3a8c510 <col:11> 'int ()' Function 0x3a8c468<br>
> 'x1' 'int ()'*<br>
<span class="">><br>
> But if I preprocess the file:<br>
><br>
> $ clang -E main.c > main.c.i<br>
><br>
> # 1 "main.c"<br>
> # 1 "<built-in>" 1<br>
> # 1 "<built-in>" 3<br>
> # 316 "<built-in>" 3<br>
> # 1 "<command line>" 1<br>
> # 1 "<built-in>" 2<br>
> # 1 "main.c" 2<br>
><br>
> int main(void)<br>
> {<br>
> int a = x();<br>
> }<br>
><br>
> and run with the same define -Dx=x1, the AST is:<br>
><br>
> FunctionDecl 0x2e583a0 <main.c:2:1, line:5:1> line:2:5 main 'int (void)'<br>
> `-CompoundStmt 0x2e586d0 <line:3:1, line:5:1><br>
> `-DeclStmt 0x2e586b8 <line:4:3, col:14><br>
> `-VarDecl 0x2e584c8 <col:3, col:13> col:7 a 'int' cinit<br>
> `-CallExpr 0x2e58690 <col:11, col:13> 'int'<br>
> `-ImplicitCastExpr 0x2e58678 <col:11> 'int (*)()'<br>
> <FunctionToPointerDecay><br>
</span>> * `-DeclRefExpr 0x2e58620 <col:11> 'int ()' Function 0x2e58578 'x'<br>
> 'int ()'*<br>
<span class="">><br>
> I guess the preprocessor is not running, given the following message I get<br>
> when directly using clang:<br>
><br>
> $ clang -E -Dx=x1 main.c.i<br>
> clang: warning: main.c.i: previously preprocessed input<br>
> clang: warning: argument unused during compilation: '-D x=x1'<br>
><br>
> Is there an option to force the preprocessor to run again?<br>
<br>
</span>clang is guessing that this is preprocessed based on the extension. One<br>
option is to tell clang what language you want to treat the file as with<br>
a -x argument:<br>
<br>
clang -E -Dx=x1 -x c main.c.i<br>
<div class="HOEnZb"><div class="h5"><br>
> Unfortunately, I need to change some function calls, even when the file is<br>
> preprocessed.<br>
><br>
> Thank you,<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><br></div><div>Mikhail Ramalho.</div></div></div>
</div>