Skip to content

[flang][OpenMP] flang core dump when using cos or sin #147027

Open
@hakostra

Description

@hakostra

I have a recent flang built from sources:

flang version 21.0.0git (https://github.com/llvm/llvm-project.git b68e8f1de71a65b21910aff4aea75fc1ca6bf6e0)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/llvm/llvm-project/install/bin

The following simple function trigger a core dump when targeting Nvidia GPUs:

MODULE trigtest_m
    IMPLICIT NONE
CONTAINS
    PURE REAL FUNCTION test(inp)
        !$omp declare target
        REAL, INTENT(IN) :: inp
        test = cos(inp)
    END FUNCTION test
END MODULE trigtest_m

When compiling this (flang -fopenmp -fopenmp-targets=nvptx64 -c trigtest.F90) a core dump is trigegred:

$ flang -fopenmp -fopenmp-targets=nvptx64 -c trigtest.F90 
LLVM ERROR: Cannot select: 0x584ecf0e8b20: f32 = fcos contract 0x584ecf0e8ab0
  0x584ecf0e8ab0: f32,ch = load<(load (s32) from %ir.0)> 0x584ecf17cba0, 0x584ecf0e8960, undef:i64
    0x584ecf0e8960: i64,ch = load<(dereferenceable invariant load (s64), addrspace 101)> 0x584ecf17cba0, ExternalSymbol:i64'_QMtrigtest_mPtest_param_0', undef:i64
In function: _QMtrigtest_mPtest
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /opt/llvm/llvm-project/install/bin/flang -fc1 -triple nvptx64-nvidia-cuda -S -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -target-cpu sm_89 -fopenmp -resource-dir /opt/llvm/llvm-project/install/lib/clang/21 -fopenmp-host-ir-file-path /tmp/trigtest-e73a63.bc -fopenmp-is-target-device -mframe-pointer=all -o /tmp/trigtest-sm_89-c45a71.s -x f95 trigtest.F90
1.	Running pass 'Function Pass Manager' on module 'FIRModule'.
2.	Running pass 'NVPTX DAG->DAG Pattern Instruction Selection' on function '@_QMtrigtest_mPtest'
 #0 0x0000584ea4b2d6b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/llvm/llvm-project/install/bin/flang+0x16586b8)
 #1 0x0000584ea4b2b385 llvm::sys::RunSignalHandlers() (/opt/llvm/llvm-project/install/bin/flang+0x1656385)
 #2 0x0000584ea4b2ddb1 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007cf0dc645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #4 0x00007cf0dc69eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007cf0dc69eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007cf0dc69eb2c pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007cf0dc64527e raise ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007cf0dc6288ff abort ./stdlib/abort.c:81:7
 #9 0x0000584ea4acdbb4 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/llvm/llvm-project/install/bin/flang+0x15f8bb4)
#10 0x0000584ea707b685 (/opt/llvm/llvm-project/install/bin/flang+0x3ba6685)
#11 0x0000584ea707ac65 (/opt/llvm/llvm-project/install/bin/flang+0x3ba5c65)
#12 0x0000584ea707175c llvm::SelectionDAGISel::DoInstructionSelection() (/opt/llvm/llvm-project/install/bin/flang+0x3b9c75c)
#13 0x0000584ea7070ef8 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/llvm/llvm-project/install/bin/flang+0x3b9bef8)
#14 0x0000584ea70706f5 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/llvm/llvm-project/install/bin/flang+0x3b9b6f5)
#15 0x0000584ea706e5db llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/llvm/llvm-project/install/bin/flang+0x3b995db)
#16 0x0000584ea49c8db5 llvm::NVPTXDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/llvm/llvm-project/install/bin/flang+0x14f3db5)
#17 0x0000584ea706cb11 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/llvm/llvm-project/install/bin/flang+0x3b97b11)
#18 0x0000584ea7333f08 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/opt/llvm/llvm-project/install/bin/flang+0x3e5ef08)
#19 0x0000584ea9611e2a llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/llvm/llvm-project/install/bin/flang+0x613ce2a)
#20 0x0000584ea9618c63 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/llvm/llvm-project/install/bin/flang+0x6143c63)
#21 0x0000584ea9612a46 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/llvm/llvm-project/install/bin/flang+0x613da46)
#22 0x0000584ea4d6fca6 generateMachineCodeOrAssemblyImpl(clang::DiagnosticsEngine&, llvm::TargetMachine&, Fortran::frontend::BackendActionTy, llvm::Module&, Fortran::frontend::CodeGenOptions const&, llvm::raw_pwrite_stream&) FrontendActions.cpp:0:0
#23 0x0000584ea4d6f955 Fortran::frontend::CodeGenAction::executeAction() (/opt/llvm/llvm-project/install/bin/flang+0x189a955)
#24 0x0000584ea4b5c8ec Fortran::frontend::FrontendAction::execute() (/opt/llvm/llvm-project/install/bin/flang+0x16878ec)
#25 0x0000584ea4b480f2 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/llvm/llvm-project/install/bin/flang+0x16730f2)
#26 0x0000584ea4b60b75 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/llvm/llvm-project/install/bin/flang+0x168bb75)
#27 0x0000584ea4643881 fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/llvm/llvm-project/install/bin/flang+0x116e881)
#28 0x0000584ea4642ab7 main (/opt/llvm/llvm-project/install/bin/flang+0x116dab7)
#29 0x00007cf0dc62a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#30 0x00007cf0dc62a28b call_init ./csu/../csu/libc-start.c:128:20
#31 0x00007cf0dc62a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#32 0x0000584ea4641c05 _start (/opt/llvm/llvm-project/install/bin/flang+0x116cc05)
flang-21: error: unable to execute command: Aborted (core dumped)
flang-21: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 21.0.0git (https://github.com/llvm/llvm-project.git b68e8f1de71a65b21910aff4aea75fc1ca6bf6e0)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/llvm/llvm-project/install/bin
flang-21: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-21: note: diagnostic msg: /tmp/trigtest-sm_89-7716ac
flang-21: note: diagnostic msg: /tmp/trigtest-cb82a3
flang-21: note: diagnostic msg: /tmp/trigtest-sm_89-7716ac.sh
flang-21: note: diagnostic msg: 

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

The core dump happens both when using cos or sin, but not with tan, acos, asin or atan, those "only" trigger a failure in Ptx assembly similar to the one reported in issue #147023. I do not know the internals of flang well enough to say if this is the same issue as #147023 or not, please forgive me for opening two issues if these are related.

Thanks for your effort.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions