Skip to content

unexpected clang crash in Function Pass Manager #47305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
honggyukim opened this issue Oct 25, 2020 · 4 comments
Closed

unexpected clang crash in Function Pass Manager #47305

honggyukim opened this issue Oct 25, 2020 · 4 comments
Labels
backend:X86 bugzilla Issues migrated from bugzilla c confirmed Verified by a second party crash-on-invalid duplicate Resolved as duplicate

Comments

@honggyukim
Copy link
Member

honggyukim commented Oct 25, 2020

Bugzilla Link 47961
Version trunk
OS Linux
CC @DougGregor,@zygoloid

Extended Description

I've seen some crashes when building uftrace, which is a C/C++/Rust function tracing tool.
https://github.com/namhyung/uftrace

Here is the sequence to reproduce the bug.

$ git clone https://github.com/namhyung/uftrace
$ cd uftrace
$ sudo ./misc/install-deps.sh -y
$ CC=clang ./configure
$ make
  CC FPIC  libmcount/script-luajit.op
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12 -D_GNU_SOURCE -iquote /home/honggyu/work/uftrace/git/uftrace -iquote /home/honggyu/work/uftrace/git/uftrace -iquote /home/honggyu/work/uftrace/git/uftrace/arch/x86_64 -Wdeclarat
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module '/home/honggyu/work/uftrace/git/uftrace/utils/script-luajit.c'.
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamEi+0x2d)[0x1f4aefd]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZN4llvm3sys17RunSignalHandlersEv+0x34)[0x1f48d14]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZN4llvm3sys15CleanupOnSignalEm+0xb9)[0x1f48fa9]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12[0x1eba848]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7ff04dc59390]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZN4llvm13PMDataManager26removeNotPreservedAnalysisEPNS_4PassE+0x12b)[0x189965b]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0x4cf)[0x189ec0f]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x31)[0x18a0151]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x4e0)[0x189deb0]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12[0x21f5176]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZN5clang17EmitBackendOutputERNS_17DiagnosticsEngineERKNS_19HeaderSearchOptionsERKNS_14CodeGenOptionsERKNS_13TargetOptionsERKNS_11LangOptionsERKN4llvm10DataLayoutEPNSE_6ModuleENS_13BackendActionESt10uniqu
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12[0x2e88ef9]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZN5clang8ParseASTERNS_4SemaEbb+0x429)[0x3cc8259]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZN5clang14FrontendAction7ExecuteEv+0xc9)[0x28117f9]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZN5clang16CompilerInstance13ExecuteActionERNS_14FrontendActionE+0x1eb)[0x27c474b]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZN5clang25ExecuteCompilerInvocationEPNS_16CompilerInstanceE+0x9f8)[0x28e1ba8]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_Z8cc1_mainN4llvm8ArrayRefIPKcEES2_Pv+0x5ed)[0x98ed2d]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12[0x98c65b]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12[0x267d535]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZN4llvm20CrashRecoveryContext9RunSafelyENS_12function_refIFvvEEE+0x23)[0x1eba943]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12[0x267e015]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZNK5clang6driver11Compilation14ExecuteCommandERKNS0_7CommandERPS3_+0x98)[0x2653818]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZNK5clang6driver11Compilation11ExecuteJobsERKNS0_7JobListERN4llvm15SmallVectorImplISt4pairIiPKNS0_7CommandEEEE+0x106)[0x26541f6]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_ZN5clang6driver6Driver18ExecuteCompilationERNS0_11CompilationERN4llvm15SmallVectorImplISt4pairIiPKNS0_7CommandEEEE+0x89)[0x265e3c9]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(main+0x1b13)[0x90c9f3]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7ff04c953830]
/home/honggyu/work/llvm/git/llvm-project/build.release/bin/clang-12(_start+0x29)[0x98c1f9]
clang-12: error: clang frontend command failed with exit code 139 (use -v to see invocation)
clang version 12.0.0 (https://github.com/llvm/llvm-project.git f81f09ba8950a199af88e5a622155fb9801b11b7)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/honggyu/work/llvm/git/llvm-project/build.release/bin
clang-12: note: diagnostic msg:
********************

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

********************
Makefile:244: recipe for target '/home/honggyu/work/uftrace/git/uftrace/libmcount/script-luajit.op' failed
make: *** [/home/honggyu/work/uftrace/git/uftrace/libmcount/script-luajit.op] Error 139
@honggyukim
Copy link
Member Author

The tested hash version is f81f09b.

The similar build error is reported at uftrace issue page.
namhyung/uftrace#1203

This bug has been reported since clang-3.8.
namhyung/uftrace#1114

The reproducible files cannot be attached here so uploaded at the github issue.

The files have to be renamed removing the last .txt postfix due to github policy.

It would be very helpful if anyone can take a look at it. Thanks!

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@Endilll
Copy link
Contributor

Endilll commented Sep 9, 2023

Still crashing as of post-17 trunk: https://godbolt.org/z/q7aP4ca6h
Reduced by C-Reduce:

static int L, setup_argument_context_spec_0;
double setup_argument_context_dval;
static void setup_argument_context() {
  for (0; setup_argument_context_spec_0 != 0; 0)
    for (0; setup_argument_context_spec_0 != 0; 0)
      dllua_pushnumber(L, setup_argument_context_dval);
}
void luajit_uftrace_entry() { setup_argument_context; }

Crash:

<source>:4:8: warning: expression result unused [-Wunused-value]
    4 |   for (0; setup_argument_context_spec_0 != 0; 0)
      |        ^
<source>:4:47: warning: expression result unused [-Wunused-value]
    4 |   for (0; setup_argument_context_spec_0 != 0; 0)
      |                                               ^
<source>:5:10: warning: expression result unused [-Wunused-value]
    5 |     for (0; setup_argument_context_spec_0 != 0; 0)
      |          ^
<source>:5:49: warning: expression result unused [-Wunused-value]
    5 |     for (0; setup_argument_context_spec_0 != 0; 0)
      |                                                 ^
<source>:8:31: warning: expression result unused [-Wunused-value]
    8 | void luajit_uftrace_entry() { setup_argument_context; }
      |                               ^~~~~~~~~~~~~~~~~~~~~~

clang++: /root/llvm-project/llvm/lib/Target/X86/X86FloatingPoint.cpp:318:
unsigned int getFPReg(const llvm::MachineOperand&):
Assertion `Reg >= X86::FP0 && Reg <= X86::FP6 && "Expected FP register!"' 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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -x c -Wno-implicit-int -Wno-implicit-function-declaration -Xclang -target-feature -Xclang -sse2 <source>
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module '<source>'.
4.	Running pass 'X86 FP Stackifier' on function '@setup_argument_context'
 #0 0x00000000036af848 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x36af848)
 #1 0x00000000036ad50c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x36ad50c)
 #2 0x00000000035f6928 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f87039b2420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f870347500b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f8703454859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f8703454729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f8703465fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x000000000227127d (anonymous namespace)::FPS::handleSpecialFP(llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>&) X86FloatingPoint.cpp:0:0
 #9 0x0000000002271a10 (anonymous namespace)::FPS::processBasicBlock(llvm::MachineFunction&, llvm::MachineBasicBlock&) (.isra.0) X86FloatingPoint.cpp:0:0
#10 0x0000000002273f94 (anonymous namespace)::FPS::runOnMachineFunction(llvm::MachineFunction&) (.part.0) X86FloatingPoint.cpp:0:0
#11 0x0000000002a92ca9 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#12 0x00000000030397a9 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x30397a9)
#13 0x00000000030399e1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x30399e1)
#14 0x000000000303a202 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x303a202)
#15 0x0000000003923b10 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) BackendUtil.cpp:0:0
#16 0x0000000003924439 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3924439)
#17 0x0000000004908d2f clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4908d2f)
#18 0x0000000005dfd8f9 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5dfd8f9)
#19 0x00000000049074d8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49074d8)
#20 0x0000000004170419 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4170419)
#21 0x00000000040f104e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40f104e)
#22 0x000000000424f82e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x424f82e)
#23 0x0000000000bd6c10 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbd6c10)
#24 0x0000000000bcee3a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#25 0x0000000003f526d9 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
#26 0x00000000035f6dd4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x35f6dd4)
#27 0x0000000003f52ccf 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
#28 0x0000000003f1b055 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f1b055)
#29 0x0000000003f1babd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f1babd)
#30 0x0000000003f239e5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f239e5)
#31 0x0000000000bd4a1c clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbd4a1c)
#32 0x0000000000ad1421 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xad1421)
#33 0x00007f8703456083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#34 0x0000000000bce91e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbce91e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)

@Endilll Endilll added backend:X86 crash-on-invalid confirmed Verified by a second party labels Sep 9, 2023
@llvmbot
Copy link
Member

llvmbot commented Sep 9, 2023

@llvm/issue-subscribers-backend-x86

@Endilll
Copy link
Contributor

Endilll commented Sep 9, 2023

Closing in favor of #65840

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 bugzilla Issues migrated from bugzilla c confirmed Verified by a second party crash-on-invalid duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

4 participants