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

    <tr>
        <th>Summary</th>
        <td>
            [flang] ICE: not a typeless expr
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          mathomp4
      </td>
    </tr>
</table>

<pre>
    We have encountered a bug in `flang` compilation. We aren't exactly sure what is happening, so I don't have a good description. The `flang` version is:
```
> flang --version
flang version 20.0.0git (git@github.com:GEOS-ESM/build-llvm-flang.git 697744d14fec6505d07f95249388ac2452ee5151)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin
```
so our `flang` is about 3 weeks old. I hope to have time next week to build the latest `flang` from `main` so maybe this is fixed, but I can't confirm this.

Traceback:
```
error: loc("/home/mathomp4/F90Files/flang-repro/reproducer.F90":12:7): not a typeless expr
LLVM ERROR: aborting
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin/flang -fc1 -triple x86_64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -resource-dir /ford1/share/gmao_SIteam/llvm-flang/2024-10-22/lib/clang/20 -mframe-pointer=all -o reproducer.o -x f95-cpp-input reproducer.F90
 #0 0x000000000152e05b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin/flang+0x152e05b)
 #1 0x000000000152b77b SignalHandler(int) Signals.cpp:0:0
 #2 0x0000149a3cbfdd10 __restore_rt (/lib64/libpthread.so.0+0x12d10)
 #3 0x0000149a3b3a052f raise (/lib64/libc.so.6+0x4e52f)
 #4 0x0000149a3b373e65 abort (/lib64/libc.so.6+0x21e65)
 #5 0x0000000000f4b0be llvm::UniqueStringSaver::save(llvm::StringRef) (.cold) StringSaver.cpp:0:0
 #6 0x00000000014b933a (/ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin/flang+0x14b933a)
 #7 0x0000000001d26cd3 (/ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin/flang+0x1d26cd3)
 #8 0x0000000001f5a8a1 mlir::Type (anonymous namespace)::TypeBuilderImpl::genExprType<Fortran::evaluate::FunctionRef<Fortran::evaluate::Type<(Fortran::common::TypeCategory)3, 2>>>(Fortran::evaluate::FunctionRef<Fortran::evaluate::Type<(Fortran::common::TypeCategory)3, 2>> const&) ConvertType.cpp:0:0
 #9 0x0000000001f5ae3a Fortran::lower::TypeBuilder<Fortran::evaluate::Type<(Fortran::common::TypeCategory)3, 1>>::genType(Fortran::lower::AbstractConverter&, Fortran::evaluate::FunctionRef<Fortran::evaluate::Type<(Fortran::common::TypeCategory)3, 1>> const&) (/ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin/flang+0x1f5ae3a)
#10 0x0000000001f47ab4 hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::Type<(Fortran::common::TypeCategory)3, 1>>(Fortran::evaluate::Expr<Fortran::evaluate::Type<(Fortran::common::TypeCategory)3, 1>> const&) ConvertExprToHLFIR.cpp:0:0
#11 0x0000000001f42abe hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)3>>(Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)3>> const&) ConvertExprToHLFIR.cpp:0:0
#12 0x0000000001f50cf1 hlfir::EntityWithAttributes (anonymous namespace)::HlfirBuilder::gen<Fortran::evaluate::SomeType>(Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&) (.part.0) ConvertExprToHLFIR.cpp:0:0
#13 0x0000000001f51073 Fortran::lower::convertExprToHLFIR(mlir::Location, Fortran::lower::AbstractConverter&, Fortran::evaluate::Expr<Fortran::evaluate::SomeType> const&, Fortran::lower::SymMap&, Fortran::lower::StatementContext&) (/ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin/flang+0x1f51073)
#14 0x0000000001d49903 (anonymous namespace)::FirConverter::genDataAssignment(Fortran::evaluate::Assignment const&, Fortran::evaluate::ProcedureRef const*) Bridge.cpp:0:0
#15 0x0000000001d6038a (anonymous namespace)::FirConverter::genAssignment(Fortran::evaluate::Assignment const&) Bridge.cpp:0:0
#16 0x0000000001d75f90 (anonymous namespace)::FirConverter::genFIR(Fortran::lower::pft::Evaluation&, bool) (.constprop.0) Bridge.cpp:0:0
#17 0x0000000001d7a68d (anonymous namespace)::FirConverter::lowerFunc(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0
#18 0x0000000001d7c149 Fortran::lower::LoweringBridge::lower(Fortran::parser::Program const&, Fortran::semantics::SemanticsContext const&) (/ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin/flang+0x1d7c149)
#19 0x0000000001cef409 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin/flang+0x1cef409)
#20 0x000000000156a3f5 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin/flang+0x156a3f5)
#21 0x00000000015599fc Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin/flang+0x15599fc)
#22 0x000000000157258d Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin/flang+0x157258d)
#23 0x0000000001071388 fc1_main(llvm::ArrayRef<char const*>, char const*) (/ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin/flang+0x1071388)
#24 0x0000000000f93dd6 main (/ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin/flang+0xf93dd6)
#25 0x0000149a3b38c7e5 __libc_start_main (/lib64/libc.so.6+0x3a7e5)
#26 0x000000000107035e _start (/ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin/flang+0x107035e)
flang-20: error: unable to execute command: Aborted (core dumped)
flang-20: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 20.0.0git (git@github.com:GEOS-ESM/build-llvm-flang.git 697744d14fec6505d07f95249388ac2452ee5151)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /ford1/share/gmao_SIteam/llvm-flang/2024-10-22/bin
flang-20: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-20: note: diagnostic msg: /home/mathomp4/tmpdir/HConfig-0c62c2
flang-20: note: diagnostic msg: /home/mathomp4/tmpdir/cutdown_module-3b0a59
flang-20: note: diagnostic msg: /home/mathomp4/tmpdir/reproducer-fb6cdb
flang-20: note: diagnostic msg: /home/mathomp4/tmpdir/HConfig-0c62c2.sh
flang-20: note: diagnostic msg:

********************
```

Per instructions here are the preprocessed source files (in a tarfile as it didn't like the separate ones):

[files-from-flang-crash.tar.gz](https://github.com/user-attachments/files/17776857/files-from-flang-crash.tar.gz)

We also have the original files which produced these if needed.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWklz2zoS_jX0pYsqElxEHnxQbCtxjd8kZftNji4QaFJ4IQEOAHqZXz8FkJJMeXlZ7MllUoptAo1evl4AokWNEY1EPA6yD0F2ekQHu1H6uKN2o7o-PaoUfzj-irChtwgomRqkRY0cKFRDA0JCkEd1S2UT5BEw1fWipVYouYCvCFSjDMjSAt5TZtsHMINGuNtQC8LAhvY9SiGbgJyAUXAOXI3kXhqFRikOHA3Toh95Xm9wJvAWtRFKgjBBsgq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