llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.81k stars 11.45k forks source link

[Clang] Assertion isCurrentFileAST() && "dumping non-AST?" failed. with `-module-file-info` #87852

Open patrick-rivos opened 5 months ago

patrick-rivos commented 5 months ago

Testcase:

int a;

Backtrace:

> /scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang -module-file-info red.c -o rv64gcv.out
clang: /scratch/tc-testing/tc-apr-4/llvm/clang/lib/Frontend/FrontendActions.cpp:841: virtual void clang::DumpModuleInfoAction::ExecuteAction(): Assertion `isCurrentFileAST() && "dumping non-AST?"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang -module-file-info red.c -o rv64gcv.out
 #0 0x00005d0ff0934730 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang+0x1e50730)
 #1 0x00005d0ff0931b3f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang+0x1e4db3f)
 #2 0x00005d0ff087f6c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x0000744d8b842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000744d8b8969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x0000744d8b8969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x0000744d8b8969fc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x0000744d8b842476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x0000744d8b8287f3 abort ./stdlib/abort.c:81:7
 #9 0x0000744d8b82871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x0000744d8b839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x00005d0ff146585c clang::DumpModuleInfoAction::ExecuteAction() (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang+0x298185c)
#12 0x00005d0ff1446539 clang::FrontendAction::Execute() (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang+0x2962539)
#13 0x00005d0ff13ca856 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang+0x28e6856)
#14 0x00005d0ff1517ee5 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang+0x2a33ee5)
#15 0x00005d0fef7e1eaf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang+0xcfdeaf)
#16 0x00005d0fef7db593 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#17 0x00005d0ff11f4fbd void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#18 0x00005d0ff087fb90 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang+0x1d9bb90)
#19 0x00005d0ff11f583e clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#20 0x00005d0ff11b987a clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang+0x26d587a)
#21 0x00005d0ff11ba34d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang+0x26d634d)
#22 0x00005d0ff11c7264 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang+0x26e3264)
#23 0x00005d0fef7df2f8 clang_main(int, char**, llvm::ToolContext const&) (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang+0xcfb2f8)
#24 0x00005d0fef71c9eb main (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang+0xc389eb)
#25 0x0000744d8b829d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#26 0x0000744d8b829e40 call_init ./csu/../csu/libc-start.c:128:20
#27 0x0000744d8b829e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#28 0x00005d0fef7da845 _start (/scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin/clang+0xcf6845)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 1b761205f2686516cebadbcbc37f798197d9c482)
Target: riscv64-unknown-linux-gnu
Thread model: posix
InstalledDir: /scratch/tc-testing/tc-apr-4/build-rv64gcv/build-llvm-linux/bin
clang: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /scratch/tmp/red-4d3a09.c
clang: note: diagnostic msg: /scratch/tmp/red-4d3a09.sh
clang: note: diagnostic msg:

********************

Reproducer: red-4d3a09.zip

Godbolt: https://godbolt.org/z/nb4G5M57f

Found via fuzzer.

shafik commented 5 months ago

I believe your supposed to pass a pcm file as an argument to -module-file-info but regardless it should not crash.

CC @ChuanqiXu9

ChuanqiXu9 commented 5 months ago

Yes, exactly. This was designed as a tool to help developers. But after all, crash is not good.