Skip to content

Commit

Permalink
rustc_target: add abi::call::Conv::Rust distinct from Conv::C.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Dec 3, 2019
1 parent e93aa10 commit 79d908b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/librustc/ty/layout.rs
Expand Up @@ -2441,7 +2441,7 @@ where

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

// It's the ABI's job to select this, not ours.
System => bug!("system abi should be selected elsewhere"),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/abi.rs
Expand Up @@ -372,7 +372,7 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {

fn llvm_cconv(&self) -> llvm::CallConv {
match self.conv {
Conv::C => llvm::CCallConv,
Conv::C | Conv::Rust => llvm::CCallConv,
Conv::AmdGpuKernel => llvm::AmdGpuKernel,
Conv::ArmAapcs => llvm::ArmAapcsCallConv,
Conv::Msp430Intr => llvm::Msp430Intr,
Expand Down
11 changes: 5 additions & 6 deletions src/librustc_codegen_llvm/attributes.rs
Expand Up @@ -6,15 +6,16 @@ use rustc::hir::CodegenFnAttrFlags;
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::session::Session;
use rustc::session::config::{Sanitizer, OptLevel};
use rustc::ty::{self, TyCtxt};
use rustc::ty::{self, TyCtxt, Ty};
use rustc::ty::layout::HasTyCtxt;
use rustc::ty::query::Providers;
use rustc_data_structures::small_c_str::SmallCStr;
use rustc_data_structures::fx::FxHashMap;
use rustc_target::abi::call::Conv;
use rustc_target::spec::PanicStrategy;
use rustc_codegen_ssa::traits::*;

use crate::abi::Abi;
use crate::abi::FnAbi;
use crate::attributes;
use crate::llvm::{self, Attribute};
use crate::llvm::AttributePlace::Function;
Expand Down Expand Up @@ -203,6 +204,7 @@ pub fn from_fn_attrs(
cx: &CodegenCx<'ll, 'tcx>,
llfn: &'ll Value,
instance: ty::Instance<'tcx>,
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
) {
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());

Expand Down Expand Up @@ -279,10 +281,7 @@ pub fn from_fn_attrs(
// Special attribute for allocator functions, which can't unwind.
false
} else {
// FIXME(eddyb) avoid this `Instance::fn_sig` call.
// Perhaps store the relevant information in `FnAbi`?
let abi = instance.fn_sig(cx.tcx()).abi();
if abi == Abi::Rust || abi == Abi::RustCall {
if fn_abi.conv == Conv::Rust {
// Any Rust method (or `extern "Rust" fn` or `extern
// "rust-call" fn`) is explicitly allowed to unwind
// (unless it has no-unwind attribute, handled above).
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/callee.rs
Expand Up @@ -80,7 +80,7 @@ pub fn get_fn(
let llfn = cx.declare_fn(&sym, &fn_abi);
debug!("get_fn: not casting pointer!");

attributes::from_fn_attrs(cx, llfn, instance);
attributes::from_fn_attrs(cx, llfn, instance, &fn_abi);

let instance_def_id = instance.def_id();

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/mono_item.rs
Expand Up @@ -70,7 +70,7 @@ impl PreDefineMethods<'tcx> for CodegenCx<'ll, 'tcx> {

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

attributes::from_fn_attrs(self, lldecl, instance);
attributes::from_fn_attrs(self, lldecl, instance, &fn_abi);

self.instances.borrow_mut().insert(instance, lldecl);
}
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_target/abi/call/mod.rs
Expand Up @@ -492,7 +492,12 @@ impl<'a, Ty> ArgAbi<'a, Ty> {

#[derive(Copy, Clone, PartialEq, Debug)]
pub enum Conv {
// General language calling conventions, for which every target
// should have its own backend (e.g. LLVM) support.
C,
Rust,

// Target-specific calling conventions.

ArmAapcs,

Expand Down

0 comments on commit 79d908b

Please sign in to comment.