Skip to content

Commit 6a0bcd9

Browse files
folkertdevbeetrees
authored andcommitted
assert that #[rustc_pass_indirectly_in_non_rustic_abis] is respected
1 parent a5a5b02 commit 6a0bcd9

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
@@ -702,13 +702,6 @@ impl<'a, Ty> FnAbi<'a, Ty> {
702702
"bpf" => bpf::compute_abi_info(cx, self),
703703
arch => panic!("no lowering implemented for {arch}"),
704704
}
705-
// Double check that any argument types annotated with the
706-
// `#[rustc_pass_indirectly_in_non_rustic_abis]` attribute are passed indirectly.
707-
for arg in &self.args {
708-
if arg.layout.pass_indirectly_in_non_rustic_abis(cx) {
709-
assert!(matches!(arg.mode, PassMode::Indirect { on_stack: false, .. }));
710-
}
711-
}
712705
}
713706

714707
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;
@@ -387,6 +388,12 @@ fn fn_abi_sanity_check<'tcx>(
387388
if let PassMode::Indirect { on_stack, .. } = arg.mode {
388389
assert!(!on_stack, "rust abi shouldn't use on_stack");
389390
}
391+
} else if arg.layout.pass_indirectly_in_non_rustic_abis(cx) {
392+
assert_matches!(
393+
arg.mode,
394+
PassMode::Indirect { on_stack: false, .. },
395+
"the {spec_abi} ABI does not implement `#[rustc_pass_indirectly_in_non_rustic_abis]`"
396+
);
390397
}
391398

392399
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)