Skip to content

Commit 3977a13

Browse files
committed
---
yaml --- r: 194494 b: refs/heads/try c: aab4bef h: refs/heads/master v: v3
1 parent 2a929b9 commit 3977a13

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
@@ -2,7 +2,7 @@
22
refs/heads/master: 242ed0b7c0f6a21096f2cc3e1ad1bdb176d02545
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a923278c6278c63468d74772c58dbf788e88f58c
5-
refs/heads/try: 4053b00112f8c3d2c797adbb360a1961a82b6644
5+
refs/heads/try: aab4bef9394daf84690474694b5a14587664be80
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
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)