Skip to content

Commit d5db9be

Browse files
committed
add extern "tail" calling convention
1 parent 9f9e508 commit d5db9be

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

src/abi.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::bug;
1010
use rustc_middle::ty::Ty;
1111
use rustc_middle::ty::layout::LayoutOf;
1212
#[cfg(feature = "master")]
13-
use rustc_session::config;
13+
use rustc_session::{Session, config};
1414
use rustc_target::callconv::{ArgAttributes, CastTarget, FnAbi, PassMode};
1515
#[cfg(feature = "master")]
1616
use rustc_target::spec::Arch;
@@ -230,32 +230,43 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
230230

231231
#[cfg(feature = "master")]
232232
fn gcc_cconv(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Option<FnAttribute<'gcc>> {
233-
conv_to_fn_attribute(self.conv, &cx.tcx.sess.target.arch)
233+
conv_to_fn_attribute(cx.sess(), self.conv)
234234
}
235235
}
236236

237237
#[cfg(feature = "master")]
238-
pub fn conv_to_fn_attribute<'gcc>(conv: CanonAbi, arch: &Arch) -> Option<FnAttribute<'gcc>> {
238+
pub fn conv_to_fn_attribute<'gcc>(sess: &Session, conv: CanonAbi) -> Option<FnAttribute<'gcc>> {
239239
let attribute = match conv {
240240
CanonAbi::C | CanonAbi::Rust => return None,
241-
// gcc/gccjit does not have anything for this.
242-
CanonAbi::RustPreserveNone => return None,
241+
CanonAbi::RustPreserveNone => {
242+
// This calling convention is LLVM-specific and unspecified.
243+
sess.dcx()
244+
.fatal("gcc/gccjit backend does not support RustPreserveNone calling convention")
245+
}
246+
CanonAbi::RustTail => {
247+
// This calling convention is LLVM-specific and unspecified.
248+
sess.dcx().fatal("gcc/gccjit backend does not support RustTail calling convention")
249+
}
243250
CanonAbi::RustCold => FnAttribute::Cold,
244251
// Functions with this calling convention can only be called from assembly, but it is
245252
// possible to declare an `extern "custom"` block, so the backend still needs a calling
246253
// convention for declaring foreign functions.
247254
CanonAbi::Custom => return None,
248-
// gcc/gccjit does not have anything for Swift's calling convention.
249-
CanonAbi::Swift => panic!("gcc/gccjit backend does not support Swift calling convention"),
255+
CanonAbi::Swift => {
256+
// gcc/gccjit does not have anything for Swift's calling convention.
257+
sess.dcx().fatal("gcc/gccjit backend does not support Swift calling convention")
258+
}
250259
CanonAbi::Arm(arm_call) => match arm_call {
251260
ArmCall::CCmseNonSecureCall => FnAttribute::ArmCmseNonsecureCall,
252261
ArmCall::CCmseNonSecureEntry => FnAttribute::ArmCmseNonsecureEntry,
253262
ArmCall::Aapcs => FnAttribute::ArmPcs("aapcs"),
254263
},
255-
CanonAbi::GpuKernel => match arch {
264+
CanonAbi::GpuKernel => match &sess.target.arch {
256265
&Arch::AmdGpu => FnAttribute::GcnAmdGpuHsaKernel,
257266
&Arch::Nvptx64 => FnAttribute::NvptxKernel,
258-
arch => panic!("Arch {arch} does not support GpuKernel calling convention"),
267+
arch => sess
268+
.dcx()
269+
.fatal(format!("Arch {arch} does not support GpuKernel calling convention")),
259270
},
260271
// FIXME(antoyo): check if those AVR attributes are mapped correctly.
261272
CanonAbi::Interrupt(interrupt_kind) => match interrupt_kind {

src/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,10 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
486486
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function> {
487487
let entry_name = self.sess().target.entry_name.as_ref();
488488
if !self.functions.borrow().contains_key(entry_name) {
489-
#[cfg(feature = "master")]
490-
let conv = conv_to_fn_attribute(self.sess().target.entry_abi, &self.sess().target.arch);
491-
#[cfg(not(feature = "master"))]
492-
let conv = None;
489+
let conv = cfg_select! {
490+
feature = "master" => conv_to_fn_attribute(self.sess(), self.sess().target.entry_abi),
491+
_ => None,
492+
};
493493
Some(self.declare_entry_fn(entry_name, fn_type, conv))
494494
} else {
495495
// If the symbol already exists, it is an error: for example, the user wrote

0 commit comments

Comments
 (0)