-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Open
Labels
clang:codegenIR generation bugs: mangling, exceptions, etc.IR generation bugs: mangling, exceptions, etc.confirmedVerified by a second partyVerified by a second partycrashPrefer [crash-on-valid] or [crash-on-invalid]Prefer [crash-on-valid] or [crash-on-invalid]good first issuehttps://github.com/llvm/llvm-project/contributehttps://github.com/llvm/llvm-project/contribute
Description
According to the Clang docs , https://clang.llvm.org/docs/AttributeReference.html#target-clones for target_clones attribute:
"This attribute may be attached to a function declaration and causes function multiversioning,"
However, with a simple test, Clang appears to require that the attribute be on the function definition, not just the declaration. When the attribute is only on the declaration and the definition lacks it, Clang crashes in CodeGen with “None multiversion type isn't valid here” and hits an UNREACHABLE.
Clang Version: 21.1.0
__attribute__((target_clones("arch=znver4", "default")))
void foo(int n, double*);
void foo(int n, double* X) {
for ( int i = 0 ; i < n ; i++ ) {
X[i] *= 2.0;
}
}
clang -O3 -c foo.c
None multiversion type isn't valid here
UNREACHABLE executed at /llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:2089!
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: ../llvm_upstream/install_dir/bin/clang -O3 -c foo.c
1. <eof> parser at end of file
2. foo.c:4:6: LLVM IR generation of declaration 'foo'
3. foo.c:4:6: Generating code for declaration 'foo'
#0 0x00007f70faf8f880 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/install_dir/bin/../lib/libLLVMSupport.so.21.1+0x1f8880)
#1 0x00007f70faf8c52f llvm::sys::RunSignalHandlers() (/install_dir/bin/../lib/libLLVMSupport.so.21.1+0x1f552f)
#2 0x00007f70fae7bf98 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f70fa642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f70fa6969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007f70fa6969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007f70fa6969fc pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007f70fa642476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007f70fa6287f3 abort ./stdlib/abort.c:81:7
#9 0x00007f70fae9917e (/install_dir/bin/../lib/libLLVMSupport.so.21.1+0x10217e)
#10 0x00007f70ff3ee8a7 getMangledNameImpl(clang::CodeGen::CodeGenModule&, clang::GlobalDecl, clang::NamedDecl const*, bool) CodeGenModule.cpp:0:0
#11 0x00007f70ff4023f4 clang::CodeGen::CodeGenModule::getMangledName(clang::GlobalDecl) (/install_dir/bin/../lib/libclangCodeGen.so.21.1+0x5983f4)
#12 0x00007f70ff42e8fd clang::CodeGen::CodeGenModule::GetAddrOfFunction(clang::GlobalDecl, llvm::Type*, bool, bool, clang::CodeGen::ForDefinition_t) (/install_dir/bin/../lib/libclangCodeGen.so.21.1+0x5c48fd)
#13 0x00007f70ff42ef01 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) /install_dir/bin/../lib/libclangCodeGen.so.21.1+0x5c4f01)
#14 0x00007f70ff4320f7 clang::CodeGen::CodeGenModule::EmitMultiVersionFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/install_dir/bin/../lib/libclangCodeGen.so.21.1+0x5c80f7)
#15 0x00007f70ff4299c5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/install_dir/bin/../lib/libclangCodeGen.so.21.1+0x5bf9c5)
#16 0x00007f70ff42a790 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/install_dir/bin/../lib/libclangCodeGen.so.21.1+0x5c0790)
#17 0x00007f70ff4342a7 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#18 0x00007f70ff4dbdd0 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#19 0x00007f70ff3a07b1 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/install_dir/bin/../lib/libclangCodeGen.so.21.1+0x5367b1)
#20 0x00007f70f7bf8c74 clang::ParseAST(clang::Sema&, bool, bool) (/install_dir/bin/../lib/../lib/libclangParse.so.21.1+0x42c74)
#21 0x00007f70fd80b5c9 clang::FrontendAction::Execute() (/install_dir/bin/../lib/libclangFrontend.so.21.1+0x1455c9)
#22 0x00007f70fd77be05 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/install_dir/bin/../lib/libclangFrontend.so.21.1+0xb5e05)
#23 0x00007f71000a8c08 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/install_dir/bin/../lib/libclangFrontendTool.so.21.1+0x5c08)
#24 0x0000562a543a85fe cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (../llvm_upstream/install_dir/bin/clang+0x175fe)
#25 0x0000562a5439e81a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#26 0x00007f70fd39569d 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 0x00007f70fae7c440 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/install_dir/bin/../lib/libLLVMSupport.so.21.1+0xe5440)
#28 0x00007f70fd395f3e 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 0x00007f70fd34db91 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/install_dir/bin/../lib/libclangDriver.so.21.1+0x79b91)
#30 0x00007f70fd34ecb1 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/install_dir/bin/../lib/libclangDriver.so.21.1+0x7acb1)
#31 0x00007f70fd35fce4 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/install_dir/bin/../lib/libclangDriver.so.21.1+0x8bce4)
#32 0x0000562a543a40d7 clang_main(int, char**, llvm::ToolContext const&) (../llvm_upstream/install_dir/bin/clang+0x130d7)
#33 0x0000562a5439deeb main (../llvm_upstream/install_dir/bin/clang+0xceeb)
#34 0x00007f70fa629d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#35 0x00007f70fa629e40 call_init ./csu/../csu/libc-start.c:128:20
#36 0x00007f70fa629e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#37 0x0000562a5439df45 _start (../llvm_upstream/install_dir/bin/clang+0xcf45)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 21.1.0 (https://github.com/llvm/llvm-project.git 3623fe661ae35c6c80ac221f14d85be76aa870f1)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /install_dir/bin
Build config: +assertions
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/foo-1c1aca.c
clang: note: diagnostic msg: /tmp/foo-1c1aca.sh
clang: note: diagnostic msg:
********************
Metadata
Metadata
Assignees
Labels
clang:codegenIR generation bugs: mangling, exceptions, etc.IR generation bugs: mangling, exceptions, etc.confirmedVerified by a second partyVerified by a second partycrashPrefer [crash-on-valid] or [crash-on-invalid]Prefer [crash-on-valid] or [crash-on-invalid]good first issuehttps://github.com/llvm/llvm-project/contributehttps://github.com/llvm/llvm-project/contribute