Skip to content

Commit bcee608

Browse files
committed
---
yaml --- r: 138418 b: refs/heads/try2 c: 1b04be6 h: refs/heads/master v: v3
1 parent 49f6726 commit bcee608

File tree

11 files changed

+195
-12
lines changed

11 files changed

+195
-12
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: e29b7eedf9670e2a86647b318f6cb9c2a8a46463
8+
refs/heads/try2: 1b04be6858bdf7c3ab06a45b8e4049d1042a5a3d
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/etc/x86.supp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,55 @@
366366
...
367367
}
368368

369+
{
370+
enum-instruction-scheduling-1
371+
Memcheck:Cond
372+
fun:*fold_mod*
373+
...
374+
}
375+
376+
{
377+
enum-instruction-scheduling-2
378+
Memcheck:Cond
379+
fun:*fold_nmod*
380+
...
381+
}
382+
383+
{
384+
enum-instruction-scheduling-3
385+
Memcheck:Cond
386+
fun:*fold_crate*
387+
...
388+
}
389+
390+
{
391+
enum-instruction-scheduling-4
392+
Memcheck:Cond
393+
fun:*fold_enum*
394+
...
395+
}
396+
397+
{
398+
enum-instruction-scheduling-5
399+
Memcheck:Cond
400+
fun:*write_variant*
401+
...
402+
}
403+
404+
{
405+
enum-instruction-scheduling-6
406+
Memcheck:Cond
407+
fun:*merge_method_attrs*
408+
...
409+
}
410+
411+
{
412+
enum-instruction-scheduling-7
413+
Memcheck:Cond
414+
fun:*parse_config_*
415+
...
416+
}
417+
369418
{
370419
llvm-user-new-leak
371420
Memcheck:Leak

branches/try2/src/librustc/lib/llvm.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ pub enum FileType {
184184
ObjectFile = 1
185185
}
186186

187+
pub enum Metadata {
188+
MD_dbg = 0,
189+
MD_tbaa = 1,
190+
MD_prof = 2,
191+
MD_fpmath = 3,
192+
MD_range = 4,
193+
MD_tbaa_struct = 5
194+
}
195+
187196
// Opaque pointer types
188197
pub enum Module_opaque {}
189198
pub type ModuleRef = *Module_opaque;

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,13 +1361,29 @@ pub fn compile_submatch(bcx: block,
13611361
if opts.len() > 0u {
13621362
match opts[0] {
13631363
var(_, vdef) => {
1364-
if (*ty::enum_variants(tcx, vdef.enm)).len() == 1u {
1364+
let variants = ty::enum_variants(tcx, vdef.enm);
1365+
if variants.len() == 1 {
13651366
kind = single;
13661367
} else {
13671368
let enumptr =
13681369
PointerCast(bcx, val, T_opaque_enum_ptr(ccx));
13691370
let discrimptr = GEPi(bcx, enumptr, [0u, 0u]);
1370-
test_val = Load(bcx, discrimptr);
1371+
1372+
1373+
assert variants.len() > 1;
1374+
let min_discrim = do variants.foldr(0) |&x, y| {
1375+
int::min(x.disr_val, y)
1376+
};
1377+
let max_discrim = do variants.foldr(0) |&x, y| {
1378+
int::max(x.disr_val, y)
1379+
};
1380+
1381+
test_val = LoadRangeAssert(bcx, discrimptr,
1382+
min_discrim as c_ulonglong,
1383+
(max_discrim + 1)
1384+
as c_ulonglong,
1385+
lib::llvm::True);
1386+
13711387
kind = switch;
13721388
}
13731389
}

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ use lib::llvm::llvm;
1414
use lib::llvm::{CallConv, TypeKind, AtomicBinOp, AtomicOrdering};
1515
use lib::llvm::{Opcode, IntPredicate, RealPredicate, True, False};
1616
use lib::llvm::{ValueRef, TypeRef, BasicBlockRef, BuilderRef, ModuleRef};
17-
use libc::{c_uint, c_int};
17+
use libc::{c_uint, c_int, c_ulonglong};
1818
use middle::trans::common::*;
19+
use middle::trans::machine::llsize_of_real;
1920

2021
use core::cast::transmute;
2122
use core::cast;
@@ -536,6 +537,25 @@ pub fn Load(cx: block, PointerVal: ValueRef) -> ValueRef {
536537
}
537538
}
538539
540+
pub fn LoadRangeAssert(cx: block, PointerVal: ValueRef, lo: c_ulonglong,
541+
hi: c_ulonglong, signed: lib::llvm::Bool) -> ValueRef {
542+
let value = Load(cx, PointerVal);
543+
544+
unsafe {
545+
let t = llvm::LLVMGetElementType(llvm::LLVMTypeOf(PointerVal));
546+
let min = llvm::LLVMConstInt(t, lo, signed);
547+
let max = llvm::LLVMConstInt(t, hi, signed);
548+
549+
550+
do vec::as_imm_buf([min, max]) |ptr, len| {
551+
llvm::LLVMSetMetadata(value, lib::llvm::MD_range as c_uint,
552+
llvm::LLVMMDNode(ptr, len as c_uint));
553+
}
554+
}
555+
556+
value
557+
}
558+
539559
pub fn Store(cx: block, Val: ValueRef, Ptr: ValueRef) {
540560
unsafe {
541561
if cx.unreachable { return; }

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,13 @@ pub impl Datum {
431431
} else {
432432
match self.mode {
433433
ByValue => self.val,
434-
ByRef => Load(bcx, self.val)
434+
ByRef => {
435+
if ty::type_is_bool(self.ty) {
436+
LoadRangeAssert(bcx, self.val, 0, 2, lib::llvm::True)
437+
} else {
438+
Load(bcx, self.val)
439+
}
440+
}
435441
}
436442
}
437443
}

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-
fn is_fn_ty(fty: t) -> bool {
2826+
pub 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: 11 additions & 2 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, path.span, pat.id);
95+
let v_def = lookup_def(pcx.fcx, pat.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,8 +125,17 @@ 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+
128132
// Assign the pattern the type of the struct.
129-
let struct_tpt = ty::lookup_item_type(tcx, struct_def_id);
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+
};
130139
instantiate_path(pcx.fcx, path, struct_tpt, pat.span, pat.id,
131140
pcx.block_region);
132141

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// error-pattern: mismatched types
2+
3+
struct S { a: int }
4+
enum E { C(int) }
5+
6+
fn main() {
7+
match S { a: 1 } {
8+
C(_) => (),
9+
_ => ()
10+
}
11+
}
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)