Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
1f3faa8
rustc_codegen_llvm: begin generalizing over backend values.
irinagpopa Aug 2, 2018
67f94d8
Reduced line length to pass tidy
denismerigoux Aug 3, 2018
bc2897e
Generalized base.rs#call_memcpy and everything that it uses
denismerigoux Aug 7, 2018
ba2ed26
Generalized BasicBlocks in BuilderMethods trait
denismerigoux Aug 20, 2018
a4f6f8e
Generalized IntPredicate in the BuilderMethods trait
denismerigoux Aug 20, 2018
c42cf09
Generalized RealPredicate
denismerigoux Aug 21, 2018
138b446
Removed useless traits for IntPredicate and RealPredicate
denismerigoux Aug 21, 2018
c62e222
Generalized OperandBundleDef in BuilderMethods
denismerigoux Aug 21, 2018
6d78a14
Generalized AtomicRmwBinOp for BuilderMethods
denismerigoux Aug 21, 2018
733840b
Generalized AtomicOrdering for BuilderMethods
denismerigoux Aug 21, 2018
a401974
Generalized SynchronisationScope for BuilderMethods
denismerigoux Aug 21, 2018
b83a2b7
Generalized AsmDialect for BuilderMethods
denismerigoux Aug 21, 2018
958f94b
Removed genericity over Value in various functions
denismerigoux Aug 22, 2018
234f537
Line too long split
denismerigoux Aug 22, 2018
9be7a5e
Use associated types instead of type parameters inside the BuilderMet…
denismerigoux Aug 22, 2018
17e3189
Removed parasite yaml file and put explicit lifetimes
denismerigoux Aug 23, 2018
2680e1b
Use real type names rather than Self::
denismerigoux Aug 23, 2018
2d8ccf2
Fixed borrow-checker deficiency at stage 1
denismerigoux Aug 23, 2018
28ee44a
New files and folders for traits
denismerigoux Aug 28, 2018
78fbb2d
New Backend trait containing associated types
denismerigoux Aug 28, 2018
dfa4f77
Traitification of common.rs methods
denismerigoux Aug 28, 2018
67e865f
Replaced Codegen field access by trait method
denismerigoux Aug 28, 2018
1174b40
Added self argument for Codegen CommonMethod trait methods
denismerigoux Aug 29, 2018
a054141
Split CommonMethods to accomodate for use in back/write.rs
denismerigoux Aug 29, 2018
c67788d
CommonWriteMethods are not static any more
denismerigoux Aug 29, 2018
bfea5b2
Removed code duplication for CommonWriteMethods
denismerigoux Aug 30, 2018
b588c00
All CommonMethods now real methods (not static)
denismerigoux Aug 30, 2018
012a6e5
Use the method form for CodegenCx everywhere
denismerigoux Aug 30, 2018
638f4ac
Small generalization of some CodegenCx methods
denismerigoux Aug 30, 2018
89cd9c0
Added definition of type trait
denismerigoux Aug 30, 2018
1d8e6dc
Traitification of type_ methods
denismerigoux Sep 5, 2018
3160690
Work around to fix issue https://github.com/rust-lang/rust/issues/53912
denismerigoux Sep 6, 2018
f8bdd1f
Prefixed const methods with "const" instead of "c"
denismerigoux Sep 6, 2018
49e5874
Prefixed type methods & removed trait impl for write::CodegenContext
denismerigoux Sep 6, 2018
2a513df
Removing LLVM content from CommonMethods -> ConstMethods
denismerigoux Sep 6, 2018
79ea68f
Removed phantomdata no longer necessary
denismerigoux Sep 6, 2018
18216fc
Fixed typos
denismerigoux Sep 7, 2018
626d3cb
Attempt at including CodegenCx within Builder with Associated types
denismerigoux Sep 7, 2018
1ef9f8f
Generalized some base.rs methods
denismerigoux Sep 7, 2018
5428c7e
Generalized memset and memcpy
denismerigoux Sep 7, 2018
20a7eef
Added StaticMethods trait
denismerigoux Sep 10, 2018
037bc7a
Transfered memcpy and memset to BuilderMethods
denismerigoux Sep 10, 2018
ff46476
Traitified IntrinsicCallMethods
denismerigoux Sep 11, 2018
9a8dfd7
Generalized base::unsized_info
denismerigoux Sep 13, 2018
56f3990
Generalized base::unsize_thin_ptr
denismerigoux Sep 13, 2018
8b9ff39
Generalized base::coerce_unsized_into
denismerigoux Sep 14, 2018
c71c6cc
Generalized mir::codegen_mir (and all subsequent functions)
denismerigoux Sep 20, 2018
da0cf8c
Added 'll lifetime parameter to backend
denismerigoux Sep 21, 2018
29f4d0e
Added new lifetimes for Funclets in FunctionsCx -> compiles
denismerigoux Sep 21, 2018
88a5dea
Tidy too long lines
denismerigoux Sep 21, 2018
48af59f
Generalized mono_item.rs and base.rs:codegen_instance
denismerigoux Sep 21, 2018
8ea0331
Adapt code to latest rustc master changes
denismerigoux Sep 24, 2018
2e8af91
Generalized base:maybe_create_entry_wrapper
denismerigoux Sep 24, 2018
4460972
Move doc to trait declarations
denismerigoux Sep 24, 2018
df5a57c
Generalized base:codegen_crate
denismerigoux Sep 25, 2018
440f2fb
Renamed lifetimes for better understanding
denismerigoux Sep 26, 2018
0c10974
Preparing the generalization of base:compile_coodegen_unit
denismerigoux Sep 26, 2018
3f6f753
Added compile codegen to backend trait
denismerigoux Sep 27, 2018
570d3c0
Starting to move backend-agnostic code into codegen_utils
denismerigoux Sep 28, 2018
0da5170
Moved common.rs enums
denismerigoux Sep 28, 2018
a03673c
Moved OperandBundleDef
denismerigoux Sep 28, 2018
4a2f7c7
Adapt to latest rustc master changes
denismerigoux Sep 28, 2018
b8e7061
Moved Funclet
denismerigoux Sep 28, 2018
c785979
Moved Backend interface into rustc_codegen_utils
denismerigoux Oct 1, 2018
9a05142
Adapted to lastest rustc master changes
denismerigoux Oct 1, 2018
31dee75
Beginning of moving all backend-agnostic code to rustc_codegen_ssa
denismerigoux Oct 1, 2018
26e18a1
Moved DeclareMethods, MiscMethods and StaticMethods
denismerigoux Oct 2, 2018
431601c
Greate separation of librsutc_codegen_llvm : librustc_codegen_ssa com…
denismerigoux Oct 3, 2018
9fe9347
Finished moving backend-agnostic code to rustc_codegen_ssa
denismerigoux Oct 3, 2018
58c8f32
Fix lines too long
denismerigoux Oct 4, 2018
2a6412b
Added some docs + start to &mut self builder methods
denismerigoux Oct 4, 2018
376f4fe
All Builder methods now take &mut self instead of &self
denismerigoux Oct 5, 2018
afd940a
Added default impl for DerivedTypeMethods + empty impl for Cranelift …
denismerigoux Oct 9, 2018
b2c66a2
Traits skeletton fully in place
denismerigoux Oct 10, 2018
6d63072
Separating the back folder between backend-agnostic and LLVM-specific…
denismerigoux Oct 23, 2018
1cdea08
Added README explaining the refactoring
denismerigoux Oct 22, 2018
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Generalized mir::codegen_mir (and all subsequent functions)
  • Loading branch information
