Skip to content

Commit 84a9e78

Browse files
committed
Implement Display by mapping Conv to ExternAbi
1 parent 05480e7 commit 84a9e78

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
@@ -882,34 +882,35 @@ impl FromStr for Conv {
882882
}
883883
}
884884

885+
fn conv_to_externabi(conv: &Conv) -> ExternAbi {
886+
match conv {
887+
Conv::Rust => ExternAbi::Rust,
888+
Conv::PreserveMost => ExternAbi::RustCold,
889+
Conv::X86Stdcall => ExternAbi::Stdcall{unwind: false},
890+
Conv::X86Fastcall => ExternAbi::Fastcall{unwind: false},
891+
Conv::X86VectorCall => ExternAbi::Vectorcall{unwind: false},
892+
Conv::X86ThisCall => ExternAbi::Thiscall{unwind: false},
893+
Conv::C => ExternAbi::C{unwind: false},
894+
Conv::X86_64Win64 => ExternAbi::Win64{unwind: false},
895+
Conv::X86_64SysV => ExternAbi::SysV64{unwind: false},
896+
Conv::ArmAapcs => ExternAbi::Aapcs{unwind: false},
897+
Conv::CCmseNonSecureCall => ExternAbi::CCmseNonSecureCall,
898+
Conv::CCmseNonSecureEntry => ExternAbi::CCmseNonSecureEntry,
899+
Conv::PtxKernel => ExternAbi::PtxKernel,
900+
Conv::Msp430Intr => ExternAbi::Msp430Interrupt,
901+
Conv::X86Intr => ExternAbi::X86Interrupt,
902+
Conv::GpuKernel => ExternAbi::GpuKernel,
903+
Conv::AvrInterrupt => ExternAbi::AvrInterrupt,
904+
Conv::AvrNonBlockingInterrupt => ExternAbi::AvrNonBlockingInterrupt,
905+
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Machine } => ExternAbi::RiscvInterruptM,
906+
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Supervisor } => ExternAbi::RiscvInterruptS,
907+
Conv::Cold | Conv::PreserveAll => panic!("This is deadcode"),
908+
}
909+
}
910+
885911
impl Display for Conv {
886912
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
887-
f.write_str(match self {
888-
Conv::C => "C",
889-
Conv::Rust => "Rust",
890-
Conv::Cold => "Cold",
891-
Conv::PreserveMost => "PreserveMost",
892-
Conv::PreserveAll => "PreserveAll",
893-
Conv::ArmAapcs => "ArmAapcs",
894-
Conv::CCmseNonSecureCall => "CCmseNonSecureCall",
895-
Conv::CCmseNonSecureEntry => "CCmseNonSecureEntry",
896-
Conv::Msp430Intr => "Msp430Intr",
897-
Conv::PtxKernel => "PtxKernel",
898-
Conv::GpuKernel => "GpuKernel",
899-
Conv::X86Fastcall => "X86Fastcall",
900-
Conv::X86Intr => "X86Intr",
901-
Conv::X86Stdcall => "X86Stdcall",
902-
Conv::X86ThisCall => "X86ThisCall",
903-
Conv::X86VectorCall => "X86VectorCall",
904-
Conv::X86_64SysV => "X86_64SysV",
905-
Conv::X86_64Win64 => "X86_64Win64",
906-
Conv::AvrInterrupt => "AvrInterrupt",
907-
Conv::AvrNonBlockingInterrupt => "AvrNonBlockingInterrupt",
908-
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Machine } => "RiscvInterrupt(machine)",
909-
Conv::RiscvInterrupt { kind: RiscvInterruptKind::Supervisor } => {
910-
"RiscvInterrupt(supervisor)"
911-
}
912-
})
913+
write!(f, "{}", conv_to_externabi(self))
913914
}
914915
}
915916

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)