Skip to content

Commit fc5e583

Browse files
committed
Warn on unsupported pass modes for extern "C"
cc rust-lang#10
1 parent eb8fd19 commit fc5e583

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/abi/mod.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ fn clif_sig_from_fn_sig<'tcx>(
8181
tcx: TyCtxt<'tcx>,
8282
triple: &target_lexicon::Triple,
8383
sig: FnSig<'tcx>,
84+
span: Span,
8485
is_vtable_fn: bool,
8586
requires_caller_location: bool,
8687
) -> Signature {
@@ -118,7 +119,25 @@ fn clif_sig_from_fn_sig<'tcx>(
118119
.layout_of(ParamEnv::reveal_all().and(tcx.mk_mut_ptr(tcx.mk_unit())))
119120
.unwrap();
120121
}
121-
get_pass_mode(tcx, layout).get_param_ty(tcx).into_iter()
122+
let pass_mode = get_pass_mode(tcx, layout);
123+
if abi != Abi::Rust && abi != Abi::RustCall && abi != Abi::RustIntrinsic {
124+
match pass_mode {
125+
PassMode::NoPass | PassMode::ByVal(_) => {}
126+
PassMode::ByValPair(_, _) | PassMode::ByRef { sized: _ } => {
127+
tcx.sess.span_warn(
128+
span,
129+
&format!(
130+
"Argument of type `{:?}` with pass mode `{:?}` is not yet supported \
131+
for non-rust abi `{}`. Calling this function may result in a crash.",
132+
layout.ty,
133+
pass_mode,
134+
abi,
135+
),
136+
);
137+
}
138+
}
139+
}
140+
pass_mode.get_param_ty(tcx).into_iter()
122141
})
123142
.flatten();
124143

@@ -171,7 +190,7 @@ pub(crate) fn get_function_name_and_sig<'tcx>(
171190
if fn_sig.c_variadic && !support_vararg {
172191
tcx.sess.span_fatal(tcx.def_span(inst.def_id()), "Variadic function definitions are not yet supported");
173192
}
174-
let sig = clif_sig_from_fn_sig(tcx, triple, fn_sig, false, inst.def.requires_caller_location(tcx));
193+
let sig = clif_sig_from_fn_sig(tcx, triple, fn_sig, tcx.def_span(inst.def_id()), false, inst.def.requires_caller_location(tcx));
175194
(tcx.symbol_name(inst).name.as_str().to_string(), sig)
176195
}
177196

@@ -584,6 +603,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
584603
fx.tcx,
585604
fx.triple(),
586605
fn_sig,
606+
span,
587607
is_virtual_call,
588608
false, // calls through function pointers never pass the caller location
589609
);
@@ -654,6 +674,7 @@ pub(crate) fn codegen_drop<'tcx>(
654674
fx.tcx,
655675
fx.triple(),
656676
fn_sig,
677+
span,
657678
true,
658679
false, // `drop_in_place` is never `#[track_caller]`
659680
);

0 commit comments

Comments
 (0)