Skip to content

Commit 5222353

Browse files
committed
---
yaml --- r: 42371 b: refs/heads/master c: 9ad616a h: refs/heads/master i: 42369: a848c42 42367: 5530c1c v: v3
1 parent e83de2f commit 5222353

File tree

6 files changed

+99
-4
lines changed

6 files changed

+99
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 9123c585268fb7ae844b6cd98559a76ba080448f
2+
refs/heads/master: 9ad616a10263fab6aed7bfa610bb6cc932936fc1
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
55
refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650

trunk/src/libcore/ptr.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,18 @@ pub trait Ptr<T> {
187187
pure fn offset(count: uint) -> Self;
188188
}
189189

190+
#[cfg(stage0)]
191+
unsafe fn memmove32(dst: *mut u8, src: *const u8, count: u32) {
192+
libc::memmove(dst as *c_void, src as *c_void, count as size_t);
193+
}
194+
#[cfg(stage0)]
195+
unsafe fn memmove64(dst: *mut u8, src: *const u8, count: u64) {
196+
libc::memmove(dst as *c_void, src as *c_void, count as size_t);
197+
}
198+
190199
#[abi="rust-intrinsic"]
200+
#[cfg(stage1)]
201+
#[cfg(stage2)]
191202
pub extern {
192203
fn memmove32(dst: *mut u8, src: *u8, size: u32);
193204
fn memmove64(dst: *mut u8, src: *u8, size: u64);

trunk/src/librustc/middle/trans/consts.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,15 @@ pub fn const_vec(cx: @crate_ctxt, e: @ast::expr, es: &[@ast::expr])
7373
let vec_ty = ty::expr_ty(cx.tcx, e);
7474
let unit_ty = ty::sequence_element_type(cx.tcx, vec_ty);
7575
let llunitty = type_of::type_of(cx, unit_ty);
76-
let v = C_array(llunitty, es.map(|e| const_expr(cx, *e)));
7776
let unit_sz = machine::llsize_of(cx, llunitty);
7877
let sz = llvm::LLVMConstMul(C_uint(cx, es.len()), unit_sz);
78+
let vs = es.map(|e| const_expr(cx, *e));
79+
// If the vector contains enums, an LLVM array won't work.
80+
let v = if vs.any(|vi| val_ty(*vi) != llunitty) {
81+
C_struct(vs)
82+
} else {
83+
C_array(llunitty, vs)
84+
};
7985
return (v, sz, llunitty);
8086
}
8187
}
@@ -434,7 +440,13 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
434440
let lldiscrim = base::get_discrim_val(cx, e.span,
435441
enum_did,
436442
variant_did);
437-
C_struct(~[lldiscrim])
443+
// However, we still have to pad it out to the
444+
// size of the full enum; see the expr_call case,
445+
// below.
446+
let ety = ty::expr_ty(cx.tcx, e);
447+
let size = machine::static_size_of_enum(cx, ety);
448+
let padding = C_null(T_array(T_i8(), size));
449+
C_struct(~[lldiscrim, padding])
438450
}
439451
Some(ast::def_struct(_)) => {
440452
let ety = ty::expr_ty(cx.tcx, e);
@@ -470,7 +482,20 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
470482

471483
// FIXME (#1645): enum body alignment is generaly wrong.
472484
if !degen {
473-
C_packed_struct(~[discrim, c_args])
485+
// Pad out the data to the size of its type_of;
486+
// this is necessary if the enum is contained
487+
// within an aggregate (tuple, struct, vector) so
488+
// that the next element is at the right offset.
489+
let actual_size =
490+
machine::llsize_of_real(cx, llvm::LLVMTypeOf(c_args));
491+
let padding =
492+
C_null(T_array(T_i8(), size - actual_size));
493+
// A packed_struct has an alignment of 1; thus,
494+
// wrapping one around c_args will misalign it the
495+
// same way we normally misalign enum bodies
496+
// without affecting its internal alignment or
497+
// changing the alignment of the enum.
498+
C_struct(~[discrim, C_packed_struct(~[c_args]), padding])
474499
} else if size == 0 {
475500
C_struct(~[discrim])
476501
} else {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum E { V16(u16), V32(u32) }
12+
const C: (E, u16, u16) = (V16(0xDEAD), 0x600D, 0xBAD);
13+
14+
fn main() {
15+
let (_, n, _) = C;
16+
assert n != 0xBAD;
17+
assert n == 0x600D;
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum E { V0, V16(u16) }
12+
const C: (E, u16, u16) = (V0, 0x600D, 0xBAD);
13+
14+
fn main() {
15+
let (_, n, _) = C;
16+
assert n != 0xBAD;
17+
assert n == 0x600D;
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum E { V1(int), V0 }
12+
const C: [E * 3] = [V0, V1(0xDEADBEE), V0];
13+
14+
fn main() {
15+
match C[1] {
16+
V1(n) => assert(n == 0xDEADBEE),
17+
_ => die!()
18+
}
19+
match C[2] {
20+
V0 => (),
21+
_ => die!()
22+
}
23+
}

0 commit comments

Comments
 (0)