Skip to content

Commit

Permalink
Add tests for emitting validation statements
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Jul 30, 2017
1 parent 7ec50df commit 57958d1
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/test/mir-opt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ the lines being too long.

compiletest handles dumping the MIR before and after every pass for you. The
test writer only has to specify the file names of the dumped files (not the
full path to the file) and what lines to expect. I added an option to rustc
full path to the file) and what lines to expect. There is an option to rustc
that tells it to dump the mir into some directly (rather then always dumping to
the current directory).

Lines match ignoring whitespace, and the prefix "//" is removed of course.

It also currently strips trailing comments -- partly because the full file path
in "scope comments" is unpredictable and partly because tidy complains about
the lines being too long.

the current directory).
48 changes: 48 additions & 0 deletions src/test/mir-opt/validate_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2017 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.

// compile-flags: -Z verbose -Z mir-emit-validate

fn foo(_x: &mut i32) {}

fn main() {
let mut x = 0;
foo(&mut x);
}

// END RUST SOURCE
// START rustc.node4.EraseRegions.after.mir
// fn foo(_1: &ReErased mut i32) -> () {
// bb0: {
// Validate(Acquire, [_1@&ReFree(DefId { krate: CrateNum(0), node: DefIndex(3) => validate_1/8cd878b::foo[0] }, BrAnon(0)) mut i32]);
// return;
// }
// }
// END rustc.node4.EraseRegions.after.mir
// START rustc.node11.EraseRegions.after.mir
// fn main() -> () {
// bb0: {
// Validate(Suspend(ReScope(Misc(NodeId(20)))), [_1@i32]);
// _4 = &ReErased mut _1;
// Validate(Acquire, [(*_4)@i32/ReScope(Misc(NodeId(20)))]);
// Validate(Suspend(ReScope(Misc(NodeId(20)))), [(*_4)@i32/ReScope(Misc(NodeId(20)))]);
// _3 = &ReErased mut (*_4);
// Validate(Acquire, [(*_3)@i32/ReScope(Misc(NodeId(20)))]);
// Validate(Release, [_3@&ReScope(Misc(NodeId(20))) mut i32]);
// _2 = const foo(_3) -> bb1;
// }
//
// bb1: {
// Validate(Acquire, [_2@()]);
// EndRegion(ReScope(Misc(NodeId(20))));
// return;
// }
// }
// END rustc.node11.EraseRegions.after.mir
26 changes: 26 additions & 0 deletions src/test/mir-opt/validate_2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2017 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.

// compile-flags: -Z verbose -Z mir-emit-validate

fn main() {
let _x : Box<[i32]> = Box::new([1, 2, 3]);
}

// END RUST SOURCE
// START rustc.node4.EraseRegions.after.mir
// fn main() -> () {
// bb1: {
// Validate(Release, [_2@std::boxed::Box<[i32; 3]>]);
// _1 = _2 as std::boxed::Box<[i32]> (Unsize);
// Validate(Acquire, [_1@std::boxed::Box<[i32]>]);
// }
// }
// END rustc.node4.EraseRegions.after.mir
45 changes: 45 additions & 0 deletions src/test/mir-opt/validate_3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2017 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.

// compile-flags: -Z verbose -Z mir-emit-validate

struct Test {
x: i32
}

fn foo(_x: &i32) {}

fn main() {
let t = Test { x: 0 };
let t = &t;
foo(&t.x);
}

// END RUST SOURCE
// START rustc.node16.EraseRegions.after.mir
// fn main() -> () {
// let mut _5: &ReErased i32;
// bb0: {
// Validate(Suspend(ReScope(Misc(NodeId(31)))), [((*_2).0: i32)@i32/ReScope(Remainder(BlockRemainder { block: NodeId(18), first_statement_index: 1 })) (imm)]);
// _5 = &ReErased ((*_2).0: i32);
// Validate(Acquire, [(*_5)@i32/ReScope(Misc(NodeId(31))) (imm)]);
// Validate(Suspend(ReScope(Misc(NodeId(31)))), [(*_5)@i32/ReScope(Misc(NodeId(31))) (imm)]);
// _4 = &ReErased (*_5);
// Validate(Acquire, [(*_4)@i32/ReScope(Misc(NodeId(31))) (imm)]);
// Validate(Release, [_4@&ReScope(Misc(NodeId(31))) i32]);
// _3 = const foo(_4) -> bb1;
// }
// bb1: {
// EndRegion(ReScope(Misc(NodeId(31))));
// EndRegion(ReScope(Remainder(BlockRemainder { block: NodeId(18), first_statement_index: 1 })));
// return;
// }
// }
// END rustc.node16.EraseRegions.after.mir

0 comments on commit 57958d1

Please sign in to comment.