Skip to content

Commit f7d1955

Browse files
committed
---
yaml --- r: 194479 b: refs/heads/auto c: aab4bef h: refs/heads/master i: 194477: fe5a895 194475: b946564 194471: 2111ed4 194463: 2160e5a v: v3
1 parent 335cff3 commit f7d1955

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
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 4053b00112f8c3d2c797adbb360a1961a82b6644
13+
refs/heads/auto: aab4bef9394daf84690474694b5a14587664be80
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
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)