2017-07-31 19:51:10 -07:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
// ignore-tidy-linelength
|
2017-08-04 17:00:21 -07:00
|
|
|
// compile-flags: -Z verbose -Z mir-emit-validate=1 -Z span_free_formats
|
2017-07-31 19:51:10 -07:00
|
|
|
|
|
|
|
// Make sure unsafe fns and fns with an unsafe block only get restricted validation.
|
|
|
|
|
|
|
|
unsafe fn write_42(x: *mut i32) -> bool {
|
2017-08-01 13:14:32 -07:00
|
|
|
let test_closure = |x: *mut i32| *x = 23;
|
|
|
|
test_closure(x);
|
2017-07-31 19:51:10 -07:00
|
|
|
*x = 42;
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test(x: &mut i32) {
|
|
|
|
unsafe { write_42(x) };
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
test(&mut 0);
|
|
|
|
|
|
|
|
let test_closure = unsafe { |x: &mut i32| write_42(x) };
|
|
|
|
test_closure(&mut 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Also test code generated inside the closure, make sure it only does restricted validation
|
|
|
|
// because it is entirely inside an unsafe block. Unfortunately, the interesting lines of code also
|
|
|
|
// contain name of the source file, so we cannot test for it.
|
|
|
|
|
|
|
|
// END RUST SOURCE
|
2017-11-04 14:27:08 +03:00
|
|
|
// START rustc.write_42.EraseRegions.after.mir
|
2017-07-31 19:51:10 -07:00
|
|
|
// fn write_42(_1: *mut i32) -> bool {
|
2017-10-09 23:14:13 -04:00
|
|
|
// ...
|
2017-07-31 19:51:10 -07:00
|
|
|
// bb0: {
|
|
|
|
// Validate(Acquire, [_1: *mut i32]);
|
|
|
|
// Validate(Release, [_1: *mut i32]);
|
2017-10-09 23:14:13 -04:00
|
|
|
// ...
|
2017-07-31 19:51:10 -07:00
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// }
|
2017-11-04 14:27:08 +03:00
|
|
|
// END rustc.write_42.EraseRegions.after.mir
|
2017-11-05 11:14:00 +03:00
|
|
|
// START rustc.write_42-{{closure}}.EraseRegions.after.mir
|
2017-08-04 17:00:21 -07:00
|
|
|
// fn write_42::{{closure}}(_1: &ReErased [closure@NodeId(22)], _2: *mut i32) -> () {
|
2017-10-09 23:14:13 -04:00
|
|
|
// ...
|
2017-08-04 17:00:21 -07:00
|
|
|
// bb0: {
|
2017-11-20 17:49:21 +02:00
|
|
|
// Validate(Acquire, [_1: &ReFree(DefId(0/1:9 ~ validate_4[317d]::write_42[0]::{{closure}}[0]), BrEnv) [closure@NodeId(22)], _2: *mut i32]);
|
|
|
|
// Validate(Release, [_1: &ReFree(DefId(0/1:9 ~ validate_4[317d]::write_42[0]::{{closure}}[0]), BrEnv) [closure@NodeId(22)], _2: *mut i32]);
|
Avoid unnecessary copies of arguments that are simple bindings
Initially MIR differentiated between arguments and locals, which
introduced a need to add extra copies assigning the argument to a
local, even for simple bindings. This differentiation no longer exists,
but we're still creating those copies, bloating the MIR and LLVM IR we
emit.
Additionally, the current approach means that we create debug info for
both the incoming argument (marking it as an argument), and then
immediately shadow it a local that goes by the same name. This can be
confusing when using e.g. "info args" in gdb, or when e.g. a debugger
with a GUI displays the function arguments separately from the local
variables, especially when the binding is mutable, because the argument
doesn't change, while the local variable does.
2017-10-11 20:49:36 +02:00
|
|
|
// (*_2) = const 23i32;
|
2017-11-27 17:58:59 +02:00
|
|
|
// _0 = ();
|
2017-08-04 17:00:21 -07:00
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// }
|
2017-11-05 11:14:00 +03:00
|
|
|
// END rustc.write_42-{{closure}}.EraseRegions.after.mir
|
2017-11-04 14:27:08 +03:00
|
|
|
// START rustc.test.EraseRegions.after.mir
|
2017-07-31 19:51:10 -07:00
|
|
|
// fn test(_1: &ReErased mut i32) -> () {
|
2017-10-09 23:14:13 -04:00
|
|
|
// ...
|
2017-07-31 19:51:10 -07:00
|
|
|
// bb0: {
|
2017-11-20 17:49:21 +02:00
|
|
|
// Validate(Acquire, [_1: &ReFree(DefId(0/0:4 ~ validate_4[317d]::test[0]), BrAnon(0)) mut i32]);
|
|
|
|
// Validate(Release, [_1: &ReFree(DefId(0/0:4 ~ validate_4[317d]::test[0]), BrAnon(0)) mut i32]);
|
2017-10-09 23:14:13 -04:00
|
|
|
// ...
|
2017-11-17 18:22:44 +02:00
|
|
|
// _2 = const write_42(move _3) -> bb1;
|
2017-07-31 19:51:10 -07:00
|
|
|
// }
|
|
|
|
// bb1: {
|
Avoid unnecessary copies of arguments that are simple bindings
Initially MIR differentiated between arguments and locals, which
introduced a need to add extra copies assigning the argument to a
local, even for simple bindings. This differentiation no longer exists,
but we're still creating those copies, bloating the MIR and LLVM IR we
emit.
Additionally, the current approach means that we create debug info for
both the incoming argument (marking it as an argument), and then
immediately shadow it a local that goes by the same name. This can be
confusing when using e.g. "info args" in gdb, or when e.g. a debugger
with a GUI displays the function arguments separately from the local
variables, especially when the binding is mutable, because the argument
doesn't change, while the local variable does.
2017-10-11 20:49:36 +02:00
|
|
|
// Validate(Acquire, [_2: bool]);
|
|
|
|
// Validate(Release, [_2: bool]);
|
2017-10-09 23:14:13 -04:00
|
|
|
// ...
|
2017-07-31 19:51:10 -07:00
|
|
|
// }
|
|
|
|
// }
|
2017-11-04 14:27:08 +03:00
|
|
|
// END rustc.test.EraseRegions.after.mir
|
2017-11-05 11:14:00 +03:00
|
|
|
// START rustc.main-{{closure}}.EraseRegions.after.mir
|
2017-08-04 17:00:21 -07:00
|
|
|
// fn main::{{closure}}(_1: &ReErased [closure@NodeId(60)], _2: &ReErased mut i32) -> bool {
|
2017-10-09 23:14:13 -04:00
|
|
|
// ...
|
2017-08-04 17:00:21 -07:00
|
|
|
// bb0: {
|
2017-11-20 17:49:21 +02:00
|
|
|
// Validate(Acquire, [_1: &ReFree(DefId(0/1:10 ~ validate_4[317d]::main[0]::{{closure}}[0]), BrEnv) [closure@NodeId(60)], _2: &ReFree(DefId(0/1:10 ~ validate_4[317d]::main[0]::{{closure}}[0]), BrAnon(0)) mut i32]);
|
|
|
|
// Validate(Release, [_1: &ReFree(DefId(0/1:10 ~ validate_4[317d]::main[0]::{{closure}}[0]), BrEnv) [closure@NodeId(60)], _2: &ReFree(DefId(0/1:10 ~ validate_4[317d]::main[0]::{{closure}}[0]), BrAnon(0)) mut i32]);
|
2017-08-04 17:00:21 -07:00
|
|
|
// StorageLive(_3);
|
2017-10-09 23:14:13 -04:00
|
|
|
// ...
|
2017-11-17 18:22:44 +02:00
|
|
|
// _0 = const write_42(move _3) -> bb1;
|
2017-08-04 17:00:21 -07:00
|
|
|
// }
|
2017-10-09 23:14:13 -04:00
|
|
|
// ...
|
2017-08-04 17:00:21 -07:00
|
|
|
// }
|
2017-11-05 11:14:00 +03:00
|
|
|
// END rustc.main-{{closure}}.EraseRegions.after.mir
|