llvm / llvm/llvm-project

[clang][diverges-from:gcc][ABI][x86-64] ABI mismatch from GCC when using vector type members with an empty base class

Open
#185,716 3 comments 0 reactions 0 assignees View on GitHub
ABI clang diverges-from:gcc
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Godbolt link: https://godbolt.org/z/84EProx4c. Compile options: `-Og -march=x86-64-v3`.

```c++
#include
template
using vec [[gnu::vector_size(N * sizeof(T))]] = T;
using data_t = vec;

struct Base { };
struct A : Base {
[[no_unique_address]]
data_t data;
};

A f() {
return A{};
}

std::uint64_t f2(A x) {
return x.data[0];
}
```

When using an empty base class, clang passes and returns `A` on stack, but gcc passes and returns `A` in register. Removing the base class makes clang passes and returns `A` in register.

Prossibly related: #183723.

Contributor guide

Open the contributing guide

Research direction

Start with the Godbolt reproducer using clang and GCC with -Og -march=x86-64-v3, then investigate Clang's x86-64 ABI classification for vector-type members, empty bases, and [[no_unique_address]]. Done means Clang passes and returns A in registers, matching GCC, while preserving the behavior when the base class is removed.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.