From 084217af65b212c3c68f66d798faa19bcef5007a Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Wed, 8 Jan 2020 22:56:33 +0000 Subject: [PATCH 1/5] Don't use f64 shims for f32 cmath functions on none 32-bit x86 MSVC These shims are only needed on 32-bit x86. Additionally since https://reviews.llvm.org/rL268875 LLVM handles adding the shims itself for the intrinsics. --- src/libstd/f32.rs | 60 +++++---------------------------- src/libstd/sys/windows/cmath.rs | 10 +++--- 2 files changed, 13 insertions(+), 57 deletions(-) diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 267d7013b1e..acca4af85be 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -44,23 +44,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn floor(self) -> f32 { - // On MSVC LLVM will lower many math intrinsics to a call to the - // corresponding function. On MSVC, however, many of these functions - // aren't actually available as symbols to call, but rather they are all - // `static inline` functions in header files. This means that from a C - // perspective it's "compatible", but not so much from an ABI - // perspective (which we're worried about). - // - // The inline header functions always just cast to a f64 and do their - // operation, so we do that here as well, but only for MSVC targets. - // - // Note that there are many MSVC-specific float operations which - // redirect to this comment, so `floorf` is just one case of a missing - // function on MSVC, but there are many others elsewhere. - #[cfg(target_env = "msvc")] - return (self as f64).floor() as f32; - #[cfg(not(target_env = "msvc"))] - return unsafe { intrinsics::floorf32(self) }; + unsafe { intrinsics::floorf32(self) } } /// Returns the smallest integer greater than or equal to a number. @@ -78,11 +62,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ceil(self) -> f32 { - // see notes above in `floor` - #[cfg(target_env = "msvc")] - return (self as f64).ceil() as f32; - #[cfg(not(target_env = "msvc"))] - return unsafe { intrinsics::ceilf32(self) }; + unsafe { intrinsics::ceilf32(self) } } /// Returns the nearest integer to a number. Round half-way cases away from @@ -348,11 +328,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn powf(self, n: f32) -> f32 { - // see notes above in `floor` - #[cfg(target_env = "msvc")] - return (self as f64).powf(n as f64) as f32; - #[cfg(not(target_env = "msvc"))] - return unsafe { intrinsics::powf32(self, n) }; + unsafe { intrinsics::powf32(self, n) } } /// Takes the square root of a number. @@ -399,11 +375,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn exp(self) -> f32 { - // see notes above in `floor` - #[cfg(target_env = "msvc")] - return (self as f64).exp() as f32; - #[cfg(not(target_env = "msvc"))] - return unsafe { intrinsics::expf32(self) }; + unsafe { intrinsics::expf32(self) } } /// Returns `2^(self)`. @@ -447,11 +419,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ln(self) -> f32 { - // see notes above in `floor` - #[cfg(target_env = "msvc")] - return (self as f64).ln() as f32; - #[cfg(not(target_env = "msvc"))] - return unsafe { intrinsics::logf32(self) }; + unsafe { intrinsics::logf32(self) } } /// Returns the logarithm of the number with respect to an arbitrary base. @@ -521,11 +489,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn log10(self) -> f32 { - // see notes above in `floor` - #[cfg(target_env = "msvc")] - return (self as f64).log10() as f32; - #[cfg(not(target_env = "msvc"))] - return unsafe { intrinsics::log10f32(self) }; + unsafe { intrinsics::log10f32(self) } } /// The positive difference of two numbers. @@ -625,11 +589,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sin(self) -> f32 { - // see notes in `core::f32::Float::floor` - #[cfg(target_env = "msvc")] - return (self as f64).sin() as f32; - #[cfg(not(target_env = "msvc"))] - return unsafe { intrinsics::sinf32(self) }; + unsafe { intrinsics::sinf32(self) } } /// Computes the cosine of a number (in radians). @@ -649,11 +609,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn cos(self) -> f32 { - // see notes in `core::f32::Float::floor` - #[cfg(target_env = "msvc")] - return (self as f64).cos() as f32; - #[cfg(not(target_env = "msvc"))] - return unsafe { intrinsics::cosf32(self) }; + unsafe { intrinsics::cosf32(self) } } /// Computes the tangent of a number (in radians). diff --git a/src/libstd/sys/windows/cmath.rs b/src/libstd/sys/windows/cmath.rs index 6f5d40b494f..1a5421facd0 100644 --- a/src/libstd/sys/windows/cmath.rs +++ b/src/libstd/sys/windows/cmath.rs @@ -27,7 +27,7 @@ extern "C" { pub use self::shims::*; -#[cfg(not(target_env = "msvc"))] +#[cfg(not(all(target_env = "msvc", target_arch = "x86")))] mod shims { use libc::c_float; @@ -43,10 +43,10 @@ mod shims { } } -// On MSVC these functions aren't defined, so we just define shims which promote -// everything fo f64, perform the calculation, and then demote back to f32. -// While not precisely correct should be "correct enough" for now. -#[cfg(target_env = "msvc")] +// On 32-bit x86 MSVC these functions aren't defined, so we just define shims +// which promote everything fo f64, perform the calculation, and then demote +// back to f32. While not precisely correct should be "correct enough" for now. +#[cfg(all(target_env = "msvc", target_arch = "x86"))] mod shims { use libc::c_float; From f2fc35128b0592f6cdab3da1cf5da9ad8a0e2847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Wed, 15 Jan 2020 00:00:00 +0000 Subject: [PATCH 2/5] Remove unused auxiliary file that was replaced with rust_test_helpers --- src/test/ui/rfcs/rfc1717/auxiliary/clibrary.rs | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/test/ui/rfcs/rfc1717/auxiliary/clibrary.rs diff --git a/src/test/ui/rfcs/rfc1717/auxiliary/clibrary.rs b/src/test/ui/rfcs/rfc1717/auxiliary/clibrary.rs deleted file mode 100644 index c1c5b70bc04..00000000000 --- a/src/test/ui/rfcs/rfc1717/auxiliary/clibrary.rs +++ /dev/null @@ -1,5 +0,0 @@ -// no-prefer-dynamic -#![crate_type = "staticlib"] - -#[no_mangle] -pub extern "C" fn foo(x:i32) -> i32 { x } From 5d00b5c4aae885a247d783f5c274df9ef0539d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Wed, 15 Jan 2020 00:00:00 +0000 Subject: [PATCH 3/5] Enable leak sanitizer test case * Use `black_box` to avoid memory leak removal during optimization. * Leak multiple objects to make test case more robust. --- src/test/run-make-fulldeps/sanitizer-leak/Makefile | 6 +----- src/test/run-make-fulldeps/sanitizer-leak/leak.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/test/run-make-fulldeps/sanitizer-leak/Makefile b/src/test/run-make-fulldeps/sanitizer-leak/Makefile index d8598b8ac93..da370335ca9 100644 --- a/src/test/run-make-fulldeps/sanitizer-leak/Makefile +++ b/src/test/run-make-fulldeps/sanitizer-leak/Makefile @@ -1,11 +1,7 @@ -include ../tools.mk # needs-sanitizer-support -# only-linux -# only-x86_64 -# ignore-test -# FIXME(#46126) ThinLTO for libstd broke this test all: - $(RUSTC) -C opt-level=1 -g -Z sanitizer=leak -Z print-link-args leak.rs | $(CGREP) rustc_rt.lsan + $(RUSTC) -O -Z sanitizer=leak -Z print-link-args leak.rs | $(CGREP) rustc_rt.lsan $(TMPDIR)/leak 2>&1 | $(CGREP) 'detected memory leaks' diff --git a/src/test/run-make-fulldeps/sanitizer-leak/leak.rs b/src/test/run-make-fulldeps/sanitizer-leak/leak.rs index ab8df5c7bfd..fb0a917dd98 100644 --- a/src/test/run-make-fulldeps/sanitizer-leak/leak.rs +++ b/src/test/run-make-fulldeps/sanitizer-leak/leak.rs @@ -1,6 +1,13 @@ +#![feature(test)] + +use std::hint::black_box; use std::mem; fn main() { - let xs = vec![1, 2, 3, 4]; - mem::forget(xs); + for _ in 0..10 { + let xs = vec![1, 2, 3]; + // Prevent compiler from removing the memory allocation. + let xs = black_box(xs); + mem::forget(xs); + } } From baf2921ebc5f5da879d00dd5fb529e5d274dce6b Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Wed, 15 Jan 2020 22:42:04 +0000 Subject: [PATCH 4/5] rustdoc: HTML escape codeblocks which fail syntax highlighting --- src/librustdoc/html/highlight.rs | 2 +- src/test/rustdoc/bad-codeblock-syntax.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index fb6bdcdc9f4..aa52b769c38 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -65,7 +65,7 @@ pub fn render_with_highlighting( Err(()) => { // If errors are encountered while trying to highlight, just emit // the unhighlighted source. - write!(out, "
{}
", src).unwrap(); + write!(out, "
{}
", Escape(src)).unwrap(); } } diff --git a/src/test/rustdoc/bad-codeblock-syntax.rs b/src/test/rustdoc/bad-codeblock-syntax.rs index 0ab2f68fcde..ae8fbe4a2a8 100644 --- a/src/test/rustdoc/bad-codeblock-syntax.rs +++ b/src/test/rustdoc/bad-codeblock-syntax.rs @@ -25,3 +25,11 @@ pub fn quux() {} /// \_ /// ``` pub fn ok() {} + +// @has bad_codeblock_syntax/fn.escape.html +// @has - '//*[@class="docblock"]/pre/code' '\_ ' +/// ``` +/// \_ +/// +/// ``` +pub fn escape() {} From c4d91aae5a72733479bab8df1aee78bb049b9735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Thu, 16 Jan 2020 08:27:41 +0100 Subject: [PATCH 5/5] remove dead code The condition if obligation.recursion_depth >= 0 is always true since recursion_depth is usize. The else branch is dead code and can be removed. Found by Clippy. Fixes #68251 --- src/librustc/traits/select.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index e96697cc7e0..fb1c46834d3 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -3767,16 +3767,12 @@ impl<'tcx> TraitObligation<'tcx> { // NOTE(flaper87): As of now, it keeps track of the whole error // chain. Ideally, we should have a way to configure this either // by using -Z verbose or just a CLI argument. - if obligation.recursion_depth >= 0 { - let derived_cause = DerivedObligationCause { - parent_trait_ref: obligation.predicate.to_poly_trait_ref(), - parent_code: Rc::new(obligation.cause.code.clone()), - }; - let derived_code = variant(derived_cause); - ObligationCause::new(obligation.cause.span, obligation.cause.body_id, derived_code) - } else { - obligation.cause.clone() - } + let derived_cause = DerivedObligationCause { + parent_trait_ref: obligation.predicate.to_poly_trait_ref(), + parent_code: Rc::new(obligation.cause.code.clone()), + }; + let derived_code = variant(derived_cause); + ObligationCause::new(obligation.cause.span, obligation.cause.body_id, derived_code) } }