I want to apply clang optimizations to a source file then generate its AST.
I tried passing -O3
flag but it seems that it is ignored.
For example I assume that for this snipped of program:
#include <stdio.h>
int main(void) {
int a = 5 + 5;
for (int i = 0; i < 10; i++) { }
printf("%i\n", a);
return 0;
}
Many optimizations can be applied, like removing the for loop converting 5 + 5 to 10.
When I dump the AST using clang -O3 -Xclang -ast-dump -fsyntax-only a.c
I get the same AST without the optimization flag.
My goal is create a TranslationUnit with flag optimizations passed.