rust-lang / rust-lang/rust

on X86 SysV the ABI of an empty struct is different from Clang and GCC

Open
#161,117 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-ABI C-bug
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

With Clang and GCC

https://godbolt.org/z/rWvcYYajx

typedef struct { } EmptyStruct;
EmptyStruct val_out(void) { EmptyStruct o = {}; return o; }
val_out:
        mov     eax, dword ptr [esp + 4]
        ret     4

But rustc

https://godbolt.org/z/E99cdz69n

#[repr(C)] pub struct EmptyStruct {}

#[unsafe(no_mangle)]
extern "C" fn val_out() -> EmptyStruct { 
    EmptyStruct {}
}

emits only

val_out:
        ret

zero-sized structs are only a GNU extension, but in practice rustc is compatible for most targets.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the difference using the two linked Godbolt examples and compare rustc's x86 SysV ABI handling with the Clang and GCC output for val_out. Determine the expected calling convention for the empty #[repr(C)] struct and define completion as rustc's behavior being resolved or the incompatibility being explicitly justified and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.