From 94f7511ac242dbdc171be2acefa089e5a9b32562 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 4 Aug 2017 17:00:21 -0700 Subject: [PATCH] test MIR validation statements in closures --- src/test/mir-opt/validate_1.rs | 28 +++++++++++++++++++++++----- src/test/mir-opt/validate_4.rs | 25 ++++++++++++++++++++++++- src/test/mir-opt/validate_5.rs | 26 +++++++++++++++++++++----- 3 files changed, 68 insertions(+), 11 deletions(-) diff --git a/src/test/mir-opt/validate_1.rs b/src/test/mir-opt/validate_1.rs index 9ac76a5f4ea..677c92ea71b 100644 --- a/src/test/mir-opt/validate_1.rs +++ b/src/test/mir-opt/validate_1.rs @@ -9,7 +9,7 @@ // except according to those terms. // ignore-tidy-linelength -// compile-flags: -Z verbose -Z mir-emit-validate=1 +// compile-flags: -Z verbose -Z mir-emit-validate=1 -Z span_free_formats struct Test(i32); @@ -20,16 +20,13 @@ fn foo(&self, _x: &mut i32) {} fn main() { let mut x = 0; - Test(0).foo(&mut x); + Test(0).foo(&mut x); // just making sure we do not panic when there is a tuple struct ctor // Also test closures let c = |x: &mut i32| { let y = &*x; *y }; c(&mut x); } -// FIXME: Also test code generated inside the closure, make sure it has validation. Unfortunately, -// the interesting lines of code also contain name of the source file, so we cannot test for it. - // END RUST SOURCE // START rustc.node12.EraseRegions.after.mir // bb0: { @@ -57,3 +54,24 @@ fn main() { // } // } // END rustc.node23.EraseRegions.after.mir +// START rustc.node50.EraseRegions.after.mir +// fn main::{{closure}}(_1: &ReErased [closure@NodeId(50)], _2: &ReErased mut i32) -> i32 { +// bb0: { +// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483663) => validate_1/8cd878b::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(50)], _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483663) => validate_1/8cd878b::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]); +// StorageLive(_3); +// _3 = _2; +// StorageLive(_4); +// Validate(Suspend(ReScope(Remainder(BlockRemainder { block: NodeId(41), first_statement_index: 0 }))), [(*_3): i32]); +// _4 = &ReErased (*_3); +// Validate(Acquire, [(*_4): i32/ReScope(Remainder(BlockRemainder { block: NodeId(41), first_statement_index: 0 })) (imm)]); +// StorageLive(_5); +// _5 = (*_4); +// _0 = _5; +// StorageDead(_5); +// StorageDead(_4); +// EndRegion(ReScope(Remainder(BlockRemainder { block: NodeId(41), first_statement_index: 0 }))); +// StorageDead(_3); +// return; +// } +// } +// END rustc.node50.EraseRegions.after.mir diff --git a/src/test/mir-opt/validate_4.rs b/src/test/mir-opt/validate_4.rs index 591de975740..2ee459d6809 100644 --- a/src/test/mir-opt/validate_4.rs +++ b/src/test/mir-opt/validate_4.rs @@ -9,7 +9,7 @@ // except according to those terms. // ignore-tidy-linelength -// compile-flags: -Z verbose -Z mir-emit-validate=1 +// compile-flags: -Z verbose -Z mir-emit-validate=1 -Z span_free_formats // Make sure unsafe fns and fns with an unsafe block only get restricted validation. @@ -45,6 +45,19 @@ fn main() { // } // } // END rustc.node4.EraseRegions.after.mir +// START rustc.node22.EraseRegions.after.mir +// fn write_42::{{closure}}(_1: &ReErased [closure@NodeId(22)], _2: *mut i32) -> () { +// bb0: { +// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483659) => validate_4/8cd878b::write_42[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(22)], _2: *mut i32]); +// Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483659) => validate_4/8cd878b::write_42[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(22)], _2: *mut i32]); +// StorageLive(_3); +// _3 = _2; +// (*_3) = const 23i32; +// StorageDead(_3); +// return; +// } +// } +// END rustc.node22.EraseRegions.after.mir // START rustc.node31.EraseRegions.after.mir // fn test(_1: &ReErased mut i32) -> () { // bb0: { @@ -58,3 +71,13 @@ fn main() { // } // } // END rustc.node31.EraseRegions.after.mir +// START rustc.node60.EraseRegions.after.mir +// fn main::{{closure}}(_1: &ReErased [closure@NodeId(60)], _2: &ReErased mut i32) -> bool { +// bb0: { +// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483663) => validate_4/8cd878b::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(60)], _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483663) => validate_4/8cd878b::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]); +// Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483663) => validate_4/8cd878b::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(60)], _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483663) => validate_4/8cd878b::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]); +// StorageLive(_3); +// _0 = const write_42(_4) -> bb1; +// } +// } +// END rustc.node60.EraseRegions.after.mir diff --git a/src/test/mir-opt/validate_5.rs b/src/test/mir-opt/validate_5.rs index e9919af9fd3..150aa2baf2d 100644 --- a/src/test/mir-opt/validate_5.rs +++ b/src/test/mir-opt/validate_5.rs @@ -9,9 +9,9 @@ // except according to those terms. // ignore-tidy-linelength -// compile-flags: -Z verbose -Z mir-emit-validate=2 +// compile-flags: -Z verbose -Z mir-emit-validate=2 -Z span_free_formats -// Make sure unsafe fns and fns with an unsafe block only get full validation. +// Make sure unsafe fns and fns with an unsafe block still get full validation. unsafe fn write_42(x: *mut i32) -> bool { *x = 42; @@ -29,9 +29,6 @@ fn main() { test_closure(&mut 0); } -// FIXME: Also test code generated inside the closure, make sure it has validation. Unfortunately, -// the interesting lines of code also contain name of the source file, so we cannot test for it. - // END RUST SOURCE // START rustc.node17.EraseRegions.after.mir // fn test(_1: &ReErased mut i32) -> () { @@ -42,3 +39,22 @@ fn main() { // } // } // END rustc.node17.EraseRegions.after.mir +// START rustc.node46.EraseRegions.after.mir +// fn main::{{closure}}(_1: &ReErased [closure@NodeId(46)], _2: &ReErased mut i32) -> bool { +// bb0: { +// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483660) => validate_5/8cd878b::main[0]::{{closure}}[0] }, "BrEnv") [closure@NodeId(46)], _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(2147483660) => validate_5/8cd878b::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]); +// StorageLive(_3); +// _3 = _2; +// StorageLive(_4); +// StorageLive(_5); +// Validate(Suspend(ReScope(Misc(NodeId(44)))), [(*_3): i32]); +// _5 = &ReErased mut (*_3); +// Validate(Acquire, [(*_5): i32/ReScope(Misc(NodeId(44)))]); +// _4 = _5 as *mut i32 (Misc); +// StorageDead(_5); +// EndRegion(ReScope(Misc(NodeId(44)))); +// Validate(Release, [_0: bool, _4: *mut i32]); +// _0 = const write_42(_4) -> bb1; +// } +// } +// END rustc.node46.EraseRegions.after.mir