Skip to content

Implement by-value object safety #54183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Oct 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

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
Make declare_fn accept PolyFnSig instead of Ty.
  • Loading branch information
qnighy committed Oct 24, 2018
commit 06b6b1c79088a2697c38cd1719ebe0ce13e67d0b
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn get_fn(
llfn
}
} else {
let llfn = declare::declare_fn(cx, &sym, fn_ty, instance.is_vtable_shim());
let llfn = declare::declare_fn(cx, &sym, common::ty_fn_sig_vtable(cx, fn_ty, instance.is_vtable_shim()));
assert_eq!(common::val_ty(llfn), llptrty);
debug!("get_fn: not casting pointer!");

Expand Down
6 changes: 3 additions & 3 deletions src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,15 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
return llfn;
}

let ty = tcx.mk_fn_ptr(ty::Binder::bind(tcx.mk_fn_sig(
let sig = ty::Binder::bind(tcx.mk_fn_sig(
iter::once(tcx.mk_mut_ptr(tcx.types.u8)),
tcx.types.never,
false,
hir::Unsafety::Unsafe,
Abi::C
)));
));

let llfn = declare::declare_fn(self, "rust_eh_unwind_resume", ty, false);
let llfn = declare::declare_fn(self, "rust_eh_unwind_resume", sig);
attributes::unwind(llfn, true);
attributes::apply_target_cpu_attr(self, llfn);
unwresume.set(Some(llfn));
Expand Down
18 changes: 7 additions & 11 deletions src/librustc_codegen_llvm/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@

use llvm;
use llvm::AttributePlace::Function;
use rustc::ty::{self, Ty};
use rustc::ty::{self, PolyFnSig};
use rustc::ty::layout::LayoutOf;
use rustc::session::config::Sanitizer;
use rustc_data_structures::small_c_str::SmallCStr;
use rustc_target::spec::PanicStrategy;
use abi::{Abi, FnType, FnTypeExt};
use attributes;
use context::CodegenCx;
use common;
use type_::Type;
use value::Value;

Expand Down Expand Up @@ -129,12 +128,9 @@ pub fn declare_cfn(cx: &CodegenCx<'ll, '_>, name: &str, fn_type: &'ll Type) -> &
pub fn declare_fn(
cx: &CodegenCx<'ll, 'tcx>,
name: &str,
fn_type: Ty<'tcx>,
is_vtable_shim: bool,
sig: PolyFnSig<'tcx>,
) -> &'ll Value {
debug!("declare_rust_fn(name={:?}, fn_type={:?}, is_vtable_shim={:?})",
name, fn_type, is_vtable_shim);
let sig = common::ty_fn_sig_vtable(cx, fn_type, is_vtable_shim);
debug!("declare_rust_fn(name={:?}, sig={:?})", name, sig);
let sig = cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
debug!("declare_rust_fn (after region erasure) sig={:?}", sig);

Expand Down Expand Up @@ -186,12 +182,12 @@ pub fn define_private_global(cx: &CodegenCx<'ll, '_>, ty: &'ll Type) -> &'ll Val
pub fn define_fn(
cx: &CodegenCx<'ll, 'tcx>,
name: &str,
fn_type: Ty<'tcx>,
fn_sig: PolyFnSig<'tcx>,
) -> &'ll Value {
if get_defined_value(cx, name).is_some() {
cx.sess().fatal(&format!("symbol `{}` already defined", name))
} else {
declare_fn(cx, name, fn_type, false)
declare_fn(cx, name, fn_sig)
}
}

Expand All @@ -203,9 +199,9 @@ pub fn define_fn(
pub fn define_internal_fn(
cx: &CodegenCx<'ll, 'tcx>,
name: &str,
fn_type: Ty<'tcx>,
fn_sig: PolyFnSig<'tcx>,
) -> &'ll Value {
let llfn = define_fn(cx, name, fn_type);
let llfn = define_fn(cx, name, fn_sig);
unsafe { llvm::LLVMRustSetLinkage(llfn, llvm::Linkage::InternalLinkage) };
llfn
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_codegen_llvm/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,14 +933,14 @@ fn gen_fn<'ll, 'tcx>(
output: Ty<'tcx>,
codegen: &mut dyn FnMut(Builder<'_, 'll, 'tcx>),
) -> &'ll Value {
let rust_fn_ty = cx.tcx.mk_fn_ptr(ty::Binder::bind(cx.tcx.mk_fn_sig(
let rust_fn_sig = ty::Binder::bind(cx.tcx.mk_fn_sig(
inputs.into_iter(),
output,
false,
hir::Unsafety::Unsafe,
Abi::Rust
)));
let llfn = declare::define_internal_fn(cx, name, rust_fn_ty);
));
let llfn = declare::define_internal_fn(cx, name, rust_fn_sig);
attributes::from_fn_attrs(cx, llfn, None);
let bx = Builder::new_block(cx, llfn, "entry-block");
codegen(bx);
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_codegen_llvm/mono_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use asm;
use attributes;
use base;
use common;
use consts;
use context::CodegenCx;
use declare;
Expand Down Expand Up @@ -154,8 +155,9 @@ fn predefine_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
!instance.substs.has_param_types());

let mono_ty = instance.ty(cx.tcx);
let mono_sig = common::ty_fn_sig_vtable(cx, mono_ty, instance.is_vtable_shim());
let attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
let lldecl = declare::declare_fn(cx, symbol_name, mono_ty, instance.is_vtable_shim());
let lldecl = declare::declare_fn(cx, symbol_name, mono_sig);
unsafe { llvm::LLVMRustSetLinkage(lldecl, base::linkage_to_llvm(linkage)) };
base::set_link_section(lldecl, &attrs);
if linkage == Linkage::LinkOnceODR ||
Expand Down