-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move ZST ABI handling to rustc_target
#125854
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ use crate::abi::call::{ | |
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, CastTarget, FnAbi, Reg, Uniform, | ||
}; | ||
use crate::abi::{self, HasDataLayout, Scalar, Size, TyAbiInterface, TyAndLayout}; | ||
use crate::spec::HasTargetSpec; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Sdata { | ||
|
@@ -211,15 +212,22 @@ where | |
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) | ||
where | ||
Ty: TyAbiInterface<'a, C> + Copy, | ||
C: HasDataLayout, | ||
C: HasDataLayout + HasTargetSpec, | ||
{ | ||
if !fn_abi.ret.is_ignore() { | ||
classify_arg(cx, &mut fn_abi.ret, Size::from_bytes(32)); | ||
} | ||
|
||
for arg in fn_abi.args.iter_mut() { | ||
if arg.is_ignore() { | ||
continue; | ||
// sparc64-unknown-linux-{gnu,musl,uclibc} doesn't ignore ZSTs. | ||
if cx.target_spec().os == "linux" | ||
&& matches!(&*cx.target_spec().env, "gnu" | "musl" | "uclibc") | ||
&& arg.layout.is_zst() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This treats all ZST the same, no matter their alignment. So for instance Is catching even aligned ZST the right thing here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clang/GCC pass ZSTs indirectly on these targets regardless of alignment. |
||
{ | ||
arg.make_indirect_force(); | ||
} | ||
return; | ||
} | ||
classify_arg(cx, arg, Size::from_bytes(16)); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
error: fn_abi_of(pass_zst) = FnAbi { | ||
args: [ | ||
ArgAbi { | ||
layout: TyAndLayout { | ||
ty: (), | ||
layout: Layout { | ||
size: Size(0 bytes), | ||
align: AbiAndPrefAlign { | ||
abi: $SOME_ALIGN, | ||
pref: $SOME_ALIGN, | ||
}, | ||
abi: Aggregate { | ||
sized: true, | ||
}, | ||
fields: Arbitrary { | ||
offsets: [], | ||
memory_index: [], | ||
}, | ||
largest_niche: None, | ||
variants: Single { | ||
index: 0, | ||
}, | ||
max_repr_align: None, | ||
unadjusted_abi_align: $SOME_ALIGN, | ||
}, | ||
}, | ||
mode: Ignore, | ||
}, | ||
], | ||
ret: ArgAbi { | ||
layout: TyAndLayout { | ||
ty: (), | ||
layout: Layout { | ||
size: Size(0 bytes), | ||
align: AbiAndPrefAlign { | ||
abi: $SOME_ALIGN, | ||
pref: $SOME_ALIGN, | ||
}, | ||
abi: Aggregate { | ||
sized: true, | ||
}, | ||
fields: Arbitrary { | ||
offsets: [], | ||
memory_index: [], | ||
}, | ||
largest_niche: None, | ||
variants: Single { | ||
index: 0, | ||
}, | ||
max_repr_align: None, | ||
unadjusted_abi_align: $SOME_ALIGN, | ||
}, | ||
}, | ||
mode: Ignore, | ||
}, | ||
c_variadic: false, | ||
fixed_count: 1, | ||
conv: C, | ||
can_unwind: false, | ||
} | ||
--> $DIR/c-zst.rs:27:1 | ||
| | ||
LL | extern "C" fn pass_zst(_: ()) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to give some kind of guidance when it is okay to use this. Presumably
make_indirect
has these checks for a reason?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is only needed for making ignored ZSTs indirect (a specific niche use-case), I've made the method more specific. Since this PR has already merged, I've submitted the changes as #129339.