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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] flang-new crashes when DO-iterator exists inside iterator of the same name
        </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/bPnd16ash

Reproducer:
```
program p
  implicit none

  integer :: i, j

  arr(j) = kind([integer:: ((i,i=1,j),i=1,j)])

end program
```

Stack dump:
```console
 #0 0x0000000003525f68 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3525f68)
 #1 0x00000000035238dc SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f98e6842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007f98e68969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007f98e6842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007f98e68287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x0000000001c260d4 Fortran::evaluate::ExpressionAnalyzer::IntegerTypeSpecKind(Fortran::parser::IntegerTypeSpec const&) (.cold) expression.cpp:0:0
 #7 0x0000000003dbe0a0 Fortran::semantics::ScopeHandler::MakeNumericType(Fortran::common::TypeCategory, std::optional<Fortran::parser::KindSelector> const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3dbe0a0)
 #8 0x0000000003de590c std::enable_if<WrapperTrait<Fortran::parser::IntegerTypeSpec>, void>::type Fortran::parser::Walk<Fortran::parser::IntegerTypeSpec, Fortran::semantics::ResolveNamesVisitor>(Fortran::parser::IntegerTypeSpec const&, Fortran::semantics::ResolveNamesVisitor&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3de590c)
 #9 0x0000000003deedc2 std::enable_if<UnionTrait<Fortran::parser::TypeSpec>, void>::type Fortran::parser::Walk<Fortran::parser::TypeSpec, Fortran::semantics::ResolveNamesVisitor>(Fortran::parser::TypeSpec const&, Fortran::semantics::ResolveNamesVisitor&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3deedc2)
#10 0x0000000003deef58 Fortran::semantics::ConstructVisitor::Pre(Fortran::parser::AcSpec const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3deef58)
#11 0x0000000003de3a71 void Fortran::parser::IterativeWalk<Fortran::parser::Expr const, Fortran::semantics::ResolveNamesVisitor, Fortran::parser::Expr::IntrinsicUnary const, Fortran::parser::Expr::IntrinsicBinary const>(Fortran::parser::Expr const&, Fortran::semantics::ResolveNamesVisitor&) resolve-names.cpp:0:0
#12 0x0000000003df4384 void Fortran::parser::Walk<Fortran::parser::ActualArgSpec, Fortran::semantics::ResolveNamesVisitor>(std::__cxx11::list<Fortran::parser::ActualArgSpec, std::allocator<Fortran::parser::ActualArgSpec>> const&, Fortran::semantics::ResolveNamesVisitor&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3df4384)
#13 0x0000000003df4455 Fortran::semantics::ResolveNamesVisitor::HandleCall(Fortran::semantics::Symbol::Flag, Fortran::parser::Call const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3df4455)
#14 0x0000000003de3ac3 void Fortran::parser::IterativeWalk<Fortran::parser::Expr const, Fortran::semantics::ResolveNamesVisitor, Fortran::parser::Expr::IntrinsicUnary const, Fortran::parser::Expr::IntrinsicBinary const>(Fortran::parser::Expr const&, Fortran::semantics::ResolveNamesVisitor&) resolve-names.cpp:0:0
#15 0x0000000003deae54 Fortran::semantics::ResolveNamesVisitor::AnalyzeStmtFunctionStmt(Fortran::parser::StmtFunctionStmt const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3deae54)
#16 0x0000000003df7706 Fortran::semantics::ResolveNamesVisitor::FinishSpecificationPart(std::__cxx11::list<Fortran::parser::DeclarationConstruct, std::allocator<Fortran::parser::DeclarationConstruct>> const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3df7706)
#17 0x0000000003dff4dd Fortran::semantics::ResolveNamesVisitor::Pre(Fortran::parser::SpecificationPart const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3dff4dd)
#18 0x0000000003dfc99b std::enable_if<TupleTrait<Fortran::parser::SpecificationPart>, void>::type Fortran::parser::Walk<Fortran::parser::SpecificationPart, Fortran::semantics::ResolveNamesVisitor>(Fortran::parser::SpecificationPart const&, Fortran::semantics::ResolveNamesVisitor&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3dfc99b)
#19 0x0000000003e1f6dd Fortran::semantics::ResolveNamesVisitor::ResolveSpecificationParts(Fortran::semantics::ProgramTree&) (.part.0) resolve-names.cpp:0:0
#20 0x0000000003e1fb86 Fortran::semantics::ResolveNamesVisitor::Pre(Fortran::parser::ProgramUnit const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3e1fb86)
#21 0x0000000003e20e5f Fortran::semantics::ResolveNames(Fortran::semantics::SemanticsContext&, Fortran::parser::Program const&, Fortran::semantics::Scope&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3e20e5f)
#22 0x0000000003e77711 Fortran::semantics::Semantics::Perform() (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3e77711)
#23 0x0000000003568cc7 Fortran::frontend::FrontendAction::runSemanticChecks() (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3568cc7)
#24 0x0000000003880440 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3880440)
#25 0x00000000035682c5 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x35682c5)
#26 0x0000000003558197 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x3558197)
#27 0x000000000356e52d Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x356e52d)
#28 0x0000000001d5cc68 fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x1d5cc68)
#29 0x0000000001c63d7d main (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x1c63d7d)
#30 0x00007f98e6829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#31 0x00007f98e6829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#32 0x0000000001d5bbce _start (/opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin/flang-new+0x1d5bbce)
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 820f244aa92f11292e59440c9bc5afbdec395b20)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-llvmflang-trunk-20240203/bin
flang-new: note: diagnostic msg: 
```

Of course, this program is invalid. If you use gfortran, the following is obtained.
```
/app/example.f90:6:37:

 6 |   arr(j) = kind([integer:: ((i,i=1,j),i=1,j)])
      | 1
Error: DO-iterator 'i' at (1) is inside iterator of the same name
Compiler returned: 1
```
</pre>
<img width="1px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