Skip to content

Commit

Permalink
Auto merge of #69535 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
[beta] backports

This backports the following PRs:

* ci: switch macOS builders to 10.15 #68863
* Backport release notes of 1.41.1 #69468
* Cherry-pick the LLVM fix for #69225 #69450
* `lit_to_const`: gracefully bubble up type errors. #69330
* [beta] bootstrap from 1.41.1 stable #69518
* bootstrap: Configure cmake when building sanitizer runtimes #69104

r? @ghost
  • Loading branch information
bors committed Feb 28, 2020
2 parents 13e0fbc + d620bec commit 4e1c5f0
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 73 deletions.
10 changes: 10 additions & 0 deletions RELEASES.md
@@ -1,3 +1,13 @@
Version 1.41.1 (2020-02-27)
===========================

* [Always check types of static items][69145]
* [Always check lifetime bounds of `Copy` impls][69145]
* [Fix miscompilation in callers of `Layout::repeat`][69225]

[69225]: https://github.com/rust-lang/rust/issues/69225
[69145]: https://github.com/rust-lang/rust/pull/69145

Version 1.41.0 (2020-01-30)
===========================

Expand Down
28 changes: 19 additions & 9 deletions src/bootstrap/native.rs
Expand Up @@ -264,7 +264,7 @@ impl Step for Llvm {
cfg.define("PYTHON_EXECUTABLE", python);
}

configure_cmake(builder, target, &mut cfg);
configure_cmake(builder, target, &mut cfg, true);

// FIXME: we don't actually need to build all LLVM tools and all LLVM
// libraries here, e.g., we just want a few components and a few
Expand Down Expand Up @@ -303,7 +303,12 @@ fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) {
panic!("\n\nbad LLVM version: {}, need >=7.0\n\n", version)
}

