Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang hangs building with -std=gnu2x, __attribute((__counted_by__())) #75173

Closed
arndb opened this issue Dec 12, 2023 · 3 comments · Fixed by #75857
Closed

clang hangs building with -std=gnu2x, __attribute((__counted_by__())) #75173

arndb opened this issue Dec 12, 2023 · 3 comments · Fixed by #75857
Labels
clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid] needs-reduction Large reproducer that should be reduced into a simpler form

Comments

@arndb
Copy link

arndb commented Dec 12, 2023

Trying to build the linux kernel with -std=gnu2x ended up never finishing as one file ended up in an endless loop:

clang-18 --target=x86_64-unknown-linux-gnu -S -O2 -D__KERNEL__ -std=gnu2x -Wno-address-of-packed-member -Wno-gnu-variable-sized-type-not-at-end -Wno-constant-logical-operand -fsanitize=array-bounds policy-e3a9a0.c

policy-e3a9a0.c.gz

Sending SIGABRT shows

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: clang-18 --target=x86_64-unknown-linux-gnu -S -O2 -D__KERNEL__ -std=gnu2x -Wno-address-of-packed-member -Wno-gnu-variable-sized-type-not-at-end -Wno-constant-logical-operand -fsanitize=array-bounds policy-e3a9a0.c
1.	/home/arnd/arm-soc/net/netlink/policy.c:485:1: current parser token 'void'
2.	/home/arnd/arm-soc/net/netlink/policy.c:430:5: LLVM IR generation of declaration 'netlink_policy_dump_write'
3.	/home/arnd/arm-soc/net/netlink/policy.c:430:5: Generating code for declaration 'netlink_policy_dump_write'
 #0 0x0000ffff2df64b40 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xd44b40)
 #1 0x0000ffff2df62de8 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xd42de8)
 #2 0x0000ffff2deb4ae8 (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xc94ae8)
 #3 0x0000ffff383307fc (linux-vdso.so.1+0x7fc)
 #4 0x0000ffff36431810 clang::CodeGen::CodeGenFunction::BuildCountedByFieldExpr(clang::Expr const*, clang::ValueDecl const*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cc1810)
 #5 0x0000ffff36431d84 clang::CodeGen::CodeGenFunction::EmitBoundsCheck(clang::Expr const*, clang::Expr const*, llvm::Value*, clang::QualType, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cc1d84)
 #6 0x0000ffff364419c8 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cd19c8)
 #7 0x0000ffff3643404c clang::CodeGen::CodeGenFunction::EmitArraySubscriptExpr(clang::ArraySubscriptExpr const*, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cc404c)
 #8 0x0000ffff3643486c clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cc486c)
 #9 0x0000ffff3642bf08 clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cbbf08)
#10 0x0000ffff36479fe0 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1d09fe0)
#11 0x0000ffff364797c0 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1d097c0)
#12 0x0000ffff3646ee30 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cfee30)
#13 0x0000ffff3642ba9c clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cbba9c)
#14 0x0000ffff3642b994 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cbb994)
#15 0x0000ffff3654cd60 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1ddcd60)
#16 0x0000ffff365560d8 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1de60d8)
#17 0x0000ffff365a2184 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1e32184)
#18 0x0000ffff365c001c clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1e5001c)
#19 0x0000ffff365b9d70 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1e49d70)
#20 0x0000ffff365bd83c clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1e4d83c)
#21 0x0000ffff365b8ad0 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1e48ad0)
#22 0x0000ffff3664fe6c (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1edfe6c)
#23 0x0000ffff36595124 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1e25124)
#24 0x0000ffff352cb3d8 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0xb5b3d8)
#25 0x0000ffff36f4aea0 clang::FrontendAction::Execute() (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x27daea0)
#26 0x0000ffff36edc8c8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x276c8c8)
#27 0x0000ffff36fc07f4 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x28507f4)
#28 0x0000aaab84c71f90 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-18/bin/clang+0x11f90)
#29 0x0000aaab84c6fb64 (/usr/lib/llvm-18/bin/clang+0xfb64)
#30 0x0000ffff36bf1c18 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x2481c18)
#31 0x0000ffff2deb485c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xc9485c)
#32 0x0000ffff36bf1534 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x2481534)
#33 0x0000ffff36bc11e8 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x24511e8)
#34 0x0000ffff36bc13f0 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&, bool) const (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x24513f0)
#35 0x0000ffff36bd8a14 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x2468a14)
#36 0x0000aaab84c6f304 clang_main(int, char**, llvm::ToolContext const&) (/usr/lib/llvm-18/bin/clang+0xf304)
#37 0x0000aaab84c7a8f4 main (/usr/lib/llvm-18/bin/clang+0x1a8f4)
#38 0x0000ffff2cd37780 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#39 0x0000ffff2cd37858 call_init ./csu/../csu/libc-start.c:128:20
#40 0x0000ffff2cd37858 __libc_start_main ./csu/../csu/libc-start.c:347:5
#41 0x0000aaab84c6c9b0 _start (/usr/lib/llvm-18/bin/clang+0xc9b0)
clang-18: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Debian clang version 18.0.0 (++20231211112323+3c1e7fb95e44-1~exp1~20231211112338.393)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang-18: note: diagnostic msg: 
********************
@github-actions github-actions bot added the clang Clang issues not falling into any other category label Dec 12, 2023
@EugeneZelenko EugeneZelenko added clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid] and removed clang Clang issues not falling into any other category labels Dec 12, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 12, 2023

