Skip to content

PhantomData fields in repr(C) structs change ABI on aarch64 #56877

Closed
@glandium

Description

@glandium

Take this testcase:

#[repr(C)]
pub struct Foo {
    pub a: f32,
    pub b: f32,
}

#[no_mangle]
pub extern "C" fn foo(f: Foo) -> bool {
    f.a != f.b
}

#[repr(C)]
pub struct Bar {
    pub a: f32,
    pub b: f32,
    pub _unit: std::marker::PhantomData<()>,
}

#[no_mangle]
pub extern "C" fn bar(f: Bar) -> bool {
    f.a != f.b
}

Compile with:

rustc +nightly --target=aarch64-pc-windows-msvc --emit asm test.rs --crate-type staticlib -C opt-level=2

And check the output test.s file:

	.text
	.section	.text,"xr",one_only,foo
	.globl	foo
	.p2align	2
foo:
.seh_proc foo
	fcmp	s0, s1
	cset	w0, ne
	ret
	.section	.xdata,"dr",associative,foo
	.seh_handlerdata
	.section	.text,"xr",one_only,foo
	.seh_endproc

	.section	.text,"xr",one_only,bar
	.globl	bar
	.p2align	2
bar:
.seh_proc bar
	lsr	x8, x0, #32
	fmov	s0, w0
	fmov	s1, w8
	fcmp	s0, s1
	cset	w0, ne
	ret
	.section	.xdata,"dr",associative,bar
	.seh_handlerdata
	.section	.text,"xr",one_only,bar
	.seh_endproc

One would expect foo and bar having the same code, but that's not the case here.

This is the root cause of https://bugzilla.mozilla.org/show_bug.cgi?id=1512519

Metadata

Metadata

Assignees

Labels

A-FFIArea: Foreign function interface (FFI)A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions