]> git.proxmox.com Git - rustc.git/blame - src/test/mir-opt/validate_5.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / test / mir-opt / validate_5.rs
CommitLineData
3b2f2976
XL
1// Copyright 2017 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// ignore-tidy-linelength
12// compile-flags: -Z verbose -Z mir-emit-validate=2 -Z span_free_formats
13
14// Make sure unsafe fns and fns with an unsafe block still get full validation.
15
16unsafe fn write_42(x: *mut i32) -> bool {
17 *x = 42;
18 true
19}
20
21fn test(x: &mut i32) {
22 unsafe { write_42(x) };
23}
24
25fn main() {
26 test(&mut 0);
27
28 let test_closure = unsafe { |x: &mut i32| write_42(x) };
29 // Note that validation will fail if this is executed: The closure keeps the lock on
30 // x, so the write in write_42 fails. This test just checks code generation,
31 // so the UB doesn't matter.
32 test_closure(&mut 0);
33}
34
35// END RUST SOURCE
abe05a73 36// START rustc.test.EraseRegions.after.mir
3b2f2976 37// fn test(_1: &ReErased mut i32) -> () {
abe05a73 38// ...
3b2f2976 39// bb0: {
abe05a73
XL
40// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:4) => validate_5[317d]::test[0] }, BrAnon(0)) mut i32]);
41// ...
42// Validate(Release, [_2: bool, _3: *mut i32]);
43// _2 = const write_42(_3) -> bb1;
3b2f2976 44// }
abe05a73 45// ...
3b2f2976 46// }
abe05a73
XL
47// END rustc.test.EraseRegions.after.mir
48// START rustc.main-{{closure}}.EraseRegions.after.mir
3b2f2976 49// fn main::{{closure}}(_1: &ReErased [closure@NodeId(46)], _2: &ReErased mut i32) -> bool {
abe05a73 50// ...
3b2f2976 51// bb0: {
abe05a73 52// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:9) => validate_5[317d]::main[0]::{{closure}}[0] }, BrEnv) [closure@NodeId(46)], _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:9) => validate_5[317d]::main[0]::{{closure}}[0] }, BrAnon(0)) mut i32]);
3b2f2976 53// StorageLive(_3);
3b2f2976 54// StorageLive(_4);
abe05a73
XL
55// Validate(Suspend(ReScope(Node(ItemLocalId(9)))), [(*_2): i32]);
56// _4 = &ReErased mut (*_2);
57// Validate(Acquire, [(*_4): i32/ReScope(Node(ItemLocalId(9)))]);
58// _3 = _4 as *mut i32 (Misc);
ea8adc8c 59// EndRegion(ReScope(Node(ItemLocalId(9))));
abe05a73
XL
60// StorageDead(_4);
61// Validate(Release, [_0: bool, _3: *mut i32]);
62// _0 = const write_42(_3) -> bb1;
3b2f2976 63// }
abe05a73 64// ...
3b2f2976 65// }
abe05a73 66// END rustc.main-{{closure}}.EraseRegions.after.mir