denismerigoux committed Oct 23, 2018
commit c71c6ccffb6d1fb602941e2ccf85194a9b9a09fb
52 changes: 50 additions & 2 deletions src/librustc_codegen_llvm/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ use mir::operand::OperandValue;
use type_::Type;
use type_of::{LayoutLlvmExt, PointerKind};
use value::Value;
use rustc_target::abi::call::ArgType;

use interfaces::{BuilderMethods, ConstMethods, BaseTypeMethods, DerivedTypeMethods};
use interfaces::*;

use rustc_target::abi::{LayoutOf, Size, TyLayout};
use rustc::ty::{self, Ty};
use rustc::ty::{self, Ty, Instance};
use rustc::ty::layout;

use libc::c_uint;
Expand Down Expand Up @@ -279,6 +280,27 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
}
}

impl<'a, 'll: 'a, 'tcx: 'll> ArgTypeMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx, &'ll Value> {
fn store_fn_arg(
&self,
ty: &ArgType<'tcx, Ty<'tcx>>,
idx: &mut usize, dst: PlaceRef<'tcx, <Self::CodegenCx as Backend>::Value>
) {
ty.store_fn_arg(&self, idx, dst)
}
fn store_arg_ty(
&self,
ty: &ArgType<'tcx, Ty<'tcx>>,
val: &'ll Value,
dst: PlaceRef<'tcx, &'ll Value>
) {
ty.store(&self, val, dst)
}
fn memory_ty(&self, ty: &ArgType<'tcx, Ty<'tcx>>) -> &'ll Type {
ty.memory_ty(self.cx())
}
}

