Skip to content

Commit 4140720

Browse files
committed
rustc_target: add abi::call::Conv::Rust distinct from Conv::C.
1 parent 5bdcde2 commit 4140720

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

src/librustc/ty/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2441,7 +2441,7 @@ where
24412441

24422442
use rustc_target::spec::abi::Abi::*;
24432443
let conv = match cx.tcx().sess.target.target.adjust_abi(sig.abi) {
2444-
RustIntrinsic | PlatformIntrinsic | Rust | RustCall => Conv::C,
2444+
RustIntrinsic | PlatformIntrinsic | Rust | RustCall => Conv::Rust,
24452445

24462446
// It's the ABI's job to select this, not ours.
24472447
System => bug!("system abi should be selected elsewhere"),

src/librustc_codegen_llvm/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
372372

373373
fn llvm_cconv(&self) -> llvm::CallConv {
374374
match self.conv {
375-
Conv::C => llvm::CCallConv,
375+
Conv::C | Conv::Rust => llvm::CCallConv,
376376
Conv::AmdGpuKernel => llvm::AmdGpuKernel,
377377
Conv::ArmAapcs => llvm::ArmAapcsCallConv,
378378
Conv::Msp430Intr => llvm::Msp430Intr,

src/librustc_codegen_llvm/attributes.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ use rustc::hir::CodegenFnAttrFlags;
66
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
77
use rustc::session::Session;
88
use rustc::session::config::{Sanitizer, OptLevel};
9-
use rustc::ty::{self, TyCtxt};
9+
use rustc::ty::{self, TyCtxt, Ty};
1010
use rustc::ty::layout::HasTyCtxt;
1111
use rustc::ty::query::Providers;
1212
use rustc_data_structures::small_c_str::SmallCStr;
1313
use rustc_data_structures::fx::FxHashMap;
14+
use rustc_target::abi::call::Conv;
1415
use rustc_target::spec::PanicStrategy;
1516
use rustc_codegen_ssa::traits::*;
1617

17-
use crate::abi::Abi;
18+
use crate::abi::FnAbi;
1819
use crate::attributes;
1920
use crate::llvm::{self, Attribute};
2021
use crate::llvm::AttributePlace::Function;
@@ -203,6 +204,7 @@ pub fn from_fn_attrs(
203204
cx: &CodegenCx<'ll, 'tcx>,
204205
llfn: &'ll Value,
205206
instance: ty::Instance<'tcx>,
207+
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
206208
) {
207209
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
208210

@@ -279,10 +281,7 @@ pub fn from_fn_attrs(
279281
// Special attribute for allocator functions, which can't unwind.
280282
false
281283
} else {
282-
// FIXME(eddyb) avoid this `Instance::fn_sig` call.
283-
// Perhaps store the relevant information in `FnAbi`?
284-
let abi = instance.fn_sig(cx.tcx()).abi();
285-
if abi == Abi::Rust || abi == Abi::RustCall {
284+
if fn_abi.conv == Conv::Rust {
286285
// Any Rust method (or `extern "Rust" fn` or `extern
287286
// "rust-call" fn`) is explicitly allowed to unwind
288287
// (unless it has no-unwind attribute, handled above).

src/librustc_codegen_llvm/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub fn get_fn(
8080
let llfn = cx.declare_fn(&sym, &fn_abi);
8181
debug!("get_fn: not casting pointer!");
8282

83-
attributes::from_fn_attrs(cx, llfn, instance);
83+
attributes::from_fn_attrs(cx, llfn, instance, &fn_abi);
8484

8585
let instance_def_id = instance.def_id();
8686

src/librustc_codegen_llvm/mono_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl PreDefineMethods<'tcx> for CodegenCx<'ll, 'tcx> {
7070

7171
debug!("predefine_fn: instance = {:?}", instance);
7272

73-
attributes::from_fn_attrs(self, lldecl, instance);
73+
attributes::from_fn_attrs(self, lldecl, instance, &fn_abi);
7474

7575
self.instances.borrow_mut().insert(instance, lldecl);
7676
}

src/librustc_target/abi/call/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,12 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
490490

491491
#[derive(Copy, Clone, PartialEq, Debug)]
492492
pub enum Conv {
493+
// General language calling conventions, for which every target
494+
// should have its own backend (e.g. LLVM) support.
493495
C,
496+
Rust,
497+
498+
// Target-specific calling conventions.
494499

495500
ArmAapcs,
496501

0 commit comments

Comments
 (0)