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

    <tr>
        <th>Summary</th>
        <td>
            clang++ segfault when using import std in module
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    While building a module that has `import std` I get a segfault in clang++ 20 building with a very new cmake.

I am using the flags `-stdlib=libc++ -Xclang -fno-validate-pch` and the linker flags `-stdlib=libc++ -lc++abi`. I have also tested with onl the `-stdlib=libc++` flag and `-stdlib=libc++ -lc++abi` linker flags and get the same error.

The CMake output before the stackdump is:
```
/usr/bin/clang++-20   -stdlib=libc++ -g -std=gnu++23 -MD -MT CMakeFiles/test.dir/test.cpp.o -MF CMakeFiles/test.dir/test.cpp.o.d @CMakeFiles/test.dir/test.cpp.o.modmap -o CMakeFiles/test.dir/test.cpp.o -c /home/jpc0/devel/git/debug/clang20/test.cpp
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
```

I am running on Ubuntu 24.04.1 LTS under WSL if that makes any difference. I do not currenly have a different configuration of OS to test under.

I have a git repo [here](https://github.com/jpc0/clang20importstdsegfault) that has a basic reproduction as well as the relevant preprocessed source and associated run script. 

In the repo run:
```sh
cmake -S . --preset debug
cmake --build build
```
and the crash will happen. All variables passed to cmake is in the CMakePresets debug preset.

```
Ubuntu clang version 20.0.0 (++20250120081916+d35d7f4b13c0-1~exp1~20250120202047.676)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-20/bin
```

```
cmake version 3.31.4-g98de8ec
```

I got clang from the ubuntu repo added video the llvm install script: `deb http://apt.llvm.org/noble/ llvm-toolchain-noble main`
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/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