[CodeGen] Assertion `paramInfos.size() <= totalArgs && "Did we forget to insert pass_object_size args?"' failed.
Reproducer: https://godbolt.org/z/hjbhx4rzG
void foo(void (*fp)(void *__attribute__((pass_object_size(0))))) {
int p[32];
fp(p);
}
Backtrace:
clang++: /root/llvm-project/llvm/tools/clang/lib/CodeGen/CGCall.cpp:194: void addExtParameterInfosForCall(llvm::SmallVectorImpl<clang::FunctionType::ExtParameterInfo>&, const clang::FunctionProtoType*, unsigned int, unsigned int): Assertion `paramInfos.size() <= totalArgs && "Did we forget to insert pass_object_size args?"' 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++ -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>:1:6: LLVM IR generation of declaration 'foo'
3. <source>:1:6: Generating code for declaration 'foo'
#0 0x00000000045a2e38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45a2e38)
#1 0x000000000459fc74 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x459fc74)
#2 0x00000000045a0294 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45a0294)
#3 0x00000000044dc7a8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007f6a9a842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x00007f6a9a8969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#6 0x00007f6a9a842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#7 0x00007f6a9a8287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#8 0x00007f6a9a82871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#9 0x00007f6a9a839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x0000000004fb9b49 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fb9b49)
#11 0x0000000004fc5b30 arrangeFreeFunctionLikeCall(clang::CodeGen::CodeGenTypes&, clang::CodeGen::CodeGenModule&, clang::CodeGen::CallArgList const&, clang::FunctionType const*, unsigned int, bool) CGCall.cpp:0:0
#12 0x0000000004ab9444 clang::CodeGen::CodeGenFunction::EmitCall(clang::QualType, clang::CodeGen::CGCallee const&, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::Value*, llvm::CallBase**, clang::CodeGen::CGFunctionInfo const**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ab9444)
#13 0x0000000004abaf4d clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4abaf4d)
#14 0x0000000004b2a182 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
#15 0x0000000004b1f690 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#16 0x0000000004b2540c clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b2540c)
#17 0x0000000004a8255e clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a8255e)
#18 0x0000000004ab603d clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ab603d)
#19 0x0000000004c4f1ff clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c4f1ff)
#20 0x0000000004c56f8b clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c56f8b)
#21 0x0000000004cc2ea6 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4cc2ea6)
#22 0x0000000004cd75c4 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4cd75c4)
#23 0x0000000004d48842 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d48842)
#24 0x0000000004d42e34 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d42e34)
#25 0x0000000004d43623 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d43623)
#26 0x0000000004d4ee83 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#27 0x00000000050dac89 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#28 0x00000000050cb0d4 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50cb0d4)
#29 0x0000000006f55054 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f55054)
#30 0x00000000050d8a28 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50d8a28)
#31 0x0000000005409e38 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5409e38)
#32 0x0000000005388868 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5388868)
#33 0x000000000550737d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x550737d)
#34 0x0000000000e0bfcb cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xe0bfcb)
#35 0x0000000000e0292a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#36 0x0000000000e02aad int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#37 0x0000000005149f59 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
#38 0x00000000044dcbe4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44dcbe4)
#39 0x000000000514a5a6 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
#40 0x0000000005108622 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5108622)
#41 0x00000000051095ce 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+++0x51095ce)
#42 0x0000000005111285 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5111285)
#43 0x0000000000e08354 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xe08354)
#44 0x0000000000caf64a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcaf64a)
#45 0x00007f6a9a829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#46 0x00007f6a9a829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#47 0x0000000000e023c5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xe023c5)
Goes back to clang-5: https://godbolt.org/z/4PP5j7n9a
@llvm/issue-subscribers-clang-codegen
Author: k-arrows
Backtrace:
clang++: /root/llvm-project/llvm/tools/clang/lib/CodeGen/CGCall.cpp:194: void addExtParameterInfosForCall(llvm::SmallVectorImpl<clang::FunctionType::ExtParameterInfo>&, const clang::FunctionProtoType*, unsigned int, unsigned int): Assertion `paramInfos.size() <= totalArgs && "Did we forget to insert pass_object_size args?"' 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++ -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>:1:6: LLVM IR generation of declaration 'foo'
3. <source>:1:6: Generating code for declaration 'foo'
#<!-- -->0 0x00000000045a2e38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45a2e38)
#<!-- -->1 0x000000000459fc74 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x459fc74)
#<!-- -->2 0x00000000045a0294 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45a0294)
#<!-- -->3 0x00000000044dc7a8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#<!-- -->4 0x00007f6a9a842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#<!-- -->5 0x00007f6a9a8969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#<!-- -->6 0x00007f6a9a842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#<!-- -->7 0x00007f6a9a8287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#<!-- -->8 0x00007f6a9a82871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#<!-- -->9 0x00007f6a9a839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#<!-- -->10 0x0000000004fb9b49 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fb9b49)
#<!-- -->11 0x0000000004fc5b30 arrangeFreeFunctionLikeCall(clang::CodeGen::CodeGenTypes&, clang::CodeGen::CodeGenModule&, clang::CodeGen::CallArgList const&, clang::FunctionType const*, unsigned int, bool) CGCall.cpp:0:0
#<!-- -->12 0x0000000004ab9444 clang::CodeGen::CodeGenFunction::EmitCall(clang::QualType, clang::CodeGen::CGCallee const&, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::Value*, llvm::CallBase**, clang::CodeGen::CGFunctionInfo const**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ab9444)
#<!-- -->13 0x0000000004abaf4d clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4abaf4d)
#<!-- -->14 0x0000000004b2a182 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
#<!-- -->15 0x0000000004b1f690 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#<!-- -->16 0x0000000004b2540c clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b2540c)
#<!-- -->17 0x0000000004a8255e clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a8255e)
#<!-- -->18 0x0000000004ab603d clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ab603d)
#<!-- -->19 0x0000000004c4f1ff clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c4f1ff)
#<!-- -->20 0x0000000004c56f8b clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c56f8b)
#<!-- -->21 0x0000000004cc2ea6 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4cc2ea6)
#<!-- -->22 0x0000000004cd75c4 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4cd75c4)
#<!-- -->23 0x0000000004d48842 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d48842)
#<!-- -->24 0x0000000004d42e34 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d42e34)
#<!-- -->25 0x0000000004d43623 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d43623)
#<!-- -->26 0x0000000004d4ee83 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#<!-- -->27 0x00000000050dac89 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#<!-- -->28 0x00000000050cb0d4 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50cb0d4)
#<!-- -->29 0x0000000006f55054 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f55054)
#<!-- -->30 0x00000000050d8a28 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50d8a28)
#<!-- -->31 0x0000000005409e38 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5409e38)
#<!-- -->32 0x0000000005388868 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5388868)
#<!-- -->33 0x000000000550737d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x550737d)
#<!-- -->34 0x0000000000e0bfcb cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xe0bfcb)
#<!-- -->35 0x0000000000e0292a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#<!-- -->36 0x0000000000e02aad int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#<!-- -->37 0x0000000005149f59 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
#<!-- -->38 0x00000000044dcbe4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44dcbe4)
#<!-- -->39 0x000000000514a5a6 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
#<!-- -->40 0x0000000005108622 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5108622)
#<!-- -->41 0x00000000051095ce 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+++0x51095ce)
#<!-- -->42 0x0000000005111285 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5111285)
#<!-- -->43 0x0000000000e08354 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xe08354)
#<!-- -->44 0x0000000000caf64a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcaf64a)
#<!-- -->45 0x00007f6a9a829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#<!-- -->46 0x00007f6a9a829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#<!-- -->47 0x0000000000e023c5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xe023c5)
I took a look intoCGCall.cpp and CGExpr.cpp. I think the problem is that the call to EmitCallArgs in CodeGenFunction::EmitCall passes a nullptr as the AC parameter, which causes the lambda MaybeEmitImplicitObjectSize to return early on the check if (!AC.hasFunctionDecl() || I >= AC.getNumParams()). This early return results in not adding the size_t argument and later causes the assertion to fail.
While it is possible to get PassObjectSizeAttr * like MaybeEmitImplicitObjectSize does using TypeLoc, I don’t think it is a good way to fix this, as we would potentially need to extract a DeclRefExpr from infinitely many combinations. Currently, I don’t see a way to get PassObjectSizeAttr * from the FunctionProtoType. A better fix would be to make FunctionProtoType save the necessary information needed by MaybeEmitImplicitObjectSize. Any thoughts on that?