Skip to content

Commit 6241d35

Browse files
committed
fix handling of ZST in win64 ABI on windows-gnu targets
1 parent 243d2ca commit 6241d35

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

compiler/rustc_abi/src/extern_abi/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ pub fn is_enabled(
192192
s
193193
}
194194

195+
/// Returns whether the ABI is stable to use.
196+
///
197+
/// Note that there is a separate check determining whether the ABI is even supported
198+
/// on the current target; see `fn is_abi_supported` in `rustc_target::spec`.
195199
pub fn is_stable(name: &str) -> Result<(), AbiDisabled> {
196200
match name {
197201
// Stable

compiler/rustc_target/src/callconv/x86_win64.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc_abi::{BackendRepr, Float, Primitive};
22

3+
use super::Conv;
34
use crate::abi::call::{ArgAbi, FnAbi, Reg};
45
use crate::spec::HasTargetSpec;
56

@@ -41,10 +42,12 @@ pub(crate) fn compute_abi_info<Ty>(cx: &impl HasTargetSpec, fn_abi: &mut FnAbi<'
4142
}
4243
for arg in fn_abi.args.iter_mut() {
4344
if arg.is_ignore() {
44-
// x86_64-pc-windows-gnu doesn't ignore ZSTs.
45+
// x86_64-pc-windows-gnu doesn't ignore ZSTs -- except in `extern "win64"`
46+
// functions which are supposed to match MSVC.
4547
if cx.target_spec().os == "windows"
4648
&& cx.target_spec().env == "gnu"
4749
&& arg.layout.is_zst()
50+
&& fn_abi.conv != Conv::X86_64Win64
4851
{
4952
arg.make_indirect_from_ignore();
5053
}

tests/ui/abi/win64-zst.rs

+2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@
2020
#[lang = "sized"]
2121
trait Sized {}
2222

23+
// Should use `mode: Ignore` on *all* targets. This ABI is explicitly
24+
// meant to be the same across the MSVC and GNU targets.
2325
#[rustc_abi(debug)]
2426
extern "win64" fn pass_zst(_: ()) {} //~ ERROR: fn_abi

tests/ui/abi/win64-zst.x86_64-windows-gnu.stderr

+1-12
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
2424
unadjusted_abi_align: $SOME_ALIGN,
2525
},
2626
},
27-
mode: Indirect {
28-
attrs: ArgAttributes {
29-
regular: NoAlias | NoCapture | NonNull | NoUndef,
30-
arg_ext: None,
31-
pointee_size: Size(0 bytes),
32-
pointee_align: Some(
33-
Align(1 bytes),
34-
),
35-
},
36-
meta_attrs: None,
37-
on_stack: false,
38-
},
27+
mode: Ignore,
3928
},
4029
],
4130
ret: ArgAbi {

0 commit comments

Comments
 (0)