[cfe-dev] cc1 problems when loading multiple AST files
Artem Dergachev via cfe-dev
cfe-dev at lists.llvm.org
Mon Apr 15 19:41:56 PDT 2019
Hi,
I probably won't be able to help with the crash.
Generally, the trivial way to obtain a Static Analyzer invocation from a
compilation database (assuming the project is already compiled with
clang) is to append `--analyze` to it. Then you can convert it to a cc1
run-line via `-###`. Clang, on its own, doesn't know how to read
compilation databases; it's supposed to work the other way round.
You also cannot construct a single cc1 run-line that would conduct
cross-translation-unit analysis. CTU is, by definition, a collaborative
effort of multiple clang instances; in order to analyze a single file,
you'll need the *whole* compilation database. That said, if you already
have precompiled ASTs and function map files, you should be able to
invoke clang -cc1 on a single file just by passing the correct ctu_dir;
it should be enough to reproduce the crash or to debug it.
I think right now the "official" (in-tree, but still mostly
unmaintained) way of invoking CTU is via scan-build-py, which is an
effort to rewrite scan-build in python. It also happily consumes
compilation databases. On the other hand, CTU developers mostly target
the out-of-tree Ericsson CodeChecker tool for this purpose.
Hope this slightly helps.
On 4/14/19 8:23 PM, Ella Oikawa via cfe-dev 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