LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 44413 - no-sse2 assert fail for functions that return `struct { double, double }`
Summary: no-sse2 assert fail for functions that return `struct { double, double }`
Status: NEW
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: X86 (show other bugs)
Version: 8.0
Hardware: PC All
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-30 19:48 PST by Felix Klock
Modified: 2020-01-02 15:49 PST (History)
6 users (show)

See Also:
Fixed By Commit(s):


Attachments
C source for reproduction (152 bytes, text/plain)
2019-12-30 19:48 PST, Felix Klock
Details
clang shell invocation for reproduction (2.03 KB, application/x-sh)
2019-12-30 19:49 PST, Felix Klock
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Felix Klock 2019-12-30 19:48:40 PST
Created attachment 22972 [details]
C source for reproduction

Spawned off of https://github.com/rust-lang/rust/issues/65844, but this is reproducible via `clang` or `rustc`, so it seems like an LLVM bug.

Consider the following C source code:

```
struct S { double x; double y; };

int indirect(struct S get_pair()) {
    struct S s = get_pair();
    return 0;
}
```

If you try to compile this via `clang -mno-sse2` with an LLVM build with assertions enabled, you will get the following assertion failure:

```
llvm/lib/Target/X86/X86FloatingPoint.cpp:317: unsigned int getFPReg(const llvm::MachineOperand&): Assertion `Reg >= X86::FP0 && Reg <= X86::FP6 && "Expected FP register!"' failed.
```

If you do it with a build without assertions enabled, at least in `rustc`, the compiler may or may not crash. (I have no idea about the correctness of the generated code; based on the assertion, I am not inclined to trust the compiler's output here.)

Here is the full transcript of my run, so that you can see the stack backtrace I get from clang:

% ./build/x86_64-unknown-linux-gnu/llvm/bin/clang -c issue65844.c -mno-sse2
clang-9: /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/llvm/lib/Target/X86/X86FloatingPoint.cpp:317: unsigned int getFPReg(const llvm::MachineOperand&): Assertion `Reg >= X86::FP0 && Reg <= X86\
::FP6 && "Expected FP register!"' failed.
Stack dump:
0.      Program arguments: /home/pnkfelix/Dev/Mozilla/rust.git/objdir-dbgopt/build/x86_64-unknown-linux-gnu/llvm/bin/clang-9 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -\
main-file-name issue65844.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -targe\
t-feature -sse2 -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /home/pnkfelix/Dev/Mozilla/rust.git/objdir-dbgopt/issue65844.gcno -resource-dir /home/pnkfelix/Dev/Mozilla/rust.git/objdir-\
dbgopt/build/x86_64-unknown-linux-gnu/llvm/lib/clang/9.0.0 -internal-isystem /usr/local/include -internal-isystem /home/pnkfelix/Dev/Mozilla/rust.git/objdir-dbgopt/build/x86_64-unknown-linux-gnu/llvm/\
lib/clang/9.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/pnkfelix/Dev/Mozilla/rust.git/objdir-dbgopt -ferror-limit 19 -fmessage-l\
ength 200 -fobjc-runtime=gcc -fdiagnostics-show-option -faddrsig -o issue65844.o -x c issue65844.c
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'issue65844.c'.
4.      Running pass 'X86 FP Stackifier' on function '@indirect'
 #0 0x00007ff499a5cda0 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:533:22
 #1 0x00007ff499a5ce33 PrintStackTraceSignalHandler(void*) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:594:1
 #2 0x00007ff499a5af61 llvm::sys::RunSignalHandlers() /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/llvm/lib/Support/Signals.cpp:68:20
 #3 0x00007ff499a5c81d SignalHandler(int) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:385:1
 #4 0x00007ff4970bfe70 __restore_rt (/lib64/libpthread.so.0+0x12e70)
 #5 0x00007ff48f4a5eb5 raise /usr/src/debug/glibc-2.29-12-g0941350c20/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #6 0x00007ff48f490895 abort /usr/src/debug/glibc-2.29-12-g0941350c20/stdlib/abort.c:81:7
 #7 0x00007ff48f490769 _nl_load_domain.cold /usr/src/debug/glibc-2.29-12-g0941350c20/intl/loadmsgcat.c:1177:9
 #8 0x00007ff48f49e5b6 (/lib64/libc.so.6+0x305b6)
 #9 0x00007ff49c8f7f68 getFPReg(llvm::MachineOperand const&) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/llvm/lib/Target/X86/X86FloatingPoint.cpp:318:21
