llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[flang] Fortran/gfortran/regression/findloc_8.f90 triggers assertion failure on several non-x86 platforms

Open tarunprabhu opened this issue 1 year ago • 6 comments

The findloc_8.f90 test from the gfortran test suite fails to compile on AArch64 and LoongArch, but compiles correctly on x86. It is possible that it fails on other, non-x86, platforms as well, but these are the only two of which I am aware. The test triggers an assertion on these platforms.

Steps to reproduce: Compile findloc_8.f90. For example, from the root of a checkout of the LLVM test suite:

$ flang -o /tmp/findloc_8 ./Fortran/gfortran/regression/findloc_8.f90

Unexpected failure on AArch64:

flang: /llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1740: SDValue llvm::SelectionDAG::getConstant(const ConstantInt &, const SDLoc &, EVT, bool, bool): Assertion `Elt->getBitWidth() == EltVT.getSizeInBits() && "APInt size does not match type size!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /flang/install/release/bin/flang -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +outline-atomics -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -resource-dir /flang/install/release/lib/clang/20 -mframe-pointer=non-leaf -o /tmp/findloc_8-fa2183.o -x f95-cpp-input /llvm-test-suite/repo/Fortran/gfortran/regression/findloc_8.f90
1.	Running pass 'Function Pass Manager' on module 'FIRModule'.
2.	Running pass 'AArch64 Instruction Selection' on function '@_QQmain'
 #0 0x0000ffff9ad1ccf4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/flang/install/release/bin/../lib/libLLVM.so.20.0git+0x1d5ccf4)
 #1 0x0000ffff9ad1aa60 llvm::sys::RunSignalHandlers() (/flang/install/release/bin/../lib/libLLVM.so.20.0git+0x1d5aa60)
 #2 0x0000ffff9ad1d45c SignalHandler(int) Signals.cpp:0:0
 #3 0x0000ffffa25607a0 (linux-vdso.so.1+0x7a0)
 #4 0x0000ffff98b0add8 (/lib64/libc.so.6+0x8add8)
 #5 0x0000ffff98abc13c raise (/lib64/libc.so.6+0x3c13c)
 #6 0x0000ffff98aa7b80 abort (/lib64/libc.so.6+0x27b80)
 #7 0x0000ffff98ab54bc (/lib64/libc.so.6+0x354bc)
 #8 0x0000ffff98ab552c (/lib64/libc.so.6+0x3552c)
 #9 0x0000ffff9b7da144 llvm::SelectionDAG::getConstant(llvm::ConstantInt const&, llvm::SDLoc const&, llvm::EVT, bool, bool) (/flang/install/release/bin/../lib/libLLVM.so.20.0git+0x281a144)
#10 0x0000ffff9b7d8dd8 llvm::SelectionDAG::getConstant(llvm::APInt const&, llvm::SDLoc const&, llvm::EVT, bool, bool) (/flang/install/release/bin/../lib/libLLVM.so.20.0git+0x2818dd8)
#11 0x0000ffff9b6c2830 llvm::DAGTypeLegalizer::SoftenFloatRes_ConstantFP(llvm::SDNode*) LegalizeFloatTypes.cpp:0:0
#12 0x0000ffff9b6c205c llvm::DAGTypeLegalizer::SoftenFloatResult(llvm::SDNode*, unsigned int) LegalizeFloatTypes.cpp:0:0
#13 0x0000ffff9b7076fc llvm::DAGTypeLegalizer::run() LegalizeTypes.cpp:0:0
#14 0x0000ffff9b70ca34 llvm::SelectionDAG::LegalizeTypes() (/flang/install/release/bin/../lib/libLLVM.so.20.0git+0x274ca34)
#15 0x0000ffff9b83bed4 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/flang/install/release/bin/../lib/libLLVM.so.20.0git+0x287bed4)
#16 0x0000ffff9b83ad98 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/flang/install/release/bin/../lib/libLLVM.so.20.0git+0x287ad98)
#17 0x0000ffff9b838238 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/flang/install/release/bin/../lib/libLLVM.so.20.0git+0x2878238)
#18 0x0000ffff9b835bd8 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/flang/install/release/bin/../lib/libLLVM.so.20.0git+0x2875bd8)
#19 0x0000ffff9b263484 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/flang/install/release/bin/../lib/libLLVM.so.20.0git+0x22a3484)
#20 0x0000ffff9aeeae20 llvm::FPPassManager::runOnFunction(llvm::Function&) (/flang/install/release/bin/../lib/libLLVM.so.20.0git+0x1f2ae20)
#21 0x0000ffff9aef2dec llvm::FPPassManager::runOnModule(llvm::Module&) (/flang/install/release/bin/../lib/libLLVM.so.20.0git+0x1f32dec)
#22 0x0000ffff9aeeb7dc llvm::legacy::PassManagerImpl::run(llvm::Module&) (/flang/install/release/bin/../lib/libLLVM.so.20.0git+0x1f2b7dc)
#23 0x0000aaaabeceac1c Fortran::frontend::CodeGenAction::executeAction() (/flang/install/release/bin/flang+0x13cac1c)
#24 0x0000aaaabecdd7c0 Fortran::frontend::FrontendAction::execute() (/flang/install/release/bin/flang+0x13bd7c0)
#25 0x0000aaaabecc8e80 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/flang/install/release/bin/flang+0x13a8e80)
#26 0x0000aaaabece1248 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/flang/install/release/bin/flang+0x13c1248)
#27 0x0000aaaabecc7694 fc1_main(llvm::ArrayRef<char const*>, char const*) (/flang/install/release/bin/flang+0x13a7694)
#28 0x0000aaaabecc6528 main (/flang/install/release/bin/flang+0x13a6528)
#29 0x0000ffff98aa8254 (/lib64/libc.so.6+0x28254)
#30 0x0000ffff98aa8338 __libc_start_main (/lib64/libc.so.6+0x28338)
#31 0x0000aaaabecc5770 _start (/flang/install/release/bin/flang+0x13a5770)
flang-20: error: unable to execute command: Aborted
flang-20: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 20.0.0git ([email protected]:llvm-project-tlp/llvm-project.git 0ee5924d9bc01c5625a41833dd9d88b89c98d986)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /flang/install/release/bin
Build config: +assertions
Configuration file: /flang/install/release/bin/flang.cfg
flang-20: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-20: note: diagnostic msg: /tmp/findloc_8-fe84dc
flang-20: note: diagnostic msg: /tmp/findloc_8-fe84dc.sh
flang-20: note: diagnostic msg: 

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

Expected results: Compilation succeeds.

tarunprabhu avatar Dec 10 '24 17:12 tarunprabhu

This could be an issue with kind=10, but if so, the failure mode should be more graceful.

tarunprabhu avatar Dec 10 '24 17:12 tarunprabhu

This test also fails on AIX and Linux on PPC but with different errors!

On Linux,

flang: /gsa/rtpgsa/home/k/l/kli/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1740: SDValue llvm::SelectionDAG::getConstant(const ConstantInt &, const SDLoc &, EVT, bool, bool): Assertion `Elt->getBitWidth() == EltVT.getSizeInBits() && "APInt size does not match type size!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
...

On AIX,

fatal Fortran runtime error(/gsa/rtpgsa/home/k/l/kli/llvm-test-suite/Fortran/gfortran/regression/findloc_8.f90:9): not yet implemented: REAL/COMPLEX(KIND=10)
IOT/Abort trap (core dumped)

kkwli avatar Dec 11 '24 00:12 kkwli

With e982b4f4, this no longer crashes on AArch64, but raises a semantic error instead:

error: Semantic errors in findloc_8.f90
findloc_8.f90:4:3: error: COMPLEX(KIND=10) is not an enabled type for this target
    complex(kind=10) :: a(6), b, d(2,2)

This is a more reasonable failure mode. @kkwli, could you check if this is the case on AIX and Linux on PPC as well. In that case, this issue can be closed. Thanks.

tarunprabhu avatar Jan 07 '26 19:01 tarunprabhu

@tarunprabhu The test no longer crashes and produces the expected semantic error message on AIX and Linux now. This issue can be closed.

kkwli avatar Jan 09 '26 21:01 kkwli

Thanks for taking a look Kelvin.

tarunprabhu avatar Jan 09 '26 21:01 tarunprabhu

This no longer fails on the platforms on which we routinely test.

tarunprabhu avatar Jan 09 '26 21:01 tarunprabhu