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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] flang-new crashes when NCOPIES argument of REPEAT intrinsic is not a scalar
        </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/xMhx4zfTf

Reproducer:
```console
$ cat test.f90
integer, parameter :: a(1) = 2
character, parameter :: b = '3'
print *, repeat(b,a)
end
```

Stack dump:
```console
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-20240418/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 -resource-dir /opt/compiler-explorer/clang-llvmflang-trunk-20240418/lib/clang/19 -mframe-pointer=all -o /app/output.s -x f95-cpp-input /app/example.f90
 #0 0x00000000036a9c18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x36a9c18)
 #1 0x00000000036a758c SignalHandler(int) Signals.cpp:0:0
 #2 0x000071839ea42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x000071839ea969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x000071839ea42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x000071839ea287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x0000000004365d96 (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x4365d96)
 #7 0x0000000004371e51 Fortran::evaluate::Expr<Fortran::evaluate::Type<(Fortran::common::TypeCategory)3, 1>> Fortran::evaluate::FoldIntrinsicFunction<1>(Fortran::evaluate::FoldingContext&, Fortran::evaluate::FunctionRef<Fortran::evaluate::Type<(Fortran::common::TypeCategory)3, 1>>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x4371e51)
 #8 0x0000000004372613 Fortran::evaluate::Expr<Fortran::evaluate::Type<(Fortran::common::TypeCategory)3, 1>> Fortran::evaluate::FoldOperation<Fortran::evaluate::Type<(Fortran::common::TypeCategory)3, 1>>(Fortran::evaluate::FoldingContext&, Fortran::evaluate::FunctionRef<Fortran::evaluate::Type<(Fortran::common::TypeCategory)3, 1>>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x4372613)
 #9 0x000000000436e785 Fortran::evaluate::ExpressionBase<Fortran::evaluate::Type<(Fortran::common::TypeCategory)3, 1>>::Rewrite(Fortran::evaluate::FoldingContext&, Fortran::evaluate::Expr<Fortran::evaluate::Type<(Fortran::common::TypeCategory)3, 1>>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x436e785)
#10 0x000000000436db35 Fortran::evaluate::ExpressionBase<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)3>>::Rewrite(Fortran::evaluate::FoldingContext&, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)3>>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x436db35)
#11 0x00000000043496ed Fortran::evaluate::ExpressionBase<Fortran::evaluate::SomeType>::Rewrite(Fortran::evaluate::FoldingContext&, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x43496ed)
#12 0x0000000003f17bcb 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-20240418/bin/flang-new+0x3f17bcb)
#13 0x0000000003f1891f Fortran::evaluate::ExpressionAnalyzer::IterativelyAnalyzeSubexpressions(Fortran::parser::Expr const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x3f1891f)
#14 0x0000000003f18cb5 Fortran::evaluate::ExpressionAnalyzer::Analyze(Fortran::parser::Expr const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x3f18cb5)
#15 0x0000000003f2bbfc 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
#16 0x0000000003f2dce0 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-20240418/bin/flang-new+0x3f2dce0)
#17 0x0000000003f38081 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-20240418/bin/flang-new+0x3f38081)
#18 0x0000000003f3947f Fortran::semantics::ExprChecker::Walk(Fortran::parser::Program const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x3f3947f)
#19 0x000000000403ac5d Fortran::semantics::Semantics::Perform() (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x403ac5d)
#20 0x00000000036ee4e7 Fortran::frontend::FrontendAction::runSemanticChecks() (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x36ee4e7)
#21 0x0000000003a18c70 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x3a18c70)
#22 0x00000000036edac5 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x36edac5)
#23 0x00000000036dd407 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x36dd407)
#24 0x00000000036f3d4d Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x36f3d4d)
#25 0x0000000001e7cfc8 fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x1e7cfc8)
#26 0x0000000001d6c7dd main (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x1d6c7dd)
#27 0x000071839ea29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#28 0x000071839ea29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#29 0x0000000001e7bf2e _start (/opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin/flang-new+0x1e7bf2e)
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 823eb1a3252dd773f9c4d92093591f1b39ac27d4)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-llvmflang-trunk-20240418/bin
```

Gfortran properly rejects this program.
```console
$ gfortran test2.f90
test2.f90:3:18:

    3 | print *, repeat(b,a)
      |                  1
Error: ‘ncopies’ argument of ‘repeat’ intrinsic at (1) must be a scalar
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWltz4yry_zTkhZJLQrIuD3nwOPH5p_67O6nJ7O5jCqGWzQaBClDinE-_BZIvUq6eMz5nHtY1F4Oa7v71rxsjgBrD1xLgEs2_oPnVBe3sRunLh4BqrZ7MRamq58tv0GpVdYyXArCS-DdVlUpYFC9QeIXCxcba1rgWWSGyWvdPZ0qvEVn9jshq-_fNNvm9_l734v2_O6Wg93pQGvZ_mJJGCRh6SYIZtdiCsbO6CPteLi2sQSOyxC3VtAELGjtN8QJTRPIIkQKj-AqTXp5tqKbMvjGi9KKIZDEiWT-g1VxajMjCDdDQArWI5CUiS4pI0cuArCaeHyO8s5Q94Kpr2g8Q3v7tenF3jU1XNtxiistu7SwqbbFVeBJdbjddOWOqQWQlxOPuv6DV6j_ALCIrbkwHBpEVprLCXDLRVYDtBjDT1GxwSdmD1ZTB7E0_wxkKi1ut1po2mOp114C0zgmMyEq1zgpTTcsF6AC2rVDaBXbFBJXrwLlT-29Wd_IhICFJwiTKEVmVXCKy6h9KeMJBzSIcWM1bAXibp_dpEnTyQaonGQguu22wlh0O7nDQaBCKUcuVDBpVgcAtZzhoOQsEPILApG9wE7QccGCpXoMNWNs5vUGa4KBxjuHANalpAvMsLd2i-MqlksCBBqM6zSCouP6DMAUvd2KIrKICB03tMi5olTOmUXxFhcCBcnZo2zprnW07OzM42OK6mAesbQMu284eRGBLm1bAoQYwInGIw224-8QpLViUY58XPrPNs-m_3Lp09kx_d9Qjkh-ENH26V8ZqoA0iqct3Lq2vH5L_VL4R-RJuByf3ReRQRBMU2Txn-I6vJRX_R2UlnLV8cKrvNjPWunwN_d-9IjIoyqI8LoAmZE7CAUZPypBk--TqH7CZUbPUu-eHjJyLxzqLtKgZbu1GA63uH7gQpxnw40cGkqnTSZbitfE4T3U-ydKR7vlYN8mzOsa0dHPLSZr9wJHm9JizJE7nVZGeJ2MG5SPr2dh6FsE8wi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