[flang] crash at Fortran::semantics::SemanticsContext::FindScope
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
https://godbolt.org/z/89s4r8fWb
The following code:
```fortran
module m1
use m3
end
module m3
use m1
end
allocate(x1, source = [1, 2, 3, 4, 5])
end
```
Resulted in this output:
```
fatal internal error: SemanticsContext::FindScope(): invalid source location for '[1, 2, 3, 4, 5]'
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: /usr/lib/llvm-22/bin/flang -fc1 -triple x86_64-pc-linux-gnu -emit-obj -ffree-form -fdefault-integer-8 -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -vectorize-loops -vectorize-slp -fversion-loops-for-stride -finit-global-zero -std=f2018 -resource-dir /usr/lib/llvm-22/lib/clang/22 -mframe-pointer=none -O3 -o /tmp/test-8178cc.o -x f95 /tmp/test.f90
#0 0x00007f88aae73d5f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-22/lib/libLLVM.so.22.1+0x4dc7d5f)
#1 0x00007f88aae715d7 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-22/lib/libLLVM.so.22.1+0x4dc55d7)
#2 0x00007f88aae74b2a (/usr/lib/llvm-22/lib/libLLVM.so.22.1+0x4dc8b2a)
#3 0x00007f88a5b48330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x00007f88a5ba1b2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#5 0x00007f88a5b4827e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#6 0x00007f88a5b2b8ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#7 0x0000556ab3fba61c (/usr/lib/llvm-22/bin/flang+0x2b2061c)
#8 0x0000556ab29136fa Fortran::semantics::SemanticsContext::FindScope(Fortran::parser::CharBlock) (/usr/lib/llvm-22/bin/flang+0x14796fa)
#9 0x0000556ab2bfe040 Fortran::semantics::AllocateChecker::Leave(Fortran::parser::AllocateStmt const&) (/usr/lib/llvm-22/bin/flang+0x1764040)
#10 0x0000556ab2920337 (/usr/lib/llvm-22/bin/flang+0x1486337)
#11 0x0000556ab291fce7 (/usr/lib/llvm-22/bin/flang+0x1485ce7)
#12 0x0000556ab292a545 (/usr/lib/llvm-22/bin/flang+0x1490545)
#13 0x0000556ab292a439 (/usr/lib/llvm-22/bin/flang+0x1490439)
#14 0x0000556ab29150b8 Fortran::semantics::Semantics::Perform() (/usr/lib/llvm-22/bin/flang+0x147b0b8)
#15 0x0000556ab206491e Fortran::frontend::FrontendAction::runSemanticChecks() (/usr/lib/llvm-22/bin/flang+0xbca91e)
#16 0x0000556ab20697da Fortran::frontend::CodeGenAction::beginSourceFileAction() (/usr/lib/llvm-22/bin/flang+0xbcf7da)
#17 0x0000556ab2063f9e Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/usr/lib/llvm-22/bin/flang+0xbc9f9e)
#18 0x0000556ab204be7f Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/usr/lib/llvm-22/bin/flang+0xbb1e7f)
#19 0x0000556ab2068ba0 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/usr/lib/llvm-22/bin/flang+0xbceba0)
#20 0x0000556ab2049d34 fc1_main(llvm::ArrayRef, char const*) (/usr/lib/llvm-22/bin/flang+0xbafd34)
#21 0x0000556ab2048fa4 main (/usr/lib/llvm-22/bin/flang+0xbaefa4)
#22 0x00007f88a5b2d1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#23 0x00007f88a5b2d28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#24 0x0000556ab2047f45 _start (/usr/lib/llvm-22/bin/flang+0xbadf45)
flang-22: error: unable to execute command: Aborted (core dumped)
flang-22: error: flang frontend command failed due to signal (use -v to see invocation)
Ubuntu flang version 22.1.8 (++20260613092238+e80beda6e255-1~exp1~20260613092253.78)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-22/bin
flang-22: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-22: note: diagnostic msg: /tmp/test-a4d5ed
flang-22: note: diagnostic msg: /tmp/test-a4d5ed.sh
flang-22: note: diagnostic msg:
********************
```
To reproduce:
```
flang ./test.f90
```
Compiler version:
```
Ubuntu flang version 22.1.8 (++20260613092238+e80beda6e255-1~exp1~20260613092253.78)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-22/bin
```
*This bug was found by [fusion-fuzz](https://github.com/fusion-fuzz/fusion-fuzz)*
Contributor guide
Research direction
Start by reproducing the crash with flang on test.f90, then inspect SemanticsContext::FindScope and AllocateChecker::Leave, the functions named in the stack trace. Compare the cyclic module-use case and the allocate statement with the reported invalid source location. Done means the reproducer no longer aborts with a fatal internal error and appropriate compiler behavior is covered.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100