@llvm/issue-subscribers-clang-codegen

Author: None (arndb)

Trying to build the linux kernel with -std=gnu2x ended up never finishing as one file ended up in an endless loop:
clang-18 --target=x86_64-unknown-linux-gnu -S -O2 -D__KERNEL__ -std=gnu2x -Wno-address-of-packed-member -Wno-gnu-variable-sized-type-not-at-end -Wno-constant-logical-operand -fsanitize=array-bounds policy-e3a9a0.c

policy-e3a9a0.c.gz

Sending SIGABRT shows

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: clang-18 --target=x86_64-unknown-linux-gnu -S -O2 -D__KERNEL__ -std=gnu2x -Wno-address-of-packed-member -Wno-gnu-variable-sized-type-not-at-end -Wno-constant-logical-operand -fsanitize=array-bounds policy-e3a9a0.c
1.	/home/arnd/arm-soc/net/netlink/policy.c:485:1: current parser token 'void'
2.	/home/arnd/arm-soc/net/netlink/policy.c:430:5: LLVM IR generation of declaration 'netlink_policy_dump_write'
3.	/home/arnd/arm-soc/net/netlink/policy.c:430:5: Generating code for declaration 'netlink_policy_dump_write'
 #<!-- -->0 0x0000ffff2df64b40 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xd44b40)
 #<!-- -->1 0x0000ffff2df62de8 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xd42de8)
 #<!-- -->2 0x0000ffff2deb4ae8 (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xc94ae8)
 #<!-- -->3 0x0000ffff383307fc (linux-vdso.so.1+0x7fc)
 #<!-- -->4 0x0000ffff36431810 clang::CodeGen::CodeGenFunction::BuildCountedByFieldExpr(clang::Expr const*, clang::ValueDecl const*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cc1810)
 #<!-- -->5 0x0000ffff36431d84 clang::CodeGen::CodeGenFunction::EmitBoundsCheck(clang::Expr const*, clang::Expr const*, llvm::Value*, clang::QualType, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cc1d84)
 #<!-- -->6 0x0000ffff364419c8 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cd19c8)
 #<!-- -->7 0x0000ffff3643404c clang::CodeGen::CodeGenFunction::EmitArraySubscriptExpr(clang::ArraySubscriptExpr const*, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cc404c)
 #<!-- -->8 0x0000ffff3643486c clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cc486c)
 #<!-- -->9 0x0000ffff3642bf08 clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cbbf08)
