Skip to content

Commit d463c5d

Browse files
committed
Implement Display by mapping Conv to ExternAbi
1 parent 43c51e9 commit d463c5d

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

compiler/rustc_target/src/callconv/mod.rs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -898,34 +898,35 @@ impl FromStr for Conv {
898898
}
899899
}
900900

901+
fn conv_to_externabi(conv: &Conv) -> ExternAbi {
902+
match conv {
903+
Conv::Rust => ExternAbi::Rust,
904+
Conv::PreserveMost => ExternAbi::RustCold,
905+
Conv::X86Stdcall => ExternAbi::Stdcall{unwind: false},
906+
Conv::X86Fastcall => ExternAbi::Fastcall{unwind: false},
907+
Conv::X86VectorCall => ExternAbi::Vectorcall{unwind: false},
908+
Conv::X86ThisCall => ExternAbi::Thiscall{unwind: false},
909+
Conv::C => ExternAbi::C{unwind: false},
910+
Conv::X86_64Win64 => ExternAbi::Win64{unwind: false},
911+
Conv::X86_64SysV => ExternAbi::SysV64{unwind: false},
912+
Conv::ArmAapcs => ExternAbi::Aapcs{unwind: false},
913+
Conv::CCmseNonSecureCall => ExternAbi::CCmseNonSecureCall,
914+
Conv::CCmseNonSecureEntry => ExternAbi::CCmseNonSecureEntry,
915+
Conv::PtxKernel => ExternAbi::PtxKernel,
916+
Conv::Msp430Intr => ExternAbi::Msp430Interrupt,
917+
Conv::X86Intr => ExternAbi::X86Interrupt,
918+
Conv::GpuKernel => ExternAbi::GpuKernel,
919+
Conv::AvrInterrupt => ExternAbi::AvrInterrupt,
920+
Conv::AvrNonBlockingInterrupt => ExternAbi::AvrNonBlockingInterrupt,
921+
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Machine } => ExternAbi::RiscvInterruptM,
922+
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Supervisor } => ExternAbi::RiscvInterruptS,
923+
Conv::Cold | Conv::PreserveAll => panic!("This is deadcode"),
924+
}
925+
}
926+
901927
impl Display for Conv {
902928
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
903-
f.write_str(match self {
904-
Conv::C => "C",
905-
Conv::Rust => "Rust",
906-
Conv::Cold => "Cold",
907-
Conv::PreserveMost => "PreserveMost",
908-
Conv::PreserveAll => "PreserveAll",
909-
Conv::ArmAapcs => "ArmAapcs",
910-
Conv::CCmseNonSecureCall => "CCmseNonSecureCall",
911-
Conv::CCmseNonSecureEntry => "CCmseNonSecureEntry",
912-
Conv::Msp430Intr => "Msp430Intr",
913-
Conv::PtxKernel => "PtxKernel",
914-
Conv::GpuKernel => "GpuKernel",
915-
Conv::X86Fastcall => "X86Fastcall",
916-
Conv::X86Intr => "X86Intr",
917-
Conv::X86Stdcall => "X86Stdcall",
918-
Conv::X86ThisCall => "X86ThisCall",
919-
Conv::X86VectorCall => "X86VectorCall",
920-
Conv::X86_64SysV => "X86_64SysV",
921-
Conv::X86_64Win64 => "X86_64Win64",
922-
Conv::AvrInterrupt => "AvrInterrupt",
923-
Conv::AvrNonBlockingInterrupt => "AvrNonBlockingInterrupt",
924-
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Machine } => "RiscvInterrupt(machine)",
925-
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Supervisor } => {
926-
"RiscvInterrupt(supervisor)"
927-
}
928-
})
929+
write!(f, "{}", conv_to_externabi(self))
929930
}
930931
}
931932

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

0 commit comments

Comments
 (0)