From 50f3b5d4cdf44f15f791e39bce68224a2c917ce4 Mon Sep 17 00:00:00 2001 From: Andre Richter Date: Sat, 18 Jan 2020 09:18:58 +0100 Subject: [PATCH 1/7] AArch64 bare-metal targets: Build rust-std This PR complements https://github.com/rust-lang/rust/pull/68253 --- src/ci/docker/dist-various-1/Dockerfile | 4 ++++ src/tools/build-manifest/src/main.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/ci/docker/dist-various-1/Dockerfile b/src/ci/docker/dist-various-1/Dockerfile index 6bbf092878311..46fce6382dad7 100644 --- a/src/ci/docker/dist-various-1/Dockerfile +++ b/src/ci/docker/dist-various-1/Dockerfile @@ -115,6 +115,8 @@ ENV TARGETS=$TARGETS,armv5te-unknown-linux-gnueabi ENV TARGETS=$TARGETS,armv5te-unknown-linux-musleabi ENV TARGETS=$TARGETS,armv7-unknown-linux-musleabihf ENV TARGETS=$TARGETS,aarch64-unknown-linux-musl +ENV TARGETS=$TARGETS,aarch64-unknown-none +ENV TARGETS=$TARGETS,aarch64-unknown-none-softfloat ENV TARGETS=$TARGETS,sparc64-unknown-linux-gnu ENV TARGETS=$TARGETS,x86_64-unknown-redox ENV TARGETS=$TARGETS,thumbv6m-none-eabi @@ -144,6 +146,8 @@ ENV CC_mipsel_unknown_linux_musl=mipsel-openwrt-linux-gcc \ CC_mips64_unknown_linux_muslabi64=mips64-linux-gnuabi64-gcc \ CC_sparc64_unknown_linux_gnu=sparc64-linux-gnu-gcc \ CC_x86_64_unknown_redox=x86_64-unknown-redox-gcc \ + CC_aarch64_unknown_none=aarch64-unknown-none \ + CC_aarch64_unknown_none_softfloat=aarch64-unknown-none-softfloat \ CC_thumbv7neon_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \ AR_thumbv7neon_unknown_linux_gnueabihf=arm-linux-gnueabihf-ar \ CXX_thumbv7neon_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ \ diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index 481163a1a9abe..77bd5fa0febc6 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -54,6 +54,8 @@ static TARGETS: &[&str] = &[ "aarch64-pc-windows-msvc", "aarch64-unknown-cloudabi", "aarch64-unknown-hermit", + "aarch64-unknown-none", + "aarch64-unknown-none-softfloat", "aarch64-unknown-linux-gnu", "aarch64-unknown-linux-musl", "aarch64-unknown-redox", From 45dd44c0e130479e6532ddb0505401a41884d2bb Mon Sep 17 00:00:00 2001 From: msizanoen1 <55322658+msizanoen1@users.noreply.github.com> Date: Sat, 18 Jan 2020 18:59:51 +0700 Subject: [PATCH 2/7] Add `riscv64gc-unknown-linux-gnu` into target list in build-manifest Missed in #68037 r? @alexcrichton --- src/tools/build-manifest/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index 481163a1a9abe..cff04e197e48a 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -110,6 +110,7 @@ static TARGETS: &[&str] = &[ "riscv32imac-unknown-none-elf", "riscv64imac-unknown-none-elf", "riscv64gc-unknown-none-elf", + "riscv64gc-unknown-linux-gnu", "s390x-unknown-linux-gnu", "sparc64-unknown-linux-gnu", "sparcv9-sun-solaris", From fd90e56120c9fec88808f9464e27283b0c6954ad Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Thu, 16 Jan 2020 18:58:32 -0800 Subject: [PATCH 3/7] Add failing #[track_caller] test with fn pointers. --- .../tracked-fn-ptr-with-arg.rs | 16 ++++++++++++++++ .../ui/rfc-2091-track-caller/tracked-fn-ptr.rs | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs create mode 100644 src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs diff --git a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs new file mode 100644 index 0000000000000..210a4f22f09cd --- /dev/null +++ b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs @@ -0,0 +1,16 @@ +// run-pass + +#![feature(track_caller)] + +fn pass_to_ptr_call(f: fn(T), x: T) { + f(x); +} + +#[track_caller] +fn tracked_unit(_: ()) { + assert_eq!(std::panic::Location::caller().file(), file!()); +} + +fn main() { + pass_to_ptr_call(tracked_unit, ()); +} diff --git a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs new file mode 100644 index 0000000000000..1ce8f678b60f7 --- /dev/null +++ b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs @@ -0,0 +1,16 @@ +// run-pass + +#![feature(track_caller)] + +fn ptr_call(f: fn()) { + f(); +} + +#[track_caller] +fn tracked() { + assert_eq!(std::panic::Location::caller().file(), file!()); +} + +fn main() { + ptr_call(tracked); +} From 0ee922123facae1a170257bf1d6c493f8fa9f29e Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Thu, 16 Jan 2020 19:23:45 -0800 Subject: [PATCH 4/7] InstanceDef::requires_caller_location limited to items. --- src/librustc/ty/instance.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index 9be50d19a5030..1ea695e40b255 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -141,7 +141,12 @@ impl<'tcx> InstanceDef<'tcx> { } pub fn requires_caller_location(&self, tcx: TyCtxt<'_>) -> bool { - tcx.codegen_fn_attrs(self.def_id()).flags.contains(CodegenFnAttrFlags::TRACK_CALLER) + match *self { + InstanceDef::Item(def_id) => { + tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::TRACK_CALLER) + } + _ => false, + } } } From 19d8527890b59ed25432fbf5a9f1bd75ac814ae2 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 19 Jan 2020 21:21:48 +0200 Subject: [PATCH 5/7] rustc_mir: don't require a self argument for ReifyShim. --- src/librustc_mir/shim.rs | 80 ++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 27 deletions(-) diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 01cecdd067945..b84616142cb07 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -31,9 +31,13 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx let mut result = match instance { ty::InstanceDef::Item(..) => bug!("item {:?} passed to make_shim", instance), - ty::InstanceDef::VtableShim(def_id) => { - build_call_shim(tcx, instance, Adjustment::DerefMove, CallKind::Direct(def_id), None) - } + ty::InstanceDef::VtableShim(def_id) => build_call_shim( + tcx, + instance, + Some(Adjustment::DerefMove), + CallKind::Direct(def_id), + None, + ), ty::InstanceDef::FnPtrShim(def_id, ty) => { let trait_ = tcx.trait_of_item(def_id).unwrap(); let adjustment = match tcx.lang_items().fn_trait_kind(trait_) { @@ -50,7 +54,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx let sig = tcx.erase_late_bound_regions(&ty.fn_sig(tcx)); let arg_tys = sig.inputs(); - build_call_shim(tcx, instance, adjustment, CallKind::Indirect, Some(arg_tys)) + build_call_shim(tcx, instance, Some(adjustment), CallKind::Indirect, Some(arg_tys)) } // We are generating a call back to our def-id, which the // codegen backend knows to turn to an actual call, be it @@ -58,7 +62,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx // indirect calls must be codegen'd differently than direct ones // (such as `#[track_caller]`). ty::InstanceDef::ReifyShim(def_id) => { - build_call_shim(tcx, instance, Adjustment::Identity, CallKind::Direct(def_id), None) + build_call_shim(tcx, instance, None, CallKind::Direct(def_id), None) } ty::InstanceDef::ClosureOnceShim { call_once: _ } => { let fn_mut = tcx.lang_items().fn_mut_trait().unwrap(); @@ -68,7 +72,13 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx .unwrap() .def_id; - build_call_shim(tcx, instance, Adjustment::RefMut, CallKind::Direct(call_mut), None) + build_call_shim( + tcx, + instance, + Some(Adjustment::RefMut), + CallKind::Direct(call_mut), + None, + ) } ty::InstanceDef::DropGlue(def_id, ty) => build_drop_shim(tcx, def_id, ty), ty::InstanceDef::CloneShim(def_id, ty) => { @@ -648,7 +658,7 @@ impl CloneShimBuilder<'tcx> { fn build_call_shim<'tcx>( tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>, - rcvr_adjustment: Adjustment, + rcvr_adjustment: Option, call_kind: CallKind, untuple_args: Option<&[Ty<'tcx>]>, ) -> BodyAndCache<'tcx> { @@ -680,14 +690,16 @@ fn build_call_shim<'tcx>( let mut local_decls = local_decls_for_sig(&sig, span); let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }; - let rcvr_arg = Local::new(1 + 0); - let rcvr_l = Place::from(rcvr_arg); + let rcvr_place = || { + assert!(rcvr_adjustment.is_some()); + Place::from(Local::new(1 + 0)) + }; let mut statements = vec![]; - let rcvr = match rcvr_adjustment { - Adjustment::Identity => Operand::Move(rcvr_l), - Adjustment::Deref => Operand::Copy(tcx.mk_place_deref(rcvr_l)), - Adjustment::DerefMove => Operand::Move(tcx.mk_place_deref(rcvr_l)), + let rcvr = rcvr_adjustment.map(|rcvr_adjustment| match rcvr_adjustment { + Adjustment::Identity => Operand::Move(rcvr_place()), + Adjustment::Deref => Operand::Copy(tcx.mk_place_deref(rcvr_place())), + Adjustment::DerefMove => Operand::Move(tcx.mk_place_deref(rcvr_place())), Adjustment::RefMut => { // let rcvr = &mut rcvr; let ref_rcvr = local_decls.push(temp_decl( @@ -703,15 +715,15 @@ fn build_call_shim<'tcx>( source_info, kind: StatementKind::Assign(box ( Place::from(ref_rcvr), - Rvalue::Ref(tcx.lifetimes.re_erased, borrow_kind, rcvr_l), + Rvalue::Ref(tcx.lifetimes.re_erased, borrow_kind, rcvr_place()), )), }); Operand::Move(Place::from(ref_rcvr)) } - }; + }); let (callee, mut args) = match call_kind { - CallKind::Indirect => (rcvr, vec![]), + CallKind::Indirect => (rcvr.unwrap(), vec![]), CallKind::Direct(def_id) => { let ty = tcx.type_of(def_id); ( @@ -720,21 +732,35 @@ fn build_call_shim<'tcx>( user_ty: None, literal: ty::Const::zero_sized(tcx, ty), }), - vec![rcvr], + rcvr.into_iter().collect::>(), ) } }; + let mut arg_range = 0..sig.inputs().len(); + + // Take the `self` ("receiver") argument out of the range (it's adjusted above). + if rcvr_adjustment.is_some() { + arg_range.start += 1; + } + + // Take the last argument, if we need to untuple it (handled below). + if untuple_args.is_some() { + arg_range.end -= 1; + } + + // Pass all of the non-special arguments directly. + args.extend(arg_range.map(|i| Operand::Move(Place::from(Local::new(1 + i))))); + + // Untuple the last argument, if we have to. if let Some(untuple_args) = untuple_args { + let tuple_arg = Local::new(1 + (sig.inputs().len() - 1)); args.extend(untuple_args.iter().enumerate().map(|(i, ity)| { - let arg_place = Place::from(Local::new(1 + 1)); - Operand::Move(tcx.mk_place_field(arg_place, Field::new(i), *ity)) + Operand::Move(tcx.mk_place_field(Place::from(tuple_arg), Field::new(i), *ity)) })); - } else { - args.extend((1..sig.inputs().len()).map(|i| Operand::Move(Place::from(Local::new(1 + i))))); } - let n_blocks = if let Adjustment::RefMut = rcvr_adjustment { 5 } else { 2 }; + let n_blocks = if let Some(Adjustment::RefMut) = rcvr_adjustment { 5 } else { 2 }; let mut blocks = IndexVec::with_capacity(n_blocks); let block = |blocks: &mut IndexVec<_, _>, statements, kind, is_cleanup| { blocks.push(BasicBlockData { @@ -752,7 +778,7 @@ fn build_call_shim<'tcx>( func: callee, args, destination: Some((Place::return_place(), BasicBlock::new(1))), - cleanup: if let Adjustment::RefMut = rcvr_adjustment { + cleanup: if let Some(Adjustment::RefMut) = rcvr_adjustment { Some(BasicBlock::new(3)) } else { None @@ -762,13 +788,13 @@ fn build_call_shim<'tcx>( false, ); - if let Adjustment::RefMut = rcvr_adjustment { + if let Some(Adjustment::RefMut) = rcvr_adjustment { // BB #1 - drop for Self block( &mut blocks, vec![], TerminatorKind::Drop { - location: Place::from(rcvr_arg), + location: rcvr_place(), target: BasicBlock::new(2), unwind: None, }, @@ -777,13 +803,13 @@ fn build_call_shim<'tcx>( } // BB #1/#2 - return block(&mut blocks, vec![], TerminatorKind::Return, false); - if let Adjustment::RefMut = rcvr_adjustment { + if let Some(Adjustment::RefMut) = rcvr_adjustment { // BB #3 - drop if closure panics block( &mut blocks, vec![], TerminatorKind::Drop { - location: Place::from(rcvr_arg), + location: rcvr_place(), target: BasicBlock::new(4), unwind: None, }, From 72dffac6cf170c6c16c043299e35848014aae8d4 Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Sun, 19 Jan 2020 14:25:43 -0800 Subject: [PATCH 6/7] Test that ReifyShim + caller_location return the def site. --- src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs | 5 ++++- src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs index 210a4f22f09cd..0407eafbfd41c 100644 --- a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs +++ b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr-with-arg.rs @@ -8,7 +8,10 @@ fn pass_to_ptr_call(f: fn(T), x: T) { #[track_caller] fn tracked_unit(_: ()) { - assert_eq!(std::panic::Location::caller().file(), file!()); + let expected_line = line!() - 1; + let location = std::panic::Location::caller(); + assert_eq!(location.file(), file!()); + assert_eq!(location.line(), expected_line, "call shims report location as fn definition"); } fn main() { diff --git a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs index 1ce8f678b60f7..a4baaa26ced1e 100644 --- a/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs +++ b/src/test/ui/rfc-2091-track-caller/tracked-fn-ptr.rs @@ -8,7 +8,10 @@ fn ptr_call(f: fn()) { #[track_caller] fn tracked() { - assert_eq!(std::panic::Location::caller().file(), file!()); + let expected_line = line!() - 1; + let location = std::panic::Location::caller(); + assert_eq!(location.file(), file!()); + assert_eq!(location.line(), expected_line, "call shims report location as fn definition"); } fn main() { From 6be3446f92b444cd6584c7948be9f7cf20ce5518 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Mon, 20 Jan 2020 10:01:17 +0000 Subject: [PATCH 7/7] Added minor clarification to specification of realloc. The `layout` for the returned allocation of a `realloc` is only implicitly specified. This change makes it explicit. --- src/libcore/alloc.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs index 4354e1c7b5f69..09f743fb81e4c 100644 --- a/src/libcore/alloc.rs +++ b/src/libcore/alloc.rs @@ -525,7 +525,8 @@ pub unsafe trait GlobalAlloc { /// The memory may or may not have been deallocated, /// and should be considered unusable (unless of course it was /// transferred back to the caller again via the return value of - /// this method). + /// this method). The new memory block is allocated with `layout`, but + /// with the `size` updated to `new_size`. /// /// If this method returns null, then ownership of the memory /// block has not been transferred to this allocator, and the