Can we provide AST as input to the clang?

I want to write the AST and use it as a input to the clang is it possible?

clang -Xclang -ast-dump file.c -shared -Xclang
-ast-dump-filter=main > file.ast

I want to pass these file.ast to clang and generate executable

1 Like

Adding to the above asked by @aabhinavg ,

clang -Xclang -ast-dump file.c -shared -Xclang -ast-dump-filter=main > dumped-file.ast

The above command will dump AST and print.

By adding -o pre-compiled-file.ast instead of output redirection, will generate a precompiled AST file.

clang -Xclang -ast-dump file.c -shared -Xclang -ast-dump-filter=main -o pre-compiled-file.ast

Final Command to be run from the dumped AST:

clang --analyze -Xclang -analyzer-checker=alpha.security.taint.TaintPropagation dumped-file.ast

The above command to be done from the dumped one but not from the pre-compiled AST file.

There’s something missing between to be done. Can anyone help with this?

Strange. I think you already posted some similar question on the bug tracker. I think it definitely worth investigating. I dont have the time unfortunately. I would recommend debugging them in paralell to see where they differ fundamentally. essentially tracing their execution and see where they differ.

you could also give a shoot at trying uftrace.

Hi @steakhal. The similar question has already been asked here, link . Question 1 asked in the link attached.

When it comes to -emit-ast, it requires all the headers to be present so that a complete AST could be built. But whereas, -ast-dump will dump the partial AST information to the console. It’s better to have a partial AST when static analysis is needed.