Skip to content

Commit 1866b3a

Browse files
committed
assert that #[rustc_pass_indirectly_in_non_rustic_abis] is respected
1 parent 7354d3d commit 1866b3a

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

compiler/rustc_target/src/callconv/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -703,13 +703,6 @@ impl<'a, Ty> FnAbi<'a, Ty> {
703703
"bpf" => bpf::compute_abi_info(cx, self),
704704
arch => panic!("no lowering implemented for {arch}"),
705705
}
706-
// Double check that any argument types annotated with the
707-
// `#[rustc_pass_indirectly_in_non_rustic_abis]` attribute are passed indirectly.
708-
for arg in &self.args {
709-
if arg.layout.pass_indirectly_in_non_rustic_abis(cx) {
710-
assert!(matches!(arg.mode, PassMode::Indirect { on_stack: false, .. }));
711-
}
712-
}
713706
}
714707

715708
pub fn adjust_for_rust_abi<C>(&mut self, cx: &C)

compiler/rustc_ty_utils/src/abi.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::assert_matches::assert_matches;
12
use std::iter;
23

34
use rustc_abi::Primitive::Pointer;
@@ -388,6 +389,12 @@ fn fn_abi_sanity_check<'tcx>(
388389
if let PassMode::Indirect { on_stack, .. } = arg.mode {
389390
assert!(!on_stack, "rust abi shouldn't use on_stack");
390391
}
392+
} else if arg.layout.pass_indirectly_in_non_rustic_abis(cx) {
393+
assert_matches!(
394+
arg.mode,
395+
PassMode::Indirect { on_stack: false, .. },
396+
"the {spec_abi} ABI does not implement `#[rustc_pass_indirectly_in_non_rustic_abis]`"
397+
);
391398
}
392399

393400
match &arg.mode {

library/core/src/ffi/va_list.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,15 @@ impl<'f> Drop for VaListImpl<'f> {
299299
// This works for now, since `va_end` is a no-op on all current LLVM targets.
300300
}
301301
}
302+
303+
// Checks (via an assert in `compiler/rustc_ty_utils/src/abi.rs`) that the C ABI for the current
304+
// target correctly implements `rustc_pass_indirectly_in_non_rustic_abis`.
305+
const _: () = {
306+
#[repr(C)]
307+
#[rustc_pass_indirectly_in_non_rustic_abis]
308+
struct Type(usize);
309+
310+
const extern "C" fn c(_: Type) {}
311+
312+
c(Type(0))
313+
};

0 commit comments

Comments
 (0)