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

    <tr>
        <th>Summary</th>
        <td>
            Clang frontend segmentation fault when using a scoped static variable as a template argument inside a template
        </td>
    </tr>

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

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

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

<pre>
    Command: `clang++ -std=c++17 Test.cpp`
Source file:
```
template <unsigned Strs>
static auto join_v = 0;

template<typename T>
void foo()
{
        static constexpr unsigned scoped_static = 123;
        auto bar = join_v<scoped_static>;
}

int main()
{
        foo<int>();
        return 0;
}
```

Output:
```
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: D:\\Programming\\LLVM\\bin\\clang++.exe -cc1 -triple x86_64-pc-windows-msvc19.34.31937 -emit-obj -mrelax-all -mincremental-linker-compatible --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Test.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -fcoverage-compilation-dir=D:\\Programming\\Medusa\\clang_crash -resource-dir D:\\Programming\\LLVM\\lib\\clang\\15.0.6 -internal-isystem D:\\Programming\\LLVM\\lib\\clang\\15.0.6\\include -internal-isystem G:\\VisualStudio\\2022\\Community\\VC\\Tools\\MSVC\\14.34.31933\\include -internal-isystem G:\\VisualStudio\\2022\\Community\\VC\\Tools\\MSVC\\14.34.31933\\atlmfc\\include -internal-isystem "D:\\Windows Kits\\10\\Include\\10.0.22000.0\\ucrt" -internal-isystem "D:\\Windows Kits\\10\\Include\\10.0.22000.0\\shared" -internal-isystem "D:\\Windows Kits\\10\\Include\\10.0.22000.0\\um" -internal-isystem "D:\\Windows Kits\\10\\Include\\10.0.22000.0\\winrt" -internal-isystem "D:\\Windows Kits\\10\\Include\\10.0.22000.0\\cppwinrt" -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=D:\\Programming\\Medusa\\clang_crash -ferror-limit 19 -fmessage-length=120 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.34.31937 -fdelayed-template-parsing -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -o C:\\Users\\AUGUST~1\\AppData\\Local\\Temp\\Test-14f1b4.o -x c++ Test.cpp
1.      Test.cpp:8:34: current parser token ';'
2. Test.cpp:6:1: parsing function body 'foo'
3.      Test.cpp:6:1: in compound statement ('{}')
Exception Code: 0xC0000005
 #0 0x00007ff70dda46da (D:\Programming\LLVM\bin\clang++.exe+0x39446da)
 #1 0x00007ff70ddeddb5 (D:\Programming\LLVM\bin\clang++.exe+0x398ddb5)
 #2 0x00007ff70bdbc31d (D:\Programming\LLVM\bin\clang++.exe+0x195c31d)
 #3 0x00007ff70dda84dd (D:\Programming\LLVM\bin\clang++.exe+0x39484dd)
 #4 0x00007ff70ddab9a4 (D:\Programming\LLVM\bin\clang++.exe+0x394b9a4)
 #5 0x00007ff70d4dcb33 (D:\Programming\LLVM\bin\clang++.exe+0x307cb33)
 #6 0x00007ff70ddade5f (D:\Programming\LLVM\bin\clang++.exe+0x394de5f)
 #7 0x00007ff70ddac49e (D:\Programming\LLVM\bin\clang++.exe+0x394c49e)
 #8 0x00007ff70ddab9f8 (D:\Programming\LLVM\bin\clang++.exe+0x394b9f8)
 #9 0x00007ff70d0cf8e8 (D:\Programming\LLVM\bin\clang++.exe+0x2c6f8e8)
#10 0x00007ff70d0cfd1b (D:\Programming\LLVM\bin\clang++.exe+0x2c6fd1b)
#11 0x00007ff70d0d03e2 (D:\Programming\LLVM\bin\clang++.exe+0x2c703e2)
#12 0x00007ff70e2f7c39 (D:\Programming\LLVM\bin\clang++.exe+0x3e97c39)
#13 0x00007ff70e2f44fe (D:\Programming\LLVM\bin\clang++.exe+0x3e944fe)
#14 0x00007ff70e2ee4de (D:\Programming\LLVM\bin\clang++.exe+0x3e8e4de)
#15 0x00007ff70e2edf45 (D:\Programming\LLVM\bin\clang++.exe+0x3e8df45)
#16 0x00007ff70e33aa3f (D:\Programming\LLVM\bin\clang++.exe+0x3edaa3f)
#17 0x00007ff70e338d96 (D:\Programming\LLVM\bin\clang++.exe+0x3ed8d96)
#18 0x00007ff70e34283e (D:\Programming\LLVM\bin\clang++.exe+0x3ee283e)
#19 0x00007ff70e343b86 (D:\Programming\LLVM\bin\clang++.exe+0x3ee3b86)
#20 0x00007ff70e2e14f4 (D:\Programming\LLVM\bin\clang++.exe+0x3e814f4)
#21 0x00007ff70d2852b5 (D:\Programming\LLVM\bin\clang++.exe+0x2e252b5)
#22 0x00007ff70d287d69 (D:\Programming\LLVM\bin\clang++.exe+0x2e27d69)
#23 0x00007ff70bdbe69b (D:\Programming\LLVM\bin\clang++.exe+0x195e69b)
#24 0x00007ff70bdbf0b6 (D:\Programming\LLVM\bin\clang++.exe+0x195f0b6)
#25 0x00007ff70df800a7 (D:\Programming\LLVM\bin\clang++.exe+0x3b200a7)
#26 0x00007ff70d59dffe (D:\Programming\LLVM\bin\clang++.exe+0x313dffe)
#27 0x00007ff70bea6cc2 (D:\Programming\LLVM\bin\clang++.exe+0x1a46cc2)
#28 0x00007ff70ac3580d (D:\Programming\LLVM\bin\clang++.exe+0x7d580d)
#29 0x00007ff70acc6e9e (D:\Programming\LLVM\bin\clang++.exe+0x866e9e)
#30 0x00007ff70a467b1b (D:\Programming\LLVM\bin\clang++.exe+0x7b1b)
#31 0x00007ff70a464a73 (D:\Programming\LLVM\bin\clang++.exe+0x4a73)
#32 0x00007ff70a46480f (D:\Programming\LLVM\bin\clang++.exe+0x480f)
#33 0x00007ff70e64a730 (D:\Programming\LLVM\bin\clang++.exe+0x41ea730)
#34 0x00007ffb80887614 (C:\Windows\System32\KERNEL32.DLL+0x17614)
#35 0x00007ffb826a26a1 (C:\Windows\SYSTEM32\ntdll.dll+0x526a1)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 15.0.6
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\Programming\LLVM\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: C:\Users\AUGUST~1\AppData\Local\Temp\Test-704475.cpp
clang++: note: diagnostic msg: C:\Users\AUGUST~1\AppData\Local\Temp\Test-704475.sh
clang++: note: diagnostic msg:

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

The crash occurs if a static variable that is scoped to a template function is used as a template argument for a const reference.

To the report I attach a zip with the `Test.cpp` input file and the 2 output files of the crash. I didn't run `creduce` since this is already only 15 lines with no includes.
[clang_crash.zip](https://github.com/llvm/llvm-project/files/10691534/clang_crash.zip)

Let me know if I can be of further help.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWV9v47ay_zTKy4CGRP2x9JCHrJ1sg6bdRZNtcZ8WFDmy2ZVIgaQSpw_3s19Qkh3T3b2np-oenCBIJP75_YacGXI0w6yVO4V4HeXvonx7xQa31-b6kQ1GKzkcrmotXq83uuuYElF6A1ER85apXUTfRfQdEOtElG759Jqs4QmtW_G-j4o4irdRfPOoB8MRGtlilN5Mbb5z-h1fHXZ9yxxClG4GNQok4NEZG6W30wjrmJMc2OA0_K6l-vwMUbqFOErfzYgBUJRu3GuPinUITyeQZy0FNFpHtIxoNc9bnwCqmYRrZR0eegMnWSzXPYrP8wDPnND0jLsaBauZGfsmAaN0E0zzYpxmrLfnYkvloGNSfUswL3O6kcp5jGnMGbdBNxh1vhcn9HCbp78fBtcP7luq-Phwe_N4C3aoO-mAQT3swGCvjQOnYe9cb_1UehfRu510-6Fecd1F9K5tn4__SG_078hdRO-ktQPaiN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