<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/123075>123075</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] CP2K fails to compile due to assertion 'result && "Fell off the end of a type-switch"'
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
pawosm-arm
</td>
</tr>
</table>
<pre>
I'm building CP2K from this SHA: https://github.com/cp2k/cp2k/commit/3905869e4cb94c1f9fc3fc3ecca6c77dece2aa01 since the next SHA (https://github.com/cp2k/cp2k/commit/4837b70ec08ad54fc946d169bea3b08710f565ab ) introduces a new code which flang cannot compile (see https://github.com/llvm/llvm-project/issues/108827 closed issue but the problem still occurs). Unfortunately, very late in the process, the compilation fails on the https://github.com/cp2k/cp2k/blob/master/src/transport.F file as such:
```
llvm/ADT/TypeSwitch.h:121: llvm::TypeSwitch<T, ResultT>::operator ResultT() [with T = mlir::Type; ResultT = {anonymous}::TargetAArch64::NRegs]: Assertion `result && "Fell off the end of a type-switch"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
```
Execution command line (including `fypp` preprocessing):
```
tools/build_utils/fypp -n src/transport.F transport.F90 mpifort -fno-backslash -c -D__FFTW3 -D__parallel -D__SCALAPACK -ffp-contract=fast -O3 -fopenmp -mcpu=native -ffree-form -D__COMPILE_ARCH="\"Linux-LLVM-flang\"" -D__COMPILE_DATE="\"Tue 14 Jan 23:36:31 UTC 2025\"" -D__COMPILE_HOST="\"host\"" -D__COMPILE_REVISION="\"git:3905869\"" -D__DATA_DIR="\"data\"" -D__SHORT_FILE__="\"transport.F\"" -I'src/' -I'obj/Linux-LLVM-flang/psmp/exts/dbcsr' transport.F90
```
The problem goes away after commenting out the following line: https://github.com/cp2k/cp2k/blob/f8b3abcd3ac413146004a9ebf8d71317c9449627/src/transport.F#L419
</pre>
<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