Skip to content

Commit 03198da

Browse files
committed
Auto merge of #42750 - arielb1:unwind-stack, r=eddyb
Update LLVM to pick StackColoring improvement Fixes #40883. r? @eddyb
2 parents 37a991a + 4f1da87 commit 03198da

File tree

3 files changed

+104
-2
lines changed

3 files changed

+104
-2
lines changed

src/rustllvm/llvm-rebuild-trigger

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# If this file is modified, then llvm will be (optionally) cleaned and then rebuilt.
22
# The actual contents of this file do not matter, but to trigger a change on the
33
# build bots then the contents should be changed so git updates the mtime.
4-
2017-06-18
4+
2017-06-19

src/test/run-pass/issue-40883.rs

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
// check that we don't have linear stack usage with multiple calls to `push`
12+
// min-llvm-version 4.0
13+
14+
#![feature(test)]
15+
16+
extern crate test;
17+
use std::mem;
18+
19+
fn meal() -> Big {
20+
if test::black_box(false) {
21+
panic!()
22+
}
23+
Big { drop_me: [
24+
None, None, None, None, None, None, None, None,
25+
None, None, None, None, None, None, None, None,
26+
None, None, None, None, None, None, None, None,
27+
None, None, None, None, None, None, None, None,
28+
None, None, None, None, None, None, None, None,
29+
None, None, None, None, None, None, None, None,
30+
]}
31+
}
32+
33+
pub struct Big {
34+
drop_me: [Option<Box<u8>>; 48],
35+
}
36+
37+
#[inline]
38+
fn push(out: &mut Vec<Big>) {
39+
out.push(meal());
40+
}
41+
42+
#[inline(never)]
43+
pub fn supersize_me(out: &mut Vec<Big>) {
44+
push(out);
45+
push(out);
46+
push(out);
47+
push(out);
48+
push(out);
49+
push(out);
50+
push(out);
51+
push(out);
52+
push(out);
53+
push(out);
54+
push(out);
55+
push(out);
56+
push(out);
57+
push(out);
58+
push(out);
59+
push(out); // 16 calls to `push`
60+
61+
verify_stack_usage(out);
62+
63+
push(out);
64+
push(out);
65+
push(out);
66+
push(out);
67+
push(out);
68+
push(out);
69+
push(out);
70+
push(out);
71+
push(out);
72+
push(out);
73+
push(out);
74+
push(out);
75+
push(out);
76+
push(out);
77+
push(out);
78+
push(out); // 16 calls to `push`
79+
}
80+
81+
#[inline(never)]
82+
fn verify_stack_usage(before_ptr: *mut Vec<Big>) {
83+
// to check stack usage, create locals before and after
84+
// and check the difference in addresses between them.
85+
let mut stack_var: Vec<Big> = vec![];
86+
test::black_box(&mut stack_var);
87+
let stack_usage = isize::abs(
88+
(&mut stack_var as *mut _ as isize) -
89+
(before_ptr as isize)) as usize;
90+
// give space for 2 copies of `Big` + 128 "misc" bytes.
91+
if stack_usage > mem::size_of::<Big>() * 2 + 128 {
92+
panic!("used {} bytes of stack, but `struct Big` is only {} bytes",
93+
stack_usage, mem::size_of::<Big>());
94+
}
95+
96+
}
97+
98+
pub fn main() {
99+
let mut v = vec![];
100+
test::black_box(&mut v);
101+
supersize_me(&mut v);
102+
}

0 commit comments

Comments
 (0)