Skip to content

Clang assertion failure in UpdateMultiVersionNames() - "Other GD should now be a multiversioned function" when generating code for 'factorial' function #144772

Open
@kappnkappn

Description

@kappnkappn

Compiler explorer: https://godbolt.org/z/sKMz9rcn8
generated by fuzzer

Code:

#define LABEL3(pfx, x) #pfx x
#define LABEL2(pfx, x) LABEL3(pfx, x)
#define LABEL(x) LABEL2(__USER_LABEL_PREFIX__, x)

unsigned int factorial_(unsigned int) __asm__(LABEL("factorial"));

unsigned int __attribute__((target_clones("default,avx"))) factorial(unsigned int i) {
  return i > 1 ? i * factorial_(i - 1) : 1;
}

Stack trace:

clang: /root/llvm-project/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp:2006: void clang::CodeGen::CodeGenModule::UpdateMultiVersionNames(clang::GlobalDecl, const clang::FunctionDecl*, llvm::StringRef&): Assertion `OtherGD.getCanonicalDecl() .getDecl() ->getAsFunction() ->isMultiVersion() && "Other GD should now be a multiversioned function"' failed.
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 -fno-verbose-asm -c --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.	<eof> parser at end of file
2.	<source>:7:60: LLVM IR generation of declaration 'factorial'
3.	<source>:7:60: Generating code for declaration 'factorial'
 #0 0x0000000003fb0f48 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fb0f48)
 #1 0x0000000003faebd4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3faebd4)
 #2 0x0000000003ef3728 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007bd13c642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007bd13c6969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007bd13c642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007bd13c6287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007bd13c62871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007bd13c639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x000000000454e39a clang::CodeGen::CodeGenModule::UpdateMultiVersionNames(clang::GlobalDecl, clang::FunctionDecl const*, llvm::StringRef&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x454e39a)
#10 0x0000000004580aea 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+0x4580aea)
#11 0x000000000458367c clang::CodeGen::CodeGenModule::GetAddrOfFunction(clang::GlobalDecl, llvm::Type*, bool, bool, clang::CodeGen::ForDefinition_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x458367c)
#12 0x0000000004583bd0 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4583bd0)
#13 0x00000000045873c8 clang::CodeGen::CodeGenModule::EmitMultiVersionFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45873c8)
#14 0x000000000457ecd5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x457ecd5)
#15 0x000000000457f353 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x457f353)
#16 0x0000000004589ef3 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#17 0x000000000496e0f6 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#18 0x000000000495dbd4 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x495dbd4)
#19 0x0000000006664364 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6664364)
#20 0x000000000496a288 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x496a288)
#21 0x0000000004c640f5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c640f5)
#22 0x0000000004be13fe clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4be13fe)
#23 0x0000000004d565e9 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4d565e9)
#24 0x0000000000d821df cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd821df)
#25 0x0000000000d78dea ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#26 0x00000000049d0d99 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 0x0000000003ef3bc4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3ef3bc4)
#28 0x00000000049d13af 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 0x000000000499344d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x499344d)
#30 0x00000000049944de 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+0x49944de)
#31 0x000000000499c1e5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x499c1e5)
#32 0x0000000000d7e6ef clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd7e6ef)
#33 0x0000000000c3c994 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc3c994)
#34 0x00007bd13c629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#35 0x00007bd13c629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#36 0x0000000000d78895 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd78895)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.crashPrefer [crash-on-valid] or [crash-on-invalid]generated by fuzzer

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions