Skip to content

Commit 125b640

Browse files
committed
---
yaml --- r: 138415 b: refs/heads/try2 c: 423843e h: refs/heads/master i: 138413: a13de82 138411: 9e2f3e7 138407: e37c816 138399: 0086df1 v: v3
1 parent 6549548 commit 125b640

File tree

6 files changed

+71
-28
lines changed

6 files changed

+71
-28
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 62f2b4943a223ff7dc168d8fed5ebc50f34150db
8+
refs/heads/try2: 423843e54bdbd6e32a0a75b7502904458e20c480
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/trans/expr.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,29 @@ fn trans_rvalue_stmt_unadjusted(bcx: block, expr: @ast::expr) -> block {
491491
ast::expr_swap(dst, src) => {
492492
let dst_datum = unpack_datum!(bcx, trans_lvalue(bcx, dst));
493493
let src_datum = unpack_datum!(bcx, trans_lvalue(bcx, src));
494-
let scratch = scratch_datum(bcx, dst_datum.ty, false);
495494

496-
let bcx = dst_datum.move_to_datum(bcx, INIT, scratch);
497-
let bcx = src_datum.move_to_datum(bcx, INIT, dst_datum);
498-
return scratch.move_to_datum(bcx, INIT, src_datum);
495+
// If the source and destination are the same, then don't swap.
496+
// Avoids performing an overlapping memcpy
497+
let dst_datum_ref = dst_datum.to_ref_llval(bcx);
498+
let src_datum_ref = src_datum.to_ref_llval(bcx);
499+
let cmp = ICmp(bcx, lib::llvm::IntEQ,
500+
src_datum_ref,
501+
dst_datum_ref);
502+
503+
let swap_cx = base::sub_block(bcx, ~"swap");
504+
let next_cx = base::sub_block(bcx, ~"next");
505+
506+
CondBr(bcx, cmp, next_cx.llbb, swap_cx.llbb);
507+
508+
let scratch = scratch_datum(swap_cx, dst_datum.ty, false);
509+
510+
let swap_cx = dst_datum.move_to_datum(swap_cx, INIT, scratch);
511+
let swap_cx = src_datum.move_to_datum(swap_cx, INIT, dst_datum);
512+
let swap_cx = scratch.move_to_datum(swap_cx, INIT, src_datum);
513+
514+
Br(swap_cx, next_cx.llbb);
515+
516+
return next_cx;
499517
}
500518
ast::expr_assign_op(op, dst, src) => {
501519
return trans_assign_op(bcx, expr, op, dst, src);

branches/try2/src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2823,7 +2823,7 @@ pub pure fn ty_fn_ret(fty: t) -> t {
28232823
}
28242824
}
28252825

2826-
pub fn is_fn_ty(fty: t) -> bool {
2826+
fn is_fn_ty(fty: t) -> bool {
28272827
match get(fty).sty {
28282828
ty_bare_fn(_) => true,
28292829
ty_closure(_) => true,

branches/try2/src/librustc/middle/typeck/check/_match.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path,
9292
match structure_of(pcx.fcx, pat.span, expected) {
9393
ty::ty_enum(_, ref expected_substs) => {
9494
// Lookup the enum and variant def ids:
95-
let v_def = lookup_def(pcx.fcx, pat.span, pat.id);
95+
let v_def = lookup_def(pcx.fcx, path.span, pat.id);
9696
let v_def_ids = ast_util::variant_def_ids(v_def);
9797

9898
// Assign the pattern the type of the *enum*, not the variant.
@@ -125,17 +125,8 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path,
125125
kind_name = "variant";
126126
}
127127
ty::ty_struct(struct_def_id, ref expected_substs) => {
128-
// Lookup the struct ctor def id
129-
let s_def = lookup_def(pcx.fcx, pat.span, pat.id);
130-
let s_def_id = ast_util::def_id_of_def(s_def);
131-
132128
// Assign the pattern the type of the struct.
133-
let ctor_tpt = ty::lookup_item_type(tcx, s_def_id);
134-
let struct_tpt = if ty::is_fn_ty(ctor_tpt.ty) {
135-
{ty: ty::ty_fn_ret(ctor_tpt.ty), ..ctor_tpt}
136-
} else {
137-
ctor_tpt
138-
};
129+
let struct_tpt = ty::lookup_item_type(tcx, struct_def_id);
139130
instantiate_path(pcx.fcx, path, struct_tpt, pat.span, pat.id,
140131
pcx.block_region);
141132

branches/try2/src/test/compile-fail/match-struct.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
// Issue #5041 - avoid overlapping memcpy when src and dest of a swap are the same
12+
13+
pub fn main() {
14+
let mut test = TestDescAndFn {
15+
desc: TestDesc {
16+
name: DynTestName(~"test"),
17+
should_fail: false
18+
},
19+
testfn: DynTestFn(|| ()),
20+
};
21+
do_swap(&mut test);
22+
}
23+
24+
fn do_swap(test: &mut TestDescAndFn) {
25+
*test <-> *test;
26+
}
27+
28+
pub enum TestName {
29+
DynTestName(~str)
30+
}
31+
32+
pub enum TestFn {
33+
DynTestFn(~fn()),
34+
DynBenchFn(~fn(&mut int))
35+
}
36+
37+
pub struct TestDesc {
38+
name: TestName,
39+
should_fail: bool
40+
}
41+
42+
pub struct TestDescAndFn {
43+
desc: TestDesc,
44+
testfn: TestFn,
45+
}

0 commit comments

Comments
 (0)