Skip to content

Commit 337998a

Browse files
authored
Merge pull request #657 from rust-lang/feature/more-calling-conv-attributes
Support more calling convention attributes
2 parents 2884979 + 6fad1ba commit 337998a

File tree

4 files changed

+48
-29
lines changed

4 files changed

+48
-29
lines changed

Cargo.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ master = ["gccjit/master"]
2222
default = ["master"]
2323

2424
[dependencies]
25-
gccjit = "2.5"
25+
gccjit = "2.7"
2626
#gccjit = { git = "https://github.com/rust-lang/gccjit.rs" }
2727

2828
# Local copy.

libgccjit.version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0ea98a1365b81f7488073512c850e8ee951a4afd
1+
8b194529188f9d3a98cc211caa805a5355bfa8f0

src/abi.rs

+42-23
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use rustc_middle::ty::Ty;
99
use rustc_middle::ty::layout::LayoutOf;
1010
#[cfg(feature = "master")]
1111
use rustc_session::config;
12-
#[cfg(feature = "master")]
13-
use rustc_target::callconv::Conv;
1412
use rustc_target::callconv::{ArgAttributes, CastTarget, FnAbi, PassMode};
13+
#[cfg(feature = "master")]
14+
use rustc_target::callconv::{Conv, RiscvInterruptKind};
1515

1616
use crate::builder::Builder;
1717
use crate::context::CodegenCx;
@@ -240,38 +240,57 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
240240

241241
#[cfg(feature = "master")]
242242
pub fn conv_to_fn_attribute<'gcc>(conv: Conv, arch: &str) -> Option<FnAttribute<'gcc>> {
243-
// TODO: handle the calling conventions returning None.
244243
let attribute = match conv {
245-
Conv::C
246-
| Conv::Rust
247-
| Conv::CCmseNonSecureCall
248-
| Conv::CCmseNonSecureEntry
249-
| Conv::RiscvInterrupt { .. } => return None,
250-
Conv::Cold => return None,
244+
Conv::C | Conv::Rust => return None,
245+
Conv::CCmseNonSecureCall => {
246+
if arch == "arm" {
247+
FnAttribute::ArmCmseNonsecureCall
248+
} else {
249+
return None;
250+
}
251+
}
252+
Conv::CCmseNonSecureEntry => {
253+
if arch == "arm" {
254+
FnAttribute::ArmCmseNonsecureEntry
255+
} else {
256+
return None;
257+
}
258+
}
259+
Conv::Cold => FnAttribute::Cold,
260+
// NOTE: the preserve attributes are not yet implemented in GCC:
261+
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110899
251262
Conv::PreserveMost => return None,
252263
Conv::PreserveAll => return None,
253264
Conv::GpuKernel => {
254-
// TODO(antoyo): remove clippy allow attribute when this is implemented.
255-
#[allow(clippy::if_same_then_else)]
256265
if arch == "amdgpu" {
257-
return None;
266+
FnAttribute::GcnAmdGpuHsaKernel
258267
} else if arch == "nvptx64" {
259-
return None;
268+
FnAttribute::NvptxKernel
260269
} else {
261270
panic!("Architecture {} does not support GpuKernel calling convention", arch);
262271
}
263272
}
264-
Conv::AvrInterrupt => return None,
265-
Conv::AvrNonBlockingInterrupt => return None,
266-
Conv::ArmAapcs => return None,
267-
Conv::Msp430Intr => return None,
268-
Conv::X86Fastcall => return None,
269-
Conv::X86Intr => return None,
270-
Conv::X86Stdcall => return None,
271-
Conv::X86ThisCall => return None,
273+
// TODO(antoyo): check if those AVR attributes are mapped correctly.
274+
Conv::AvrInterrupt => FnAttribute::AvrSignal,
275+
Conv::AvrNonBlockingInterrupt => FnAttribute::AvrInterrupt,
276+
Conv::ArmAapcs => FnAttribute::ArmPcs("aapcs"),
277+
Conv::Msp430Intr => FnAttribute::Msp430Interrupt,
278+
Conv::RiscvInterrupt { kind } => {
279+
let kind = match kind {
280+
RiscvInterruptKind::Machine => "machine",
281+
RiscvInterruptKind::Supervisor => "supervisor",
282+
};
283+
FnAttribute::RiscvInterrupt(kind)
284+
}
285+
Conv::X86Fastcall => FnAttribute::X86FastCall,
286+
Conv::X86Intr => FnAttribute::X86Interrupt,
287+
Conv::X86Stdcall => FnAttribute::X86Stdcall,
288+
Conv::X86ThisCall => FnAttribute::X86ThisCall,
289+
// NOTE: the vectorcall calling convention is not yet implemented in GCC:
290+
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89485
272291
Conv::X86VectorCall => return None,
273-
Conv::X86_64SysV => FnAttribute::SysvAbi,
274-
Conv::X86_64Win64 => FnAttribute::MsAbi,
292+
Conv::X86_64SysV => FnAttribute::X86SysvAbi,
293+
Conv::X86_64Win64 => FnAttribute::X86MsAbi,
275294
};
276295
Some(attribute)
277296
}

0 commit comments

Comments
 (0)