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

David Blaikie via cfe-dev cfe-dev at lists.llvm.org
Tue Jan 26 13:16:56 PST 2021


There's certainly something we do that can make clang header modules
standalone - including the source inside the module. But I don't know the
name of the flags to do that...

On Tue, Jan 26, 2021 at 1:14 PM Hartogs Siegfried via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> 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
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210126/619e519b/attachment.html>


More information about the cfe-dev mailing list