#10 0x00007ff49c8fb6ef (anonymous namespace)::FPS::handleSpecialFP(llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>&) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/llvm/lib/Target/X8\
6/X86FloatingPoint.cpp:1460:30
#11 0x00007ff49c8f89ba (anonymous namespace)::FPS::processBasicBlock(llvm::MachineFunction&, llvm::MachineBasicBlock&) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/llvm/lib/Target/X86/X86Float\
ingPoint.cpp:461:49
#12 0x00007ff49c8f8290 (anonymous namespace)::FPS::runOnMachineFunction(llvm::MachineFunction&) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/llvm/lib/Target/X86/X86FloatingPoint.cpp:374:13
#13 0x00007ff499fb50e4 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:73:33
#14 0x00007ff499c540f3 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1648:20
#15 0x00007ff499c543a8 llvm::FPPassManager::runOnModule(llvm::Module&) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1685:13
#16 0x00007ff499c547ea (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1750:20
#17 0x00007ff499c54f4c llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1863:13
#18 0x00007ff499c55143 llvm::legacy::PassManager::run(llvm::Module&) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1895:1
#19 0x00007ff492542d1f (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) /home/pnkf\
elix/Dev/Mozilla/rust.git/src/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:897:55
#20 0x00007ff492547d8c clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm\
::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/\
clang/lib/CodeGen/BackendUtil.cpp:1498:27
#21 0x00007ff4928d3998 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:303:24
#22 0x00007ff4910e5488 clang::ParseAST(clang::Sema&, bool, bool) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/clang/lib/Parse/ParseAST.cpp:178:14
#23 0x00007ff4938a818f clang::ASTFrontendAction::ExecuteAction() /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1041:11
#24 0x00007ff4928d7098 clang::CodeGenAction::ExecuteAction() /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1060:1
#25 0x00007ff4938a7afb clang::FrontendAction::Execute() /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/clang/lib/Frontend/FrontendAction.cpp:938:38
#26 0x00007ff493854d7e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:944:42
#27 0x00007ff493960f4b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:291:38
#28 0x000000000044eb05 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/clang/tools/driver/cc1_main.cpp:249:40
#29 0x0000000000444936 ExecuteCC1Tool(llvm::ArrayRef<char const*>, llvm::StringRef) /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/clang/tools/driver/driver.cpp:309:64
#30 0x000000000044526b main /home/pnkfelix/Dev/Mozilla/rust.git/src/llvm-project/clang/tools/driver/driver.cpp:381:26
#31 0x00007ff48f491f33 __libc_start_main /usr/src/debug/glibc-2.29-12-g0941350c20/csu/../csu/libc-start.c:308:16
#32 0x0000000000441a4e _start (/home/pnkfelix/Dev/Mozilla/rust.git/objdir-dbgopt/build/x86_64-unknown-linux-gnu/llvm/bin/clang-9+0x441a4e)
clang-9: error: unable to execute command: Aborted (core dumped)
clang-9: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 9.0.0 (https://github.com/rust-lang/llvm-project.git 2cb41005ed5c4747b10d2bf01d8779d3bb4ae32d)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/pnkfelix/Dev/Mozilla/rust.git/objdir-dbgopt/./build/x86_64-unknown-linux-gnu/llvm/bin
clang-9: note: diagnostic msg: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
clang-9: note: diagnostic msg:
********************

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

********************
[ERROR#1] %
Comment 1 Felix Klock 2019-12-30 19:49:20 PST
Created attachment 22973 [details]
clang shell invocation for reproduction
Comment 2 Craig Topper 2019-12-31 00:31:44 PST
I think I fixed the assert/crash in e898ba2d151d621dcfc35828aad6fcded5a554e8. The code generated is completely wrong and does not follow any ABI, but we did signal an error through the diagnostic system as well.
Comment 3 Reid Kleckner 2020-01-02 15:49:09 PST
Any thoughts on https://reviews.llvm.org/D70465, since it's in the area?