fn configure_cmake(builder: &Builder<'_>, target: Interned<String>, cfg: &mut cmake::Config) {
fn configure_cmake(
builder: &Builder<'_>,
target: Interned<String>,
cfg: &mut cmake::Config,
use_compiler_launcher: bool,
) {
// Do not print installation messages for up-to-date files.
// LLVM and LLD builds can produce a lot of those and hit CI limits on log size.
cfg.define("CMAKE_INSTALL_MESSAGE", "LAZY");
Expand Down Expand Up @@ -374,9 +379,11 @@ fn configure_cmake(builder: &Builder<'_>, target: Interned<String>, cfg: &mut cm
} else {
// If ccache is configured we inform the build a little differently how
// to invoke ccache while also invoking our compilers.
if let Some(ref ccache) = builder.config.ccache {
cfg.define("CMAKE_C_COMPILER_LAUNCHER", ccache)
.define("CMAKE_CXX_COMPILER_LAUNCHER", ccache);
if use_compiler_launcher {
if let Some(ref ccache) = builder.config.ccache {
cfg.define("CMAKE_C_COMPILER_LAUNCHER", ccache)
.define("CMAKE_CXX_COMPILER_LAUNCHER", ccache);
}
}
cfg.define("CMAKE_C_COMPILER", sanitize_cc(cc))
.define("CMAKE_CXX_COMPILER", sanitize_cc(cxx));
Expand Down Expand Up @@ -460,7 +467,7 @@ impl Step for Lld {
t!(fs::create_dir_all(&out_dir));

let mut cfg = cmake::Config::new(builder.src.join("src/llvm-project/lld"));
configure_cmake(builder, target, &mut cfg);
configure_cmake(builder, target, &mut cfg, true);

// This is an awful, awful hack. Discovered when we migrated to using
// clang-cl to compile LLVM/LLD it turns out that LLD, when built out of
Expand Down Expand Up @@ -597,10 +604,7 @@ impl Step for Sanitizers {
let _time = util::timeit(&builder);

let mut cfg = cmake::Config::new(&compiler_rt_dir);
cfg.target(&self.target);
cfg.host(&builder.config.build);
cfg.profile("Release");

cfg.define("CMAKE_C_COMPILER_TARGET", self.target);
cfg.define("COMPILER_RT_BUILD_BUILTINS", "OFF");
cfg.define("COMPILER_RT_BUILD_CRT", "OFF");
Expand All @@ -612,6 +616,12 @@ impl Step for Sanitizers {
cfg.define("COMPILER_RT_USE_LIBCXX", "OFF");
cfg.define("LLVM_CONFIG_PATH", &llvm_config);

// On Darwin targets the sanitizer runtimes are build as universal binaries.
// Unfortunately sccache currently lacks support to build them successfully.
// Disable compiler launcher on Darwin targets to avoid potential issues.
let use_compiler_launcher = !self.target.contains("apple-darwin");
configure_cmake(builder, self.target, &mut cfg, use_compiler_launcher);

t!(fs::create_dir_all(&out_dir));
cfg.out_dir(out_dir);

Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/test.rs
Expand Up @@ -1050,10 +1050,10 @@ impl Step for Compiletest {
cmd.arg("--docck-python").arg(builder.python());

if builder.config.build.ends_with("apple-darwin") {
// Force /usr/bin/python on macOS for LLDB tests because we're loading the
// Force /usr/bin/python3 on macOS for LLDB tests because we're loading the
// LLDB plugin's compiled module which only works with the system python
// (namely not Homebrew-installed python)
cmd.arg("--lldb-python").arg("/usr/bin/python");
cmd.arg("--lldb-python").arg("/usr/bin/python3");
} else {
cmd.arg("--lldb-python").arg(builder.python());
}
Expand Down
2 changes: 1 addition & 1 deletion src/ci/azure-pipelines/auto.yml
Expand Up @@ -63,7 +63,7 @@ jobs:
- job: macOS
timeoutInMinutes: 600
pool:
vmImage: macos-10.13
vmImage: macos-10.15
steps:
- template: steps/run.yml
strategy:
Expand Down
4 changes: 0 additions & 4 deletions src/ci/azure-pipelines/steps/run.yml
Expand Up @@ -51,10 +51,6 @@ steps:
displayName: Install clang
condition: and(succeeded(), not(variables.SKIP_JOB))

- bash: src/ci/scripts/switch-xcode.sh
displayName: Switch to Xcode 9.3
condition: and(succeeded(), not(variables.SKIP_JOB))

- bash: src/ci/scripts/install-wix.sh
displayName: Install wix
condition: and(succeeded(), not(variables.SKIP_JOB))
Expand Down
2 changes: 1 addition & 1 deletion src/ci/azure-pipelines/try.yml
Expand Up @@ -25,7 +25,7 @@ jobs:
# - job: macOS
# timeoutInMinutes: 600
# pool:
# vmImage: macos-10.13
# vmImage: macos-10.15
# steps:
# - template: steps/run.yml
# strategy:
Expand Down
4 changes: 1 addition & 3 deletions src/ci/scripts/install-clang.sh
Expand Up @@ -19,9 +19,7 @@ if isMacOS; then
# native clang is configured to use the correct path, but our custom one
# doesn't. This sets the SDKROOT environment variable to the SDK so that
# our own clang can figure out the correct include path on its own.
if ! [[ -d "/usr/include" ]]; then
ciCommandSetEnv SDKROOT "$(xcrun --sdk macosx --show-sdk-path)"
fi
ciCommandSetEnv SDKROOT "$(xcrun --sdk macosx --show-sdk-path)"

# Configure `AR` specifically so rustbuild doesn't try to infer it as
# `clang-ar` by accident.
Expand Down
13 changes: 0 additions & 13 deletions src/ci/scripts/switch-xcode.sh

This file was deleted.

4 changes: 4 additions & 0 deletions src/librustc/mir/interpret/mod.rs
Expand Up @@ -162,6 +162,10 @@ pub struct LitToConstInput<'tcx> {
/// Error type for `tcx.lit_to_const`.
#[derive(Copy, Clone, Debug, Eq, PartialEq, HashStable)]
pub enum LitToConstError {
/// The literal's inferred type did not match the expected `ty` in the input.
/// This is used for graceful error handling (`delay_span_bug`) in
/// type checking (`AstConv::ast_const_to_const`).
TypeError,
UnparseableFloat,
Reported,
}
Expand Down
59 changes: 22 additions & 37 deletions src/librustc_mir_build/hair/constant.rs
@@ -1,7 +1,7 @@
use rustc::mir::interpret::{
truncate, Allocation, ConstValue, LitToConstError, LitToConstInput, Scalar,
};
use rustc::ty::{self, layout::Size, ParamEnv, TyCtxt};
use rustc::ty::{self, layout::Size, ParamEnv, TyCtxt, TyS};
use rustc_span::symbol::Symbol;
use syntax::ast;

Expand All @@ -20,50 +20,35 @@ crate fn lit_to_const<'tcx>(
Ok(ConstValue::Scalar(Scalar::from_uint(result, width)))
};

let lit = match *lit {
ast::LitKind::Str(ref s, _) => {
let lit = match (lit, &ty.kind) {
(ast::LitKind::Str(s, _), ty::Ref(_, TyS { kind: ty::Str, .. }, _)) => {
let s = s.as_str();
let allocation = Allocation::from_byte_aligned_bytes(s.as_bytes());
let allocation = tcx.intern_const_alloc(allocation);
ConstValue::Slice { data: allocation, start: 0, end: s.len() }
}
ast::LitKind::ByteStr(ref data) => {
if let ty::Ref(_, ref_ty, _) = ty.kind {
match ref_ty.kind {
ty::Slice(_) => {
let allocation = Allocation::from_byte_aligned_bytes(data as &Vec<u8>);
let allocation = tcx.intern_const_alloc(allocation);
ConstValue::Slice { data: allocation, start: 0, end: data.len() }
}
ty::Array(_, _) => {
let id = tcx.allocate_bytes(data);
ConstValue::Scalar(Scalar::Ptr(id.into()))
}
_ => {
bug!("bytestring should have type of either &[u8] or &[u8; _], not {}", ty)
}
}
} else {
bug!("bytestring should have type of either &[u8] or &[u8; _], not {}", ty)
}
(ast::LitKind::ByteStr(data), ty::Ref(_, TyS { kind: ty::Slice(_), .. }, _)) => {
let allocation = Allocation::from_byte_aligned_bytes(data as &Vec<u8>);
let allocation = tcx.intern_const_alloc(allocation);
ConstValue::Slice { data: allocation, start: 0, end: data.len() }
}
(ast::LitKind::ByteStr(data), ty::Ref(_, TyS { kind: ty::Array(_, _), .. }, _)) => {
let id = tcx.allocate_bytes(data);
ConstValue::Scalar(Scalar::Ptr(id.into()))
}
(ast::LitKind::Byte(n), ty::Uint(ast::UintTy::U8)) => {
ConstValue::Scalar(Scalar::from_uint(*n, Size::from_bytes(1)))
}
ast::LitKind::Byte(n) => ConstValue::Scalar(Scalar::from_uint(n, Size::from_bytes(1))),
ast::LitKind::Int(n, _) if neg => {
let n = n as i128;
let n = n.overflowing_neg().0;
trunc(n as u128)?
(ast::LitKind::Int(n, _), ty::Uint(_)) | (ast::LitKind::Int(n, _), ty::Int(_)) => {
trunc(if neg { (*n as i128).overflowing_neg().0 as u128 } else { *n })?
}
ast::LitKind::Int(n, _) => trunc(n)?,
ast::LitKind::Float(n, _) => {
let fty = match ty.kind {
ty::Float(fty) => fty,
_ => bug!(),
};
parse_float(n, fty, neg).map_err(|_| LitToConstError::UnparseableFloat)?
(ast::LitKind::Float(n, _), ty::Float(fty)) => {
parse_float(*n, *fty, neg).map_err(|_| LitToConstError::UnparseableFloat)?
}
ast::LitKind::Bool(b) => ConstValue::Scalar(Scalar::from_bool(b)),
ast::LitKind::Char(c) => ConstValue::Scalar(Scalar::from_char(c)),
ast::LitKind::Err(_) => return Err(LitToConstError::Reported),
(ast::LitKind::Bool(b), ty::Bool) => ConstValue::Scalar(Scalar::from_bool(*b)),
(ast::LitKind::Char(c), ty::Char) => ConstValue::Scalar(Scalar::from_char(*c)),
(ast::LitKind::Err(_), _) => return Err(LitToConstError::Reported),
_ => return Err(LitToConstError::TypeError),
};
Ok(tcx.mk_const(ty::Const { val: ty::ConstKind::Value(lit), ty }))
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir_build/hair/cx/mod.rs
Expand Up @@ -148,6 +148,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> {
// create a dummy value and continue compiling
Const::from_bits(self.tcx, 0, self.param_env.and(ty))
}
Err(LitToConstError::TypeError) => bug!("const_eval_literal: had type error"),
}
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir_build/hair/pattern/mod.rs
Expand Up @@ -843,6 +843,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
PatKind::Wild
}
Err(LitToConstError::Reported) => PatKind::Wild,
Err(LitToConstError::TypeError) => bug!("lower_lit: had type error"),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_typeck/astconv.rs
Expand Up @@ -2738,6 +2738,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// mir.
if let Ok(c) = tcx.at(expr.span).lit_to_const(lit_input) {
return c;
} else {
tcx.sess.delay_span_bug(expr.span, "ast_const_to_const: couldn't lit_to_const");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/stage0.txt
Expand Up @@ -12,8 +12,8 @@
# source tarball for a stable release you'll likely see `1.x.0` for rustc and
# `0.x.0` for Cargo where they were released on `date`.

date: 2020-01-30
rustc: 1.41.0
date: 2020-02-27
rustc: 1.41.1
cargo: 0.42.0

# We use a nightly rustfmt to format the source because it solves some bootstrapping
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/consts/issue-69310-array-size-lit-wrong-ty.rs
@@ -0,0 +1,11 @@
// This is a regression test for #69310, which was injected by #68118.
// The issue here was that as a performance optimization,
// we call the query `lit_to_const(input);`.
// However, the literal `input.lit` would not be of the type expected by `input.ty`.
// As a result, we immediately called `bug!(...)` instead of bubbling up the problem
// so that it could be handled by the caller of `lit_to_const` (`ast_const_to_const`).

fn main() {}

const A: [(); 0.1] = [()]; //~ ERROR mismatched types
const B: [(); b"a"] = [()]; //~ ERROR mismatched types
15 changes: 15 additions & 0 deletions src/test/ui/consts/issue-69310-array-size-lit-wrong-ty.stderr
@@ -0,0 +1,15 @@
error[E0308]: mismatched types
--> $DIR/issue-69310-array-size-lit-wrong-ty.rs:10:15
|
LL | const A: [(); 0.1] = [()];
| ^^^ expected `usize`, found floating-point number

error[E0308]: mismatched types
--> $DIR/issue-69310-array-size-lit-wrong-ty.rs:11:15
|
LL | const B: [(); b"a"] = [()];
| ^^^^ expected `usize`, found `&[u8; 1]`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
33 changes: 33 additions & 0 deletions src/test/ui/issues/issue-69225-SCEVAddExpr-wrap-flag.rs
@@ -0,0 +1,33 @@
// run-fail
// compile-flags: -C opt-level=3
// error-pattern: index out of bounds: the len is 0 but the index is 16777216
// ignore-wasm no panic or subprocess support
// ignore-emscripten no panic or subprocess support

fn do_test(x: usize) {
let mut arr = vec![vec![0u8; 3]];

let mut z = vec![0];
for arr_ref in arr.iter_mut() {
for y in 0..x {
for _ in 0..1 {
z.reserve_exact(x);
let iterator = std::iter::repeat(0).take(x);
let mut cnt = 0;
iterator.for_each(|_| {
z[0] = 0;
cnt += 1;
});
let a = y * x;
let b = (y + 1) * x - 1;
let slice = &mut arr_ref[a..b];
slice[1 << 24] += 1;
}
}
}
}

fn main() {
do_test(1);
do_test(2);
}

0 comments on commit 4e1c5f0

Please sign in to comment.