Is there a way to analyze multiple translation units / files using clang? I’m trying to implement a simple analysis to match up each function call to its potential FunctionDecls, where the decls might be defined in multiple files.
According to my investigation, you can enable CTU analysis with experimental-enable-naive-ctu-analysis=true and ctu-dir parameters when executing clang.
And before your analysis, you should create the external definition mapping file with clang-extdef-mapping or clang-func-mapping (depending on your clang’s version, see clang/tools/).
With the mapping file, CTU analysis can find the desired FunctionDecls outside current TU when CTU analysis is enabled.
An example of invoking clang with CTU analysis enabled:
The CTU functionality is kind of there but we lack good support for driver scripts to actually drive the analysis. The scan-build-py has some support but is poorly maintained at the point. The most mature solution is in CodeChecker 1. Most of the problems with CTU analysis coming from the ASTImporter. Ericsson also has some ASTImporter patches downstream that are being upstreamed gradually. So if you want the best possible result, you could try their fork 2. It should work reasonably well for most projects (last time I checked it was able to analyze more than 99% of LLVM and Clang sources with CTU enabled).