rustc: remove unnecessary unsafe blocks/methods
This commit is contained in:
parent
52445129fd
commit
72c24e20a9
6 changed files with 155 additions and 177 deletions
|
@ -615,9 +615,7 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn truncated_hash_result(symbol_hasher: &hash::State) -> ~str {
|
pub fn truncated_hash_result(symbol_hasher: &hash::State) -> ~str {
|
||||||
unsafe {
|
symbol_hasher.result_str()
|
||||||
symbol_hasher.result_str()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -369,7 +369,7 @@ pub impl<'self> LanguageItemCollector<'self> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_local_language_items(&self) {
|
fn collect_local_language_items(&self) {
|
||||||
let this = unsafe { ptr::addr_of(&self) };
|
let this = ptr::addr_of(&self);
|
||||||
visit_crate(*self.crate, (), mk_simple_visitor(@SimpleVisitor {
|
visit_crate(*self.crate, (), mk_simple_visitor(@SimpleVisitor {
|
||||||
visit_item: |item| {
|
visit_item: |item| {
|
||||||
for item.attrs.each |attribute| {
|
for item.attrs.each |attribute| {
|
||||||
|
|
|
@ -19,7 +19,7 @@ use metadata::csearch::get_type_name_if_impl;
|
||||||
use metadata::cstore::find_extern_mod_stmt_cnum;
|
use metadata::cstore::find_extern_mod_stmt_cnum;
|
||||||
use metadata::decoder::{def_like, dl_def, dl_field, dl_impl};
|
use metadata::decoder::{def_like, dl_def, dl_field, dl_impl};
|
||||||
use middle::lang_items::LanguageItems;
|
use middle::lang_items::LanguageItems;
|
||||||
use middle::lint::{deny, allow, forbid, level, unused_imports, warn};
|
use middle::lint::{allow, level, unused_imports};
|
||||||
use middle::lint::{get_lint_level, get_lint_settings_level};
|
use middle::lint::{get_lint_level, get_lint_settings_level};
|
||||||
use middle::pat_util::pat_bindings;
|
use middle::pat_util::pat_bindings;
|
||||||
|
|
||||||
|
|
|
@ -91,10 +91,8 @@ pub struct icx_popper {
|
||||||
#[unsafe_destructor]
|
#[unsafe_destructor]
|
||||||
impl Drop for icx_popper {
|
impl Drop for icx_popper {
|
||||||
fn finalize(&self) {
|
fn finalize(&self) {
|
||||||
unsafe {
|
if self.ccx.sess.count_llvm_insns() {
|
||||||
if self.ccx.sess.count_llvm_insns() {
|
self.ccx.stats.llvm_insn_ctxt.pop();
|
||||||
self.ccx.stats.llvm_insn_ctxt.pop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,9 +143,7 @@ pub fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
|
||||||
llvm::LLVMGetOrInsertFunction(llmod, buf, llty)
|
llvm::LLVMGetOrInsertFunction(llmod, buf, llty)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
unsafe {
|
lib::llvm::SetFunctionCallConv(llfn, cc);
|
||||||
lib::llvm::SetFunctionCallConv(llfn, cc);
|
|
||||||
}
|
|
||||||
return llfn;
|
return llfn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -730,11 +726,9 @@ pub fn cast_shift_expr_rhs(cx: block, op: ast::binop,
|
||||||
|
|
||||||
pub fn cast_shift_const_rhs(op: ast::binop,
|
pub fn cast_shift_const_rhs(op: ast::binop,
|
||||||
lhs: ValueRef, rhs: ValueRef) -> ValueRef {
|
lhs: ValueRef, rhs: ValueRef) -> ValueRef {
|
||||||
unsafe {
|
cast_shift_rhs(op, lhs, rhs,
|
||||||
cast_shift_rhs(op, lhs, rhs,
|
|a, b| unsafe { llvm::LLVMConstTrunc(a, b) },
|
||||||
|a, b| unsafe { llvm::LLVMConstTrunc(a, b) },
|
|a, b| unsafe { llvm::LLVMConstZExt(a, b) })
|
||||||
|a, b| unsafe { llvm::LLVMConstZExt(a, b) })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cast_shift_rhs(op: ast::binop,
|
pub fn cast_shift_rhs(op: ast::binop,
|
||||||
|
@ -2865,9 +2859,7 @@ pub fn create_module_map(ccx: @CrateContext) -> ValueRef {
|
||||||
llvm::LLVMAddGlobal(ccx.llmod, maptype, buf)
|
llvm::LLVMAddGlobal(ccx.llmod, maptype, buf)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
unsafe {
|
lib::llvm::SetLinkage(map, lib::llvm::InternalLinkage);
|
||||||
lib::llvm::SetLinkage(map, lib::llvm::InternalLinkage);
|
|
||||||
}
|
|
||||||
let mut elts: ~[ValueRef] = ~[];
|
let mut elts: ~[ValueRef] = ~[];
|
||||||
for ccx.module_data.each |key, &val| {
|
for ccx.module_data.each |key, &val| {
|
||||||
let elt = C_struct(~[p2i(ccx, C_cstr(ccx, @/*bad*/ copy *key)),
|
let elt = C_struct(~[p2i(ccx, C_cstr(ccx, @/*bad*/ copy *key)),
|
||||||
|
|
|
@ -27,9 +27,7 @@ use core::str;
|
||||||
use core::vec;
|
use core::vec;
|
||||||
|
|
||||||
pub fn terminate(cx: block, _: &str) {
|
pub fn terminate(cx: block, _: &str) {
|
||||||
unsafe {
|
cx.terminated = true;
|
||||||
cx.terminated = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_not_terminated(cx: block) {
|
pub fn check_not_terminated(cx: block) {
|
||||||
|
|
|
@ -172,17 +172,15 @@ fn cast_safely<T:Copy,U>(val: T) -> U {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn md_from_metadata<T>(val: debug_metadata) -> T {
|
fn md_from_metadata<T>(val: debug_metadata) -> T {
|
||||||
unsafe {
|
match val {
|
||||||
match val {
|
file_metadata(md) => cast_safely(md),
|
||||||
file_metadata(md) => cast_safely(md),
|
compile_unit_metadata(md) => cast_safely(md),
|
||||||
compile_unit_metadata(md) => cast_safely(md),
|
subprogram_metadata(md) => cast_safely(md),
|
||||||
subprogram_metadata(md) => cast_safely(md),
|
local_var_metadata(md) => cast_safely(md),
|
||||||
local_var_metadata(md) => cast_safely(md),
|
tydesc_metadata(md) => cast_safely(md),
|
||||||
tydesc_metadata(md) => cast_safely(md),
|
block_metadata(md) => cast_safely(md),
|
||||||
block_metadata(md) => cast_safely(md),
|
argument_metadata(md) => cast_safely(md),
|
||||||
argument_metadata(md) => cast_safely(md),
|
retval_metadata(md) => cast_safely(md)
|
||||||
retval_metadata(md) => cast_safely(md)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,56 +188,52 @@ fn cached_metadata<T:Copy>(cache: metadata_cache,
|
||||||
mdtag: int,
|
mdtag: int,
|
||||||
eq_fn: &fn(md: T) -> bool)
|
eq_fn: &fn(md: T) -> bool)
|
||||||
-> Option<T> {
|
-> Option<T> {
|
||||||
unsafe {
|
if cache.contains_key(&mdtag) {
|
||||||
if cache.contains_key(&mdtag) {
|
let items = cache.get(&mdtag);
|
||||||
let items = cache.get(&mdtag);
|
for items.each |item| {
|
||||||
for items.each |item| {
|
let md: T = md_from_metadata::<T>(*item);
|
||||||
let md: T = md_from_metadata::<T>(*item);
|
if eq_fn(md) {
|
||||||
if eq_fn(md) {
|
return option::Some(md);
|
||||||
return option::Some(md);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return option::None;
|
|
||||||
}
|
}
|
||||||
|
return option::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_compile_unit(cx: @CrateContext) -> @Metadata<CompileUnitMetadata> {
|
fn create_compile_unit(cx: @CrateContext) -> @Metadata<CompileUnitMetadata> {
|
||||||
unsafe {
|
let cache = get_cache(cx);
|
||||||
let cache = get_cache(cx);
|
let crate_name = /*bad*/copy (/*bad*/copy cx.dbg_cx).get().crate_file;
|
||||||
let crate_name = /*bad*/copy (/*bad*/copy cx.dbg_cx).get().crate_file;
|
let tg = CompileUnitTag;
|
||||||
let tg = CompileUnitTag;
|
match cached_metadata::<@Metadata<CompileUnitMetadata>>(cache, tg,
|
||||||
match cached_metadata::<@Metadata<CompileUnitMetadata>>(cache, tg,
|
|md| md.data.name == crate_name) {
|
||||||
|md| md.data.name == crate_name) {
|
option::Some(md) => return md,
|
||||||
option::Some(md) => return md,
|
option::None => ()
|
||||||
option::None => ()
|
|
||||||
}
|
|
||||||
|
|
||||||
let (_, work_dir) = get_file_path_and_dir(
|
|
||||||
cx.sess.working_dir.to_str(), crate_name);
|
|
||||||
let unit_metadata = ~[lltag(tg),
|
|
||||||
llunused(),
|
|
||||||
lli32(DW_LANG_RUST),
|
|
||||||
llstr(crate_name),
|
|
||||||
llstr(work_dir),
|
|
||||||
llstr(env!("CFG_VERSION")),
|
|
||||||
lli1(true), // deprecated: main compile unit
|
|
||||||
lli1(cx.sess.opts.optimize != session::No),
|
|
||||||
llstr(~""), // flags (???)
|
|
||||||
lli32(0) // runtime version (???)
|
|
||||||
];
|
|
||||||
let unit_node = llmdnode(unit_metadata);
|
|
||||||
add_named_metadata(cx, ~"llvm.dbg.cu", unit_node);
|
|
||||||
let mdval = @Metadata {
|
|
||||||
node: unit_node,
|
|
||||||
data: CompileUnitMetadata {
|
|
||||||
name: crate_name
|
|
||||||
}
|
|
||||||
};
|
|
||||||
update_cache(cache, tg, compile_unit_metadata(mdval));
|
|
||||||
|
|
||||||
return mdval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let (_, work_dir) = get_file_path_and_dir(
|
||||||
|
cx.sess.working_dir.to_str(), crate_name);
|
||||||
|
let unit_metadata = ~[lltag(tg),
|
||||||
|
llunused(),
|
||||||
|
lli32(DW_LANG_RUST),
|
||||||
|
llstr(crate_name),
|
||||||
|
llstr(work_dir),
|
||||||
|
llstr(env!("CFG_VERSION")),
|
||||||
|
lli1(true), // deprecated: main compile unit
|
||||||
|
lli1(cx.sess.opts.optimize != session::No),
|
||||||
|
llstr(~""), // flags (???)
|
||||||
|
lli32(0) // runtime version (???)
|
||||||
|
];
|
||||||
|
let unit_node = llmdnode(unit_metadata);
|
||||||
|
add_named_metadata(cx, ~"llvm.dbg.cu", unit_node);
|
||||||
|
let mdval = @Metadata {
|
||||||
|
node: unit_node,
|
||||||
|
data: CompileUnitMetadata {
|
||||||
|
name: crate_name
|
||||||
|
}
|
||||||
|
};
|
||||||
|
update_cache(cache, tg, compile_unit_metadata(mdval));
|
||||||
|
|
||||||
|
return mdval;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_cache(cx: @CrateContext) -> metadata_cache {
|
fn get_cache(cx: @CrateContext) -> metadata_cache {
|
||||||
|
@ -710,114 +704,110 @@ fn create_var(type_tag: int, context: ValueRef, name: &str, file: ValueRef,
|
||||||
|
|
||||||
pub fn create_local_var(bcx: block, local: @ast::local)
|
pub fn create_local_var(bcx: block, local: @ast::local)
|
||||||
-> @Metadata<LocalVarMetadata> {
|
-> @Metadata<LocalVarMetadata> {
|
||||||
unsafe {
|
let cx = bcx.ccx();
|
||||||
let cx = bcx.ccx();
|
let cache = get_cache(cx);
|
||||||
let cache = get_cache(cx);
|
let tg = AutoVariableTag;
|
||||||
let tg = AutoVariableTag;
|
match cached_metadata::<@Metadata<LocalVarMetadata>>(
|
||||||
match cached_metadata::<@Metadata<LocalVarMetadata>>(
|
cache, tg, |md| md.data.id == local.node.id) {
|
||||||
cache, tg, |md| md.data.id == local.node.id) {
|
option::Some(md) => return md,
|
||||||
option::Some(md) => return md,
|
option::None => ()
|
||||||
option::None => ()
|
|
||||||
}
|
|
||||||
|
|
||||||
let name = match local.node.pat.node {
|
|
||||||
ast::pat_ident(_, pth, _) => ast_util::path_to_ident(pth),
|
|
||||||
// FIXME this should be handled (#2533)
|
|
||||||
_ => fail!(~"no single variable name for local")
|
|
||||||
};
|
|
||||||
let loc = cx.sess.codemap.lookup_char_pos(local.span.lo);
|
|
||||||
let ty = node_id_type(bcx, local.node.id);
|
|
||||||
let tymd = create_ty(cx, ty, local.node.ty.span);
|
|
||||||
let filemd = create_file(cx, /*bad*/copy loc.file.name);
|
|
||||||
let context = match bcx.parent {
|
|
||||||
None => create_function(bcx.fcx).node,
|
|
||||||
Some(_) => create_block(bcx).node
|
|
||||||
};
|
|
||||||
let mdnode = create_var(tg, context, *cx.sess.str_of(name),
|
|
||||||
filemd.node, loc.line as int, tymd.node);
|
|
||||||
let mdval = @Metadata {
|
|
||||||
node: mdnode,
|
|
||||||
data: LocalVarMetadata {
|
|
||||||
id: local.node.id
|
|
||||||
}
|
|
||||||
};
|
|
||||||
update_cache(cache, AutoVariableTag, local_var_metadata(mdval));
|
|
||||||
|
|
||||||
let llptr = match bcx.fcx.lllocals.find(&local.node.id) {
|
|
||||||
option::Some(&local_mem(v)) => v,
|
|
||||||
option::Some(_) => {
|
|
||||||
bcx.tcx().sess.span_bug(local.span, ~"local is bound to \
|
|
||||||
something weird");
|
|
||||||
}
|
|
||||||
option::None => {
|
|
||||||
match *bcx.fcx.lllocals.get(&local.node.pat.id) {
|
|
||||||
local_imm(v) => v,
|
|
||||||
_ => bcx.tcx().sess.span_bug(local.span, ~"local is bound to \
|
|
||||||
something weird")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let declargs = ~[llmdnode(~[llptr]), mdnode];
|
|
||||||
trans::build::Call(bcx, *cx.intrinsics.get(&~"llvm.dbg.declare"),
|
|
||||||
declargs);
|
|
||||||
return mdval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let name = match local.node.pat.node {
|
||||||
|
ast::pat_ident(_, pth, _) => ast_util::path_to_ident(pth),
|
||||||
|
// FIXME this should be handled (#2533)
|
||||||
|
_ => fail!(~"no single variable name for local")
|
||||||
|
};
|
||||||
|
let loc = cx.sess.codemap.lookup_char_pos(local.span.lo);
|
||||||
|
let ty = node_id_type(bcx, local.node.id);
|
||||||
|
let tymd = create_ty(cx, ty, local.node.ty.span);
|
||||||
|
let filemd = create_file(cx, /*bad*/copy loc.file.name);
|
||||||
|
let context = match bcx.parent {
|
||||||
|
None => create_function(bcx.fcx).node,
|
||||||
|
Some(_) => create_block(bcx).node
|
||||||
|
};
|
||||||
|
let mdnode = create_var(tg, context, *cx.sess.str_of(name),
|
||||||
|
filemd.node, loc.line as int, tymd.node);
|
||||||
|
let mdval = @Metadata {
|
||||||
|
node: mdnode,
|
||||||
|
data: LocalVarMetadata {
|
||||||
|
id: local.node.id
|
||||||
|
}
|
||||||
|
};
|
||||||
|
update_cache(cache, AutoVariableTag, local_var_metadata(mdval));
|
||||||
|
|
||||||
|
let llptr = match bcx.fcx.lllocals.find(&local.node.id) {
|
||||||
|
option::Some(&local_mem(v)) => v,
|
||||||
|
option::Some(_) => {
|
||||||
|
bcx.tcx().sess.span_bug(local.span, ~"local is bound to \
|
||||||
|
something weird");
|
||||||
|
}
|
||||||
|
option::None => {
|
||||||
|
match *bcx.fcx.lllocals.get(&local.node.pat.id) {
|
||||||
|
local_imm(v) => v,
|
||||||
|
_ => bcx.tcx().sess.span_bug(local.span, ~"local is bound to \
|
||||||
|
something weird")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let declargs = ~[llmdnode(~[llptr]), mdnode];
|
||||||
|
trans::build::Call(bcx, *cx.intrinsics.get(&~"llvm.dbg.declare"),
|
||||||
|
declargs);
|
||||||
|
return mdval;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
|
pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
|
||||||
-> Option<@Metadata<ArgumentMetadata>> {
|
-> Option<@Metadata<ArgumentMetadata>> {
|
||||||
unsafe {
|
let fcx = bcx.fcx, cx = *fcx.ccx;
|
||||||
let fcx = bcx.fcx, cx = *fcx.ccx;
|
let cache = get_cache(cx);
|
||||||
let cache = get_cache(cx);
|
let tg = ArgVariableTag;
|
||||||
let tg = ArgVariableTag;
|
match cached_metadata::<@Metadata<ArgumentMetadata>>(
|
||||||
match cached_metadata::<@Metadata<ArgumentMetadata>>(
|
cache, ArgVariableTag, |md| md.data.id == arg.id) {
|
||||||
cache, ArgVariableTag, |md| md.data.id == arg.id) {
|
option::Some(md) => return Some(md),
|
||||||
option::Some(md) => return Some(md),
|
option::None => ()
|
||||||
option::None => ()
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let loc = cx.sess.codemap.lookup_char_pos(sp.lo);
|
let loc = cx.sess.codemap.lookup_char_pos(sp.lo);
|
||||||
if loc.file.name == ~"<intrinsic>" {
|
if loc.file.name == ~"<intrinsic>" {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let ty = node_id_type(bcx, arg.id);
|
||||||
|
let tymd = create_ty(cx, ty, arg.ty.span);
|
||||||
|
let filemd = create_file(cx, /*bad*/copy loc.file.name);
|
||||||
|
let context = create_function(bcx.fcx);
|
||||||
|
|
||||||
|
match arg.pat.node {
|
||||||
|
ast::pat_ident(_, path, _) => {
|
||||||
|
// XXX: This is wrong; it should work for multiple bindings.
|
||||||
|
let mdnode = create_var(
|
||||||
|
tg,
|
||||||
|
context.node,
|
||||||
|
*cx.sess.str_of(*path.idents.last()),
|
||||||
|
filemd.node,
|
||||||
|
loc.line as int,
|
||||||
|
tymd.node
|
||||||
|
);
|
||||||
|
|
||||||
|
let mdval = @Metadata {
|
||||||
|
node: mdnode,
|
||||||
|
data: ArgumentMetadata {
|
||||||
|
id: arg.id
|
||||||
|
}
|
||||||
|
};
|
||||||
|
update_cache(cache, tg, argument_metadata(mdval));
|
||||||
|
|
||||||
|
let llptr = match *fcx.llargs.get(&arg.id) {
|
||||||
|
local_mem(v) | local_imm(v) => v,
|
||||||
|
};
|
||||||
|
let declargs = ~[llmdnode(~[llptr]), mdnode];
|
||||||
|
trans::build::Call(bcx,
|
||||||
|
*cx.intrinsics.get(&~"llvm.dbg.declare"),
|
||||||
|
declargs);
|
||||||
|
return Some(mdval);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let ty = node_id_type(bcx, arg.id);
|
|
||||||
let tymd = create_ty(cx, ty, arg.ty.span);
|
|
||||||
let filemd = create_file(cx, /*bad*/copy loc.file.name);
|
|
||||||
let context = create_function(bcx.fcx);
|
|
||||||
|
|
||||||
match arg.pat.node {
|
|
||||||
ast::pat_ident(_, path, _) => {
|
|
||||||
// XXX: This is wrong; it should work for multiple bindings.
|
|
||||||
let mdnode = create_var(
|
|
||||||
tg,
|
|
||||||
context.node,
|
|
||||||
*cx.sess.str_of(*path.idents.last()),
|
|
||||||
filemd.node,
|
|
||||||
loc.line as int,
|
|
||||||
tymd.node
|
|
||||||
);
|
|
||||||
|
|
||||||
let mdval = @Metadata {
|
|
||||||
node: mdnode,
|
|
||||||
data: ArgumentMetadata {
|
|
||||||
id: arg.id
|
|
||||||
}
|
|
||||||
};
|
|
||||||
update_cache(cache, tg, argument_metadata(mdval));
|
|
||||||
|
|
||||||
let llptr = match *fcx.llargs.get(&arg.id) {
|
|
||||||
local_mem(v) | local_imm(v) => v,
|
|
||||||
};
|
|
||||||
let declargs = ~[llmdnode(~[llptr]), mdnode];
|
|
||||||
trans::build::Call(bcx,
|
|
||||||
*cx.intrinsics.get(&~"llvm.dbg.declare"),
|
|
||||||
declargs);
|
|
||||||
return Some(mdval);
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue