Accessing Clang Frontend Compiler through command line

Hi,
After reading the llvm source code, I realize that if we use clang directly with clang test.cpp ..., we actually use clang like a driver. It just get the options and invokes an executable, which might not allow us to trace its execution.

In my case, I would like to use the clang Compiler Instance, which can be accessed with -cc1. However, with -cc1, we need to specify all the configurations as we use the compiler instance programmatically.

Another way might be to use -Xclang, which allow us to access the clang flags for the next argument. However, it seems not working with -fprofile-instrument-path. When I try clang ./test.cpp -Xclang -fprofile-instrument-path=./, I do get the object file as the output but missing the instrumentation symbols inside the file.

I wonder if I miss anything or my understanding is not correct. I would appreciate any help and clarification. Thank you so much!

It doesn’t look like you’re using the correct flag. The correct flag for -cc1 should be -fprofile-instrument-use-path.

Hi,

Thank you so much for the quick response! Actually I want to setup the path for generating the profiling results, instead of the profiling data to be accessed by the compiler. But I really appreciate the answer because it reminds me that I might use the wrong flag. In fact, Here I should use -fprofile-instrument to achieve my goal.

Thank you so much once again!