Skip to content

Commit 36a50c2

Browse files
committed
Auto merge of #55803 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 17 pull requests Successful merges: - #55576 (Clarify error message for -C opt-level) - #55633 (Support memcpy/memmove with differing src/dst alignment) - #55638 (Fix ICE in msg_span_from_free_region on ReEmpty) - #55659 (rustc: Delete grouping logic from the musl target) - #55719 (Sidestep link error from rustfix'ed code by using a *defined* static.) - #55736 (Elide anon lifetimes in conflicting impl note) - #55739 (Consume optimization fuel from the MIR inliner) - #55742 (Avoid panic when matching function call) - #55753 (borrow_set: remove a helper function and a clone it uses) - #55755 (Improve creation of 3 IndexVecs) - #55758 ([regression - rust2018]: unused_mut lint false positives on nightly) - #55760 (Remove intermediate font specs) - #55761 (mir: remove a hacky recursive helper function) - #55774 (wasm32-unknown-emscripten expects the rust_eh_personality symbol) - #55777 (Use `Lit` rather than `P<Lit>` in `ast::ExprKind`.) - #55783 (Deprecate mpsc channel selection) - #55788 (rustc: Request ansi colors if stderr isn't a tty) Failed merges: r? @ghost
2 parents 653da4f + d293d1e commit 36a50c2

File tree

47 files changed

+403
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+403
-172
lines changed

src/libpanic_abort/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ pub unsafe extern fn __rust_start_panic(_payload: usize) -> u32 {
9797
pub mod personalities {
9898
#[no_mangle]
9999
#[cfg(not(any(
100-
target_arch = "wasm32",
100+
all(
101+
target_arch = "wasm32",
102+
not(target_os = "emscripten"),
103+
),
101104
all(
102105
target_os = "windows",
103106
target_env = "gnu",

src/librustc/hir/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3705,7 +3705,7 @@ impl<'a> LoweringContext<'a> {
37053705
let ohs = P(self.lower_expr(ohs));
37063706
hir::ExprKind::Unary(op, ohs)
37073707
}
3708-
ExprKind::Lit(ref l) => hir::ExprKind::Lit(P((**l).clone())),
3708+
ExprKind::Lit(ref l) => hir::ExprKind::Lit(P((*l).clone())),
37093709
ExprKind::Cast(ref expr, ref ty) => {
37103710
let expr = P(self.lower_expr(expr));
37113711
hir::ExprKind::Cast(expr, self.lower_ty(ty, ImplTraitContext::disallowed()))

src/librustc/infer/error_reporting/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
178178
self.msg_span_from_early_bound_and_free_regions(region)
179179
}
180180
ty::ReStatic => ("the static lifetime".to_owned(), None),
181+
ty::ReEmpty => ("an empty lifetime".to_owned(), None),
181182
_ => bug!("{:?}", region),
182183
}
183184
}

src/librustc/mir/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,20 @@ impl<'tcx> Mir<'tcx> {
304304
})
305305
}
306306

307+
/// Returns an iterator over all user-declared mutable locals.
308+
#[inline]
309+
pub fn mut_vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a {
310+
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
311+
let local = Local::new(index);
312+
let decl = &self.local_decls[local];
313+
if decl.is_user_variable.is_some() && decl.mutability == Mutability::Mut {
314+
Some(local)
315+
} else {
316+
None
317+
}
318+
})
319+
}
320+
307321
/// Returns an iterator over all user-declared mutable arguments and locals.
308322
#[inline]
309323
pub fn mut_vars_and_args_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a {

src/librustc/session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ pub fn build_session_options_and_crate_config(
20822082
error_format,
20832083
&format!(
20842084
"optimization level needs to be \
2085-
between 0-3 (instead was `{}`)",
2085+
between 0-3, s or z (instead was `{}`)",
20862086
arg
20872087
),
20882088
);

src/librustc/traits/specialize/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,10 @@ fn to_pretty_impl_header(tcx: TyCtxt<'_, '_, '_>, impl_def_id: DefId) -> Option<
396396
if !substs.is_noop() {
397397
types_without_default_bounds.extend(substs.types());
398398
w.push('<');
399-
w.push_str(&substs.iter().map(|k| k.to_string()).collect::<Vec<_>>().join(", "));
399+
w.push_str(&substs.iter()
400+
.map(|k| k.to_string())
401+
.filter(|k| &k[..] != "'_")
402+
.collect::<Vec<_>>().join(", "));
400403
w.push('>');
401404
}
402405

src/librustc/ty/query/on_disk_cache.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,7 @@ impl<'sess> OnDiskCache<'sess> {
450450
.map(|&(cnum, ..)| cnum)
451451
.max()
452452
.unwrap_or(0) + 1;
453-
let mut map = IndexVec::new();
454-
map.resize(map_size as usize, None);
453+
let mut map = IndexVec::from_elem_n(None, map_size as usize);
455454

456455
for &(prev_cnum, ref crate_name, crate_disambiguator) in prev_cnums {
457456
let key = (crate_name.clone(), crate_disambiguator);

src/librustc_codegen_llvm/abi.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,10 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
225225
// ...and then memcpy it to the intended destination.
226226
base::call_memcpy(bx,
227227
bx.pointercast(dst.llval, Type::i8p(cx)),
228+
self.layout.align,
228229
bx.pointercast(llscratch, Type::i8p(cx)),
230+
scratch_align,
229231
C_usize(cx, self.layout.size.bytes()),
230-
self.layout.align.min(scratch_align),
231232
MemFlags::empty());
232233

233234
bx.lifetime_end(llscratch, scratch_size);

src/librustc_codegen_llvm/base.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use mir::place::PlaceRef;
5353
use attributes;
5454
use builder::{Builder, MemFlags};
5555
use callee;
56-
use common::{C_bool, C_bytes_in_context, C_i32, C_usize};
56+
use common::{C_bool, C_bytes_in_context, C_usize};
5757
use rustc_mir::monomorphize::item::DefPathBasedNames;
5858
use common::{C_struct_in_context, C_array, val_ty};
5959
use consts;
@@ -77,7 +77,6 @@ use rustc_data_structures::sync::Lrc;
7777
use std::any::Any;
7878
use std::cmp;
7979
use std::ffi::CString;
80-
use std::i32;
8180
use std::ops::{Deref, DerefMut};
8281
use std::sync::mpsc;
8382
use std::time::{Instant, Duration};
@@ -319,8 +318,8 @@ pub fn coerce_unsized_into(
319318
}
320319

321320
if src_f.layout.ty == dst_f.layout.ty {
322-
memcpy_ty(bx, dst_f.llval, src_f.llval, src_f.layout,
323-
src_f.align.min(dst_f.align), MemFlags::empty());
321+
memcpy_ty(bx, dst_f.llval, dst_f.align, src_f.llval, src_f.align,
322+
src_f.layout, MemFlags::empty());
324323
} else {
325324
coerce_unsized_into(bx, src_f, dst_f);
326325
}
@@ -420,44 +419,42 @@ pub fn to_immediate_scalar(
420419
pub fn call_memcpy(
421420
bx: &Builder<'_, 'll, '_>,
422421
dst: &'ll Value,
422+
dst_align: Align,
423423
src: &'ll Value,
424+
src_align: Align,
424425
n_bytes: &'ll Value,
425-
align: Align,
426426
flags: MemFlags,
427427
) {
428428
if flags.contains(MemFlags::NONTEMPORAL) {
429429
// HACK(nox): This is inefficient but there is no nontemporal memcpy.
430-
let val = bx.load(src, align);
430+
let val = bx.load(src, src_align);
431431
let ptr = bx.pointercast(dst, val_ty(val).ptr_to());
432-
bx.store_with_flags(val, ptr, align, flags);
432+
bx.store_with_flags(val, ptr, dst_align, flags);
433433
return;
434434
}
435435
let cx = bx.cx;
436-
let ptr_width = &cx.sess().target.target.target_pointer_width;
437-
let key = format!("llvm.memcpy.p0i8.p0i8.i{}", ptr_width);
438-
let memcpy = cx.get_intrinsic(&key);
439436
let src_ptr = bx.pointercast(src, Type::i8p(cx));
440437
let dst_ptr = bx.pointercast(dst, Type::i8p(cx));
441438
let size = bx.intcast(n_bytes, cx.isize_ty, false);
442-
let align = C_i32(cx, align.abi() as i32);
443-
let volatile = C_bool(cx, flags.contains(MemFlags::VOLATILE));
444-
bx.call(memcpy, &[dst_ptr, src_ptr, size, align, volatile], None);
439+
let volatile = flags.contains(MemFlags::VOLATILE);
440+
bx.memcpy(dst_ptr, dst_align.abi(), src_ptr, src_align.abi(), size, volatile);
445441
}
446442

447443
pub fn memcpy_ty(
448444
bx: &Builder<'_, 'll, 'tcx>,
449445
dst: &'ll Value,
446+
dst_align: Align,
450447
src: &'ll Value,
448+
src_align: Align,
451449
layout: TyLayout<'tcx>,
452-
align: Align,
453450
flags: MemFlags,
454451
) {
455452
let size = layout.size.bytes();
456453
if size == 0 {
457454
return;
458455
}
459456

460-
call_memcpy(bx, dst, src, C_usize(bx.cx, size), align, flags);
457+
call_memcpy(bx, dst, dst_align, src, src_align, C_usize(bx.cx, size), flags);
461458
}
462459

463460
pub fn call_memset(

src/librustc_codegen_llvm/builder.rs

+18
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,24 @@ impl Builder<'a, 'll, 'tcx> {
781781
}
782782
}
783783

784+
pub fn memcpy(&self, dst: &'ll Value, dst_align: u64,
785+
src: &'ll Value, src_align: u64,
786+
size: &'ll Value, is_volatile: bool) -> &'ll Value {
787+
unsafe {
788+
llvm::LLVMRustBuildMemCpy(self.llbuilder, dst, dst_align as c_uint,
789+
src, src_align as c_uint, size, is_volatile)
790+
}
791+
}
792+
793+
pub fn memmove(&self, dst: &'ll Value, dst_align: u64,
794+
src: &'ll Value, src_align: u64,
795+
size: &'ll Value, is_volatile: bool) -> &'ll Value {
796+
unsafe {
797+
llvm::LLVMRustBuildMemMove(self.llbuilder, dst, dst_align as c_uint,
798+
src, src_align as c_uint, size, is_volatile)
799+
}
800+
}
801+
784802
pub fn minnum(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
785803
self.count_insn("minnum");
786804
unsafe {

src/librustc_codegen_llvm/context.rs

-6
Original file line numberDiff line numberDiff line change
@@ -530,12 +530,6 @@ fn declare_intrinsic(cx: &CodegenCx<'ll, '_>, key: &str) -> Option<&'ll Value> {
530530
let t_v4f64 = Type::vector(t_f64, 4);
531531
let t_v8f64 = Type::vector(t_f64, 8);
532532

533-
ifn!("llvm.memcpy.p0i8.p0i8.i16", fn(i8p, i8p, t_i16, t_i32, i1) -> void);
534-
ifn!("llvm.memcpy.p0i8.p0i8.i32", fn(i8p, i8p, t_i32, t_i32, i1) -> void);
535-
ifn!("llvm.memcpy.p0i8.p0i8.i64", fn(i8p, i8p, t_i64, t_i32, i1) -> void);
536-
ifn!("llvm.memmove.p0i8.p0i8.i16", fn(i8p, i8p, t_i16, t_i32, i1) -> void);
537-
ifn!("llvm.memmove.p0i8.p0i8.i32", fn(i8p, i8p, t_i32, t_i32, i1) -> void);
538-
ifn!("llvm.memmove.p0i8.p0i8.i64", fn(i8p, i8p, t_i64, t_i32, i1) -> void);
539533
ifn!("llvm.memset.p0i8.i16", fn(i8p, t_i8, t_i16, t_i32, i1) -> void);
540534
ifn!("llvm.memset.p0i8.i32", fn(i8p, t_i8, t_i32, t_i32, i1) -> void);
541535
ifn!("llvm.memset.p0i8.i64", fn(i8p, t_i8, t_i64, t_i32, i1) -> void);

src/librustc_codegen_llvm/intrinsic.rs

+7-21
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use glue;
2323
use type_::Type;
2424
use type_of::LayoutLlvmExt;
2525
use rustc::ty::{self, Ty};
26-
use rustc::ty::layout::{HasDataLayout, LayoutOf};
26+
use rustc::ty::layout::LayoutOf;
2727
use rustc::hir;
2828
use syntax::ast;
2929
use syntax::symbol::Symbol;
@@ -690,28 +690,14 @@ fn copy_intrinsic(
690690
let cx = bx.cx;
691691
let (size, align) = cx.size_and_align_of(ty);
692692
let size = C_usize(cx, size.bytes());
693-
let align = C_i32(cx, align.abi() as i32);
694-
695-
let operation = if allow_overlap {
696-
"memmove"
697-
} else {
698-
"memcpy"
699-
};
700-
701-
let name = format!("llvm.{}.p0i8.p0i8.i{}", operation,
702-
cx.data_layout().pointer_size.bits());
703-
693+
let align = align.abi();
704694
let dst_ptr = bx.pointercast(dst, Type::i8p(cx));
705695
let src_ptr = bx.pointercast(src, Type::i8p(cx));
706-
let llfn = cx.get_intrinsic(&name);
707-
708-
bx.call(llfn,
709-
&[dst_ptr,
710-
src_ptr,
711-
bx.mul(size, count),
712-
align,
713-
C_bool(cx, volatile)],
714-
None)
696+
if allow_overlap {
697+
bx.memmove(dst_ptr, align, src_ptr, align, bx.mul(size, count), volatile)
698+
} else {
699+
bx.memcpy(dst_ptr, align, src_ptr, align, bx.mul(size, count), volatile)
700+
}
715701
}
716702

717703
fn memset_intrinsic(

src/librustc_codegen_llvm/llvm/ffi.rs

+16
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,22 @@ extern "C" {
998998
Bundle: Option<&OperandBundleDef<'a>>,
999999
Name: *const c_char)
10001000
-> &'a Value;
1001+
pub fn LLVMRustBuildMemCpy(B: &Builder<'a>,
1002+
Dst: &'a Value,
1003+
DstAlign: c_uint,
1004+
Src: &'a Value,
1005+
SrcAlign: c_uint,
1006+
Size: &'a Value,
1007+
IsVolatile: bool)
1008+
-> &'a Value;
1009+
pub fn LLVMRustBuildMemMove(B: &Builder<'a>,
1010+
Dst: &'a Value,
1011+
DstAlign: c_uint,
1012+
Src: &'a Value,
1013+
SrcAlign: c_uint,
1014+
Size: &'a Value,
1015+
IsVolatile: bool)
1016+
-> &'a Value;
10011017
pub fn LLVMBuildSelect(B: &Builder<'a>,
10021018
If: &'a Value,
10031019
Then: &'a Value,

src/librustc_codegen_llvm/mir/block.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,8 @@ impl FunctionCx<'a, 'll, 'tcx> {
784784
// have scary latent bugs around.
785785

786786
let scratch = PlaceRef::alloca(bx, arg.layout, "arg");
787-
base::memcpy_ty(bx, scratch.llval, llval, op.layout, align, MemFlags::empty());
787+
base::memcpy_ty(bx, scratch.llval, scratch.align, llval, align,
788+
op.layout, MemFlags::empty());
788789
(scratch.llval, scratch.align, true)
789790
} else {
790791
(llval, align, true)

src/librustc_codegen_llvm/mir/operand.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ impl OperandValue<'ll> {
282282
}
283283
match self {
284284
OperandValue::Ref(r, None, source_align) => {
285-
base::memcpy_ty(bx, dest.llval, r, dest.layout,
286-
source_align.min(dest.align), flags)
285+
base::memcpy_ty(bx, dest.llval, dest.align, r, source_align,
286+
dest.layout, flags)
287287
}
288288
OperandValue::Ref(_, Some(_), _) => {
289289
bug!("cannot directly store unsized values");
@@ -324,7 +324,7 @@ impl OperandValue<'ll> {
324324
// Allocate an appropriate region on the stack, and copy the value into it
325325
let (llsize, _) = glue::size_and_align_of_dst(&bx, unsized_ty, Some(llextra));
326326
let lldst = bx.array_alloca(Type::i8(bx.cx), llsize, "unsized_tmp", max_align);
327-
base::call_memcpy(&bx, lldst, llptr, llsize, min_align, flags);
327+
base::call_memcpy(&bx, lldst, max_align, llptr, min_align, llsize, flags);
328328

329329
// Store the allocated region and the extra to the indirect place.
330330
let indirect_operand = OperandValue::Pair(lldst, llextra);

src/librustc_errors/emitter.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,13 @@ pub enum ColorConfig {
108108
impl ColorConfig {
109109
fn to_color_choice(&self) -> ColorChoice {
110110
match *self {
111-
ColorConfig::Always => ColorChoice::Always,
111+
ColorConfig::Always => {
112+
if atty::is(atty::Stream::Stderr) {
113+
ColorChoice::Always
114+
} else {
115+
ColorChoice::AlwaysAnsi
116+
}
117+
}
112118
ColorConfig::Never => ColorChoice::Never,
113119
ColorConfig::Auto if atty::is(atty::Stream::Stderr) => {
114120
ColorChoice::Auto

src/librustc_mir/borrow_check/borrow_set.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use rustc::util::nodemap::{FxHashMap, FxHashSet};
2121
use rustc_data_structures::indexed_vec::IndexVec;
2222
use rustc_data_structures::bit_set::BitSet;
2323
use std::fmt;
24-
use std::hash::Hash;
2524
use std::ops::Index;
2625

2726
crate struct BorrowSet<'tcx> {
@@ -233,21 +232,13 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
233232

234233
self.insert_as_pending_if_two_phase(location, &assigned_place, region, kind, idx);
235234

236-
insert(&mut self.region_map, &region, idx);
235+
self.region_map.entry(region).or_default().insert(idx);
237236
if let Some(local) = borrowed_place.root_local() {
238-
insert(&mut self.local_map, &local, idx);
237+
self.local_map.entry(local).or_default().insert(idx);
239238
}
240239
}
241240

242-
return self.super_assign(block, assigned_place, rvalue, location);
243-
244-
fn insert<'a, K, V>(map: &'a mut FxHashMap<K, FxHashSet<V>>, k: &K, v: V)
245-
where
246-
K: Clone + Eq + Hash,
247-
V: Eq + Hash,
248-
{
249-
map.entry(k.clone()).or_default().insert(v);
250-
}
241+
self.super_assign(block, assigned_place, rvalue, location)
251242
}
252243

253244
fn visit_place(

src/librustc_mir/borrow_check/mod.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -281,23 +281,21 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
281281
// Note that this set is expected to be small - only upvars from closures
282282
// would have a chance of erroneously adding non-user-defined mutable vars
283283
// to the set.
284-
let temporary_used_locals: FxHashSet<Local> = mbcx
285-
.used_mut
286-
.iter()
284+
let temporary_used_locals: FxHashSet<Local> = mbcx.used_mut.iter()
287285
.filter(|&local| mbcx.mir.local_decls[*local].is_user_variable.is_none())
288286
.cloned()
289287
.collect();
290-
mbcx.gather_used_muts(temporary_used_locals);
288+
// For the remaining unused locals that are marked as mutable, we avoid linting any that
289+
// were never initialized. These locals may have been removed as unreachable code; or will be
290+
// linted as unused variables.
291+
let unused_mut_locals = mbcx.mir.mut_vars_iter()
292+
.filter(|local| !mbcx.used_mut.contains(local))
293+
.collect();
294+
mbcx.gather_used_muts(temporary_used_locals, unused_mut_locals);
291295

292296
debug!("mbcx.used_mut: {:?}", mbcx.used_mut);
293-
294297
let used_mut = mbcx.used_mut;
295-
296-
for local in mbcx
297-
.mir
298-
.mut_vars_and_args_iter()
299-
.filter(|local| !used_mut.contains(local))
300-
{
298+
for local in mbcx.mir.mut_vars_and_args_iter().filter(|local| !used_mut.contains(local)) {
301299
if let ClearCrossCrate::Set(ref vsi) = mbcx.mir.source_scope_local_data {
302300
let local_decl = &mbcx.mir.local_decls[local];
303301

0 commit comments

Comments
 (0)