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

    <tr>
        <th>Summary</th>
        <td>
            Crash with assertion failure when compiling c++20 module
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    I was playing around with C++20 modules and came across this crash when trying to include simdjson. Notably this only appeared when i switched to clang18, compilation under clang17 failed for other reason (without crash).

```
FAILED: Profiler/CMakeFiles/profilerLib.dir/modules/Scope.cppm.o Profiler/CMakeFiles/profilerLib.dir/profiler.scope.pcm 
/opt/clang/18.1.8/bin/clang++ -DSIMDJSON_DISABLE_DEPRECATED_API=1 -DSIMDJSON_THREADS_ENABLED=1 -I/home/jonas/Workspace/ModuleTest/cmake-build-debug-clang-18/_deps/simdjson-src/include -g -std=gnu++20 -fcolor-diagnostics -Wall -Wextra -Wpedantic -MD -MT Profiler/CMakeFiles/profilerLib.dir/modules/Scope.cppm.o -MF Profiler/CMakeFiles/profilerLib.dir/modules/Scope.cppm.o.d @Profiler/CMakeFiles/profilerLib.dir/modules/Scope.cppm.o.modmap -o Profiler/CMakeFiles/profilerLib.dir/modules/Scope.cppm.o -c /home/jonas/Workspace/ModuleTest/Profiler/modules/Scope.cppm
clang-18: /home/jonas/.cache/yay/clang-prefixed-release/src/llvm-project-llvmorg-18.1.8/clang/include/clang/AST/Decl.h:4976: void clang::Redeclarable<clang::FunctionDecl>::setPreviousDecl(decl_type *) [decl_type = clang::FunctionDecl]: Assertion `!isa<NamedDecl>(static_cast<decl_type*>(this)) || cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /opt/clang/18.1.8/bin/clang-18 -cc1 -triple x86_64-unknown-linux-gnu -emit-module-interface -disable-free -clear-ast-before-backend -main-file-name Scope.cppm -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -fdebug-compilation-dir=/home/jonas/Workspace/ModuleTest/cmake-build-debug-clang-18 -fcoverage-compilation-dir=/home/jonas/Workspace/ModuleTest/cmake-build-debug-clang-18 -resource-dir /opt/clang/18.1.8/lib/clang/18 -dependency-file Profiler/CMakeFiles/profilerLib.dir/modules/Scope.cppm.o.d -MT Profiler/CMakeFiles/profilerLib.dir/modules/Scope.cppm.o -sys-header-deps -module-file-deps -D SIMDJSON_DISABLE_DEPRECATED_API=1 -D SIMDJSON_THREADS_ENABLED=1 -I /home/jonas/Workspace/ModuleTest/cmake-build-debug-clang-18/_deps/simdjson-src/include -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../include/c++/14.1.1 -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../include/c++/14.1.1/x86_64-pc-linux-gnu -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../include/c++/14.1.1/backward -internal-isystem /opt/clang/18.1.8/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../x86_64-pc-linux-gnu/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wall -Wextra -Wpedantic -std=gnu++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o Profiler/CMakeFiles/profilerLib.dir/profiler.scope.pcm -x c++ /home/jonas/Workspace/ModuleTest/Profiler/modules/Scope.cppm
1.      /home/jonas/Workspace/ModuleTest/cmake-build-debug-clang-18/_deps/simdjson-src/include/simdjson/generic/ondemand/token_iterator.h:136:222: current parser token ';'
2.      /home/jonas/Workspace/ModuleTest/cmake-build-debug-clang-18/_deps/simdjson-src/include/simdjson/generic/ondemand/token_iterator.h:10:1: parsing namespace 'simdjson'
3.      /home/jonas/Workspace/ModuleTest/cmake-build-debug-clang-18/_deps/simdjson-src/include/simdjson/generic/ondemand/token_iterator.h:11:1: parsing namespace 'simdjson::fallback'
4.      /home/jonas/Workspace/ModuleTest/cmake-build-debug-clang-18/_deps/simdjson-src/include/simdjson/generic/ondemand/token_iterator.h:12:1: parsing namespace 'simdjson::fallback::ondemand'
5.      /home/jonas/Workspace/ModuleTest/cmake-build-debug-clang-18/_deps/simdjson-src/include/simdjson/generic/ondemand/token_iterator.h:20:1: parsing struct/union/class body 'simdjson::fallback::ondemand::token_iterator'
#0 0x0000776d4e624767 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/clang/18.1.8/bin/../lib/libLLVM.so.18.1+0x3e24767)
clang++: error: unable to execute command: Aborted (core dumped)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 18.1.8 (https://aur.archlinux.org/clang-prefixed-release.git 5b99959cda7596f74533734675cdc4796a2653c4)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/clang/18.1.8/bin
clang++: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: /tmp/Scope-ed983e.cppm
clang++: note: diagnostic msg: /tmp/Scope-ed983e.sh
clang++: note: diagnostic msg: 

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

[Scope-ed983e.cppm.txt](https://github.com/user-attachments/files/15978031/Scope-ed983e.cppm.txt)
[Scope-ed983e.sh.txt](https://github.com/user-attachments/files/15978032/Scope-ed983e.sh.txt)



</pre>
<img width="1px" height="1px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