Issue 130850
Summary Clang crashes on inline function with `target_clones` attribute
Labels clang
Assignees
Reporter bi6c
    Clang crashes with an UNREACHABLE assertion when compiling code that combines an extern inline function with a subsequent redeclaration that adds the target_clones attribute. The error occurs during the LLVM IR generation phase.

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

(Generated by fuzzer)

**Code:**
```c
#if __STDC_VERSION__ >= 199901L
#define inline __attribute__((gnu_inline)) inline
#endif

extern inline int func1(void) { return 0; }
inline int __attribute__((target_clones("default,avx"))) func1(void) { return 1; }
```

**Observed Behavior:**

```
<source>:6:27: warning: attribute declaration must precede definition [-Wignored-attributes]
    6 | inline int __attribute__((target_clones("default,avx"))) func1(void) { return 1; }
      |                           ^
<source>:5:19: note: previous definition is here
    5 | extern inline int func1(void) { return 0; }
 |                   ^
None multiversion type isn't valid here
UNREACHABLE executed at /root/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:1961!
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.	<source>:6:58: LLVM IR generation of declaration 'func1'
3.	<source>:6:58: Generating code for declaration 'func1'
 #0 0x0000000003e6dcc8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e6dcc8)
 #1 0x0000000003e6b984 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e6b984)
 #2 0x0000000003db8298 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x0000709700a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000709700a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x0000709700a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x0000709700a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x0000000003dc3bfa (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3dc3bfa)
 #8 0x00000000043dedca getMangledNameImpl(clang::CodeGen::CodeGenModule&, clang::GlobalDecl, clang::NamedDecl const*, bool) CodeGenModule.cpp:0:0
 #9 0x00000000043f57a6 clang::CodeGen::CodeGenModule::UpdateMultiVersionNames(clang::GlobalDecl, clang::FunctionDecl const*, llvm::StringRef&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43f57a6)
#10 0x000000000442d4ca clang::CodeGen::CodeGenModule::GetOrCreateLLVMFunction(llvm::StringRef, llvm::Type*, clang::GlobalDecl, bool, bool, bool, llvm::AttributeList, clang::CodeGen::ForDefinition_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x442d4ca)
#11 0x0000000004430288 clang::CodeGen::CodeGenModule::GetAddrOfFunction(clang::GlobalDecl, llvm::Type*, bool, bool, clang::CodeGen::ForDefinition_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4430288)
#12 0x0000000004430609 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4430609)
#13 0x000000000443364b clang::CodeGen::CodeGenModule::EmitMultiVersionFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x443364b)
#14 0x000000000442b9e5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x442b9e5)
#15 0x000000000442bdcb clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x442bdcb)
#16 0x0000000004436183 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#17 0x00000000048346c6 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#18 0x0000000004824684 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4824684)
#19 0x000000000642f404 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x642f404)
#20 0x0000000004830ea8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4830ea8)
#21 0x0000000004af9d95 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4af9d95)
#22 0x0000000004a7d56e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4a7d56e)
#23 0x0000000004be7f2e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4be7f2e)
#24 0x0000000000d535a7 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd535a7)
#25 0x0000000000d4a36a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#26 0x0000000004879539 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
#27 0x0000000003db8744 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3db8744)
#28 0x0000000004879b2f 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
#29 0x000000000483c07d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x483c07d)
#30 0x000000000483d0fe 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+0x483d0fe)
#31 0x0000000004845015 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4845015)
#32 0x0000000000d4f843 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd4f843)
#33 0x0000000000c17374 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc17374)
#34 0x0000709700a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#35 0x0000709700a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#36 0x0000000000d49e15 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd49e15)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to