pub trait FnTypeExt<'tcx> {
fn of_instance(cx: &CodegenCx<'ll, 'tcx, &'ll Value>, instance: &ty::Instance<'tcx>) -> Self;
fn new(cx: &CodegenCx<'ll, 'tcx, &'ll Value>,
Expand Down Expand Up @@ -754,3 +776,29 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
}
}
}

impl AbiMethods<'tcx> for CodegenCx<'ll, 'tcx, &'ll Value> {
fn new_fn_type(&self, sig: ty::FnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> FnType<'tcx, Ty<'tcx>> {
FnType::new(&self, sig, extra_args)
}
fn new_vtable(
&self,
sig: ty::FnSig<'tcx>,
extra_args: &[Ty<'tcx>]
) -> FnType<'tcx, Ty<'tcx>> {
FnType::new_vtable(&self, sig, extra_args)
}
fn fn_type_of_instance(&self, instance: &Instance<'tcx>) -> FnType<'tcx, Ty<'tcx>> {
FnType::of_instance(&self, instance)
}
}

impl AbiBuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx, &'ll Value> {
fn apply_attrs_callsite(
&self,
ty: &FnType<'tcx, Ty<'tcx>>,
callsite: <Self::CodegenCx as Backend>::Value
) {
ty.apply_attrs_callsite(&self, callsite)
}
}
84 changes: 44 additions & 40 deletions src/librustc_codegen_llvm/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,43 @@ use builder::Builder;
use value::Value;

use rustc::hir;
use interfaces::{BuilderMethods, ConstMethods, BaseTypeMethods};
use interfaces::*;

use mir::place::PlaceRef;
use mir::operand::OperandValue;

use std::ffi::CString;
use libc::{c_uint, c_char};

// Take an inline assembly expression and splat it out via LLVM
pub fn codegen_inline_asm(
bx: &Builder<'a, 'll, 'tcx, &'ll Value>,
ia: &hir::InlineAsm,
outputs: Vec<PlaceRef<'tcx, &'ll Value>>,
mut inputs: Vec<&'ll Value>
) -> bool {
let mut ext_constraints = vec![];
let mut output_types = vec![];

// Prepare the output operands
let mut indirect_outputs = vec![];
for (i, (out, place)) in ia.outputs.iter().zip(&outputs).enumerate() {
if out.is_rw {
inputs.push(bx.load_ref(place).immediate());
ext_constraints.push(i.to_string());

impl AsmBuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx, &'ll Value> {
// Take an inline assembly expression and splat it out via LLVM
fn codegen_inline_asm(
&self,
ia: &hir::InlineAsm,
outputs: Vec<PlaceRef<'tcx, &'ll Value>>,
mut inputs: Vec<&'ll Value>
) -> bool {
let mut ext_constraints = vec![];
let mut output_types = vec![];

// Prepare the output operands
let mut indirect_outputs = vec![];
for (i, (out, place)) in ia.outputs.iter().zip(&outputs).enumerate() {
if out.is_rw {
inputs.push(self.load_ref(place).immediate());
ext_constraints.push(i.to_string());
}
if out.is_indirect {
indirect_outputs.push(self.load_ref(place).immediate());
} else {
output_types.push(place.layout.llvm_type(self.cx()));
}
}
if out.is_indirect {
indirect_outputs.push(bx.load_ref(place).immediate());
} else {
output_types.push(place.layout.llvm_type(bx.cx()));
if !indirect_outputs.is_empty() {
indirect_outputs.extend_from_slice(&inputs);
inputs = indirect_outputs;
}
}
if !indirect_outputs.is_empty() {
indirect_outputs.extend_from_slice(&inputs);
inputs = indirect_outputs;
}

let clobbers = ia.clobbers.iter()
.map(|s| format!("~{{{}}}", &s));
Expand Down Expand Up @@ -103,26 +105,28 @@ pub fn codegen_inline_asm(
OperandValue::Immediate(v).store(bx, place);
}

// Store mark in a metadata node so we can map LLVM errors
// back to source locations. See #17552.
unsafe {
let key = "srcloc";
let kind = llvm::LLVMGetMDKindIDInContext(bx.cx().llcx,
key.as_ptr() as *const c_char, key.len() as c_uint);
// Store mark in a metadata node so we can map LLVM errors
// back to source locations. See #17552.
unsafe {
let key = "srcloc";
let kind = llvm::LLVMGetMDKindIDInContext(self.cx().llcx,
key.as_ptr() as *const c_char, key.len() as c_uint);

let val: &'ll Value = bx.cx().const_i32(ia.ctxt.outer().as_u32() as i32);
let val: &'ll Value = self.cx().const_i32(ia.ctxt.outer().as_u32() as i32);

llvm::LLVMSetMetadata(r, kind,
llvm::LLVMMDNodeInContext(bx.cx().llcx, &val, 1));
llvm::LLVMSetMetadata(r, kind,
llvm::LLVMMDNodeInContext(self.cx().llcx, &val, 1));
}
}

return true;
}

pub fn codegen_global_asm<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx, &'a Value>,
ga: &hir::GlobalAsm) {
let asm = CString::new(ga.asm.as_str().as_bytes()).unwrap();
unsafe {
llvm::LLVMRustAppendModuleInlineAsm(cx.llmod, asm.as_ptr());
impl AsmMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
fn codegen_global_asm(&self, ga: &hir::GlobalAsm) {
let asm = CString::new(ga.asm.as_str().as_bytes()).unwrap();
unsafe {
llvm::LLVMRustAppendModuleInlineAsm(self.llmod, asm.as_ptr());
}
}
}
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use rustc::session::Session;
use rustc::session::config::Sanitizer;
use rustc::ty::TyCtxt;
use rustc::ty::layout::HasTyCtxt;
use rustc::ty::query::Providers;
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::fx::FxHashMap;
use rustc_target::spec::PanicStrategy;
use interfaces::*;

use attributes;
use llvm::{self, Attribute};
Expand Down
22 changes: 12 additions & 10 deletions src/librustc_codegen_llvm/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ use rustc_mir::monomorphize::item::DefPathBasedNames;
use common::{self, IntPredicate, RealPredicate, TypeKind};
use context::CodegenCx;
use debuginfo;
use declare;
use meth;
use mir;
use monomorphize::Instance;
Expand Down Expand Up @@ -395,15 +394,18 @@ pub fn wants_msvc_seh(sess: &Session) -> bool {
sess.target.target.options.is_like_msvc
}

pub fn call_assume(bx: &Builder<'_, 'll, '_, &'ll Value>, val: &'ll Value) {
pub fn call_assume<'a, 'll: 'a, 'tcx: 'll, Bx : BuilderMethods<'a, 'll ,'tcx>>(
bx: &Bx,
val: <Bx::CodegenCx as Backend>::Value
) {
let assume_intrinsic = bx.cx().get_intrinsic("llvm.assume");
bx.call(assume_intrinsic, &[val], None);
}

pub fn from_immediate<'a, 'll: 'a, 'tcx: 'll, Builder : BuilderMethods<'a, 'll ,'tcx>>(
bx: &Builder,
val: <Builder::CodegenCx as Backend>::Value
) -> <Builder::CodegenCx as Backend>::Value {
pub fn from_immediate<'a, 'll: 'a, 'tcx: 'll, Bx : BuilderMethods<'a, 'll ,'tcx>>(
bx: &Bx,
val: <Bx::CodegenCx as Backend>::Value
) -> <Bx::CodegenCx as Backend>::Value {
if bx.cx().val_ty(val) == bx.cx().type_i1() {
bx.zext(val, bx.cx().type_i8())
} else {
Expand Down Expand Up @@ -449,7 +451,7 @@ pub fn memcpy_ty<'a, 'll: 'a, 'tcx: 'll, Builder : BuilderMethods<'a, 'll, 'tcx>
bx.call_memcpy(dst, src, bx.cx().const_usize(size), align, flags);
}

pub fn codegen_instance<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx, &'a Value>, instance: Instance<'tcx>) {
pub fn codegen_instance<'a, 'll: 'a, 'tcx: 'll>(cx: &'a CodegenCx<'ll, 'tcx, &'ll Value>, instance: Instance<'tcx>) {
let _s = if cx.sess().codegen_stats() {
let mut instance_name = String::new();
DefPathBasedNames::new(cx.tcx, true, true)
Expand All @@ -474,7 +476,7 @@ pub fn codegen_instance<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx, &'a Value>, instance:
cx.stats.borrow_mut().n_closures += 1;

let mir = cx.tcx.instance_mir(instance.def);
mir::codegen_mir(cx, lldecl, &mir, instance, sig);
mir::codegen_mir::<'a, 'll, 'tcx, Builder<'a, 'll, 'tcx, &'ll Value>>(cx, lldecl, &mir, instance, sig);
}

pub fn set_link_section(llval: &Value, attrs: &CodegenFnAttrs) {
Expand Down Expand Up @@ -535,15 +537,15 @@ fn maybe_create_entry_wrapper(cx: &CodegenCx<'ll, '_, &'ll Value>) {
&main_ret_ty.no_late_bound_regions().unwrap(),
);

if declare::get_defined_value(cx, "main").is_some() {
if cx.get_defined_value("main").is_some() {
// FIXME: We should be smart and show a better diagnostic here.
cx.sess().struct_span_err(sp, "entry symbol `main` defined multiple times")
.help("did you use #[no_mangle] on `fn main`? Use #[start] instead")
.emit();
cx.sess().abort_if_errors();
bug!();
}
let llfn = declare::declare_cfn(cx, "main", llfty);
let llfn = cx.declare_cfn("main", llfty);

// `main` should respect same config for frame pointer elimination as rest of code
attributes::set_frame_pointer_elimination(cx, llfn);
Expand Down
22 changes: 14 additions & 8 deletions src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use value::Value;
use libc::{c_uint, c_char};
use rustc::ty::TyCtxt;
use rustc::ty::layout::{self, Align, Size};
use rustc::session::{config, Session};
use rustc::session::config;
use rustc_data_structures::small_c_str::SmallCStr;
use interfaces::*;
use syntax;
Expand Down Expand Up @@ -99,10 +99,6 @@ impl BuilderMethods<'a, 'll, 'tcx>
Builder::new_block(self.cx, self.llfn(), name)
}

fn sess(&self) -> &Session {
self.cx.sess()
}

fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
self.cx.tcx
}
Expand Down Expand Up @@ -605,7 +601,7 @@ impl BuilderMethods<'a, 'll, 'tcx>


fn range_metadata(&self, load: &'ll Value, range: Range<u128>) {
if self.sess().target.target.arch == "amdgpu" {
if self.cx().sess().target.target.arch == "amdgpu" {
// amdgpu/LLVM does something weird and thinks a i64 value is
// split into a v2i32, halving the bitwidth LLVM expects,
// tripping an assertion. So, for now, just disable this
Expand Down Expand Up @@ -1381,7 +1377,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
return;
}
let cx = &self.cx();
let ptr_width = &self.sess().target.target.target_pointer_width;
let ptr_width = &self.cx().sess().target.target.target_pointer_width;
let key = format!("llvm.memcpy.p0i8.p0i8.i{}", ptr_width);
let memcpy = cx.get_intrinsic(&key);
let src_ptr = &self.pointercast(src, cx.type_i8p());
Expand All @@ -1400,7 +1396,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
align: &'ll Value,
volatile: bool,
) -> &'ll Value {
let ptr_width = &self.sess().target.target.target_pointer_width;
let ptr_width = &self.cx().sess().target.target.target_pointer_width;
let intrinsic_key = format!("llvm.memset.p0i8.i{}", ptr_width);
let llintrinsicfn = &self.cx().get_intrinsic(&intrinsic_key);
let volatile = &self.cx().const_bool(volatile);
Expand All @@ -1425,4 +1421,14 @@ impl BuilderMethods<'a, 'll, 'tcx>
fn cx(&self) -> &'a CodegenCx<'ll, 'tcx, &'ll Value> {
&self.cx
}

fn delete_basic_block(&self, bb: &'ll BasicBlock) {
unsafe {
llvm::LLVMDeleteBasicBlock(bb);
}
}

fn do_not_inline(&self, llret: &'ll Value) {
llvm::Attribute::NoInline.apply_callsite(llvm::AttributePlace::Function, llret);
}
}
22 changes: 10 additions & 12 deletions src/librustc_codegen_llvm/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
//! closure.

use attributes;
use common::{self, CodegenCx};
use consts;
use declare;
use common;
use llvm;
use monomorphize::Instance;
use type_of::LayoutLlvmExt;
use context::CodegenCx;
use value::Value;
use interfaces::*;

Expand All @@ -40,16 +38,16 @@ pub fn get_fn(
cx: &CodegenCx<'ll, 'tcx, &'ll Value>,
instance: Instance<'tcx>,
) -> &'ll Value {
let tcx = cx.tcx;
let tcx = cx.tcx();

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

assert!(!instance.substs.needs_infer());
assert!(!instance.substs.has_escaping_regions());
assert!(!instance.substs.has_param_types());

let fn_ty = instance.ty(cx.tcx);
if let Some(&llfn) = cx.instances.borrow().get(&instance) {
let fn_ty = instance.ty(*cx.tcx());
if let Some(&llfn) = cx.instances().borrow().get(&instance) {
return llfn;
}

Expand All @@ -58,9 +56,9 @@ pub fn get_fn(

// Create a fn pointer with the substituted signature.
let fn_ptr_ty = tcx.mk_fn_ptr(common::ty_fn_sig(cx, fn_ty));
let llptrty = cx.layout_of(fn_ptr_ty).llvm_type(cx);
let llptrty = cx.backend_type(&cx.layout_of(fn_ptr_ty));

let llfn = if let Some(llfn) = declare::get_declared_value(cx, &sym) {
let llfn = if let Some(llfn) = cx.get_declared_value(&sym) {
// This is subtle and surprising, but sometimes we have to bitcast
// the resulting fn pointer. The reason has to do with external
// functions. If you have two crates that both bind the same C
Expand All @@ -86,17 +84,17 @@ pub fn get_fn(
// other weird situations. Annoying.
if cx.val_ty(llfn) != llptrty {
debug!("get_fn: casting {:?} to {:?}", llfn, llptrty);
consts::ptrcast(llfn, llptrty)
cx.static_ptrcast(llfn, llptrty)
} else {
debug!("get_fn: not casting pointer!");
llfn
}
} else {
let llfn = declare::declare_fn(cx, &sym, fn_ty);
let llfn = cx.declare_fn(&sym, fn_ty);
assert_eq!(cx.val_ty(llfn), llptrty);
debug!("get_fn: not casting pointer!");

if instance.def.is_inline(tcx) {
if instance.def.is_inline(*tcx) {
attributes::inline(cx, llfn, attributes::InlineAttr::Hint);
}
attributes::from_fn_attrs(cx, llfn, Some(instance.def.def_id()));
Expand Down
Loading