llvm / llvm/llvm-project

[SPARC] Zero-sized struct arguments consume a stack argument slot in clang, but not in GCC

Open
#213,561 8 comments 0 reactions 1 assignee Claimed by @koachan View on GitHub
ABI backend:Sparc
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

On sparc64 GCC does not store zero-sized arguments on the stack, Clang uses a 64-bit slot for them.

https://godbolt.org/z/a6WqKjYfY

```c
struct E {};
void f(struct E a0, struct E a1, struct E a2, struct E a3,
struct E a4, struct E a5, struct E a6, unsigned char u);

void caller1(void) {
struct E e;
f(e, e, e, e, e, e, e, 0x5A);
}

void g(struct E a0, struct E a1, struct E a2, struct E a3,
struct E a4, struct E a5, struct E a6, struct E a7, unsigned char u);

void caller2(void) {
struct E e;
g(e, e, e, e, e, e, e, e, 0x5A);
}
```

On GCC the `unsigned char` is stored at the same stack offset

```assembly
caller1:
save %sp, -192, %sp
mov 90, %g1
call f, 0
stx %g1, [%sp+2223]
return %i7+8
nop
caller2:
save %sp, -192, %sp
mov 90, %g1
call g, 0
stx %g1, [%sp+2223]
return %i7+8
nop
```

But with clang the stack offset is different (by 8 bytes):

```assembly
caller1:
save %sp, -192, %sp
mov 90, %i0
call f
stx %i0, [%sp+2231]
ret
restore

caller2:
save %sp, -208, %sp
mov 90, %i0
call g
stx %i0, [%sp+2239]
ret
restore
```

Because zero-sized structs are a GNU extension, sparc64 really should follow GCC here. It's even more efficient too.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.