[cfe-dev] Running clang tools on .ast files

Hartogs Siegfried via cfe-dev cfe-dev at lists.llvm.org
Tue Jan 26 13:14:20 PST 2021


Hello everyone,

We are working on a ClangTool that analyzes C/C++ projects on the clang AST level.
Our goal is to first store ASTs of the translation units on disk s.t. we later read and analyze them with our tool.
Using
clang++ file.cpp -emit-ast -o file.ast
we generate and store AST files.

However, when reading in .ast files with the tool we run into two problems:
- If you move source/header files the .ast was generated from to a different location, the tool complains that it can no longer find those. It seems that the source file location is hardcoded in absolute form inside the AST file, which is especially bad if you want to build AST and use the tool on different machines. E.g.
fatal error: malformed or corrupted AST file: 'could not find file '/home/fba_code/source/lib/memdebug.h' referenced by AST file '/home/fba_code/source/lib/altsvc.ast''
1 error generated.

- mtime changed: analyzing some a.ast, whose source the tool is able to find, it prompts that a header b.h it depends on has been modified, and that we should rebuilt b.ast. E.g.
fatal error: file '/home/fba_code/source/lib/memdebug.h' has been modified since the AST file '/home/fba_code/source/lib/altsvc.ast' was built: mtime changed
note: please rebuild precompiled header '/home/fba_code/source/lib/altsvc.ast'
1 error generated.

Are there any flags we can use when doing -emit-ast s.t. the AST files no longer depend on the source files or are otherwise "relocatable"?

Best,
Siegfried
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210126/e7478c67/attachment.html>


More information about the cfe-dev mailing list