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

    <tr>
        <th>Summary</th>
        <td>
            [clang] unexpected MultiVersionKind UNREACHABLE executed at /root/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:4327!
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:codegen,
            crash-on-valid,
            clang:frontend:fuzzer
      </td>
    </tr>

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

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

<pre>
    **This testcase is generated by a fuzzer.**

Compiler Explorer: [https://godbolt.org/z/qTe9ajeK7](https://godbolt.org/z/qTe9ajeK7)

This valid code will crash on Clang Trunk and Clang Assertion Trunk.
```cpp
template <typename T_1> int foo();
int __attribute__((target("default"))) foo(void) { return 2; }

int bar() {
  return foo();
}
```

It seems that this goes back to clang-7.

Stack dump:
```
unexpected MultiVersionKind
UNREACHABLE executed at /root/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:4327!
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/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
 #0 0x0000000003bcced8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bcced8)
 #1 0x0000000003bcab9c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bcab9c)
 #2 0x0000000003b18248 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007ab480242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007ab4802969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007ab480242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007ab4802287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x0000000003b23b1a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b23b1a)
 #8 0x000000000401bdac clang::CodeGen::CodeGenModule::emitMultiVersionFunctions()::'lambda0'(clang::FunctionDecl const*)::operator()(clang::FunctionDecl const*) const CodeGenModule.cpp:0:0
 #9 0x00000000078e8f71 clang::ASTContext::forEachMultiversionedFunctionVersion(clang::FunctionDecl const*, llvm::function_ref<void (clang::FunctionDecl*)>) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x78e8f71)
#10 0x0000000004021e32 clang::CodeGen::CodeGenModule::emitMultiVersionFunctions() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4021e32)
#11 0x0000000004023f18 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4023f18)
#12 0x000000000454483e (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#13 0x0000000004542495 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4542495)
#14 0x000000000669945c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x669945c)
#15 0x0000000004542c48 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4542c48)
#16 0x00000000047fe239 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47fe239)
#17 0x000000000477cbde clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x477cbde)
#18 0x00000000048e3a0e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48e3a0e)
#19 0x0000000000ce1c8f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce1c8f)
#20 0x0000000000cd998a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#21 0x0000000004586969 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#22 0x0000000003b186f4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b186f4)
#23 0x0000000004586f5f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#24 0x000000000454c85d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x454c85d)
#25 0x000000000454d94d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x454d94d)
#26 0x0000000004555275 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4555275)
#27 0x0000000000cdeb4f clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcdeb4f)
#28 0x0000000000badae4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbadae4)
#29 0x00007ab480229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#30 0x00007ab480229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#31 0x0000000000cd943e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcd943e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
ASM generation compiler returned: 134
```


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWU1z2zjS_jX0BUUVCX4ffJBl-53MJO-mYk-uKhBsSkhIgAuAjpxfvwWAsghZ9sZTci6bsmMJbHQ__aDR3SCIUmzDAS6D7CrIri_IqLdCXj6yb4SnZZpd1KJ5vAzwMsDL-y1TSIPSlChATKENcJBEQ4PqR0RQO_78CXLhhIPoOoim_1eiH1gHEt3shk5IkEGyREF2tdV6UEGyDPBtgG83oqlFpxdCbgJ8-zPAt_--h4p8g7-KILsOcPnr4riam7e4H0jHGkRFA-gH6zpEJVFbJDhadYRv0L0c-XdEeDN9XyoFUjPB3ZPFpC-P3A8dBjeioR86ogEFyUo_DsBJD-h-HQfJDWJco1aIAJcGUHLlZpjR9ZpoLVk9aliv7fNSE7kBbT_jBloydjrA2Ey0P5OiB8Ea8y0orpAEPUqOcJBcoaC4nntsbNREOstG2A2j_ZznqA4K9i7O9X3QSAH0Cukt0UgbPjcCFKoJ_Y60QNRwFhaL-Zw7bR42Yz-YJTule-SwG4Ca-Pk0dpp9BamY4H8x3jiBv___y81y9cfy6uMNgh3Q0YgSjQJ8K4XQAb7tuoc-HKT4BtR8tTjMMKsDfLsSDfwf8MOnT6IZO1iYxUuWaYKLAMfO0uePN8u7G6TGumcaEVSPGyRhEFIb944Cj-ntWC-o6CcAz3EwpUZQAb61EcU47cYGkN7CFHaGNy0JhQCv0CBhkIKCUtAgJUbphs1MopSgzO4wOXKkqG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