Don't copy const data to do an autoderef+autoref.

This commit is contained in:
Jed Davis 2013-03-08 11:29:47 -08:00
parent c929ddde16
commit 122e4a28b8
2 changed files with 27 additions and 3 deletions

View File

@ -182,8 +182,10 @@ pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
}
Some(@ty::AutoDerefRef(ref adj)) => {
let mut ty = ety;
let mut maybe_ptr = None;
for adj.autoderefs.times {
let (dv, dt) = const_deref(cx, llconst, ty, false);
maybe_ptr = Some(llconst);
llconst = dv;
ty = dt;
}
@ -193,17 +195,21 @@ pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
Some(ref autoref) => {
fail_unless!(autoref.region == ty::re_static);
fail_unless!(autoref.mutbl != ast::m_mutbl);
// Don't copy data to do a deref+ref.
let llptr = match maybe_ptr {
Some(ptr) => ptr,
None => const_addr_of(cx, llconst)
};
match autoref.kind {
ty::AutoPtr => {
llconst = const_addr_of(cx, llconst);
llconst = llptr;
}
ty::AutoBorrowVec => {
let base = const_addr_of(cx, llconst);
let size = machine::llsize_of(cx,
val_ty(llconst));
fail_unless!(abi::slice_elt_base == 0);
fail_unless!(abi::slice_elt_len == 1);
llconst = C_struct(~[base, size]);
llconst = C_struct(~[llptr, size]);
}
_ => {
cx.sess.span_bug(e.span,

View File

@ -0,0 +1,18 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
type Big = [u64 * 8];
struct Pair { a: int, b: &'self Big }
const x: &'static Big = &([13, 14, 10, 13, 11, 14, 14, 15]);
const y: &'static Pair<'static> = &Pair {a: 15, b: x};
pub fn main() {
fail_unless!(ptr::addr_of(x) == ptr::addr_of(y.b));
}