From cc08c0643466c30b5de35273af12bdd6b67241e6 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Wed, 5 Feb 2020 15:47:01 +0100 Subject: [PATCH 1/6] ci: switch macOS builders to 10.15 --- src/bootstrap/test.rs | 4 ++-- src/ci/azure-pipelines/auto.yml | 2 +- src/ci/azure-pipelines/steps/run.yml | 4 ---- src/ci/azure-pipelines/try.yml | 2 +- src/ci/scripts/install-clang.sh | 4 +--- src/ci/scripts/switch-xcode.sh | 13 ------------- 6 files changed, 5 insertions(+), 24 deletions(-) delete mode 100755 src/ci/scripts/switch-xcode.sh diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index a186c16f1aa71..659a308d5b93f 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -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()); } diff --git a/src/ci/azure-pipelines/auto.yml b/src/ci/azure-pipelines/auto.yml index 79a49fc48be72..74b7469ea27b7 100644 --- a/src/ci/azure-pipelines/auto.yml +++ b/src/ci/azure-pipelines/auto.yml @@ -63,7 +63,7 @@ jobs: - job: macOS timeoutInMinutes: 600 pool: - vmImage: macos-10.13 + vmImage: macos-10.15 steps: - template: steps/run.yml strategy: diff --git a/src/ci/azure-pipelines/steps/run.yml b/src/ci/azure-pipelines/steps/run.yml index c39f75aba89d8..ee9425aa1c51f 100644 --- a/src/ci/azure-pipelines/steps/run.yml +++ b/src/ci/azure-pipelines/steps/run.yml @@ -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)) diff --git a/src/ci/azure-pipelines/try.yml b/src/ci/azure-pipelines/try.yml index b6177b2cc9b25..f8ddf0eb46cfd 100644 --- a/src/ci/azure-pipelines/try.yml +++ b/src/ci/azure-pipelines/try.yml @@ -25,7 +25,7 @@ jobs: # - job: macOS # timeoutInMinutes: 600 # pool: -# vmImage: macos-10.13 +# vmImage: macos-10.15 # steps: # - template: steps/run.yml # strategy: diff --git a/src/ci/scripts/install-clang.sh b/src/ci/scripts/install-clang.sh index e16a4814197b3..c242f5d456269 100755 --- a/src/ci/scripts/install-clang.sh +++ b/src/ci/scripts/install-clang.sh @@ -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. diff --git a/src/ci/scripts/switch-xcode.sh b/src/ci/scripts/switch-xcode.sh deleted file mode 100755 index 2cbb2ddbc7046..0000000000000 --- a/src/ci/scripts/switch-xcode.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -# Switch to XCode 9.3 on OSX since it seems to be the last version that supports -# i686-apple-darwin. We'll eventually want to upgrade this and it will probably -# force us to drop i686-apple-darwin, but let's keep the wheels turning for now. - -set -euo pipefail -IFS=$'\n\t' - -source "$(cd "$(dirname "$0")" && pwd)/../shared.sh" - -if isMacOS; then - sudo xcode-select --switch /Applications/Xcode_9.3.app -fi From 705b5bd74af51877792cebccc070dea47ad3ac10 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Tue, 25 Feb 2020 20:19:12 +0100 Subject: [PATCH 2/6] backport release notes of 1.41.1 --- RELEASES.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index 10e485c1a40d5..427aa71b4b5dc 100644 --- a/RELEASES.md +++ b/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) =========================== From 6f7372bdd1ec2b96f00ec4ac6d1bcf9a7d408bef Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 24 Feb 2020 16:21:22 -0800 Subject: [PATCH 3/6] Cherry-pick the LLVM fix for #69225 --- src/llvm-project | 2 +- .../issue-69225-SCEVAddExpr-wrap-flag.rs | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/issues/issue-69225-SCEVAddExpr-wrap-flag.rs diff --git a/src/llvm-project b/src/llvm-project index d7cdb4359223b..73cf98d865673 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit d7cdb4359223be265da34ebeaa00b92b7c5419fd +Subproject commit 73cf98d8656736781e3ea667011d2aefc21f521e diff --git a/src/test/ui/issues/issue-69225-SCEVAddExpr-wrap-flag.rs b/src/test/ui/issues/issue-69225-SCEVAddExpr-wrap-flag.rs new file mode 100644 index 0000000000000..6e030f1cc4875 --- /dev/null +++ b/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); +} From 86050108523e1f40b094bec1f29a5b423a6fa21b Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 20 Feb 2020 23:23:22 +0100 Subject: [PATCH 4/6] lit_to_const: gracefully bubble up type errors. --- src/librustc/mir/interpret/mod.rs | 4 ++ src/librustc_mir_build/hair/constant.rs | 59 +++++++------------ src/librustc_mir_build/hair/cx/mod.rs | 1 + src/librustc_mir_build/hair/pattern/mod.rs | 1 + src/librustc_typeck/astconv.rs | 2 + .../issue-69310-array-size-lit-wrong-ty.rs | 11 ++++ ...issue-69310-array-size-lit-wrong-ty.stderr | 15 +++++ 7 files changed, 56 insertions(+), 37 deletions(-) create mode 100644 src/test/ui/consts/issue-69310-array-size-lit-wrong-ty.rs create mode 100644 src/test/ui/consts/issue-69310-array-size-lit-wrong-ty.stderr diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index 54e196f4b3341..108d3ef557190 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -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, } diff --git a/src/librustc_mir_build/hair/constant.rs b/src/librustc_mir_build/hair/constant.rs index 266f4738c50a6..2d9ee62da3de2 100644 --- a/src/librustc_mir_build/hair/constant.rs +++ b/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; @@ -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); - 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); + 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 })) } diff --git a/src/librustc_mir_build/hair/cx/mod.rs b/src/librustc_mir_build/hair/cx/mod.rs index 497c6610550f3..5503d1a86e1fe 100644 --- a/src/librustc_mir_build/hair/cx/mod.rs +++ b/src/librustc_mir_build/hair/cx/mod.rs @@ -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"), } } diff --git a/src/librustc_mir_build/hair/pattern/mod.rs b/src/librustc_mir_build/hair/pattern/mod.rs index 2657050583071..b44c7a8c6662d 100644 --- a/src/librustc_mir_build/hair/pattern/mod.rs +++ b/src/librustc_mir_build/hair/pattern/mod.rs @@ -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"), } } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 89eeed8d11ebc..c4a7f5aeb8e27 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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"); } } diff --git a/src/test/ui/consts/issue-69310-array-size-lit-wrong-ty.rs b/src/test/ui/consts/issue-69310-array-size-lit-wrong-ty.rs new file mode 100644 index 0000000000000..98be8c345a9ed --- /dev/null +++ b/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 diff --git a/src/test/ui/consts/issue-69310-array-size-lit-wrong-ty.stderr b/src/test/ui/consts/issue-69310-array-size-lit-wrong-ty.stderr new file mode 100644 index 0000000000000..7078b4bd7be1d --- /dev/null +++ b/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`. From 025e9745fd655cbfcd12c95128dde973003bccb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Thu, 27 Feb 2020 16:51:09 +0100 Subject: [PATCH 5/6] [beta] bootstrap from 1.41.1 stable 1.41.1 contains fixes to miscompilations, we should bootstrap from that to avoid potential hazards. --- src/stage0.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stage0.txt b/src/stage0.txt index 99d2062d3f8ad..f25838ea822c5 100644 --- a/src/stage0.txt +++ b/src/stage0.txt @@ -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 From d620bec5dfa950e497c3cb3778a9ea7ca20c12e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Wed, 12 Feb 2020 00:00:00 +0000 Subject: [PATCH 6/6] bootstrap: Configure cmake when building sanitizer runtimes --- src/bootstrap/native.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 5bbd9f47fc907..a796685f9ddc9 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -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 @@ -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, cfg: &mut cmake::Config) { +fn configure_cmake( + builder: &Builder<'_>, + target: Interned, + 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"); @@ -374,9 +379,11 @@ fn configure_cmake(builder: &Builder<'_>, target: Interned, 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)); @@ -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 @@ -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"); @@ -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);