Skip to content

Commit

Permalink
rustc: remove some unnecessary transmutes.
Browse files Browse the repository at this point in the history
These can all be done by implicit or explicit &T -> *T casts, which are
more restricted and so are safer.
  • Loading branch information
huonw committed Feb 19, 2014
1 parent c4afcf4 commit dcee327
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
5 changes: 1 addition & 4 deletions src/librustc/middle/trans/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use syntax::codemap::Span;
use middle::trans::builder::Builder;
use middle::trans::type_::Type;

use std::cast;
use std::libc::{c_uint, c_ulonglong, c_char};

pub fn terminate(cx: &Block, _: &str) {
Expand Down Expand Up @@ -623,9 +622,7 @@ pub fn Phi(cx: &Block, Ty: Type, vals: &[ValueRef], bbs: &[BasicBlockRef]) -> Va
pub fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) {
unsafe {
if llvm::LLVMIsUndef(phi) == lib::llvm::True { return; }
let valptr = cast::transmute(&val);
let bbptr = cast::transmute(&bb);
llvm::LLVMAddIncoming(phi, valptr, bbptr, 1 as c_uint);
llvm::LLVMAddIncoming(phi, &val, &bb, 1 as c_uint);
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/librustc/middle/trans/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use middle::trans::base;
use middle::trans::common::*;
use middle::trans::machine::llalign_of_pref;
use middle::trans::type_::Type;
use std::cast;
use std::hashmap::HashMap;
use std::libc::{c_uint, c_ulonglong, c_char};
use syntax::codemap::Span;
Expand All @@ -30,10 +29,8 @@ pub struct Builder<'a> {
// This is a really awful way to get a zero-length c-string, but better (and a
// lot more efficient) than doing str::as_c_str("", ...) every time.
pub fn noname() -> *c_char {
unsafe {
static cnull: uint = 0u;
cast::transmute(&cnull)
}
static cnull: c_char = 0;
&cnull as *c_char
}

impl<'a> Builder<'a> {
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ use util::ppaux::Repr;

use arena::TypedArena;
use std::c_str::ToCStr;
use std::cast::transmute;
use std::cast;
use std::cell::{Cell, RefCell};
use std::hashmap::HashMap;
use std::libc::{c_uint, c_longlong, c_ulonglong, c_char};
Expand Down Expand Up @@ -668,7 +666,7 @@ pub fn C_array(ty: Type, elts: &[ValueRef]) -> ValueRef {

pub fn C_bytes(bytes: &[u8]) -> ValueRef {
unsafe {
let ptr = cast::transmute(bytes.as_ptr());
let ptr = bytes.as_ptr() as *c_char;
return llvm::LLVMConstStringInContext(base::task_llcx(), ptr, bytes.len() as c_uint, True);
}
}
Expand Down

1 comment on commit dcee327

@pnkfelix
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

Please sign in to comment.