Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #73053

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
58ae4a9
de-promote Duration::from_secs
RalfJung May 2, 2020
071f042
linker: Add a linker rerun hack for gcc versions not supporting -stat…
petrochenkov May 28, 2020
7242bda
Be more careful around ty::Error in generators
jonas-schievink May 30, 2020
95e9768
test: codegen: skip tests inappropriate for riscv64
tblah May 20, 2020
c872dcf
test: codegen: riscv64-abi: print value numbers for unnamed func args
tblah Jun 4, 2020
37e8e05
test: codegen: Add riscv abi llvm intrinsics test
tblah Jun 4, 2020
08529af
test: codegen: skip catch-unwind on riscv64
tblah Jun 4, 2020
94605b9
run-make regression test for issue #70924.
pnkfelix Jun 3, 2020
2764e54
impl ToSocketAddrs for (String, u16)
yoshuawuyts Jun 4, 2020
a9d5dff
Ignore windows in the test.
pnkfelix Jun 5, 2020
84e4777
save_analysis: fix ice in `get_expr_data`
marmeladema Jun 5, 2020
4d6a307
save_analysis: fix panic in `write_sub_paths_truncated`
marmeladema Jun 5, 2020
1088317
Rollup merge of #71796 - RalfJung:from-secs, r=nikomatsakis
RalfJung Jun 6, 2020
78e7b45
Rollup merge of #72708 - petrochenkov:linkhack, r=cuviper
RalfJung Jun 6, 2020
c5f2de0
Rollup merge of #72764 - jonas-schievink:mind-the-tyerr, r=estebank
RalfJung Jun 6, 2020
82d2781
Rollup merge of #72952 - pnkfelix:regression-test-for-issue-70924, r=…
RalfJung Jun 6, 2020
4d1c35a
Rollup merge of #72977 - tblah:riscv-codegen-llvm10, r=nikomatsakis
RalfJung Jun 6, 2020
849c351
Rollup merge of #73007 - yoshuawuyts:socketaddr-from-string-u16, r=sf…
RalfJung Jun 6, 2020
473e1a9
Rollup merge of #73046 - marmeladema:save-analysis-fix-path, r=Xanewok
RalfJung Jun 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/libcore/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ impl Duration {
/// ```
#[stable(feature = "duration", since = "1.3.0")]
#[inline]
#[rustc_promotable]
#[rustc_const_stable(feature = "duration_consts", since = "1.32.0")]
pub const fn from_secs(secs: u64) -> Duration {
Duration { secs, nanos: 0 }
Expand Down
65 changes: 57 additions & 8 deletions src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_session::utils::NativeLibKind;
/// need out of the shared crate context before we get rid of it.
use rustc_session::{filesearch, Session};
use rustc_span::symbol::Symbol;
use rustc_target::spec::crt_objects::CrtObjectsFallback;
use rustc_target::spec::crt_objects::{CrtObjects, CrtObjectsFallback};
use rustc_target::spec::{LinkOutputKind, LinkerFlavor, LldFlavor};
use rustc_target::spec::{PanicStrategy, RelocModel, RelroLevel};

Expand All @@ -25,16 +25,10 @@ use crate::{looks_like_rust_object_file, CodegenResults, CrateInfo, METADATA_FIL
use cc::windows_registry;
use tempfile::{Builder as TempFileBuilder, TempDir};

use std::ascii;
use std::char;
use std::env;
use std::ffi::OsString;
use std::fmt;
use std::fs;
use std::io;
use std::path::{Path, PathBuf};
use std::process::{ExitStatus, Output, Stdio};
use std::str;
use std::{ascii, char, env, fmt, fs, io, mem, str};

pub fn remove(sess: &Session, path: &Path) {
if let Err(e) = fs::remove_file(path) {
Expand Down Expand Up @@ -543,6 +537,61 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
continue;
}

// Detect '-static-pie' used with an older version of gcc or clang not supporting it.
// Fallback from '-static-pie' to '-static' in that case.
if sess.target.target.options.linker_is_gnu
&& flavor != LinkerFlavor::Ld
&& (out.contains("unrecognized command line option")
|| out.contains("unknown argument"))
&& (out.contains("-static-pie") || out.contains("--no-dynamic-linker"))
&& cmd.get_args().iter().any(|e| e.to_string_lossy() == "-static-pie")
{
info!("linker output: {:?}", out);
warn!(
"Linker does not support -static-pie command line option. Retrying with -static instead."
);
// Mirror `add_(pre,post)_link_objects` to replace CRT objects.
let fallback = crt_objects_fallback(sess, crate_type);
let opts = &sess.target.target.options;
let pre_objects =
if fallback { &opts.pre_link_objects_fallback } else { &opts.pre_link_objects };
let post_objects =
if fallback { &opts.post_link_objects_fallback } else { &opts.post_link_objects };
let get_objects = |objects: &CrtObjects, kind| {
objects
.get(&kind)
.iter()
.copied()
.flatten()
.map(|obj| get_object_file_path(sess, obj).into_os_string())
.collect::<Vec<_>>()
};
let pre_objects_static_pie = get_objects(pre_objects, LinkOutputKind::StaticPicExe);
let post_objects_static_pie = get_objects(post_objects, LinkOutputKind::StaticPicExe);
let mut pre_objects_static = get_objects(pre_objects, LinkOutputKind::StaticNoPicExe);
let mut post_objects_static = get_objects(post_objects, LinkOutputKind::StaticNoPicExe);
// Assume that we know insertion positions for the replacement arguments from replaced
// arguments, which is true for all supported targets.
assert!(pre_objects_static.is_empty() || !pre_objects_static_pie.is_empty());
assert!(post_objects_static.is_empty() || !post_objects_static_pie.is_empty());
for arg in cmd.take_args() {
if arg.to_string_lossy() == "-static-pie" {
// Replace the output kind.
cmd.arg("-static");
} else if pre_objects_static_pie.contains(&arg) {
// Replace the pre-link objects (replace the first and remove the rest).
cmd.args(mem::take(&mut pre_objects_static));
} else if post_objects_static_pie.contains(&arg) {
// Replace the post-link objects (replace the first and remove the rest).
cmd.args(mem::take(&mut post_objects_static));
} else {
cmd.arg(arg);
}
}
info!("{:?}", &cmd);
continue;
}

// Here's a terribly awful hack that really shouldn't be present in any
// compiler. Here an environment variable is supported to automatically
// retry the linker invocation if the linker looks like it segfaulted.
Expand Down
69 changes: 43 additions & 26 deletions src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,40 +669,33 @@ fn compute_storage_conflicts(
storage_conflicts
}

fn compute_layout<'tcx>(
/// Validates the typeck view of the generator against the actual set of types retained between
/// yield points.
fn sanitize_witness<'tcx>(
tcx: TyCtxt<'tcx>,
source: MirSource<'tcx>,
body: &Body<'tcx>,
did: DefId,
witness: Ty<'tcx>,
upvars: &Vec<Ty<'tcx>>,
interior: Ty<'tcx>,
always_live_locals: &storage::AlwaysLiveLocals,
movable: bool,
body: &mut Body<'tcx>,
) -> (
FxHashMap<Local, (Ty<'tcx>, VariantIdx, usize)>,
GeneratorLayout<'tcx>,
IndexVec<BasicBlock, Option<BitSet<Local>>>,
retained: &BitSet<Local>,
) {
// Use a liveness analysis to compute locals which are live across a suspension point
let LivenessInfo {
live_locals,
live_locals_at_suspension_points,
storage_conflicts,
storage_liveness,
} = locals_live_across_suspend_points(tcx, body, source, always_live_locals, movable);

// Erase regions from the types passed in from typeck so we can compare them with
// MIR types
let allowed_upvars = tcx.erase_regions(upvars);
let allowed = match interior.kind {
let allowed = match witness.kind {
ty::GeneratorWitness(s) => tcx.erase_late_bound_regions(&s),
_ => bug!(),
_ => {
tcx.sess.delay_span_bug(
body.span,
&format!("unexpected generator witness type {:?}", witness.kind),
);
return;
}
};

let param_env = tcx.param_env(source.def_id());
let param_env = tcx.param_env(did);

for (local, decl) in body.local_decls.iter_enumerated() {
// Ignore locals which are internal or not live
if !live_locals.contains(local) || decl.internal {
// Ignore locals which are internal or not retained between yields.
if !retained.contains(local) || decl.internal {
continue;
}
let decl_ty = tcx.normalize_erasing_regions(param_env, decl.ty);
Expand All @@ -715,10 +708,34 @@ fn compute_layout<'tcx>(
"Broken MIR: generator contains type {} in MIR, \
but typeck only knows about {}",
decl.ty,
interior
witness,
);
}
}
}

fn compute_layout<'tcx>(
tcx: TyCtxt<'tcx>,
source: MirSource<'tcx>,
upvars: &Vec<Ty<'tcx>>,
interior: Ty<'tcx>,
always_live_locals: &storage::AlwaysLiveLocals,
movable: bool,
body: &mut Body<'tcx>,
) -> (
FxHashMap<Local, (Ty<'tcx>, VariantIdx, usize)>,
GeneratorLayout<'tcx>,
IndexVec<BasicBlock, Option<BitSet<Local>>>,
) {
// Use a liveness analysis to compute locals which are live across a suspension point
let LivenessInfo {
live_locals,
live_locals_at_suspension_points,
storage_conflicts,
storage_liveness,
} = locals_live_across_suspend_points(tcx, body, source, always_live_locals, movable);

sanitize_witness(tcx, body, source.def_id(), interior, upvars, &live_locals);

// Gather live local types and their indices.
let mut locals = IndexVec::<GeneratorSavedLocal, _>::new();
Expand Down
8 changes: 5 additions & 3 deletions src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,11 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
// As write_sub_paths, but does not process the last ident in the path (assuming it
// will be processed elsewhere). See note on write_sub_paths about global.
fn write_sub_paths_truncated(&mut self, path: &'tcx hir::Path<'tcx>) {
for seg in &path.segments[..path.segments.len() - 1] {
if let Some(data) = self.save_ctxt.get_path_segment_data(seg) {
self.dumper.dump_ref(data);
if path.segments.len() > 0 {
for seg in &path.segments[..path.segments.len() - 1] {
if let Some(data) = self.save_ctxt.get_path_segment_data(seg) {
self.dumper.dump_ref(data);
}
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,14 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
}
}
}
hir::ExprKind::Struct(hir::QPath::Resolved(_, path), ..) => {
hir::ExprKind::Struct(qpath, ..) => {
let segment = match qpath {
hir::QPath::Resolved(_, path) => path.segments.last().unwrap(),
hir::QPath::TypeRelative(_, segment) => segment,
};
match self.tables.expr_ty_adjusted(&hir_node).kind {
ty::Adt(def, _) if !def.is_enum() => {
let sub_span = path.segments.last().unwrap().ident.span;
let sub_span = segment.ident.span;
filter!(self.span_utils, sub_span);
let span = self.span_from_span(sub_span);
Some(Data::RefData(Ref {
Expand Down Expand Up @@ -580,7 +584,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
}
_ => {
// FIXME
bug!();
bug!("invalid expression: {:?}", expr);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_target/spec/tests/tests_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@ impl Target {
assert_eq!(self.options.lld_flavor, LldFlavor::Link);
}
}
assert!(
(self.options.pre_link_objects_fallback.is_empty()
&& self.options.post_link_objects_fallback.is_empty())
|| self.options.crt_objects_fallback.is_some()
);
}
}
10 changes: 8 additions & 2 deletions src/librustc_ty/needs_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ where
}
}

ty::Generator(_, substs, _) => {
ty::Generator(def_id, substs, _) => {
let substs = substs.as_generator();
for upvar_ty in substs.upvar_tys() {
queue_type(self, upvar_ty);
Expand All @@ -108,7 +108,13 @@ where
let witness = substs.witness();
let interior_tys = match &witness.kind {
ty::GeneratorWitness(tys) => tcx.erase_late_bound_regions(tys),
_ => bug!(),
_ => {
tcx.sess.delay_span_bug(
tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP),
&format!("unexpected generator witness type {:?}", witness),
);
return Some(Err(AlwaysRequiresDrop));
}
};

for interior_ty in interior_tys {
Expand Down
8 changes: 8 additions & 0 deletions src/libstd/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,14 @@ impl ToSocketAddrs for (&str, u16) {
}
}

#[stable(feature = "string_u16_to_socket_addrs", since = "1.46.0")]
impl ToSocketAddrs for (String, u16) {
type Iter = vec::IntoIter<SocketAddr>;
fn to_socket_addrs(&self) -> io::Result<vec::IntoIter<SocketAddr>> {
(&*self.0, self.1).to_socket_addrs()
}
}

// accepts strings like 'localhost:12345'
#[stable(feature = "rust1", since = "1.0.0")]
impl ToSocketAddrs for str {
Expand Down
1 change: 1 addition & 0 deletions src/test/codegen/abi-main-signature-16bit-c-int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// ignore-mips64
// ignore-powerpc
// ignore-powerpc64
// ignore-riscv64
// ignore-s390x
// ignore-sparc
// ignore-sparc64
Expand Down
1 change: 1 addition & 0 deletions src/test/codegen/abi-sysv64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// ignore-arm
// ignore-aarch64
// ignore-riscv64 sysv64 not supported

// compile-flags: -C no-prepopulate-passes

Expand Down
1 change: 1 addition & 0 deletions src/test/codegen/abi-x86-interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// ignore-arm
// ignore-aarch64
// ignore-riscv64 x86-interrupt is not supported

// compile-flags: -C no-prepopulate-passes

Expand Down
2 changes: 2 additions & 0 deletions src/test/codegen/call-llvm-intrinsics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// compile-flags: -C no-prepopulate-passes

// ignore-riscv64

#![feature(link_llvm_intrinsics)]
#![crate_type = "lib"]

Expand Down
9 changes: 9 additions & 0 deletions src/test/codegen/catch-unwind.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// compile-flags: -O

// On x86 the closure is inlined in foo() producting something like
// define i32 @foo() [...] {
// tail call void @bar() [...]
// ret i32 0
// }
// On riscv the closure is another function, placed before fn foo so CHECK can't
// find it
// ignore-riscv64 FIXME

#![crate_type = "lib"]

extern "C" {
Expand Down
1 change: 1 addition & 0 deletions src/test/codegen/fastcall-inreg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// ignore-powerpc64le
// ignore-powerpc
// ignore-r600
// ignore-riscv64
// ignore-amdgcn
// ignore-sparc
// ignore-sparc64
Expand Down
1 change: 1 addition & 0 deletions src/test/codegen/repr-transparent-aggregates-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// ignore-mips64
// ignore-powerpc
// ignore-powerpc64
// ignore-riscv64 see codegen/riscv-abi
// ignore-windows
// See repr-transparent.rs

Expand Down
1 change: 1 addition & 0 deletions src/test/codegen/repr-transparent-aggregates-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// ignore-powerpc
// ignore-powerpc64
// ignore-powerpc64le
// ignore-riscv64 see codegen/riscv-abi
// ignore-s390x
// ignore-sparc
// ignore-sparc64
Expand Down
3 changes: 3 additions & 0 deletions src/test/codegen/repr-transparent.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// compile-flags: -C no-prepopulate-passes

// ignore-riscv64 riscv64 has an i128 type used with test_Vector
// see codegen/riscv-abi for riscv functiona call tests

#![crate_type="lib"]
#![feature(repr_simd, transparent_unions)]

Expand Down
30 changes: 30 additions & 0 deletions src/test/codegen/riscv-abi/call-llvm-intrinsics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// compile-flags: -C no-prepopulate-passes

// only-riscv64

#![feature(link_llvm_intrinsics)]
#![crate_type = "lib"]

struct A;

impl Drop for A {
fn drop(&mut self) {
println!("A");
}
}

extern {
#[link_name = "llvm.sqrt.f32"]
fn sqrt(x: f32) -> f32;
}

pub fn do_call() {
let _a = A;

unsafe {
// Ensure that we `call` LLVM intrinsics instead of trying to `invoke` them
// CHECK: store float 4.000000e+00, float* %{{.}}, align 4
// CHECK: call float @llvm.sqrt.f32(float %{{.}}
sqrt(4.0);
}
}
Loading