Skip to content

Commit 0f7ea2a

Browse files
authored
Merge pull request #36433 from alexcrichton/beta-next
Backport PRs to beta
2 parents 389dad7 + 74cf38c commit 0f7ea2a

File tree

11 files changed

+130
-5
lines changed

11 files changed

+130
-5
lines changed

src/librustc/middle/liveness.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
14791479
self.ir.tcx.region_maps.call_site_extent(id, body.id),
14801480
&self.fn_ret(id));
14811481

1482-
if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() {
1482+
if fn_ret.is_never() {
1483+
// FIXME(durka) this rejects code like `fn foo(x: !) -> ! { x }`
1484+
if self.live_on_entry(entry_ln, self.s.clean_exit_var).is_some() {
1485+
span_err!(self.ir.tcx.sess, sp, E0270,
1486+
"computation may converge in a function marked as diverging");
1487+
}
1488+
} else if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() {
14831489
let param_env = ParameterEnvironment::for_item(self.ir.tcx, id);
14841490
let t_ret_subst = fn_ret.subst(self.ir.tcx, &param_env.free_substs);
14851491
let is_nil = self.ir.tcx.infer_ctxt(None, Some(param_env),

src/librustc_trans/mir/analyze.rs

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ pub fn lvalue_locals<'bcx, 'tcx>(bcx: Block<'bcx,'tcx>,
4848
common::type_is_fat_ptr(bcx.tcx(), ty));
4949
} else if common::type_is_imm_pair(bcx.ccx(), ty) {
5050
// We allow pairs and uses of any of their 2 fields.
51+
} else if !analyzer.seen_assigned.contains(index) {
52+
// No assignment has been seen, which means that
53+
// either the local has been marked as lvalue
54+
// already, or there is no possible initialization
55+
// for the local, making any reads invalid.
56+
// This is useful in weeding out dead temps.
5157
} else {
5258
// These sorts of types require an alloca. Note that
5359
// type_is_immediate() may *still* be true, particularly

src/librustc_typeck/check/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,13 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
709709

710710
inherited.tables.borrow_mut().liberated_fn_sigs.insert(fn_id, fn_sig);
711711

712-
fcx.check_block_with_expected(body, ExpectHasType(fcx.ret_ty));
712+
// FIXME(aburka) do we need this special case? and should it be is_uninhabited?
713+
let expected = if fcx.ret_ty.is_never() {
714+
NoExpectation
715+
} else {
716+
ExpectHasType(fcx.ret_ty)
717+
};
718+
fcx.check_block_with_expected(body, expected);
713719

714720
fcx
715721
}

src/libstd/memchr.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ mod fallback {
209209
let end_align = (ptr as usize + len) & (usize_bytes - 1);
210210
let mut offset;
211211
if end_align > 0 {
212-
offset = len - cmp::min(usize_bytes - end_align, len);
212+
offset = if end_align >= len { 0 } else { len - end_align };
213213
if let Some(index) = text[offset..].iter().rposition(|elt| *elt == x) {
214214
return Some(offset + index);
215215
}
@@ -309,6 +309,17 @@ mod fallback {
309309
fn no_match_reversed() {
310310
assert_eq!(None, memrchr(b'a', b"xyz"));
311311
}
312+
313+
#[test]
314+
fn each_alignment_reversed() {
315+
let mut data = [1u8; 64];
316+
let needle = 2;
317+
let pos = 40;
318+
data[pos] = needle;
319+
for start in 0..16 {
320+
assert_eq!(Some(pos - start), memrchr(needle, &data[start..]));
321+
}
322+
}
312323
}
313324

314325
#[cfg(test)]
@@ -385,4 +396,15 @@ mod tests {
385396
fn no_match_reversed() {
386397
assert_eq!(None, memrchr(b'a', b"xyz"));
387398
}
399+
400+
#[test]
401+
fn each_alignment() {
402+
let mut data = [1u8; 64];
403+
let needle = 2;
404+
let pos = 40;
405+
data[pos] = needle;
406+
for start in 0..16 {
407+
assert_eq!(Some(pos - start), memchr(needle, &data[start..]));
408+
}
409+
}
388410
}

src/rustllvm/llvm-auto-clean-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 forcibly 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-
2016-08-07
4+
2016-08-23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 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+
fn _converge() -> ! { //~ ERROR computation may converge
12+
42
13+
}
14+
15+
fn main() { }
16+

src/test/run-fail/call-fn-never-arg.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
// Test that we can use a ! for an argument of type !
1212

13+
// ignore-test FIXME(durka) can't be done with the current liveness code
1314
// error-pattern:wowzers!
1415

1516
#![feature(never_type)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 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+
fn assert_sizeof() -> ! {
12+
unsafe {
13+
::std::mem::transmute::<f64, [u8; 8]>(panic!())
14+
}
15+
}
16+
17+
fn main() { }
18+

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

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2016 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+
use std::ops::Deref;
12+
13+
fn main() {
14+
if env_var("FOOBAR").as_ref().map(Deref::deref).ok() == Some("yes") {
15+
panic!()
16+
}
17+
18+
let env_home: Result<String, ()> = Ok("foo-bar-baz".to_string());
19+
let env_home = env_home.as_ref().map(Deref::deref).ok();
20+
21+
if env_home == Some("") { panic!() }
22+
}
23+
24+
#[inline(never)]
25+
fn env_var(s: &str) -> Result<String, VarError> {
26+
Err(VarError::NotPresent)
27+
}
28+
29+
pub enum VarError {
30+
NotPresent,
31+
NotUnicode(String),
32+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 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+
const TEST_DATA: [u8; 32 * 1024 * 1024] = [42; 32 * 1024 * 1024];
12+
13+
// Check that the promoted copy of TEST_DATA doesn't
14+
// leave an alloca from an unused temp behind, which,
15+
// without optimizations, can still blow the stack.
16+
fn main() {
17+
println!("{}", TEST_DATA.len());
18+
}

0 commit comments

Comments
 (0)