Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e8423b7

Browse files
authored
Unrolled build for rust-lang#135808
Rollup merge of rust-lang#135808 - tiif:conv_display, r=workingjubilee Implement Display for ``rustc_target::callconv::Conv`` Follow up of rust-lang#133103 (comment)
2 parents 2c12b4a + 41a2260 commit e8423b7

15 files changed

+58
-27
lines changed

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
353353
if caller_fn_abi.conv != callee_fn_abi.conv {
354354
throw_ub_custom!(
355355
fluent::const_eval_incompatible_calling_conventions,
356-
callee_conv = format!("{:?}", callee_fn_abi.conv),
357-
caller_conv = format!("{:?}", caller_fn_abi.conv),
356+
callee_conv = format!("{}", callee_fn_abi.conv),
357+
caller_conv = format!("{}", caller_fn_abi.conv),
358358
)
359359
}
360360

compiler/rustc_target/src/callconv/mod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::fmt::Display;
12
use std::str::FromStr;
23
use std::{fmt, iter};
34

@@ -895,6 +896,37 @@ impl FromStr for Conv {
895896
}
896897
}
897898

899+
fn conv_to_externabi(conv: &Conv) -> ExternAbi {
900+
match conv {
901+
Conv::C => ExternAbi::C { unwind: false },
902+
Conv::Rust => ExternAbi::Rust,
903+
Conv::PreserveMost => ExternAbi::RustCold,
904+
Conv::ArmAapcs => ExternAbi::Aapcs { unwind: false },
905+
Conv::CCmseNonSecureCall => ExternAbi::CCmseNonSecureCall,
906+
Conv::CCmseNonSecureEntry => ExternAbi::CCmseNonSecureEntry,
907+
Conv::Msp430Intr => ExternAbi::Msp430Interrupt,
908+
Conv::GpuKernel => ExternAbi::GpuKernel,
909+
Conv::X86Fastcall => ExternAbi::Fastcall { unwind: false },
910+
Conv::X86Intr => ExternAbi::X86Interrupt,
911+
Conv::X86Stdcall => ExternAbi::Stdcall { unwind: false },
912+
Conv::X86ThisCall => ExternAbi::Thiscall { unwind: false },
913+
Conv::X86VectorCall => ExternAbi::Vectorcall { unwind: false },
914+
Conv::X86_64SysV => ExternAbi::SysV64 { unwind: false },
915+
Conv::X86_64Win64 => ExternAbi::Win64 { unwind: false },
916+
Conv::AvrInterrupt => ExternAbi::AvrInterrupt,
917+
Conv::AvrNonBlockingInterrupt => ExternAbi::AvrNonBlockingInterrupt,
918+
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Machine } => ExternAbi::RiscvInterruptM,
919+
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Supervisor } => ExternAbi::RiscvInterruptS,
920+
Conv::Cold | Conv::PreserveAll => unreachable!(),
921+
}
922+
}
923+
924+
impl Display for Conv {
925+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
926+
write!(f, "{}", conv_to_externabi(self))
927+
}
928+
}
929+
898930
// Some types are used a lot. Make sure they don't unintentionally get bigger.
899931
#[cfg(target_pointer_width = "64")]
900932
mod size_asserts {

src/tools/miri/src/helpers.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -932,12 +932,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
932932
self.read_c_str_with_char_size(ptr, wchar_t.size, wchar_t.align.abi)
933933
}
934934

