Skip to content

Commit

Permalink
Fix passing self by value for types passed by value
Browse files Browse the repository at this point in the history
For types that are passed by value, we can't just cast the value to a
pointer, but have to use an alloca and copy the value there. This
handling is already present for all other arguments, but was missing
for "self".

Fixes #6682, #4850 and #4878
  • Loading branch information
dotdash committed Jun 2, 2013
1 parent c354a0c commit b51f44e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1730,8 +1730,15 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt,
// We really should do this regardless of whether self is owned, but
// it doesn't work right with default method impls yet. (FIXME: #2794)
if slf.is_owned {
let self_val = PointerCast(bcx, slf.v,
T_ptr(type_of(bcx.ccx(), slf.t)));
let self_val = if datum::appropriate_mode(slf.t).is_by_value() {
let tmp = BitCast(bcx, slf.v, type_of(bcx.ccx(), slf.t));
let alloc = alloc_ty(bcx, slf.t);
Store(bcx, tmp, alloc);
alloc
} else {
PointerCast(bcx, slf.v, T_ptr(type_of(bcx.ccx(), slf.t)))
};

fcx.llself = Some(ValSelfData {v: self_val, ..slf});
add_clean(bcx, self_val, slf.t);
}
Expand Down

5 comments on commit b51f44e

@bors
Copy link
Contributor

@bors bors commented on b51f44e Jun 3, 2013

Choose a reason for hiding this comment

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

saw approval from catamorphism
at dotdash@b51f44e

@bors
Copy link
Contributor

@bors bors commented on b51f44e Jun 3, 2013

Choose a reason for hiding this comment

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

merging dotdash/rust/self_by_value = b51f44e into auto

@bors
Copy link
Contributor

@bors bors commented on b51f44e Jun 3, 2013

Choose a reason for hiding this comment

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

dotdash/rust/self_by_value = b51f44e merged ok, testing candidate = 4f6285f

@bors
Copy link
Contributor

@bors bors commented on b51f44e Jun 3, 2013

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 b51f44e Jun 3, 2013

Choose a reason for hiding this comment

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

fast-forwarding incoming to auto = 4f6285f

Please sign in to comment.