#<!-- -->10 0x0000ffff36479fe0 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1d09fe0)
#<!-- -->11 0x0000ffff364797c0 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1d097c0)
#<!-- -->12 0x0000ffff3646ee30 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cfee30)
#<!-- -->13 0x0000ffff3642ba9c clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cbba9c)
#<!-- -->14 0x0000ffff3642b994 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1cbb994)
#<!-- -->15 0x0000ffff3654cd60 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef&lt;clang::Attr const*&gt;) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1ddcd60)
#<!-- -->16 0x0000ffff365560d8 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&amp;, bool, clang::CodeGen::AggValueSlot) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1de60d8)
#<!-- -->17 0x0000ffff365a2184 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&amp;) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1e32184)
#<!-- -->18 0x0000ffff365c001c clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1e5001c)
#<!-- -->19 0x0000ffff365b9d70 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1e49d70)
#<!-- -->20 0x0000ffff365bd83c clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1e4d83c)
#<!-- -->21 0x0000ffff365b8ad0 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1e48ad0)
#<!-- -->22 0x0000ffff3664fe6c (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1edfe6c)
#<!-- -->23 0x0000ffff36595124 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x1e25124)
#<!-- -->24 0x0000ffff352cb3d8 clang::ParseAST(clang::Sema&amp;, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0xb5b3d8)
#<!-- -->25 0x0000ffff36f4aea0 clang::FrontendAction::Execute() (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x27daea0)
#<!-- -->26 0x0000ffff36edc8c8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x276c8c8)
#<!-- -->27 0x0000ffff36fc07f4 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x28507f4)
#<!-- -->28 0x0000aaab84c71f90 cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) (/usr/lib/llvm-18/bin/clang+0x11f90)
#<!-- -->29 0x0000aaab84c6fb64 (/usr/lib/llvm-18/bin/clang+0xfb64)
#<!-- -->30 0x0000ffff36bf1c18 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x2481c18)
#<!-- -->31 0x0000ffff2deb485c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref&lt;void ()&gt;) (/usr/lib/llvm-18/bin/../lib/libLLVM-18.so.1+0xc9485c)
#<!-- -->32 0x0000ffff36bf1534 clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt; &gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;*, bool*) const (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x2481534)
#<!-- -->33 0x0000ffff36bc11e8 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&amp;, clang::driver::Command const*&amp;, bool) const (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x24511e8)
#<!-- -->34 0x0000ffff36bc13f0 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt; &gt;&amp;, bool) const (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x24513f0)
#<!-- -->35 0x0000ffff36bd8a14 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt; &gt;&amp;) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18+0x2468a14)
#<!-- -->36 0x0000aaab84c6f304 clang_main(int, char**, llvm::ToolContext const&amp;) (/usr/lib/llvm-18/bin/clang+0xf304)
#<!-- -->37 0x0000aaab84c7a8f4 main (/usr/lib/llvm-18/bin/clang+0x1a8f4)
#<!-- -->38 0x0000ffff2cd37780 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#<!-- -->39 0x0000ffff2cd37858 call_init ./csu/../csu/libc-start.c:128:20
#<!-- -->40 0x0000ffff2cd37858 __libc_start_main ./csu/../csu/libc-start.c:347:5
#<!-- -->41 0x0000aaab84c6c9b0 _start (/usr/lib/llvm-18/bin/clang+0xc9b0)
clang-18: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Debian clang version 18.0.0 (++20231211112323+3c1e7fb95e44-1~exp1~20231211112338.393)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang-18: note: diagnostic msg: 
********************

@shafik
Copy link
Collaborator

shafik commented Dec 12, 2023

@shafik shafik added the needs-reduction Large reproducer that should be reduced into a simpler form label Dec 12, 2023
@nathanchance
Copy link
Member

This is likely the same issue as #75173, which should be fixed by #73730.

bwendling added a commit that referenced this issue Dec 18, 2023
There are many issues that popped up with the counted_by feature. The
patch #73730 has grown too large and approval is blocking Linux testing.

Includes reverts of:
commit 769bc11 ("[Clang] Implement the 'counted_by' attribute
(#68750)")
commit bc09ec6 ("[CodeGen] Revamp counted_by calculations
(#70606)")
commit 1a09cfb ("[Clang] counted_by attr can apply only to C99
flexible array members (#72347)")
commit a76adfb ("[NFC][Clang] Refactor code to calculate flexible
array member size (#72790)")
commit d8447c7 ("[Clang] Correct handling of negative and
out-of-bounds indices (#71877)")
Partial commit b31cd07 ("[Clang] Regenerate test checks (NFC)")

Closes #73168
Closes #75173
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen crash Prefer [crash-on-valid] or [crash-on-invalid] needs-reduction Large reproducer that should be reduced into a simpler form
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants