llvm / llvm/llvm-project

Assertion failure numElts > 1 && "illegal vector length" in isLegalVectorType (SwiftCallingConv.cpp) on a single-element vector type passed via swiftcall

Open
#223,871 2 comments 0 reactions 0 assignees View on GitHub
clang:codegen crash
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Description

Clang crashes lowering a swiftcall-ABI struct/parameter containing a single-element vector type, e.g. `__attribute__((vector_size(8)))` on `long long`.

## Reproduction

Repro.c

```c
typedef long long CVectorOne __attribute__((vector_size(8)));

struct VectorBox { CVectorOne v; };

__attribute__((swiftcall)) void takeVectorBox(struct VectorBox box) {}
```

`$ clang -target x86_64-apple-macosx13.0 -c Repro.c`

```
Assertion failed: (numElts > 1 && "illegal vector length"), function isLegalVectorType, file SwiftCallingConv.cpp, line 696.
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: /Users/hiroshi/upstream-llvm/llvm-project/build/bin/clang -target x86_64-apple-macosx13.0 -c Repro.c
1. parser at end of file
2. Repro.c:5:33: LLVM IR generation of declaration 'takeVectorBox'
3. Repro.c:5:33: Generating code for declaration 'takeVectorBox'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 clang-24 0x000000010716ed2c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 clang-24 0x000000010716c134 llvm::sys::RunSignalHandlers() + 204
2 clang-24 0x000000010716db70 llvm::sys::CleanupOnSignal(unsigned long) + 304
3 clang-24 0x00000001070ab1dc CrashRecoverySignalHandler(int) + 164
4 libsystem_platform.dylib 0x0000000192d64144 _sigtramp + 56
5 libsystem_pthread.dylib 0x0000000192d5997c pthread_kill + 296
6 libsystem_c.dylib 0x0000000192c5c458 abort + 148
7 libsystem_c.dylib 0x0000000192c5b6a0 err + 0
8 clang-24 0x000000010a184368 clang::CodeGen::swiftcall::SwiftAggLowering::addLegalTypedData(llvm::Type*, clang::CharUnits, clang::CharUnits) (.cold.1) + 0
9 clang-24 0x0000000107a7ff38 clang::CodeGen::swiftcall::legalizeVectorType(clang::CodeGen::CodeGenModule&, clang::CharUnits, llvm::VectorType*, llvm::SmallVectorImpl&) + 912
10 clang-24 0x0000000107a7f3cc clang::CodeGen::swiftcall::SwiftAggLowering::addTypedData(llvm::Type*, clang::CharUnits, clang::CharUnits) + 160
11 clang-24 0x0000000107a7f8fc clang::CodeGen::swiftcall::SwiftAggLowering::addTypedData(clang::RecordDecl const*, clang::CharUnits, clang::ASTRecordLayout const&) + 728
12 clang-24 0x0000000107a81828 classifyType(clang::CodeGen::CodeGenModule&, clang::CanQual, bool) + 516
13 clang-24 0x0000000107a81964 clang::CodeGen::swiftcall::computeABIInfo(clang::CodeGen::CodeGenModule&, clang::CodeGen::CGFunctionInfo&) + 96
14 clang-24 0x00000001077450dc clang::CodeGen::CodeGenTypes::findOrInsertCGFunctionInfo(bool, bool, bool, unsigned int, clang::FunctionType::ExtInfo const&, llvm::ArrayRef, clang::CodeGen::RequiredArgs, clang::CanQual, llvm::ArrayRef>) + 676
15 clang-24 0x0000000107741064 clang::CodeGen::CodeGenTypes::arrangeLLVMFunctionInfo(clang::CanQual, clang::CodeGen::FnInfoOpts, llvm::ArrayRef>, clang::FunctionType::ExtInfo, llvm::ArrayRef, clang::CodeGen::RequiredArgs, clang::FunctionDecl const*) + 264
16 clang-24 0x0000000107742ea8 clang::CodeGen::CodeGenTypes::arrangeFunctionDeclaration(clang::GlobalDecl) + 1076
17 clang-24 0x00000001079e6c70 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) + 116
18 clang-24 0x00000001079dfb28 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) + 424
19 clang-24 0x00000001079e3f9c clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) + 1768
20 clang-24 0x00000001079de1a4 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) + 268
21 clang-24 0x0000000107a6644c (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) + 144
22 clang-24 0x00000001079ae3f8 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) + 172
23 clang-24 0x00000001089b68b0 clang::ParseAST(clang::Sema&, bool, bool) + 580
24 clang-24 0x0000000107db7c80 clang::FrontendAction::Execute() + 48
25 clang-24 0x0000000107d465f0 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1144
26 clang-24 0x0000000107e33dbc clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 452
27 clang-24 0x000000010435d9c0 cc1_main(llvm::ArrayRef, char const*, void*) + 1424
28 clang-24 0x000000010435b968 ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) + 1220
29 clang-24 0x000000010435d250 int llvm::function_ref&)>::callback_fn(long, llvm::SmallVectorImpl&) + 60
30 clang-24 0x0000000107b95694 void llvm::function_ref::callback_fn>, std::__1::basic_string, std::__1::allocator>*, bool*) const::$_0>(long) + 32
31 clang-24 0x00000001070aaed8 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) + 168
32 clang-24 0x0000000107b94fe4 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__1::basic_string, std::__1::allocator>*, bool*) const + 288
33 clang-24 0x0000000107b5b80c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 728
34 clang-24 0x0000000107b5bed0 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const + 1328
35 clang-24 0x0000000107b7ce88 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) + 328
36 clang-24 0x000000010435a9c0 clang_main(int, char**, llvm::ToolContext const&) + 4340
37 clang-24 0x0000000104367e30 main + 92
38 dyld 0x0000000192983e80 start + 6688
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 24.0.0git (git@github.com:llvm/llvm-project.git 3018c32171d439dec1b76ef961cc60c0d8db2c6c)
Target: x86_64-apple-macosx13.0
Thread model: posix
InstalledDir: /Users/hiroshi/upstream-llvm/llvm-project/build/bin
Build config: +assertions
clang: note: diagnostic msg:
```

Contributor guide

Open the contributing guide

Research direction

Start with the Repro.c example and run the provided clang command for the x86_64 Apple target. Then inspect SwiftCallingConv.cpp around isLegalVectorType and legalizeVectorType; done means this single-element vector in the swiftcall struct no longer triggers the assertion, with regression coverage for the reproducer.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.