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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] fatal internal error: CHECK(j >= lb && j - lb < extent) failed at /root/llvm-project/flang/lib/Evaluate/constant.cpp(76)
        </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>
    Reproducible on Godbolt:
https://godbolt.org/z/WsejT7Ya5

Reproducer:
```console
$ cat test.f90
real, parameter :: a(2:3) = 0.0
print *, norm2(a)
end
```

Stack dump:
```console
fatal internal error: CHECK(j >= lb && j - lb < extent) failed at /root/llvm-project/flang/lib/Evaluate/constant.cpp(76)
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-20240327/bin/flang-new -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 -mframe-pointer=all -o /app/output.s -x f95-cpp-input /app/example.f90
 #0 0x0000000003767418 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x3767418)
 #1 0x0000000003764d8c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f7f6ba42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007f7f6ba969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007f7f6ba42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007f7f6ba287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x0000000004be0609 (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x4be0609)
 #7 0x00000000043d794e Fortran::evaluate::ConstantBounds::SubscriptsToOffset(std::vector<long, std::allocator<long>> const&) const (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x43d794e)
 #8 0x00000000043de249 Fortran::evaluate::Constant<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>>::At(std::vector<long, std::allocator<long>> const&) const (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x43de249)
 #9 0x00000000046e8616 Fortran::evaluate::MaxvalMinvalAccumulator<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>, true>::operator()(Fortran::evaluate::value::Real<Fortran::evaluate::value::Integer<32, true, 32, unsigned int, unsigned long>, 24>&, std::vector<long, std::allocator<long>> const&, bool) const (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x46e8616)
#10 0x00000000046e921e Fortran::evaluate::Expr<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>> Fortran::evaluate::FoldNorm2<4>(Fortran::evaluate::FoldingContext&, Fortran::evaluate::FunctionRef<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>>&&) fold-real.cpp:0:0
#11 0x000000000473b9bc Fortran::evaluate::Expr<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>> Fortran::evaluate::FoldIntrinsicFunction<4>(Fortran::evaluate::FoldingContext&, Fortran::evaluate::FunctionRef<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x473b9bc)
#12 0x000000000473cf46 Fortran::evaluate::Expr<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>> Fortran::evaluate::FoldOperation<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>>(Fortran::evaluate::FoldingContext&, Fortran::evaluate::FunctionRef<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x473cf46)
#13 0x000000000472e1de Fortran::evaluate::ExpressionBase<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>>::Rewrite(Fortran::evaluate::FoldingContext&, Fortran::evaluate::Expr<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x472e1de)
#14 0x000000000471bce8 Fortran::evaluate::ExpressionBase<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)1>>::Rewrite(Fortran::evaluate::FoldingContext&, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)1>>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x471bce8)
#15 0x00000000044080f0 Fortran::evaluate::ExpressionBase<Fortran::evaluate::SomeType>::Rewrite(Fortran::evaluate::FoldingContext&, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x44080f0)
#16 0x0000000003fd701b std::optional<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>> Fortran::evaluate::ExpressionAnalyzer::ExprOrVariable<Fortran::parser::Expr>(Fortran::parser::Expr const&, Fortran::parser::CharBlock) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x3fd701b)
#17 0x0000000003fd7d6f Fortran::evaluate::ExpressionAnalyzer::IterativelyAnalyzeSubexpressions(Fortran::parser::Expr const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x3fd7d6f)
#18 0x0000000003fd8105 Fortran::evaluate::ExpressionAnalyzer::Analyze(Fortran::parser::Expr const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x3fd8105)
#19 0x0000000003feaf6c void Fortran::parser::IterativeWalk<Fortran::parser::Expr const, Fortran::semantics::ExprChecker, Fortran::parser::Expr::IntrinsicUnary const, Fortran::parser::Expr::IntrinsicBinary const>(Fortran::parser::Expr const&, Fortran::semantics::ExprChecker&) expression.cpp:0:0
#20 0x0000000003fed050 void Fortran::parser::Walk<Fortran::parser::OutputItem, Fortran::semantics::ExprChecker>(std::__cxx11::list<Fortran::parser::OutputItem, std::allocator<Fortran::parser::OutputItem>> const&, Fortran::semantics::ExprChecker&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x3fed050)
#21 0x0000000003ff73c1 void Fortran::parser::Walk<Fortran::semantics::ExprChecker>(std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>> const&, Fortran::semantics::ExprChecker&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x3ff73c1)
#22 0x0000000003ff885f Fortran::semantics::ExprChecker::Walk(Fortran::parser::Program const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x3ff885f)
#23 0x00000000040f979d Fortran::semantics::Semantics::Perform() (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x40f979d)
#24 0x00000000037ab967 Fortran::frontend::FrontendAction::runSemanticChecks() (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x37ab967)
#25 0x0000000003ad6490 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x3ad6490)
#26 0x00000000037aaf45 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x37aaf45)
#27 0x000000000379acf7 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x379acf7)
#28 0x00000000037b11cd Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x37b11cd)
#29 0x0000000001f493d8 fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x1f493d8)
#30 0x0000000001e4d75d main (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x1e4d75d)
#31 0x00007f7f6ba29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#32 0x00007f7f6ba29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#33 0x0000000001f4833e _start (/opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin/flang-new+0x1f4833e)
flang-new: error: unable to execute command: Aborted (core dumped)
flang-new: error: flang frontend command failed due to signal (use -v to see invocation)
flang-new version 19.0.0git (https://github.com/llvm/llvm-project.git 54a9f0e441c7cc3c954d24cfde00cb933306a9e9)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-llvmflang-trunk-20240327/bin
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWl1v27jS_jXKDSGDImV9XOTCdeLdYN99WzQ9Z3GuAooaOWooUqCo1Nlff0BK_qCTOHW32vYcnKItTJEczjPPzIikhnVdvZYAl8H8XTC_umC9uVf68iFkWqsv3UWhyqfLj9BqVfa8LgQgJdEvqiyUMAFdBPgqwIt7Y9rOtsgqIKv10DtTeh2Q1Z8BWf3RwedP6b_YfBg-_L8VCnonJ0jw8Jcr2SkB41MSI84MMtCZWZXj4akGJgKyRC3TrAEDGlkxdIFYQDIS0AUNSI4CeoXwbJzS6loaFJCFnSeVbkhAMhaQfOgGWR6pcajurWH8AZV9076hbsUME6iWBrRkAoHWyiJEy1-vl78FJPuMAnpt9RIFCkgSkAR9RqFr0SWCjQFprOoVqwWUiFmNV1opE5CVEI9N2Gr1GbhtVoJJa2NRFwFZXT8y0T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