[clang] Assertion `(T->hasSignedIntegerRepresentation() || T->isSignedFixedPointType()) && "Unexpected signed integer or fixed point type"' failed.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer:
https://godbolt.org/z/1aG3KfWKW
```cpp
__builtin_va_list ap;
void foo() {
enum E : char16_t {};
(void)__builtin_va_arg(ap, E);
}
```
Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/AST/ASTContext.cpp:12491: clang::QualType clang::ASTContext::getCorrespondingSignedType(clang::QualType) const: Assertion `(T->hasSignedIntegerRepresentation() || T->isSignedFixedPointType()) && "Unexpected signed integer or fixed point type"' 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
1. :5:32: current parser token ';'
2. :3:12: parsing function body 'foo'
3. :3:12: in compound statement ('{}')
#0 0x00000000044bf168 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44bf168)
#1 0x00000000044bbf94 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44bbf94)
#2 0x00000000044bc5b4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44bc5b4)
#3 0x00000000043fa2f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x000070c58ec42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x000070c58ec969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#6 0x000070c58ec42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#7 0x000070c58ec287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#8 0x000070c58ec2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#9 0x000070c58ec39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x0000000007d71025 clang::ASTContext::getCorrespondingSignedType(clang::QualType) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7d71025)
#11 0x000000000730feb5 clang::Sema::BuildVAArgExpr(clang::SourceLocation, clang::Expr*, clang::TypeSourceInfo*, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x730feb5)
#12 0x0000000007310009 clang::Sema::ActOnVAArg(clang::SourceLocation, clang::Expr*, clang::OpaquePtr, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7310009)
#13 0x0000000006e21584 clang::Parser::ParseBuiltinPrimaryExpression() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e21584)
#14 0x0000000006e18dee clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e18dee)
#15 0x0000000006e1aeb7 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e1aeb7)
#16 0x0000000006e23a28 clang::Parser::ParseParenExpression(clang::ParenParseOption&, bool, clang::ParenExprKind, clang::TypoCorrectionTypeBehavior, clang::OpaquePtr&, clang::SourceLocation&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e23a28)
#17 0x0000000006e19c40 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e19c40)
#18 0x0000000006e1aeb7 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e1aeb7)
#19 0x0000000006e1af49 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e1af49)
#20 0x0000000006e1f569 clang::Parser::ParseExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e1f569)
#21 0x0000000006ea5bf9 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ea5bf9)
#22 0x0000000006e9d024 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9d024)
#23 0x0000000006e9da09 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9da09)
#24 0x0000000006ea637e clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ea637e)
#25 0x0000000006ea6b9a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ea6b9a)
#26 0x0000000006dac9a3 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dac9a3)
#27 0x0000000006de336d 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+++0x6de336d)
#28 0x0000000006d9ff4b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d9ff4b)
#29 0x0000000006da074f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6da074f)
#30 0x0000000006da81d1 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6da81d1)
#31 0x0000000006da90e5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6da90e5)
#32 0x0000000006d8a04a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d8a04a)
#33 0x0000000004fc54c8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fc54c8)
#34 0x00000000052df1f5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52df1f5)
#35 0x000000000525dece clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x525dece)
#36 0x00000000053dc18d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x53dc18d)
#37 0x0000000000dde3c2 cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdde3c2)
#38 0x0000000000dd4cfa ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#39 0x0000000000dd4e7d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#40 0x000000000502f6c9 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#41 0x00000000043fa734 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43fa734)
#42 0x000000000502fcf6 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#43 0x0000000004fee412 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fee412)
#44 0x0000000004fef3be clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fef3be)
#45 0x0000000004ff7085 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ff7085)
#46 0x0000000000dda724 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdda724)
#47 0x0000000000c938ba main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc938ba)
#48 0x000070c58ec29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#49 0x000070c58ec29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#50 0x0000000000dd4795 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdd4795)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```
Contributor guide
Research direction
Reproduce the assertion with the C++ snippet and inspect clang::ASTContext::getCorrespondingSignedType in llvm/tools/clang/lib/AST/ASTContext.cpp, then follow its caller in clang::Sema::BuildVAArgExpr. Determine the expected handling of the enum type in __builtin_va_arg and add regression coverage; done means the reproducer no longer aborts in the frontend.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100