935-
/// Check that the ABI is what we expect.
936-
fn check_abi<'a>(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, exp_abi: Conv) -> InterpResult<'a, ()> {
935+
/// Check that the calling convention is what we expect.
936+
fn check_callconv<'a>(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, exp_abi: Conv) -> InterpResult<'a, ()> {
937937
if fn_abi.conv != exp_abi {
938938
throw_ub_format!(
939-
"calling a function with ABI {:?} using caller ABI {:?}",
940-
exp_abi,
939+
"calling a function with calling convention {exp_abi} using caller calling convention {}",
941940
fn_abi.conv
942941
);
943942
}
@@ -973,7 +972,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
973972
exp_abi: Conv,
974973
link_name: Symbol,
975974
) -> InterpResult<'tcx, ()> {
976-
self.check_abi(abi, exp_abi)?;
975+
self.check_callconv(abi, exp_abi)?;
977976
if let Some((body, instance)) = self.eval_context_mut().lookup_exported_symbol(link_name)? {
978977
// If compiler-builtins is providing the symbol, then don't treat it as a clash.
979978
// We'll use our built-in implementation in `emulate_foreign_item_inner` for increased

src/tools/miri/tests/fail/function_calls/check_arg_abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ fn main() {
44
}
55

66
unsafe {
7-
let _ = malloc(0); //~ ERROR: calling a function with ABI C using caller ABI Rust
7+
let _ = malloc(0); //~ ERROR: calling a function with calling convention "C" using caller calling convention "Rust"
88
};
99
}

src/tools/miri/tests/fail/function_calls/check_arg_abi.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: calling a function with ABI C using caller ABI Rust
1+
error: Undefined Behavior: calling a function with calling convention "C" using caller calling convention "Rust"
22
--> tests/fail/function_calls/check_arg_abi.rs:LL:CC
33
|
44
LL | let _ = malloc(0);
5-
| ^^^^^^^^^ calling a function with ABI C using caller ABI Rust
5+
| ^^^^^^^^^ calling a function with calling convention "C" using caller calling convention "Rust"
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail/function_calls/check_callback_abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99
// Make sure we check the ABI when Miri itself invokes a function
1010
// as part of a shim implementation.
1111
std::intrinsics::catch_unwind(
12-
//~^ ERROR: calling a function with calling convention C using calling convention Rust
12+
//~^ ERROR: calling a function with calling convention "C" using calling convention "Rust"
1313
std::mem::transmute::<extern "C" fn(*mut u8), _>(try_fn),
1414
std::ptr::null_mut(),
1515
|_, _| unreachable!(),

src/tools/miri/tests/fail/function_calls/check_callback_abi.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: Undefined Behavior: calling a function with calling convention C using calling convention Rust
1+
error: Undefined Behavior: calling a function with calling convention "C" using calling convention "Rust"
22
--> tests/fail/function_calls/check_callback_abi.rs:LL:CC
33
|
44
LL | / std::intrinsics::catch_unwind(
@@ -7,7 +7,7 @@ LL | | std::mem::transmute::<extern "C" fn(*mut u8), _>(try_fn),
77
LL | | std::ptr::null_mut(),
88
LL | | |_, _| unreachable!(),
99
LL | | );
10-
| |_________^ calling a function with calling convention C using calling convention Rust
10+
| |_________^ calling a function with calling convention "C" using calling convention "Rust"
1111
|
1212
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
1313
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail/function_calls/exported_symbol_abi_mismatch.cache.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: calling a function with calling convention Rust using calling convention C
1+
error: Undefined Behavior: calling a function with calling convention "Rust" using calling convention "C"
22
--> tests/fail/function_calls/exported_symbol_abi_mismatch.rs:LL:CC
33
|
44
LL | foo();
5-
| ^^^^^ calling a function with calling convention Rust using calling convention C
5+
| ^^^^^ calling a function with calling convention "Rust" using calling convention "C"
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail/function_calls/exported_symbol_abi_mismatch.fn_ptr.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: calling a function with calling convention Rust using calling convention C
1+
error: Undefined Behavior: calling a function with calling convention "Rust" using calling convention "C"
22
--> tests/fail/function_calls/exported_symbol_abi_mismatch.rs:LL:CC
33
|
44
LL | std::mem::transmute::<unsafe fn(), unsafe extern "C" fn()>(foo)();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with calling convention Rust using calling convention C
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with calling convention "Rust" using calling convention "C"
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail/function_calls/exported_symbol_abi_mismatch.no_cache.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: calling a function with calling convention Rust using calling convention C
1+
error: Undefined Behavior: calling a function with calling convention "Rust" using calling convention "C"
22
--> tests/fail/function_calls/exported_symbol_abi_mismatch.rs:LL:CC
33
|
44
LL | foo();
5-
| ^^^^^ calling a function with calling convention Rust using calling convention C
5+
| ^^^^^ calling a function with calling convention "Rust" using calling convention "C"
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

src/tools/miri/tests/fail/function_calls/exported_symbol_abi_mismatch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
#[cfg(fn_ptr)]
1313
unsafe {
1414
std::mem::transmute::<unsafe fn(), unsafe extern "C" fn()>(foo)();
15-
//~[fn_ptr]^ ERROR: calling a function with calling convention Rust using calling convention C
15+
//~[fn_ptr]^ ERROR: calling a function with calling convention "Rust" using calling convention "C"
1616
}
1717

1818
// `Instance` caching should not suppress ABI check.
@@ -28,8 +28,8 @@ fn main() {
2828
}
2929
unsafe {
3030
foo();
31-
//~[no_cache]^ ERROR: calling a function with calling convention Rust using calling convention C
32-
//~[cache]| ERROR: calling a function with calling convention Rust using calling convention C
31+
//~[no_cache]^ ERROR: calling a function with calling convention "Rust" using calling convention "C"
32+
//~[cache]| ERROR: calling a function with calling convention "Rust" using calling convention "C"
3333
}
3434
}
3535
}

src/tools/miri/tests/fail/tail_calls/cc-mismatch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@error-in-other-file: Undefined Behavior: calling a function with calling convention C using calling convention Rust
1+
//@error-in-other-file: Undefined Behavior: calling a function with calling convention "C" using calling convention "Rust"
22
#![feature(explicit_tail_calls)]
33
#![allow(incomplete_features)]
44

src/tools/miri/tests/fail/tail_calls/cc-mismatch.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Undefined Behavior: calling a function with calling convention C using calling convention Rust
1+
error: Undefined Behavior: calling a function with calling convention "C" using calling convention "Rust"
22
--> RUSTLIB/core/src/ops/function.rs:LL:CC
33
|
44
LL | extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with calling convention C using calling convention Rust
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with calling convention "C" using calling convention "Rust"
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

tests/ui/consts/miri_unleashed/abi-mismatch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const fn call_rust_fn(my_fn: extern "Rust" fn()) {
1010

1111
static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
1212
//~^ ERROR could not evaluate static initializer
13-
//~| NOTE calling a function with calling convention C using calling convention Rust
13+
//~| NOTE calling a function with calling convention "C" using calling convention "Rust"
1414

1515
fn main() {}
1616

tests/ui/consts/miri_unleashed/abi-mismatch.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: could not evaluate static initializer
22
--> $DIR/abi-mismatch.rs:11:18
33
|
44
LL | static VAL: () = call_rust_fn(unsafe { std::mem::transmute(c_fn as extern "C" fn()) });
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with calling convention C using calling convention Rust
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling a function with calling convention "C" using calling convention "Rust"
66
|
77
note: inside `call_rust_fn`
88
--> $DIR/abi-mismatch.rs:7:5

0 commit comments

Comments
 (0)