[clang] Assertion `llvm::isUIntN(BitWidth, val) && "Value is not an N-bit unsigned value"' failed with -m32
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer:
https://godbolt.org/z/dsbe7bs83
```cpp
struct T {
template struct S {
T data;
};
void *operator new[](unsigned int) {}
S foo[2147483647u];
};
void bar() {
T t;
new T;
}
```
Backtrace:
```console
clang++: /root/llvm-project/llvm/include/llvm/ADT/APInt.h:127: llvm::APInt::APInt(unsigned int, uint64_t, bool, bool): Assertion `llvm::isUIntN(BitWidth, val) && "Value is not an N-bit unsigned value"' 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 -m32
1. :13:8: current parser token ';'
2. :11:12: parsing function body 'bar'
3. :11:12: in compound statement ('{}')
#0 0x0000000004494808 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4494808)
#1 0x0000000004491a64 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4491a64)
#2 0x000000000449209c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x449209c)
#3 0x00000000043cedd8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x0000741596245330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x000074159629ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x000074159624527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007415962288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x000074159622881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x000074159623b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x0000000000df5e69 llvm::APInt::APInt(unsigned int, unsigned long, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdf5e69)
#11 0x0000000007487824 clang::Sema::BuildCXXNew(clang::SourceRange, bool, clang::SourceLocation, llvm::MutableArrayRef, clang::SourceLocation, clang::SourceRange, clang::QualType, clang::TypeSourceInfo*, std::optional, clang::SourceRange, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7487824)
#12 0x00000000074899f6 clang::Sema::ActOnCXXNew(clang::SourceLocation, bool, clang::SourceLocation, llvm::MutableArrayRef, clang::SourceLocation, clang::SourceRange, clang::Declarator&, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x74899f6)
#13 0x0000000006e8cda2 clang::Parser::ParseCXXNewExpression(bool, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e8cda2)
#14 0x0000000006e74821 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e74821)
#15 0x0000000006e75e07 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e75e07)
#16 0x0000000006e75e99 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e75e99)
#17 0x0000000006e7a5e9 clang::Parser::ParseExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e7a5e9)
#18 0x0000000006f07299 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f07299)
#19 0x0000000006efeb8f clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6efeb8f)
#20 0x0000000006eff506 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6eff506)
#21 0x0000000006f07a7e clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f07a7e)
#22 0x0000000006f0829a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f0829a)
#23 0x0000000006e0485e clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e0485e)
#24 0x0000000006e4e236 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+++0x6e4e236)
#25 0x0000000006df892b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6df892b)
#26 0x0000000006df911f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6df911f)
#27 0x0000000006e05b88 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e05b88)
#28 0x0000000006e06ac5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e06ac5)
#29 0x0000000006de2e9a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6de2e9a)
#30 0x0000000004fa9bc8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fa9bc8)
#31 0x00000000052c9b68 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52c9b68)
#32 0x000000000525767d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x525767d)
#33 0x000000000539e32d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x539e32d)
#34 0x0000000000d8d90c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd8d90c)
#35 0x0000000000d8460a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#36 0x0000000000d8478d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#37 0x000000000501d149 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#38 0x00000000043cf1d4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43cf1d4)
#39 0x000000000501dcb5 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#40 0x0000000004fdc272 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fdc272)
#41 0x0000000004fe0bd7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fe0bd7)
#42 0x0000000004feb065 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4feb065)
#43 0x0000000000d89dfa clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd89dfa)
#44 0x0000000000cc7a5a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc7a5a)
#45 0x000074159622a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#46 0x000074159622a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#47 0x0000000000d83fb5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd83fb5)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Program terminated with signal SIGABRT (6)
Compiler returned: 134
```
Contributor guide
Research direction
Reproduce the assertion with the linked example using clang++ -m32. Start in clang::Sema::BuildCXXNew and inspect the llvm::APInt assertion in llvm/include/llvm/ADT/APInt.h, then trace the path from ParseCXXNewExpression. Done means the reproducer no longer aborts and a regression test covers this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100