[cfe-dev] cc1 problems when loading multiple AST files

Gábor Márton via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 16 05:37:58 PDT 2019


Hi Ella,

> ../bin/clang -cc1 -analyze -analyzer-checker=core,debug.ExprInspection -o reports/ home/ella/workspace/llvm-project/build/analyzer-test/src/getzero.cpp.ast home/ella/workspace/llvm-project/build/analyzer-test/src/test.cpp.ast

The way you executed clang does not merge the AST files. (Still, this
is probably an error, but rather in ASTUnit. Do you get this error
when you pass only one .ast file as a parameter?)

The golden way to achieve what you want, is to use CodeChecker
(https://github.com/Ericsson/codechecker/).
With it you can log the compile commands from a build process (CodeChecker log).
Once you have the compile_commands.json, you can configure the
analysis to properly create all the PCH files (--ctu-collect) and it
will execute the analysis with ctu enabled (--ctu-analysis).
https://github.com/Ericsson/codechecker/blob/master/docs/analyzer/user_guide.md#ctu

Note that the Ericsson Clang fork is far more stable and usable with
the CTU analysis of C++ projects, you should try it:
https://github.com/Ericsson/clang

Gabor

On Mon, Apr 15, 2019 at 5:37 PM Ella Oikawa via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
>
> Hi,
>
> The scene of my usage is I want to analyze multiple source code files with CSA and CTU enabled. Since it will report a header file not found error when using `clang -cc1` to analyze source code files (*.cpp), I turn to AST files for simplicity.
>
> Here is the bug. If I only analyze a single AST file, it works fine. However, when I append multiple AST files for analysis, it crashes all the time. It has been reproduced both on my fedora-29 desktop and ubuntu-18.04 server with the code from git commit e03301a3b32.
>
> The code I use to trigger this bug is provided in the attachments. See core dump file (./coredump) for more details. According to the stack trace, I think the bug is not in CSA and CTU.
>
> **Besides, could you please tell me how to make cc1 to parse AST with the compile commands provided in the compile_commands.json file? Or make clang-check enable CTU IPA? I did not find any code to enable CTU IPA in clang-check, and if it is useful to others, I would like to share my customized clang-check.**
>
> Regards,
> Ella
>
> P.S. I do not know whether it is allowed to ask a question together with a bug report here. Sorry for annoying you.
>
> ---
>
> $ clang --version
> clang version 9.0.0 (https://github.com/llvm/llvm-project.git e03301a3b32d048d8975e0fe21d80489505415c8)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /home/ella/workspace/llvm-project/build/bin
>
> ERROR MESSAGE:
> clang: /home/ella/workspace/llvm-project/clang/include/clang/Basic/Diagnostic.h:528: void clang::DiagnosticsEngine::setSourceManager(clang::SourceManager*): Assertion `DiagStatesByLoc.empty() && "Leftover diag state from a different SourceManager."' failed.
> Stack dump:
> 0. Program arguments: ../bin/clang -cc1 -analyze -analyzer-checker=core,debug.ExprInspection -o reports/ home/ella/workspace/llvm-project/build/analyzer-test/src/getzero.cpp.ast home/ella/workspace/llvm-project/build/analyzer-test/src/test.cpp.ast
>  #0 0x000000000457075a llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/ella/workspace/llvm-project/llvm/lib/Support/Unix/Signals.inc:494:22
>  #1 0x00000000045707ed PrintStackTraceSignalHandler(void*) /home/ella/workspace/llvm-project/llvm/lib/Support/Unix/Signals.inc:558:1
>  #2 0x000000000456eabf llvm::sys::RunSignalHandlers() /home/ella/workspace/llvm-project/llvm/lib/Support/Signals.cpp:68:20
>  #3 0x0000000004570250 SignalHandler(int) /home/ella/workspace/llvm-project/llvm/lib/Support/Unix/Signals.inc:357:1
>  #4 0x00007f52db212070 __restore_rt (/lib64/libpthread.so.0+0x13070)
>  #5 0x00007f52d94ec57f __GI_raise (/lib64/libc.so.6+0x3857f)
>  #6 0x00007f52d94d6895 __GI_abort (/lib64/libc.so.6+0x22895)
>  #7 0x00007f52d94d6769 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x22769)
>  #8 0x00007f52d94e4a26 (/lib64/libc.so.6+0x30a26)
>  #9 0x000000000476fa4b clang::DiagnosticsEngine::setSourceManager(clang::SourceManager*) /home/ella/workspace/llvm-project/clang/include/clang/Basic/Diagnostic.h:527:5
> #10 0x0000000004768d72 clang::SourceManager::SourceManager(clang::DiagnosticsEngine&, clang::FileManager&, bool) /home/ella/workspace/llvm-project/clang/lib/Basic/SourceManager.cpp:319:1
> #11 0x0000000004fba66c clang::ASTUnit::LoadFromASTFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, clang::PCHContainerReader const&, clang::ASTUnit::WhatToLoad, llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>, clang::FileSystemOptions const&, bool, bool, llvm::ArrayRef<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, llvm::MemoryBuffer*> >, bool, bool, bool) /home/ella/workspace/llvm-project/clang/lib/Frontend/ASTUnit.cpp:760:58
> #12 0x0000000004eb1850 clang::FrontendAction::BeginSourceFile(clang::CompilerInstance&, clang::FrontendInputFile const&) /home/ella/workspace/llvm-project/clang/lib/Frontend/FrontendAction.cpp:632:69
> #13 0x0000000004e5576f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/ella/workspace/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:949:5
> #14 0x0000000004ff5b4b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/ella/workspace/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:271:38
> #15 0x000000000221e5d9 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/ella/workspace/llvm-project/clang/tools/driver/cc1_main.cpp:225:40
> #16 0x0000000002214598 ExecuteCC1Tool(llvm::ArrayRef<char const*>, llvm::StringRef) /home/ella/workspace/llvm-project/clang/tools/driver/driver.cpp:309:64
> #17 0x0000000002214bea main /home/ella/workspace/llvm-project/clang/tools/driver/driver.cpp:381:26
> #18 0x00007f52d94d8413 __libc_start_main (/lib64/libc.so.6+0x24413)
> #19 0x0000000002212f3e _start (../bin/clang+0x2212f3e)
> [1]    32214 abort (core dumped)  ../bin/clang -cc1 -analyze -analyzer-checker=core,debug.ExprInspection -o
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


More information about the cfe-dev mailing list