From 829bc268a9e3ef4d0f8ec4f6a2fadd604bdc7b8d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 18 Jul 2018 11:37:56 -0700 Subject: [PATCH 1/8] rustc: Remove a workaroudn in ThinLTO fixed upstream This commit removes a hack in our ThinLTO passes which removes available externally functions manually. The [upstream bug][1] has long since been fixed, so we should be able to rely on LLVM natively for this now! [1]: https://bugs.llvm.org/show_bug.cgi?id=35736 --- src/librustc_codegen_llvm/back/lto.rs | 14 -------------- src/librustc_llvm/ffi.rs | 1 - src/rustllvm/PassWrapper.cpp | 14 -------------- 3 files changed, 29 deletions(-) diff --git a/src/librustc_codegen_llvm/back/lto.rs b/src/librustc_codegen_llvm/back/lto.rs index a33f8b569d0a8..60b5cf2ec7651 100644 --- a/src/librustc_codegen_llvm/back/lto.rs +++ b/src/librustc_codegen_llvm/back/lto.rs @@ -759,20 +759,6 @@ impl ThinModule { cgcx.save_temp_bitcode(&module, "thin-lto-after-pm"); timeline.record("thin-done"); - // FIXME: this is a hack around a bug in LLVM right now. Discovered in - // #46910 it was found out that on 32-bit MSVC LLVM will hit a codegen - // error if there's an available_externally function in the LLVM module. - // Typically we don't actually use these functions but ThinLTO makes - // heavy use of them when inlining across modules. - // - // Tracked upstream at https://bugs.llvm.org/show_bug.cgi?id=35736 this - // function call (and its definition on the C++ side of things) - // shouldn't be necessary eventually and we can safetly delete these few - // lines. - llvm::LLVMRustThinLTORemoveAvailableExternally(llmod); - cgcx.save_temp_bitcode(&module, "thin-lto-after-rm-ae"); - timeline.record("no-ae"); - Ok(module) } } diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index b4483557dd33f..8d04438eea290 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -1791,7 +1791,6 @@ extern "C" { CU1: *mut *mut c_void, CU2: *mut *mut c_void); pub fn LLVMRustThinLTOPatchDICompileUnit(M: ModuleRef, CU: *mut c_void); - pub fn LLVMRustThinLTORemoveAvailableExternally(M: ModuleRef); pub fn LLVMRustLinkerNew(M: ModuleRef) -> LinkerRef; pub fn LLVMRustLinkerAdd(linker: LinkerRef, diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index a00ff3b345d11..2f28c5b32fb88 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -1228,15 +1228,6 @@ LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) { MD->addOperand(Unit); } -extern "C" void -LLVMRustThinLTORemoveAvailableExternally(LLVMModuleRef Mod) { - Module *M = unwrap(Mod); - for (Function &F : M->functions()) { - if (F.hasAvailableExternallyLinkage()) - F.deleteBody(); - } -} - #else extern "C" bool @@ -1328,9 +1319,4 @@ LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod) { report_fatal_error("ThinLTO not available"); } -extern "C" void -LLVMRustThinLTORemoveAvailableExternally(LLVMModuleRef Mod) { - report_fatal_error("ThinLTO not available"); -} - #endif // LLVM_VERSION_GE(4, 0) From 16c057256f68b39df70737838f367cf645d6e0c7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 19 Jul 2018 09:11:56 +0200 Subject: [PATCH 2/8] fix safety-related comment in slice::rotate --- src/libcore/slice/rotate.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/slice/rotate.rs b/src/libcore/slice/rotate.rs index e4a4e33c1729e..28ef53ccb5cb6 100644 --- a/src/libcore/slice/rotate.rs +++ b/src/libcore/slice/rotate.rs @@ -48,7 +48,6 @@ impl RawArray { /// # Safety /// /// The specified range must be valid for reading and writing. -/// The type `T` must have non-zero size. /// /// # Algorithm /// @@ -73,6 +72,7 @@ pub unsafe fn ptr_rotate(mut left: usize, mid: *mut T, mut right: usize) { loop { let delta = cmp::min(left, right); if delta <= RawArray::::cap() { + // We will always hit this immediately for ZST. break; } From 0700558673a545413de75bab8c0a9be27e524b5c Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 19 Jul 2018 10:11:55 +0200 Subject: [PATCH 3/8] Enable run-pass/sepcomp-lib-lto.rs on Android --- src/test/run-pass/sepcomp-lib-lto.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/run-pass/sepcomp-lib-lto.rs b/src/test/run-pass/sepcomp-lib-lto.rs index f3e52fbd32f3e..8d73f4db7d234 100644 --- a/src/test/run-pass/sepcomp-lib-lto.rs +++ b/src/test/run-pass/sepcomp-lib-lto.rs @@ -14,7 +14,6 @@ // aux-build:sepcomp_lib.rs // compile-flags: -C lto -g // no-prefer-dynamic -// ignore-android FIXME #18800 extern crate sepcomp_lib; use sepcomp_lib::a::one; From f2f7ab9da835f5fd66722f2efec9285ea72ad0f4 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 19 Jul 2018 07:43:58 -0700 Subject: [PATCH 4/8] rustc: Fix two custom attributes with custom derive This commit fixes an issue where multiple custom attributes could not be fed into a custom derive in some situations with the `use_extern_macros` feature enabled. The problem was that the macro expander didn't consider that it was making progress when we were deducing that attributes should be lumped in with custom derive invocations. The fix applied here was to track in the expander if our attribute is changing (getting stashed away elsewhere and replaced with a new invocation). If it is swapped then it's considered progress, otherwise behavior should remain the same. Closes #52525 --- src/libsyntax/ext/expand.rs | 17 +++++++++++++ .../proc-macro/auxiliary/derive-two-attrs.rs | 22 +++++++++++++++++ .../proc-macro/derive-two-attrs.rs | 24 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 src/test/run-pass-fulldeps/proc-macro/auxiliary/derive-two-attrs.rs create mode 100644 src/test/run-pass-fulldeps/proc-macro/derive-two-attrs.rs diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 1241e230b26d6..d64f3de8daa97 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -240,6 +240,13 @@ impl Invocation { InvocationKind::Derive { ref path, .. } => path.span, } } + + pub fn attr_id(&self) -> Option { + match self.kind { + InvocationKind::Attr { attr: Some(ref attr), .. } => Some(attr.id), + _ => None, + } + } } pub struct MacroExpander<'a, 'b:'a> { @@ -331,10 +338,20 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let scope = if self.monotonic { invoc.expansion_data.mark } else { orig_expansion_data.mark }; + let attr_id_before = invoc.attr_id(); let ext = match self.cx.resolver.resolve_invoc(&mut invoc, scope, force) { Ok(ext) => Some(ext), Err(Determinacy::Determined) => None, Err(Determinacy::Undetermined) => { + // Sometimes attributes which we thought were invocations + // end up being custom attributes for custom derives. If + // that's the case our `invoc` will have changed out from + // under us. If this is the case we're making progress so we + // want to flag it as such, and we test this by looking if + // the `attr_id()` method has been changing over time. + if invoc.attr_id() != attr_id_before { + progress = true; + } undetermined_invocations.push(invoc); continue } diff --git a/src/test/run-pass-fulldeps/proc-macro/auxiliary/derive-two-attrs.rs b/src/test/run-pass-fulldeps/proc-macro/auxiliary/derive-two-attrs.rs new file mode 100644 index 0000000000000..d02edb50fb2b5 --- /dev/null +++ b/src/test/run-pass-fulldeps/proc-macro/auxiliary/derive-two-attrs.rs @@ -0,0 +1,22 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// no-prefer-dynamic + +#![crate_type = "proc-macro"] + +extern crate proc_macro; + +use proc_macro::*; + +#[proc_macro_derive(A, attributes(b))] +pub fn foo(_x: TokenStream) -> TokenStream { + TokenStream::new() +} diff --git a/src/test/run-pass-fulldeps/proc-macro/derive-two-attrs.rs b/src/test/run-pass-fulldeps/proc-macro/derive-two-attrs.rs new file mode 100644 index 0000000000000..6a0a3b3a9416a --- /dev/null +++ b/src/test/run-pass-fulldeps/proc-macro/derive-two-attrs.rs @@ -0,0 +1,24 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:derive-two-attrs.rs + +#![feature(use_extern_macros)] + +extern crate derive_two_attrs as foo; + +use foo::A; + +#[derive(A)] +#[b] +#[b] +struct B; + +fn main() {} From f775c6d7ce07ccc839ec9339e3b8fd8cc539c97b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 19 Jul 2018 07:48:17 -0700 Subject: [PATCH 5/8] Fix docker/run.sh script when run locally Switch a `mkdir $foo` to `mkdir -p $foo` to handle the case that this script is being run locally and has previously executed. --- src/ci/docker/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/run.sh b/src/ci/docker/run.sh index 931c28f1ca98e..b1ee636644ec7 100755 --- a/src/ci/docker/run.sh +++ b/src/ci/docker/run.sh @@ -99,7 +99,7 @@ objdir=$root_dir/obj mkdir -p $HOME/.cargo mkdir -p $objdir/tmp -mkdir $objdir/cores +mkdir -p $objdir/cores args= if [ "$SCCACHE_BUCKET" != "" ]; then From 576cfc510aefc1b21c1ff3a0e8ff5efe84529434 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 19 Jul 2018 10:28:25 +0200 Subject: [PATCH 6/8] Remove duplicate E0396 tests --- src/test/run-pass/const-block.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/test/run-pass/const-block.rs b/src/test/run-pass/const-block.rs index e56d01d7ba8ce..e6f191ea9522f 100644 --- a/src/test/run-pass/const-block.rs +++ b/src/test/run-pass/const-block.rs @@ -39,13 +39,6 @@ static BLOCK_FN: fn(usize) -> usize = { foo:: }; static BLOCK_ENUM_CONSTRUCTOR: fn(usize) -> Option = { Some }; -// FIXME #13972 -// static BLOCK_UNSAFE_SAFE_PTR: &'static isize = unsafe { &*(0xdeadbeef as *const isize) }; -// static BLOCK_UNSAFE_SAFE_PTR_2: &'static isize = unsafe { -// const X: *const isize = 0xdeadbeef as *const isize; -// &*X -// }; - pub fn main() { assert_eq!(BLOCK_INTEGRAL, 1); assert_eq!(BLOCK_EXPLICIT_UNIT, ()); @@ -58,7 +51,4 @@ pub fn main() { assert_eq!(BLOCK_FN_INFERRED(300), 300); assert_eq!(BLOCK_FN(300), 300); assert_eq!(BLOCK_ENUM_CONSTRUCTOR(200), Some(200)); - // FIXME #13972 - // assert_eq!(BLOCK_UNSAFE_SAFE_PTR as *const isize as usize, 0xdeadbeef); - // assert_eq!(BLOCK_UNSAFE_SAFE_PTR_2 as *const isize as usize, 0xdeadbeef); } From 7cab813ad91ec7b2016ae3c0e6fc804becb2d623 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 20 Jul 2018 17:19:58 +0200 Subject: [PATCH 7/8] Only methods are fn-like, not other associated items --- src/librustc/hir/map/blocks.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 5a595d14db7aa..f2f7f95426ab8 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -51,6 +51,12 @@ impl MaybeFnLike for ast::Item { } } +impl MaybeFnLike for ast::ImplItem { + fn is_fn_like(&self) -> bool { + match self.node { ast::ImplItemKind::Method(..) => true, _ => false, } + } +} + impl MaybeFnLike for ast::TraitItem { fn is_fn_like(&self) -> bool { match self.node { @@ -141,7 +147,7 @@ impl<'a> FnLikeNode<'a> { let fn_like = match node { map::NodeItem(item) => item.is_fn_like(), map::NodeTraitItem(tm) => tm.is_fn_like(), - map::NodeImplItem(_) => true, + map::NodeImplItem(it) => it.is_fn_like(), map::NodeExpr(e) => e.is_fn_like(), _ => false }; From c7d39e0c510206b74453ca8636e647852e6f294c Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 20 Jul 2018 18:42:45 +0200 Subject: [PATCH 8/8] Remove unused method --- src/librustc_codegen_llvm/builder.rs | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/librustc_codegen_llvm/builder.rs b/src/librustc_codegen_llvm/builder.rs index c71e49b0d8821..e4acb2ad4b161 100644 --- a/src/librustc_codegen_llvm/builder.rs +++ b/src/librustc_codegen_llvm/builder.rs @@ -13,7 +13,7 @@ use llvm; use llvm::{AtomicRmwBinOp, AtomicOrdering, SynchronizationScope, AsmDialect}; use llvm::{Opcode, IntPredicate, RealPredicate, False, OperandBundleDef}; -use llvm::{ValueRef, BasicBlockRef, BuilderRef, ModuleRef}; +use llvm::{ValueRef, BasicBlockRef, BuilderRef}; use common::*; use type_::Type; use value::Value; @@ -1157,23 +1157,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - pub fn trap(&self) { - unsafe { - let bb: BasicBlockRef = llvm::LLVMGetInsertBlock(self.llbuilder); - let fn_: ValueRef = llvm::LLVMGetBasicBlockParent(bb); - let m: ModuleRef = llvm::LLVMGetGlobalParent(fn_); - let p = "llvm.trap\0".as_ptr(); - let t: ValueRef = llvm::LLVMGetNamedFunction(m, p as *const _); - assert!((t as isize != 0)); - let args: &[ValueRef] = &[]; - self.count_insn("trap"); - llvm::LLVMRustBuildCall(self.llbuilder, t, - args.as_ptr(), args.len() as c_uint, - ptr::null_mut(), - noname()); - } - } - pub fn landing_pad(&self, ty: Type, pers_fn: ValueRef, num_clauses: usize) -> ValueRef { self.count_insn("landingpad");