<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/66631>66631</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] flang-new crashes with "fatal internal error: nullptr dereference"
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k-arrows
</td>
</tr>
</table>
<pre>
Here is the reproducer (from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106948#c0).
```console
$ cat test.f90
module a
implicit none
interface new
pure module subroutine b(x, f)
integer, intent(inout) :: x
interface
pure function f(x) result(r)
real, intent(in) :: x
real :: r
end function f
end interface
end subroutine b
end interface new
end module a
submodule(a) a_b
implicit none
contains
module procedure b
x = int(f(real(x)) * 0.1)
end procedure b
end submodule a_b
program test
use a
implicit none
integer :: x
x = 10
call new(x, g)
print *, x
contains
pure function g(y) result(r)
real, intent(in) :: y
real :: r
r = sqrt(y)
end function g
end program test
```
Stack dump:
```console
#0 0x0000559b23dff24d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
#1 0x0000559b23dff8c8 SignalHandler(int) Signals.cpp:0:0
#2 0x00007f9cebb24520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x00007f9cebb78a7c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#4 0x00007f9cebb78a7c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#5 0x00007f9cebb78a7c pthread_kill ./nptl/pthread_kill.c:89:10
#6 0x00007f9cebb24476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#7 0x00007f9cebb0a7f3 abort ./stdlib/abort.c:81:7
#8 0x0000559b24abdc2a Fortran::common::getFlangRepositoryPath[abi:cxx11]()
#9 0x0000559b244fff41 Fortran::semantics::PutLower(llvm::raw_ostream&, std::basic_string_view<char, std::char_traits<char>>) mod-file.cpp:0:0
#10 0x0000559b244fe46a Fortran::semantics::ModFileWriter::PutSymbol(llvm::raw_ostream&, Fortran::semantics::Symbol const&)
#11 0x0000559b244ffa4c Fortran::semantics::ModFileWriter::PutSubprogram(Fortran::semantics::Symbol const&)
#12 0x0000559b244fe46a Fortran::semantics::ModFileWriter::PutSymbol(llvm::raw_ostream&, Fortran::semantics::Symbol const&)
#13 0x0000559b244fdf7f Fortran::semantics::ModFileWriter::PutSymbols(Fortran::semantics::Scope const&)
#14 0x0000559b244fd030 Fortran::semantics::ModFileWriter::Write(Fortran::semantics::Symbol const&)
#15 0x0000559b244fce32 Fortran::semantics::ModFileWriter::WriteOne(Fortran::semantics::Scope const&)
#16 0x0000559b244fce02 Fortran::semantics::ModFileWriter::WriteAll(Fortran::semantics::Scope const&)
#17 0x0000559b244fcdbf Fortran::semantics::ModFileWriter::WriteAll()
#18 0x0000559b243ab6d2 Fortran::semantics::Semantics::Perform()
#19 0x0000559b23e21d7f Fortran::frontend::FrontendAction::runSemanticChecks()
#20 0x0000559b23f4c90a Fortran::frontend::CodeGenAction::beginSourceFileAction()
#21 0x0000559b23e2145d Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&)
#22 0x0000559b23e18cfc Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&)
#23 0x0000559b23e24702 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*)
#24 0x0000559b22e1cb18 fc1_main(llvm::ArrayRef<char const*>, char const*)
#25 0x0000559b22e1bb06 main
#26 0x00007f9cebb0bd90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#27 0x00007f9cebb0be40 call_init ./csu/../csu/libc-start.c:128:20
#28 0x00007f9cebb0be40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#29 0x0000559b22e1b065 _start
flang-new: error: unable to execute command: Aborted
flang-new: error: flang frontend command failed due to signal (use -v to see invocation)
flang-new version 18.0.0 (https://github.com/llvm/llvm-project.git 7afc7db7fc807a4a7ee623db491622698e8edcca)
Target: x86_64-unknown-linux-gnu
Thread model: posix
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWF1v67gR_TX0CxGBImV9PPjB96buLtCii80CfTQoaiSzoUmXpBKnv74gJduSknXuTZ9qOI5EDs-cORyNh-bOyU4DbND6G1o_rnjvD8Zunh-4tebVrWrTvG1-AQtYOuwPgC2crGl6ARYjWrbWHPHB-5NDbIvoDtFdJ0TS6T4xtkN0V_fdf6RSHNGdO5jXfd13iegkYjvZIPaYkrzKSkSZIIhWCSKPiGxRToa3MNoZBeMozbDgHntwPmkrMoweTdMrwHy4w1geT0oK6bE2-rLwMqU92JYLwBpex8FTbwGPGK6vrem91IBrRMszot9xi2h1WR9eAaMDG6bCpfaIllKb3iNa4SAB2-LzuODqbwqAB5dtr4WXRgcHwVOFLbheBTi7cBleFrha-PzA4cz8Mmnnk6CbqfPJXJj5gHIYnikzzszMb4qG4fmeDJ-ur4dhREseuPN9_emeCaM9l9pdDEfgkzUCmiBjfeN5xog9BkYhK4OMUbKobZSKbjFJ0om2gek7pDHaSwQXjtPPkzWd5ceYhxes3v1QCo7Zs9i3y7ohgpRc7gVXKgo75mI3IX-yUvsQVJg4_7lmV_tZ0nWIlm93ku5-ur3NDReJNpmM8bh_Wz-6myo_4XIV_r2y10owxX7yXDzjpj-eguc7FQMjyggmZ0IIWa-rmrKmbWnWYKVejgNr9-aGi9-CoBH5Dxvyn5Y3I8tf98Z5C_yIaD4Kc4sHUZYuvZSixE-y01z9wnWjQsUoh0XjsEvEKfAn8e8KREegoq0E1DXN1pSEOovoTska0d25zPd59qCk7s8Pne6HCZE4k-SIfiPnjK4pmZFjc8yi5IXA-_3JHyzwZv8sldqHnIUjaM_jpiSI7vTJK0R3U7NEILbNMsS2RX7Dz34EP1QKzdVd5KJEbJtO1Fh_hDxddheurBZw-VLcrMhx5-J-RKThEtFdEu_eXAMnF6CNk2dEd5ZLBxGbFohtJxoUc2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