Skip to content

Commit

Permalink
handle attributes for non-immediate types first
Browse files Browse the repository at this point in the history
Slices are non-immediate and were not having these attributes applied.
  • Loading branch information
thestinger committed May 26, 2014
1 parent 0c51149 commit 22ab530
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/librustc/middle/trans/base.rs
Expand Up @@ -1728,16 +1728,20 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6

for (idx, &t) in fn_sig.inputs.iter().enumerate().map(|(i, v)| (i + first_arg_offset, v)) {
match ty::get(t).sty {
// this needs to be first to prevent fat pointers from falling through
_ if !type_is_immediate(ccx, t) => {
// For non-immediate arguments the callee gets its own copy of
// the value on the stack, so there are no aliases. It's also
// program-invisible so can't possibly capture
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
attrs.push((idx, lib::llvm::NoCaptureAttribute as u64));
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
}
// `~` pointer parameters never alias because ownership is transferred
ty::ty_uniq(_) => {
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
}
// These are not really pointers but pairs, (pointer, len)
ty::ty_rptr(_, ty::mt { ty: it, .. }) |
ty::ty_rptr(_, ty::mt { ty: it, .. }) if match ty::get(it).sty {
ty::ty_str | ty::ty_vec(..) => true, _ => false
} => {}
// `&mut` pointer parameters never alias other parameters, or mutable global data
ty::ty_rptr(b, mt) if mt.mutbl == ast::MutMutable => {
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
Expand All @@ -1759,16 +1763,7 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6
ty::ty_rptr(_, _) => {
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
}
_ => {
// For non-immediate arguments the callee gets its own copy of
// the value on the stack, so there are no aliases. It's also
// program-invisible so can't possibly capture
if !type_is_immediate(ccx, t) {
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
attrs.push((idx, lib::llvm::NoCaptureAttribute as u64));
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
}
}
_ => ()
}
}

Expand Down

5 comments on commit 22ab530

@bors
Copy link
Contributor

@bors bors commented on 22ab530 May 26, 2014

Choose a reason for hiding this comment

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

@bors
Copy link
Contributor

@bors bors commented on 22ab530 May 26, 2014

Choose a reason for hiding this comment

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

merging thestinger/rust/nonnull = 22ab530 into auto

@bors
Copy link
Contributor

@bors bors commented on 22ab530 May 26, 2014

Choose a reason for hiding this comment

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

thestinger/rust/nonnull = 22ab530 merged ok, testing candidate = 6fad19e

@bors
Copy link
Contributor

@bors bors commented on 22ab530 May 26, 2014

@bors
Copy link
Contributor

@bors bors commented on 22ab530 May 26, 2014

Choose a reason for hiding this comment

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

fast-forwarding master to auto = 6fad19e

Please sign in to comment.