[Clang] Assertion `getActiveBits() <= 64 && "Too many bits for uint64_t"' failed with _BitInt.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer: https://godbolt.org/z/ah5ePc3h8
Reduced case (the original case is well-defined):
```c
const _BitInt(67) g28 = 7 << 64
__attribute__((__vector_size__(sizeof(int)))) a3;
as9as9 = a3[g28]
```
Dump:
```
clang: /root/llvm-project/llvm/include/llvm/ADT/APInt.h:1564: uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64 && "Too many bits for uint64_t"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
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
1. parser at end of file
#0 0x00000000044c5bd8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44c5bd8)
#1 0x00000000044c2e34 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44c2e34)
#2 0x00000000044c346c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44c346c)
#3 0x00000000043ffc78 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007b5b52e45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x00007b5b52e9ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x00007b5b52e4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007b5b52e288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x00007b5b52e2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x00007b5b52e3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x0000000000dfcecd (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdfcecd)
#11 0x0000000008248b1f (anonymous namespace)::LValueExprEvaluator::VisitArraySubscriptExpr(clang::ArraySubscriptExpr const*) ExprConstant.cpp:0:0
#12 0x000000000821fa62 clang::StmtVisitorBase::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#13 0x0000000008220e6f EvaluateLValue(clang::Expr const*, (anonymous namespace)::LValue&, (anonymous namespace)::EvalInfo&, bool) ExprConstant.cpp:0:0
#14 0x000000000822b1ca Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#15 0x000000000822bee2 EvaluateAsRValue((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) ExprConstant.cpp:0:0
#16 0x000000000823217e clang::Expr::EvaluateAsRValue(clang::Expr::EvalResult&, clang::ASTContext const&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x823217e)
#17 0x00000000082322fa clang::Expr::isEvaluatable(clang::ASTContext const&, clang::Expr::SideEffectsKind) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x82322fa)
#18 0x00000000081cd04a clang::Expr::isConstantInitializer(clang::ASTContext&, bool, clang::Expr const**) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x81cd04a)
#19 0x00000000081cd08e clang::Expr::isConstantInitializer(clang::ASTContext&, bool, clang::Expr const**) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x81cd08e)
#20 0x0000000007228ab0 clang::Sema::CheckForConstantInitializer(clang::Expr*, unsigned int) (.part.0) SemaDecl.cpp:0:0
#21 0x000000000725d0ee clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x725d0ee)
#22 0x0000000006e6bd61 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6e6bd61)
#23 0x0000000006e8bbd9 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+0x6e8bbd9)
#24 0x0000000006e36d1b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6e36d1b)
#25 0x0000000006e3750f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6e3750f)
#26 0x0000000006e43f78 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6e43f78)
#27 0x0000000006e44ea5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6e44ea5)
#28 0x0000000006e213aa clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6e213aa)
#29 0x0000000004fd9968 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4fd9968)
#30 0x00000000052fad68 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x52fad68)
#31 0x00000000052889dd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x52889dd)
#32 0x00000000053cf4fd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x53cf4fd)
#33 0x0000000000d90b8c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd90b8c)
#34 0x0000000000d878ba ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#35 0x0000000000d87a3d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#36 0x000000000504dd99 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#37 0x0000000004400074 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4400074)
#38 0x000000000504e905 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#39 0x000000000500cbc2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x500cbc2)
#40 0x0000000005011527 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5011527)
#41 0x000000000501ba55 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x501ba55)
#42 0x0000000000d8d0aa clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd8d0aa)
#43 0x0000000000cca86a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcca86a)
#44 0x00007b5b52e2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#45 0x00007b5b52e2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#46 0x0000000000d87265 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd87265)
```
Contributor guide
Research direction
Compile the reduced case from the issue first, then inspect ExprConstant.cpp, especially LValueExprEvaluator::VisitArraySubscriptExpr, and the APInt assertion in llvm/include/llvm/ADT/APInt.h. Done means the reproducer no longer triggers the assertion and regression coverage demonstrates correct handling of the _BitInt index.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100