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 45329 - segfault with frounding-math
Summary: segfault with frounding-math
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Common Code Generator Code (show other bugs)
Version: trunk
Hardware: PC Linux
: P enhancement
Assignee: Kevin P. Neal
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-27 07:34 PDT by Brian Cain
Modified: 2020-10-06 12:57 PDT (History)
7 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Cain 2020-03-27 07:34:37 PDT
Several targets fail with "-frounding-math" and a cast.  This fails on 10.0.0 but also trunk.  I discovered this while building musl for hexagon-unknown-musl-linux.

The failure I see is a segfault.

~~~~
$ cat double_cast.c 
double a;
void b() { unsigned c = a; }

~~~~
/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang --target=mips -frounding-math -c double_cast.c
/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang --target=powerpc -frounding-math -c double_cast.c
/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang --target=hexagon -frounding-math -c double_cast.c

~~~~
...

 #0 0x0000000002048214 PrintStackTraceSignalHandler(void*) (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x2048214)
 #1 0x0000000002045ffe llvm::sys::RunSignalHandlers() (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x2045ffe)
 #2 0x00000000020474bd llvm::sys::CleanupOnSignal(unsigned long) (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x20474bd)
 #3 0x0000000001fde5ca CrashRecoverySignalHandler(int) (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x1fde5ca)
 #4 0x00007f4108d04890 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
 #5 0x0000000002b32df4 llvm::SelectionDAG::ReplaceAllUsesWith(llvm::SDNode*, llvm::SDValue const*) (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x2b32df4)
 #6 0x0000000002aa94fe (anonymous namespace)::SelectionDAGLegalize::ExpandNode(llvm::SDNode*) (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x2aa94fe)
 #7 0x0000000002a9a472 (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*) (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x2a9a472)
 #8 0x0000000002a99604 llvm::SelectionDAG::Legalize() (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x2a99604)
 #9 0x0000000002b462b5 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x2b462b5)
#10 0x0000000002b45ab7 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x2b45ab7)
#11 0x0000000002b433e6 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x2b433e6)
#12 0x000000000102dbba llvm::MipsDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x102dbba)
#13 0x00000000018140c8 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x18140c8)
#14 0x0000000001aeb6f6 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x1aeb6f6)
#15 0x0000000001aeb973 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x1aeb973)
#16 0x0000000001aebfc8 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x1aebfc8)
#17 0x00000000021d5b3e 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> >) (/opt/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang+0x21d5b3e)
...
Comment 1 Brian Cain 2020-03-27 07:36:31 PDT
To be more explicit: none of these fail without "-frounding-math".  None of them fail with "-fno-rounding-math" either.
Comment 2 Kevin P. Neal 2020-04-09 09:22:40 PDT
A debug build fails with this message:

Assertion failed: (!IsStrict && "Don't know how to expand for strict nodes."), function ExpandNode, file /sasusr/u/saskpn/clvm/trunk/llvm-sdagbug/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp, line 3713

The relevant code:
    // FIXME: It seems Legalized is false iff CCCode is Legal. I don't
    // understand if this code is useful for strict nodes.
    assert(!IsStrict && "Don't know how to expand for strict nodes.");

I'll see what I can do.
Comment 3 rian 2020-04-09 18:16:35 PDT
Another stack trace from d32170dbd5b0d54436537b6b75beaf44324e0c28 (10.0.0 release) in case it helps:
 #0 0x000055590fe63e5c llvm::sys::PrintStackTrace(llvm::raw_ostream&) ./llvm/lib/Support/Unix/Signals.inc:564:22
 #1 0x000055590fe63eef PrintStackTraceSignalHandler(void*) ./llvm/lib/Support/Unix/Signals.inc:625:1
 #2 0x000055590fe61f94 llvm::sys::RunSignalHandlers() ./llvm/lib/Support/Signals.cpp:68:20
 #3 0x000055590fe6389e SignalHandler(int) ./llvm/lib/Support/Unix/Signals.inc:406:1
 #4 0x00007ff1b3144520 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13520)
 #5 0x00007ff1b16c1081 raise /build/glibc-kSJANG/glibc-2.29/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #6 0x00007ff1b16ac535 abort /build/glibc-kSJANG/glibc-2.29/stdlib/abort.c:81:7
 #7 0x00007ff1b16ac40f _nl_load_domain /build/glibc-kSJANG/glibc-2.29/intl/loadmsgcat.c:1177:9
 #8 0x00007ff1b16b9b92 (/lib/x86_64-linux-gnu/libc.so.6+0x32b92)
 #9 0x0000555910ff311d (anonymous namespace)::SelectionDAGLegalize::ExpandNode(llvm::SDNode*) ./llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:3642:34
#10 0x0000555910fdf21c (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*) ./llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1253:7
#11 0x0000555910ffb314 llvm::SelectionDAG::Legalize() ./llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:4751:25
#12 0x0000555910ec960c llvm::SelectionDAGISel::CodeGenAndEmitDAG() ./llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:924:61
#13 0x0000555910ec820a llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, bool&\
)
 ./llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:737:1
#14 0x0000555910ecc9ab llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) ./llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1611:33
#15 0x0000555910ec6c71 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) ./llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:504:7
#16 0x000055590ec00166 (anonymous namespace)::WebAssemblyDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) ./llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp:62:3
#17 0x000055590f1544fe llvm::MachineFunctionPass::runOnFunction(llvm::Function&) ./llvm/lib/CodeGen/MachineFunctionPass.cpp:73:33
#18 0x000055590f66f945 llvm::FPPassManager::runOnFunction(llvm::Function&) ./llvm/lib/IR/LegacyPassManager.cpp:1481:20
#19 0x000055590f66fbaa llvm::FPPassManager::runOnModule(llvm::Module&) ./llvm/lib/IR/LegacyPassManager.cpp:1517:13
#20 0x000055590f66ffd4 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) ./llvm/lib/IR/LegacyPassManager.cpp:1582:20
#21 0x000055590f670750 llvm::legacy::PassManagerImpl::run(llvm::Module&) ./llvm/lib/IR/LegacyPassManager.cpp:1694:13
#22 0x000055590f67094d llvm::legacy::PassManager::run(llvm::Module&) ./llvm/lib/IR/LegacyPassManager.cpp:1726:1
#23 0x000055591015443f (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) ./clang/lib/CodeGen/BackendUtil.cpp:911:51
#24 0x00005559101587d8 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> >) ./clang/lib/CodeGen/BackendUtil.cpp:1550:27
#25 0x00005559110aa037 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) ./clang/lib/CodeGen/CodeGenAction.cpp:335:24
#26 0x0000555912589d10 clang::ParseAST(clang::Sema&, bool, bool) ./clang/lib/Parse/ParseAST.cpp:178:14
#27 0x00005559108be065 clang::ASTFrontendAction::ExecuteAction() ./clang/lib/Frontend/FrontendAction.cpp:1043:11
#28 0x00005559110a77c0 clang::CodeGenAction::ExecuteAction() ./clang/lib/CodeGen/CodeGenAction.cpp:1180:1
#29 0x00005559108bd9d1 clang::FrontendAction::Execute() ./clang/lib/Frontend/FrontendAction.cpp:940:38
#30 0x0000555910856671 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) ./clang/lib/Frontend/CompilerInstance.cpp:965:42
#31 0x0000555910a1828b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) ./clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:290:38
#32 0x000055590eb70948 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) ./clang/tools/driver/cc1_main.cpp:240:40
#33 0x000055590eb66543 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) ./clang/tools/driver/driver.cpp:329:20
#34 0x000055590eb66c04 main ./clang/tools/driver/driver.cpp:403:26
#35 0x00007ff1b16adbbb __libc_start_main /build/glibc-kSJANG/glibc-2.29/csu/../csu/libc-start.c:342:3
#36 0x000055590eb64dea _start (./build/bin/clang-10+0x2243dea)
Aborted
Comment 4 Brian Cain 2020-07-07 09:12:29 PDT
Ping -- Kevin, any update/progress?
Comment 5 Kevin P. Neal 2020-07-07 09:38:22 PDT
I'm working on a set of changes to clang to disable non-default rounding modes and non-default exception handling. This will turn the options back into no-ops and eliminate the crashes.

https://reviews.llvm.org/D80952

I hope to have it in for the 11.0 release. Cross your fingers.
Comment 6 Brian Cain 2020-07-07 15:12:37 PDT
Thanks for working on it, Kevin!  Would it be possible to backport to 10.0 branch?
Comment 7 Kevin P. Neal 2020-07-08 07:06:34 PDT
(In reply to Brian Cain from comment #6)
> Thanks for working on it, Kevin!  Would it be possible to backport to 10.0
> branch?

Probably, but I doubt it will make it into 10.0.1. They just tagged 10.0.1-rc4, but this patch hasn't made it into the head of the tree yet.
Comment 8 Kevin P. Neal 2020-10-06 12:57:20 PDT
I have a patch against 10.0.1 here:
https://reviews.llvm.org/F13185315

This patch disables use of constrained floating point on hosts that don't support it. A warning will be printed in this case.

This code will be in 11 when it ships as well.