Skip to content

Commit df7bcd4

Browse files
committed
on Windows, consistently pass ZST by-ref
1 parent fa92272 commit df7bcd4

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

compiler/rustc_target/src/callconv/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -665,11 +665,11 @@ impl<'a, Ty> FnAbi<'a, Ty> {
665665
"x86_64" => match abi {
666666
ExternAbi::SysV64 { .. } => x86_64::compute_abi_info(cx, self),
667667
ExternAbi::Win64 { .. } | ExternAbi::Vectorcall { .. } => {
668-
x86_win64::compute_abi_info(cx, self, abi)
668+
x86_win64::compute_abi_info(cx, self)
669669
}
670670
_ => {
671671
if cx.target_spec().is_like_windows {
672-
x86_win64::compute_abi_info(cx, self, abi)
672+
x86_win64::compute_abi_info(cx, self)
673673
} else {
674674
x86_64::compute_abi_info(cx, self)
675675
}

compiler/rustc_target/src/callconv/x86_win64.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
use rustc_abi::{BackendRepr, ExternAbi, Float, Primitive};
1+
use rustc_abi::{BackendRepr, Float, Primitive};
22

33
use crate::abi::call::{ArgAbi, FnAbi, Reg};
44
use crate::spec::HasTargetSpec;
55

66
// Win64 ABI: https://docs.microsoft.com/en-us/cpp/build/parameter-passing
77

8-
pub(crate) fn compute_abi_info<Ty>(
9-
cx: &impl HasTargetSpec,
10-
fn_abi: &mut FnAbi<'_, Ty>,
11-
abi: ExternAbi,
12-
) {
8+
pub(crate) fn compute_abi_info<Ty>(_cx: &impl HasTargetSpec, fn_abi: &mut FnAbi<'_, Ty>) {
139
let fixup = |a: &mut ArgAbi<'_, Ty>| {
1410
match a.layout.backend_repr {
1511
BackendRepr::Uninhabited | BackendRepr::Memory { sized: false } => {}
@@ -48,16 +44,14 @@ pub(crate) fn compute_abi_info<Ty>(
4844
// Windows ABIs do not talk about ZST since such types do not exist in MSVC.
4945
// In that sense we can do whatever we want here, and maybe we should throw an error
5046
// (but of course that would be a massive breaking change now).
51-
// We try to match clang and gcc, so we make windows-gnu and the native
52-
// Windows ABIs (i.e., everything except for `extern "C"`) pass ZST via
53-
// pointer indirection. windows-msvc `extern "C"` still skips ZST.
54-
if (cx.target_spec().os == "windows" && cx.target_spec().env == "gnu")
55-
|| !matches!(abi, ExternAbi::C { .. })
56-
{
57-
arg.make_indirect_from_ignore();
58-
}
47+
// We try to match clang and gcc (which allow ZST is their windows-gnu targets), so we
48+
// pass ZST via pointer indirection.
49+
arg.make_indirect_from_ignore();
5950
continue;
6051
}
6152
fixup(arg);
6253
}
54+
// FIXME: We should likely also do something about ZST return types, similar to above.
55+
// However, that's non-trivial due to `()`.
56+
// See <https://github.com/rust-lang/unsafe-code-guidelines/issues/552>.
6357
}

tests/codegen/abi-win64-zst.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ extern "fastcall" fn pass_zst_fastcall(_: ()) {}
4141
#[no_mangle]
4242
extern "sysv64" fn pass_zst_sysv64(_: ()) {}
4343

44-
// For `extern "C"` functions, ZST are ignored on windows-msvc.
44+
// For `extern "C"` functions, ZST are ignored on Linux put passed on Windows.
4545

4646
// linux: define void @pass_zst_c()
47-
// windows-msvc: define void @pass_zst_c()
47+
// windows-msvc: define void @pass_zst_c(ptr {{.*}})
4848
// windows-gnu: define void @pass_zst_c(ptr {{.*}})
4949
#[no_mangle]
5050
extern "C" fn pass_zst_c(_: ()) {}

0 commit comments

Comments
 (0)