<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/143510>143510</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang] fatal internal error: nullptr dereference at /root/llvm-project/flang/lib/Semantics/tools.cpp(358)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            crash-on-invalid,
            flang:frontend
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          k-arrows
      </td>
    </tr>
</table>

<pre>
    Compiling the following invalid program results in fatal internal error.
https://godbolt.org/z/4oo8EYcq6
```f90
module m
  real, target :: r
  pointer(p, r)
end module m

use m, rr => r
print *, rr
end
```

Backtrace:
```console
fatal internal error: nullptr dereference at /root/llvm-project/flang/lib/Semantics/tools.cpp(358)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-llvmflang-trunk-20250610/bin/flang -fc1 -triple x86_64-unknown-linux-gnu -S -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -resource-dir /opt/compiler-explorer/clang-llvmflang-trunk-20250610/lib/clang/21 -mframe-pointer=all -o /app/output.s -x f95 /app/example.f90
 #0 0x0000000003eb6618 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20250610/bin/flang+0x3eb6618)
 #1 0x0000000003eb41d4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x0000778d37a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x0000778d37a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x0000778d37a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x0000778d37a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x0000000005bb67a9 (/opt/compiler-explorer/clang-llvmflang-trunk-20250610/bin/flang+0x5bb67a9)
 #7 0x0000000004a3a968 Fortran::semantics::GetCrayPointer(Fortran::semantics::Symbol const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20250610/bin/flang+0x4a3a968)
 #8 0x0000000004563531 (anonymous namespace)::HlfirDesignatorBuilder::gen(Fortran::common::Reference<Fortran::semantics::Symbol const> const&) ConvertExprToHLFIR.cpp:0:0
 #9 0x000000000458a7ad hlfir::EntityWithAttributes Fortran::common::log2visit::Log2VisitHelper<0ul, 4ul, hlfir::EntityWithAttributes, (anonymous namespace)::HlfirDesignatorBuilder::gen(std::variant<Fortran::common::Reference<Fortran::semantics::Symbol const>, Fortran::evaluate::Component, Fortran::evaluate::ArrayRef, Fortran::evaluate::CoarrayRef, Fortran::evaluate::ComplexPart> const&, bool)::'lambda'(auto const&), std::variant<Fortran::common::Reference<Fortran::semantics::Symbol const>, Fortran::evaluate::Component, Fortran::evaluate::ArrayRef, Fortran::evaluate::CoarrayRef, Fortran::evaluate::ComplexPart> const&>((anonymous namespace)::HlfirDesignatorBuilder::gen(std::variant<Fortran::common::Reference<Fortran::semantics::Symbol const>, Fortran::evaluate::Component, Fortran::evaluate::ArrayRef, Fortran::evaluate::CoarrayRef, Fortran::evaluate::ComplexPart> const&, bool)::'lambda'(auto const&)&&, unsigned long, std::variant<Fortran::common::Reference<Fortran::semantics::Symbol const>, Fortran::evaluate::Component, Fortran::evaluate::ArrayRef, Fortran::evaluate::CoarrayRef, Fortran::evaluate::ComplexPart> const&) ConvertExprToHLFIR.cpp:0:0
#10 0x000000000459dd1c hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::Type<(Fortran::common::TypeCategory)2, 4>>(Fortran::evaluate::Expr<Fortran::evaluate::Type<(Fortran::common::TypeCategory)2, 4>> const&) ConvertExprToHLFIR.cpp:0:0
#11 0x000000000457d74b hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)2>>(Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)2>> const&) ConvertExprToHLFIR.cpp:0:0
#12 0x00000000045b8d8f hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeType>(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&) (.part.0) ConvertExprToHLFIR.cpp:0:0
#13 0x00000000045b9185 Fortran::lower::convertExprToValue(mlir::Location, Fortran::lower::AbstractConverter&, Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&, Fortran::lower::SymMap&, Fortran::lower::StatementContext&) (/opt/compiler-explorer/clang-llvmflang-trunk-20250610/bin/flang+0x45b9185)
#14 0x00000000043096d5 (anonymous namespace)::FirConverter::genExprValue(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&, Fortran::lower::StatementContext&, mlir::Location*) Bridge.cpp:0:0
#15 0x000000000461ca8b genOutputItemList(Fortran::lower::AbstractConverter&, mlir::Value, std::__cxx11::list<Fortran::parser::OutputItem, std::allocator<Fortran::parser::OutputItem>> const&, bool, bool, mlir::Value&, bool) IO.cpp:0:0
#16 0x0000000004623386 mlir::Value genDataTransferStmt<false, false, Fortran::parser::PrintStmt>(Fortran::lower::AbstractConverter&, Fortran::parser::PrintStmt const&) IO.cpp:0:0
#17 0x00000000043427cb (anonymous namespace)::FirConverter::genFIR(Fortran::lower::pft::Evaluation&, bool) (.constprop.0) Bridge.cpp:0:0
#18 0x000000000434629c (anonymous namespace)::FirConverter::lowerFunc(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0
#19 0x0000000004348414 Fortran::lower::LoweringBridge::lower(Fortran::parser::Program const&, Fortran::semantics::SemanticsContext const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20250610/bin/flang+0x4348414)
#20 0x00000000041c1466 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20250610/bin/flang+0x41c1466)
#21 0x0000000003f0dca5 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20250610/bin/flang+0x3f0dca5)
#22 0x0000000003efc757 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20250610/bin/flang+0x3efc757)
#23 0x0000000003f17613 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20250610/bin/flang+0x3f17613)
#24 0x0000000002209eca fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20250610/bin/flang+0x2209eca)
#25 0x00000000020bfbc6 main (/opt/compiler-explorer/clang-llvmflang-trunk-20250610/bin/flang+0x20bfbc6)
#26 0x0000778d37a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#27 0x0000778d37a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#28 0x0000000002208895 _start (/opt/compiler-explorer/clang-llvmflang-trunk-20250610/bin/flang+0x2208895)
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 3e6a704b5fe33aa0e25cc482199985368a8ee6cf)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-llvmflang-trunk-20250610/bin
flang-21: note: diagnostic msg: 
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWktz27oV_jX0BkMNCb4XXiiydeOpOzcTp7fTlQYED2nUIMCCoCL113cAUqbIyA8lUbPJnZsxIQLnfOc7D7xI2pZVAuDaiT440c0V6fSjVNdPLlFKfm2vclnsr1eybhhnokL6EVApOZdfTYu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