Skip to content

Commit 8f5b83a

Browse files
committed
---
yaml --- r: 194995 b: refs/heads/beta c: aab4bef h: refs/heads/master i: 194993: 3a1a3b3 194991: d4cef3d v: v3
1 parent 977c077 commit 8f5b83a

File tree

3 files changed

+135
-1
lines changed

3 files changed

+135
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3131
refs/heads/issue-18208-method-dispatch-3-quick-reject: 2009f85b9f99dedcec4404418eda9ddba90258a2
3232
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3333
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
34-
refs/heads/beta: 4053b00112f8c3d2c797adbb360a1961a82b6644
34+
refs/heads/beta: aab4bef9394daf84690474694b5a14587664be80
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3737
refs/heads/tmp: be7f6ac7008f8ddf980ac07026b05bdd865f29cc
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2015 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+
// compile-flags: -Z force-dropflag-checks=on
12+
13+
// Quick-and-dirty test to ensure -Z force-dropflag-checks=on works as
14+
// expected. Note that the inlined drop-flag is slated for removal
15+
// (RFC 320); when that happens, the -Z flag and this test should
16+
// simply be removed.
17+
//
18+
// See also drop-flag-skip-sanity-check.rs.
19+
20+
use std::env;
21+
use std::old_io::process::{Command, ExitSignal, ExitStatus};
22+
23+
fn main() {
24+
let args: Vec<String> = env::args().collect();
25+
if args.len() > 1 && args[1] == "test" {
26+
return test();
27+
}
28+
29+
let mut p = Command::new(&args[0]).arg("test").spawn().unwrap();
30+
// The invocation should fail due to the drop-flag sanity check.
31+
assert!(!p.wait().unwrap().success());
32+
}
33+
34+
#[derive(Debug)]
35+
struct Corrupted {
36+
x: u8
37+
}
38+
39+
impl Drop for Corrupted {
40+
fn drop(&mut self) { println!("dropping"); }
41+
}
42+
43+
fn test() {
44+
{
45+
let mut c1 = Corrupted { x: 1 };
46+
let mut c2 = Corrupted { x: 2 };
47+
unsafe {
48+
let p1 = &mut c1 as *mut Corrupted as *mut u8;
49+
let p2 = &mut c2 as *mut Corrupted as *mut u8;
50+
for i in 0..std::mem::size_of::<Corrupted>() {
51+
// corrupt everything, *including the drop flag.
52+
//
53+
// (We corrupt via two different means to safeguard
54+
// against the hypothetical assignment of the
55+
// dtor_needed/dtor_done values to v and v+k. that
56+
// happen to match with one of the corruption values
57+
// below.)
58+
*p1.offset(i as isize) += 2;
59+
*p2.offset(i as isize) += 3;
60+
}
61+
}
62+
// Here, at the end of the scope of `c1` and `c2`, the
63+
// drop-glue should detect the corruption of (at least one of)
64+
// the drop-flags.
65+
}
66+
println!("We should never get here.");
67+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2015 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+
// compile-flags: -Z force-dropflag-checks=off
12+
13+
// Quick-and-dirty test to ensure -Z force-dropflag-checks=off works as
14+
// expected. Note that the inlined drop-flag is slated for removal
15+
// (RFC 320); when that happens, the -Z flag and this test should
16+
// simply be removed.
17+
//
18+
// See also drop-flag-sanity-check.rs.
19+
20+
use std::env;
21+
use std::old_io::process::{Command, ExitSignal, ExitStatus};
22+
23+
fn main() {
24+
let args: Vec<String> = env::args().collect();
25+
if args.len() > 1 && args[1] == "test" {
26+
return test();
27+
}
28+
29+
let mut p = Command::new(&args[0]).arg("test").spawn().unwrap();
30+
// Invocatinn should succeed as drop-flag sanity check is skipped.
31+
assert!(p.wait().unwrap().success());
32+
}
33+
34+
#[derive(Debug)]
35+
struct Corrupted {
36+
x: u8
37+
}
38+
39+
impl Drop for Corrupted {
40+
fn drop(&mut self) { println!("dropping"); }
41+
}
42+
43+
fn test() {
44+
{
45+
let mut c1 = Corrupted { x: 1 };
46+
let mut c2 = Corrupted { x: 2 };
47+
unsafe {
48+
let p1 = &mut c1 as *mut Corrupted as *mut u8;
49+
let p2 = &mut c2 as *mut Corrupted as *mut u8;
50+
for i in 0..std::mem::size_of::<Corrupted>() {
51+
// corrupt everything, *including the drop flag.
52+
//
53+
// (We corrupt via two different means to safeguard
54+
// against the hypothetical assignment of the
55+
// dtor_needed/dtor_done values to v and v+k. that
56+
// happen to match with one of the corruption values
57+
// below.)
58+
*p1.offset(i as isize) += 2;
59+
*p2.offset(i as isize) += 3;
60+
}
61+
}
62+
// Here, at the end of the scope of `c1` and `c2`, the
63+
// drop-glue should detect the corruption of (at least one of)
64+
// the drop-flags.
65+
}
66+
println!("We should never get here.");
67+
}

0 commit comments

Comments
 (0)