[clang] crash when applying sizeof to __builtin_shufflevector
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Reproducer:
https://godbolt.org/z/hTEbKfYMj
```cpp
auto foo = sizeof(__builtin_shufflevector);
```
Backtrace:
```console
Unknown builtin type!
UNREACHABLE executed at /root/llvm-project/llvm/tools/clang/lib/AST/ASTContext.cpp:2207!
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 -std=c++20
1. :1:48: current parser token ';'
#0 0x00000000044b9718 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44b9718)
#1 0x00000000044b6974 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44b6974)
#2 0x00000000044b6fac llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44b6fac)
#3 0x00000000043f35c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x000071ee90445330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x000071ee9049ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x000071ee9044527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x000071ee904288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x00000000043fdb5a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43fdb5a)
#9 0x0000000007e1efbb clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7e1efbb)
#10 0x0000000007e1c15b clang::ASTContext::getTypeInfo(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7e1c15b)
#11 0x0000000007e1f21b clang::ASTContext::getTypeInfoInChars(clang::Type const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7e1f21b)
#12 0x0000000007e1f3c2 clang::ASTContext::getTypeSizeInChars(clang::QualType) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7e1f3c2)
#13 0x00000000081d6fb1 HandleSizeof((anonymous namespace)::EvalInfo&, clang::SourceLocation, clang::QualType, clang::CharUnits&, SizeOfType) ExprConstant.cpp:0:0
#14 0x000000000822029f (anonymous namespace)::IntExprEvaluator::VisitUnaryExprOrTypeTraitExpr(clang::UnaryExprOrTypeTraitExpr const*) ExprConstant.cpp:0:0
#15 0x000000000822dd7b clang::StmtVisitorBase::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#16 0x00000000082167af Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#17 0x0000000008252e7b EvaluateInPlace(clang::APValue&, (anonymous namespace)::EvalInfo&, (anonymous namespace)::LValue const&, clang::Expr const*, bool) (.part.0) ExprConstant.cpp:0:0
#18 0x000000000827cf65 clang::Expr::EvaluateAsInitializer(clang::ASTContext const&, clang::VarDecl const*, clang::Expr::EvalResult&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x827cf65)
#19 0x000000000807300c clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl>*, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x807300c)
#20 0x0000000008073582 clang::VarDecl::checkForConstantInitialization(llvm::SmallVectorImpl>&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x8073582)
#21 0x00000000072331d2 clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x72331d2)
#22 0x0000000007246eba clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7246eba)
#23 0x0000000006e571f1 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e571f1)
#24 0x0000000006e77089 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+++0x6e77089)
#25 0x0000000006e2219b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e2219b)
#26 0x0000000006e2298f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e2298f)
#27 0x0000000006e2f3f8 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e2f3f8)
#28 0x0000000006e30335 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e30335)
#29 0x0000000006e30720 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e30720)
#30 0x0000000006e0c7fc clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e0c7fc)
#31 0x0000000004fcee98 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fcee98)
#32 0x00000000052efb78 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52efb78)
#33 0x000000000527d78d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x527d78d)
#34 0x00000000053c439d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x53c439d)
#35 0x0000000000d9173c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd9173c)
#36 0x0000000000d8845a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#37 0x0000000000d885dd int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#38 0x0000000005043169 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#39 0x00000000043f39c4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43f39c4)
#40 0x0000000005043cd5 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#41 0x0000000005002102 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5002102)
#42 0x0000000005006a67 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5006a67)
#43 0x0000000005010fc5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5010fc5)
#44 0x0000000000d8dc4a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd8dc4a)
#45 0x0000000000ccb5ea main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xccb5ea)
#46 0x000071ee9042a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#47 0x000071ee9042a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#48 0x0000000000d87e05 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd87e05)
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 exact C++ snippet and start at ASTContext.cpp:2207, following the ASTContext::getTypeInfoImpl and ExprConstant.cpp HandleSizeof frames from the backtrace. Inspect how __builtin_shufflevector is represented and how similar invalid builtin types are handled. Add a Clang regression test for this reproducer and verify it no longer reaches the assertion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 52/100