[clang] crashes when multiple ownership_returns attributes are applied to a function
Reproducer: https://godbolt.org/z/9qW6b3re8
void *f(int, int)
__attribute__((ownership_returns(used)))
__attribute__((ownership_returns(foo, 2)));
Backtrace:
clang++: /root/llvm-project/llvm/tools/clang/include/clang/AST/Attr.h:350: unsigned int clang::ParamIdx::getSourceIndex() const: Assertion `isValid() && "ParamIdx must be valid"' 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. <source>:3:45: current parser token ';'
#0 0x00000000044ee5a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44ee5a8)
#1 0x00000000044eb3d4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44eb3d4)
#2 0x00000000044eb9f4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44eb9f4)
#3 0x000000000442ac98 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x0000724373e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x0000724373e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#6 0x0000724373e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#7 0x0000724373e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#8 0x0000724373e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#9 0x0000724373e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x00000000071b8a41 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71b8a41)
#11 0x00000000071e3bac handleOwnershipAttr(clang::Sema&, clang::Decl*, clang::ParsedAttr const&) SemaDeclAttr.cpp:0:0
#12 0x00000000071f7633 ProcessDeclAttribute(clang::Sema&, clang::Scope*, clang::Decl*, clang::ParsedAttr const&, clang::Sema::ProcessDeclAttributeOptions const&) (.isra.0) SemaDeclAttr.cpp:0:0
#13 0x00000000071fa79b clang::Sema::ProcessDeclAttributes(clang::Scope*, clang::Decl*, clang::Declarator const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71fa79b)
#14 0x00000000071a84e3 clang::Sema::ActOnFunctionDeclarator(clang::Scope*, clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&, llvm::MutableArrayRef<clang::TemplateParameterList*>, bool&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71a84e3)
#15 0x00000000071aed9b clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71aed9b)
#16 0x00000000071afbb4 clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71afbb4)
#17 0x0000000006dddac3 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dddac3)
#18 0x0000000006deb2ea clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6deb2ea)
#19 0x0000000006da899b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6da899b)
#20 0x0000000006da919f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6da919f)
#21 0x0000000006db0bd1 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6db0bd1)
#22 0x0000000006db1ae5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6db1ae5)
#23 0x0000000006db1ed0 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6db1ed0)
#24 0x0000000006d92a63 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d92a63)
#25 0x0000000004fef9d8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fef9d8)
#26 0x00000000053092c5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x53092c5)
#27 0x0000000005288e0e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5288e0e)
#28 0x0000000005405b2d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5405b2d)
#29 0x0000000000de5fc2 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde5fc2)
#30 0x0000000000ddc8fa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#31 0x0000000000ddca7d 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
#32 0x0000000005058e89 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
#33 0x000000000442b0d4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x442b0d4)
#34 0x00000000050594b6 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
#35 0x0000000005018592 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5018592)
#36 0x000000000501953e 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+++0x501953e)
#37 0x00000000050210f5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50210f5)
#38 0x0000000000de2324 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde2324)
#39 0x0000000000c9954a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc9954a)
#40 0x0000724373e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#41 0x0000724373e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#42 0x0000000000ddc395 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xddc395)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
@llvm/issue-subscribers-clang-frontend
Author: k-arrows
Backtrace:
clang++: /root/llvm-project/llvm/tools/clang/include/clang/AST/Attr.h:350: unsigned int clang::ParamIdx::getSourceIndex() const: Assertion `isValid() && "ParamIdx must be valid"' 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. <source>:3:45: current parser token ';'
#<!-- -->0 0x00000000044ee5a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44ee5a8)
#<!-- -->1 0x00000000044eb3d4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44eb3d4)
#<!-- -->2 0x00000000044eb9f4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44eb9f4)
#<!-- -->3 0x000000000442ac98 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#<!-- -->4 0x0000724373e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#<!-- -->5 0x0000724373e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#<!-- -->6 0x0000724373e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#<!-- -->7 0x0000724373e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#<!-- -->8 0x0000724373e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#<!-- -->9 0x0000724373e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#<!-- -->10 0x00000000071b8a41 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71b8a41)
#<!-- -->11 0x00000000071e3bac handleOwnershipAttr(clang::Sema&, clang::Decl*, clang::ParsedAttr const&) SemaDeclAttr.cpp:0:0
#<!-- -->12 0x00000000071f7633 ProcessDeclAttribute(clang::Sema&, clang::Scope*, clang::Decl*, clang::ParsedAttr const&, clang::Sema::ProcessDeclAttributeOptions const&) (.isra.0) SemaDeclAttr.cpp:0:0
#<!-- -->13 0x00000000071fa79b clang::Sema::ProcessDeclAttributes(clang::Scope*, clang::Decl*, clang::Declarator const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71fa79b)
#<!-- -->14 0x00000000071a84e3 clang::Sema::ActOnFunctionDeclarator(clang::Scope*, clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&, llvm::MutableArrayRef<clang::TemplateParameterList*>, bool&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71a84e3)
#<!-- -->15 0x00000000071aed9b clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71aed9b)
#<!-- -->16 0x00000000071afbb4 clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71afbb4)
#<!-- -->17 0x0000000006dddac3 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dddac3)
#<!-- -->18 0x0000000006deb2ea clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6deb2ea)
#<!-- -->19 0x0000000006da899b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6da899b)
#<!-- -->20 0x0000000006da919f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6da919f)
#<!-- -->21 0x0000000006db0bd1 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6db0bd1)
#<!-- -->22 0x0000000006db1ae5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6db1ae5)
#<!-- -->23 0x0000000006db1ed0 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6db1ed0)
#<!-- -->24 0x0000000006d92a63 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d92a63)
#<!-- -->25 0x0000000004fef9d8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fef9d8)
#<!-- -->26 0x00000000053092c5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x53092c5)
#<!-- -->27 0x0000000005288e0e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5288e0e)
#<!-- -->28 0x0000000005405b2d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5405b2d)
#<!-- -->29 0x0000000000de5fc2 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde5fc2)
#<!-- -->30 0x0000000000ddc8fa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#<!-- -->31 0x0000000000ddca7d 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
#<!-- -->32 0x0000000005058e89 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
#<!-- -->33 0x000000000442b0d4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x442b0d4)
#<!-- -->34 0x00000000050594b6 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
#<!-- -->35 0x0000000005018592 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5018592)
#<!-- -->36 0x000000000501953e 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+++0x501953e)
#<!-- -->37 0x00000000050210f5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50210f5)
#<!-- -->38 0x0000000000de2324 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde2324)
#<!-- -->39 0x0000000000c9954a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc9954a)
#<!-- -->40 0x0000724373e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#<!-- -->41 0x0000724373e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#<!-- -->42 0x0000000000ddc395 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xddc395)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
Goes back to clang-16: https://godbolt.org/z/KeEK5d6h3
Goes back to clang-16: https://godbolt.org/z/KeEK5d6h3
clang-9 might be the first one (I overlooked it because there are a few exceptional versions that don’t crash) https://godbolt.org/z/T8M1f8ev5
It seems that the reproducer here is flaky.
Hi!
This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
- Check that no other contributor is working on this issue. If someone is assigned to the issue or claimed to be working on it, ping the person. After one week without a response, the assignee may be changed.
- Leave a comment indicating that you are working on the issue, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
- Fix the issue locally.
- Run the test suite locally. Remember that the subdirectories under
test/create fine-grained testing targets, so you can e.g. usemake check-clang-astto only run Clang's AST tests. - Create a Git commit.
- Run
git clang-format HEAD~1to format your changes. - Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.
If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.
@llvm/issue-subscribers-good-first-issue
Author: k-arrows
Backtrace:
clang++: /root/llvm-project/llvm/tools/clang/include/clang/AST/Attr.h:350: unsigned int clang::ParamIdx::getSourceIndex() const: Assertion `isValid() && "ParamIdx must be valid"' 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. <source>:3:45: current parser token ';'
#<!-- -->0 0x00000000044ee5a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44ee5a8)
#<!-- -->1 0x00000000044eb3d4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44eb3d4)
#<!-- -->2 0x00000000044eb9f4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44eb9f4)
#<!-- -->3 0x000000000442ac98 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#<!-- -->4 0x0000724373e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#<!-- -->5 0x0000724373e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#<!-- -->6 0x0000724373e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#<!-- -->7 0x0000724373e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#<!-- -->8 0x0000724373e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#<!-- -->9 0x0000724373e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#<!-- -->10 0x00000000071b8a41 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71b8a41)
#<!-- -->11 0x00000000071e3bac handleOwnershipAttr(clang::Sema&, clang::Decl*, clang::ParsedAttr const&) SemaDeclAttr.cpp:0:0
#<!-- -->12 0x00000000071f7633 ProcessDeclAttribute(clang::Sema&, clang::Scope*, clang::Decl*, clang::ParsedAttr const&, clang::Sema::ProcessDeclAttributeOptions const&) (.isra.0) SemaDeclAttr.cpp:0:0
#<!-- -->13 0x00000000071fa79b clang::Sema::ProcessDeclAttributes(clang::Scope*, clang::Decl*, clang::Declarator const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71fa79b)
#<!-- -->14 0x00000000071a84e3 clang::Sema::ActOnFunctionDeclarator(clang::Scope*, clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&, llvm::MutableArrayRef<clang::TemplateParameterList*>, bool&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71a84e3)
#<!-- -->15 0x00000000071aed9b clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71aed9b)
#<!-- -->16 0x00000000071afbb4 clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71afbb4)
#<!-- -->17 0x0000000006dddac3 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dddac3)
#<!-- -->18 0x0000000006deb2ea clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6deb2ea)
#<!-- -->19 0x0000000006da899b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6da899b)
#<!-- -->20 0x0000000006da919f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6da919f)
#<!-- -->21 0x0000000006db0bd1 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6db0bd1)
#<!-- -->22 0x0000000006db1ae5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6db1ae5)
#<!-- -->23 0x0000000006db1ed0 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6db1ed0)
#<!-- -->24 0x0000000006d92a63 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d92a63)
#<!-- -->25 0x0000000004fef9d8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fef9d8)
#<!-- -->26 0x00000000053092c5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x53092c5)
#<!-- -->27 0x0000000005288e0e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5288e0e)
#<!-- -->28 0x0000000005405b2d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5405b2d)
#<!-- -->29 0x0000000000de5fc2 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde5fc2)
#<!-- -->30 0x0000000000ddc8fa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#<!-- -->31 0x0000000000ddca7d 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
#<!-- -->32 0x0000000005058e89 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
#<!-- -->33 0x000000000442b0d4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x442b0d4)
#<!-- -->34 0x00000000050594b6 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
#<!-- -->35 0x0000000005018592 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5018592)
#<!-- -->36 0x000000000501953e 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+++0x501953e)
#<!-- -->37 0x00000000050210f5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50210f5)
#<!-- -->38 0x0000000000de2324 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde2324)
#<!-- -->39 0x0000000000c9954a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc9954a)
#<!-- -->40 0x0000724373e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#<!-- -->41 0x0000724373e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#<!-- -->42 0x0000000000ddc395 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xddc395)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
An issue is here: https://github.com/llvm/llvm-project/blob/66c45a3b4964106abfa6388056fba57edfde216d/clang/lib/Sema/SemaDeclAttr.cpp#L1572
We're not checking I->args_size() before asking for the args_begin() and so we're calling a member function on an invalid pointer there. However, the documentation says:
- Use
ownership_returnsto mark a function as an allocating function. Takes 1 parameter to denote the allocation type.
So it's not clear why this code is written to allow for two arguments:
https://github.com/llvm/llvm-project/blob/66c45a3b4964106abfa6388056fba57edfde216d/clang/lib/Sema/SemaDeclAttr.cpp#L1507 I think that was a mistake that came in with 00e99966c4574b084b5211924f97547930995a15:
CC @haoNoQ @Xazax-hun @steakhal @DonatNagyE as static analyzer owners; I think this might be a good first issue, but I can't tell whether the correct fix is to allow only the identifier argument for ownership_returns (so we reject __attribute__((ownership_returns(foo, 2)))) or is to the diagnostic logic for mismatched indexes (so we check for arg_size() before getting args_begin()).
[...] but I can't tell whether the correct fix is to allow only the identifier argument for ownership_returns (so we reject attribute((ownership_returns(foo, 2)))) or is to the diagnostic logic for mismatched indexes (so we check for arg_size() before getting args_begin()).
I'll be honest. IDK. None of us were here at the time it was added to clang. We only fairly recently tried to reverse-engineer what it does and write some documentation to it as we understand it. I'll have a deeper look to see what's behind this.
I had a look at the attribute and I think the fix is more nuanced. To document my understanding of the attribute, I proposed https://github.com/llvm/llvm-project/pull/191005 to update the docs with my findings.
The fix would be to enforce that if the attribute ownership_returns is present, then they all should have the exact same parameters. Otherwise we should diagnose an error flagging the misuse of this attribute.
If we had this check, then we wouldn't have this crash either.
So, I don't think either of the previously proposed "solutions" are appropriate. @AaronBallman
I think, once I've updated the docs, new contributors could come and work on this; and we shall mark it good-first-issue.
I had a look at the attribute and I think the fix is more nuanced. To document my understanding of the attribute, I proposed #191005 to update the docs with my findings.
The fix would be to enforce that if the attribute
ownership_returnsis present, then they all should have the exact same parameters. Otherwise we should diagnose an error flagging the misuse of this attribute. If we had this check, then we wouldn't have this crash either. So, I don't think either of the previously proposed "solutions" are appropriate. @AaronBallmanI think, once I've updated the docs, new contributors could come and work on this; and we shall mark it
good-first-issue.
Thank you for the research and updated docs! I think the new plan makes sense, my only concern is if we're breaking a lot of code by making non-matching arguments an error, but I have a hard time imagining that's a common scenario.
Now that the docs are updating, marking this as a good first issue.
Hi!
This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
- Check that no other contributor is working on this issue. If someone is assigned to the issue or claimed to be working on it, ping the person. After one week without a response, the assignee may be changed.
- Leave a comment indicating that you are working on the issue, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
- Fix the issue locally.
- Run the test suite locally. Remember that the subdirectories under
test/create fine-grained testing targets, so you can e.g. usemake check-clang-astto only run Clang's AST tests. - Create a Git commit.
- Run
git clang-format HEAD~1to format your changes. - Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.
If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.
@llvm/issue-subscribers-good-first-issue
Author: k-arrows
Backtrace:
clang++: /root/llvm-project/llvm/tools/clang/include/clang/AST/Attr.h:350: unsigned int clang::ParamIdx::getSourceIndex() const: Assertion `isValid() && "ParamIdx must be valid"' 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. <source>:3:45: current parser token ';'
#<!-- -->0 0x00000000044ee5a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44ee5a8)
#<!-- -->1 0x00000000044eb3d4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44eb3d4)
#<!-- -->2 0x00000000044eb9f4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44eb9f4)
#<!-- -->3 0x000000000442ac98 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#<!-- -->4 0x0000724373e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#<!-- -->5 0x0000724373e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#<!-- -->6 0x0000724373e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#<!-- -->7 0x0000724373e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#<!-- -->8 0x0000724373e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#<!-- -->9 0x0000724373e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#<!-- -->10 0x00000000071b8a41 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71b8a41)
#<!-- -->11 0x00000000071e3bac handleOwnershipAttr(clang::Sema&, clang::Decl*, clang::ParsedAttr const&) SemaDeclAttr.cpp:0:0
#<!-- -->12 0x00000000071f7633 ProcessDeclAttribute(clang::Sema&, clang::Scope*, clang::Decl*, clang::ParsedAttr const&, clang::Sema::ProcessDeclAttributeOptions const&) (.isra.0) SemaDeclAttr.cpp:0:0
#<!-- -->13 0x00000000071fa79b clang::Sema::ProcessDeclAttributes(clang::Scope*, clang::Decl*, clang::Declarator const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71fa79b)
#<!-- -->14 0x00000000071a84e3 clang::Sema::ActOnFunctionDeclarator(clang::Scope*, clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&, llvm::MutableArrayRef<clang::TemplateParameterList*>, bool&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71a84e3)
#<!-- -->15 0x00000000071aed9b clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71aed9b)
#<!-- -->16 0x00000000071afbb4 clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71afbb4)
#<!-- -->17 0x0000000006dddac3 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dddac3)
#<!-- -->18 0x0000000006deb2ea clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6deb2ea)
#<!-- -->19 0x0000000006da899b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6da899b)
#<!-- -->20 0x0000000006da919f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6da919f)
#<!-- -->21 0x0000000006db0bd1 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6db0bd1)
#<!-- -->22 0x0000000006db1ae5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6db1ae5)
#<!-- -->23 0x0000000006db1ed0 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6db1ed0)
#<!-- -->24 0x0000000006d92a63 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d92a63)
#<!-- -->25 0x0000000004fef9d8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fef9d8)
#<!-- -->26 0x00000000053092c5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x53092c5)
#<!-- -->27 0x0000000005288e0e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5288e0e)
#<!-- -->28 0x0000000005405b2d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5405b2d)
#<!-- -->29 0x0000000000de5fc2 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde5fc2)
#<!-- -->30 0x0000000000ddc8fa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#<!-- -->31 0x0000000000ddca7d 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
#<!-- -->32 0x0000000005058e89 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
#<!-- -->33 0x000000000442b0d4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x442b0d4)
#<!-- -->34 0x00000000050594b6 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
#<!-- -->35 0x0000000005018592 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5018592)
#<!-- -->36 0x000000000501953e 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+++0x501953e)
#<!-- -->37 0x00000000050210f5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50210f5)
#<!-- -->38 0x0000000000de2324 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde2324)
#<!-- -->39 0x0000000000c9954a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc9954a)
#<!-- -->40 0x0000724373e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#<!-- -->41 0x0000724373e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#<!-- -->42 0x0000000000ddc395 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xddc395)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
@k-arrows I would like to give this a try
@k-arrows I would like to give this a try
We don't assign issues until there is a PR and we can confirm it is moving in the right direction. Although announcing that you plan to work on it helps prevent duplicate effort.
@shafik: Was this issue resolved?