Skip to content

Commit c6bd7e2

Browse files
committed
Auto merge of rust-lang#103513 - Dylan-DPC:rollup-nn3ite2, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#98204 (Stabilize `Option::unzip()`) - rust-lang#102587 (rustc: Use `unix_sigpipe` instead of `rustc_driver::set_sigpipe_handler`) - rust-lang#103122 (Remove misc_cast and validate types when casting) - rust-lang#103379 (Truncate thread names on Linux and Apple targets) - rust-lang#103482 (Clairify Vec::capacity docs) - rust-lang#103511 (Codegen tweaks) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 31d754a + 6aea54c commit c6bd7e2

File tree

13 files changed

+203
-118
lines changed

13 files changed

+203
-118
lines changed

compiler/rustc/src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![feature(unix_sigpipe)]
2+
13
// A note about jemalloc: rustc uses jemalloc when built for CI and
24
// distribution. The obvious way to do this is with the `#[global_allocator]`
35
// mechanism. However, for complicated reasons (see
@@ -23,6 +25,7 @@
2325
// libraries. So we must reference jemalloc symbols one way or another, because
2426
// this file is the only object code in the rustc executable.
2527

28+
#[unix_sigpipe = "sig_dfl"]
2629
fn main() {
2730
// See the comment at the top of this file for an explanation of this.
2831
#[cfg(feature = "jemalloc-sys")]
@@ -58,6 +61,5 @@ fn main() {
5861
}
5962
}
6063

61-
rustc_driver::set_sigpipe_handler();
6264
rustc_driver::main()
6365
}

compiler/rustc_codegen_ssa/src/base.rs

+16-30
Original file line numberDiff line numberDiff line change
@@ -337,40 +337,26 @@ pub fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
337337

338338
pub fn cast_shift_expr_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
339339
bx: &mut Bx,
340-
op: hir::BinOpKind,
341-
lhs: Bx::Value,
342-
rhs: Bx::Value,
343-
) -> Bx::Value {
344-
cast_shift_rhs(bx, op, lhs, rhs)
345-
}
346-
347-
fn cast_shift_rhs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
348-
bx: &mut Bx,
349-
op: hir::BinOpKind,
350340
lhs: Bx::Value,
351341
rhs: Bx::Value,
352342
) -> Bx::Value {
353343
// Shifts may have any size int on the rhs
354-
if op.is_shift() {
355-
let mut rhs_llty = bx.cx().val_ty(rhs);
356-
let mut lhs_llty = bx.cx().val_ty(lhs);
357-
if bx.cx().type_kind(rhs_llty) == TypeKind::Vector {
358-
rhs_llty = bx.cx().element_type(rhs_llty)
359-
}
360-
if bx.cx().type_kind(lhs_llty) == TypeKind::Vector {
361-
lhs_llty = bx.cx().element_type(lhs_llty)
362-
}
363-
let rhs_sz = bx.cx().int_width(rhs_llty);
364-
let lhs_sz = bx.cx().int_width(lhs_llty);
365-
if lhs_sz < rhs_sz {
366-
bx.trunc(rhs, lhs_llty)
367-
} else if lhs_sz > rhs_sz {
368-
// FIXME (#1877: If in the future shifting by negative
369-
// values is no longer undefined then this is wrong.
370-
bx.zext(rhs, lhs_llty)
371-
} else {
372-
rhs
373-
}
344+
let mut rhs_llty = bx.cx().val_ty(rhs);
345+
let mut lhs_llty = bx.cx().val_ty(lhs);
346+
if bx.cx().type_kind(rhs_llty) == TypeKind::Vector {
347+
rhs_llty = bx.cx().element_type(rhs_llty)
348+
}
349+
if bx.cx().type_kind(lhs_llty) == TypeKind::Vector {
350+
lhs_llty = bx.cx().element_type(lhs_llty)
351+
}
352+
let rhs_sz = bx.cx().int_width(rhs_llty);
353+
let lhs_sz = bx.cx().int_width(lhs_llty);
354+
if lhs_sz < rhs_sz {
355+
bx.trunc(rhs, lhs_llty)
356+
} else if lhs_sz > rhs_sz {
357+
// FIXME (#1877: If in the future shifting by negative
358+
// values is no longer undefined then this is wrong.
359+
bx.zext(rhs, lhs_llty)
374360
} else {
375361
rhs
376362
}

compiler/rustc_codegen_ssa/src/common.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![allow(non_camel_case_types)]
22

33
use rustc_errors::struct_span_err;
4-
use rustc_hir as hir;
54
use rustc_hir::LangItem;
65
use rustc_middle::mir::interpret::ConstValue;
76
use rustc_middle::ty::{self, layout::TyAndLayout, Ty, TyCtxt};
@@ -140,7 +139,7 @@ pub fn build_unchecked_lshift<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
140139
lhs: Bx::Value,
141140
rhs: Bx::Value,
142141
) -> Bx::Value {
143-
let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shl, lhs, rhs);
142+
let rhs = base::cast_shift_expr_rhs(bx, lhs, rhs);
144143
// #1877, #10183: Ensure that input is always valid
145144
let rhs = shift_mask_rhs(bx, rhs);
146145
bx.shl(lhs, rhs)
@@ -152,7 +151,7 @@ pub fn build_unchecked_rshift<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
152151
lhs: Bx::Value,
153152
rhs: Bx::Value,
154153
) -> Bx::Value {
155-
let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shr, lhs, rhs);
154+
let rhs = base::cast_shift_expr_rhs(bx, lhs, rhs);
156155
// #1877, #10183: Ensure that input is always valid
157156
let rhs = shift_mask_rhs(bx, rhs);
158157
let is_signed = lhs_t.is_signed();

compiler/rustc_codegen_ssa/src/mir/block.rs

+47-39
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
6363
}
6464
}
6565

66-
fn lltarget<Bx: BuilderMethods<'a, 'tcx>>(
66+
/// Get a basic block (creating it if necessary), possibly with a landing
67+
/// pad next to it.
68+
fn llbb_with_landing_pad<Bx: BuilderMethods<'a, 'tcx>>(
6769
&self,
6870
fx: &mut FunctionCx<'a, 'tcx, Bx>,
6971
target: mir::BasicBlock,
@@ -73,32 +75,36 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
7375
let target_funclet = fx.cleanup_kinds[target].funclet_bb(target);
7476
match (self.funclet_bb, target_funclet) {
7577
(None, None) => (lltarget, false),
76-
(Some(f), Some(t_f)) if f == t_f || !base::wants_msvc_seh(fx.cx.tcx().sess) => {
77-
(lltarget, false)
78-
}
7978
// jump *into* cleanup - need a landing pad if GNU, cleanup pad if MSVC
8079
(None, Some(_)) => (fx.landing_pad_for(target), false),
8180
(Some(_), None) => span_bug!(span, "{:?} - jump out of cleanup?", self.terminator),
82-
(Some(_), Some(_)) => (fx.landing_pad_for(target), true),
81+
(Some(f), Some(t_f)) => {
82+
if f == t_f || !base::wants_msvc_seh(fx.cx.tcx().sess) {
83+
(lltarget, false)
84+
} else {
85+
(fx.landing_pad_for(target), true)
86+
}
87+
}
8388
}
8489
}
8590

86-
/// Create a basic block.
87-
fn llblock<Bx: BuilderMethods<'a, 'tcx>>(
91+
/// Get a basic block (creating it if necessary), possibly with cleanup
92+
/// stuff in it or next to it.
93+
fn llbb_with_cleanup<Bx: BuilderMethods<'a, 'tcx>>(
8894
&self,
8995
fx: &mut FunctionCx<'a, 'tcx, Bx>,
9096
target: mir::BasicBlock,
9197
) -> Bx::BasicBlock {
92-
let (lltarget, is_cleanupret) = self.lltarget(fx, target);
98+
let (lltarget, is_cleanupret) = self.llbb_with_landing_pad(fx, target);
9399
if is_cleanupret {
94100
// MSVC cross-funclet jump - need a trampoline
95-
96-
debug!("llblock: creating cleanup trampoline for {:?}", target);
101+
debug_assert!(base::wants_msvc_seh(fx.cx.tcx().sess));
102+
debug!("llbb_with_cleanup: creating cleanup trampoline for {:?}", target);
97103
let name = &format!("{:?}_cleanup_trampoline_{:?}", self.bb, target);
98-
let trampoline = Bx::append_block(fx.cx, fx.llfn, name);
99-
let mut trampoline_bx = Bx::build(fx.cx, trampoline);
104+
let trampoline_llbb = Bx::append_block(fx.cx, fx.llfn, name);
105+
let mut trampoline_bx = Bx::build(fx.cx, trampoline_llbb);
100106
trampoline_bx.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget));
101-
trampoline
107+
trampoline_llbb
102108
} else {
103109
lltarget
104110
}
@@ -110,10 +116,11 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
110116
bx: &mut Bx,
111117
target: mir::BasicBlock,
112118
) {
113-
let (lltarget, is_cleanupret) = self.lltarget(fx, target);
119+
let (lltarget, is_cleanupret) = self.llbb_with_landing_pad(fx, target);
114120
if is_cleanupret {
115-
// micro-optimization: generate a `ret` rather than a jump
121+
// MSVC micro-optimization: generate a `ret` rather than a jump
116122
// to a trampoline.
123+
debug_assert!(base::wants_msvc_seh(fx.cx.tcx().sess));
117124
bx.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget));
118125
} else {
119126
bx.br(lltarget);
@@ -138,7 +145,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
138145
let fn_ty = bx.fn_decl_backend_type(&fn_abi);
139146

140147
let unwind_block = if let Some(cleanup) = cleanup.filter(|_| fn_abi.can_unwind) {
141-
Some(self.llblock(fx, cleanup))
148+
Some(self.llbb_with_cleanup(fx, cleanup))
142149
} else if fx.mir[self.bb].is_cleanup
143150
&& fn_abi.can_unwind
144151
&& !base::wants_msvc_seh(fx.cx.tcx().sess)
@@ -231,7 +238,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
231238
options,
232239
line_spans,
233240
instance,
234-
Some((ret_llbb, self.llblock(fx, cleanup), self.funclet(fx))),
241+
Some((ret_llbb, self.llbb_with_cleanup(fx, cleanup), self.funclet(fx))),
235242
);
236243
} else {
237244
bx.codegen_inline_asm(template, &operands, options, line_spans, instance, None);
@@ -281,8 +288,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
281288
if target_iter.len() == 1 {
282289
// If there are two targets (one conditional, one fallback), emit br instead of switch
283290
let (test_value, target) = target_iter.next().unwrap();
284-
let lltrue = helper.llblock(self, target);
285-
let llfalse = helper.llblock(self, targets.otherwise());
291+
let lltrue = helper.llbb_with_cleanup(self, target);
292+
let llfalse = helper.llbb_with_cleanup(self, targets.otherwise());
286293
if switch_ty == bx.tcx().types.bool {
287294
// Don't generate trivial icmps when switching on bool
288295
match test_value {
@@ -299,8 +306,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
299306
} else {
300307
bx.switch(
301308
discr.immediate(),
302-
helper.llblock(self, targets.otherwise()),
303-
target_iter.map(|(value, target)| (value, helper.llblock(self, target))),
309+
helper.llbb_with_cleanup(self, targets.otherwise()),
310+
target_iter.map(|(value, target)| (value, helper.llbb_with_cleanup(self, target))),
304311
);
305312
}
306313
}
@@ -530,7 +537,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
530537
let cond = bx.expect(cond, expected);
531538

532539
// Create the failure block and the conditional branch to it.
533-
let lltarget = helper.llblock(self, target);
540+
let lltarget = helper.llbb_with_cleanup(self, target);
534541
let panic_block = bx.append_sibling_block("panic");
535542
if expected {
536543
bx.cond_br(cond, lltarget, panic_block);
@@ -1459,20 +1466,20 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
14591466
// bar();
14601467
// }
14611468
Some(&mir::TerminatorKind::Abort) => {
1462-
let cs_bb =
1469+
let cs_llbb =
14631470
Bx::append_block(self.cx, self.llfn, &format!("cs_funclet{:?}", bb));
1464-
let cp_bb =
1471+
let cp_llbb =
14651472
Bx::append_block(self.cx, self.llfn, &format!("cp_funclet{:?}", bb));
1466-
ret_llbb = cs_bb;
1473+
ret_llbb = cs_llbb;
14671474

1468-
let mut cs_bx = Bx::build(self.cx, cs_bb);
1469-
let cs = cs_bx.catch_switch(None, None, &[cp_bb]);
1475+
let mut cs_bx = Bx::build(self.cx, cs_llbb);
1476+
let cs = cs_bx.catch_switch(None, None, &[cp_llbb]);
14701477

14711478
// The "null" here is actually a RTTI type descriptor for the
14721479
// C++ personality function, but `catch (...)` has no type so
14731480
// it's null. The 64 here is actually a bitfield which
14741481
// represents that this is a catch-all block.
1475-
let mut cp_bx = Bx::build(self.cx, cp_bb);
1482+
let mut cp_bx = Bx::build(self.cx, cp_llbb);
14761483
let null = cp_bx.const_null(
14771484
cp_bx.type_i8p_ext(cp_bx.cx().data_layout().instruction_address_space),
14781485
);
@@ -1481,30 +1488,31 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
14811488
cp_bx.br(llbb);
14821489
}
14831490
_ => {
1484-
let cleanup_bb =
1491+
let cleanup_llbb =
14851492
Bx::append_block(self.cx, self.llfn, &format!("funclet_{:?}", bb));
1486-
ret_llbb = cleanup_bb;
1487-
let mut cleanup_bx = Bx::build(self.cx, cleanup_bb);
1493+
ret_llbb = cleanup_llbb;
1494+
let mut cleanup_bx = Bx::build(self.cx, cleanup_llbb);
14881495
funclet = cleanup_bx.cleanup_pad(None, &[]);
14891496
cleanup_bx.br(llbb);
14901497
}
14911498
}
14921499
self.funclets[bb] = Some(funclet);
14931500
ret_llbb
14941501
} else {
1495-
let bb = Bx::append_block(self.cx, self.llfn, "cleanup");
1496-
let mut bx = Bx::build(self.cx, bb);
1502+
let cleanup_llbb = Bx::append_block(self.cx, self.llfn, "cleanup");
1503+
let mut cleanup_bx = Bx::build(self.cx, cleanup_llbb);
14971504

14981505
let llpersonality = self.cx.eh_personality();
14991506
let llretty = self.landing_pad_type();
1500-
let lp = bx.cleanup_landing_pad(llretty, llpersonality);
1507+
let lp = cleanup_bx.cleanup_landing_pad(llretty, llpersonality);
15011508

1502-
let slot = self.get_personality_slot(&mut bx);
1503-
slot.storage_live(&mut bx);
1504-
Pair(bx.extract_value(lp, 0), bx.extract_value(lp, 1)).store(&mut bx, slot);
1509+
let slot = self.get_personality_slot(&mut cleanup_bx);
1510+
slot.storage_live(&mut cleanup_bx);
1511+
Pair(cleanup_bx.extract_value(lp, 0), cleanup_bx.extract_value(lp, 1))
1512+
.store(&mut cleanup_bx, slot);
15051513

1506-
bx.br(llbb);
1507-
bx.llbb()
1514+
cleanup_bx.br(llbb);
1515+
cleanup_llbb
15081516
}
15091517
}
15101518

compiler/rustc_codegen_ssa/src/mir/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
148148
let debug_context = cx.create_function_debug_context(instance, &fn_abi, llfn, &mir);
149149

150150
let start_llbb = Bx::append_block(cx, llfn, "start");
151-
let mut bx = Bx::build(cx, start_llbb);
151+
let mut start_bx = Bx::build(cx, start_llbb);
152152

153153
if mir.basic_blocks.iter().any(|bb| bb.is_cleanup) {
154-
bx.set_personality_fn(cx.eh_personality());
154+
start_bx.set_personality_fn(cx.eh_personality());
155155
}
156156

157157
let cleanup_kinds = analyze::cleanup_kinds(&mir);
@@ -180,7 +180,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
180180
caller_location: None,
181181
};
182182

183-
fx.per_local_var_debug_info = fx.compute_per_local_var_debug_info(&mut bx);
183+
fx.per_local_var_debug_info = fx.compute_per_local_var_debug_info(&mut start_bx);
184184

185185
// Evaluate all required consts; codegen later assumes that CTFE will never fail.
186186
let mut all_consts_ok = true;
@@ -206,29 +206,29 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
206206

207207
// Allocate variable and temp allocas
208208
fx.locals = {
209-
let args = arg_local_refs(&mut bx, &mut fx, &memory_locals);
209+
let args = arg_local_refs(&mut start_bx, &mut fx, &memory_locals);
210210

211211
let mut allocate_local = |local| {
212212
let decl = &mir.local_decls[local];
213-
let layout = bx.layout_of(fx.monomorphize(decl.ty));
213+
let layout = start_bx.layout_of(fx.monomorphize(decl.ty));
214214
assert!(!layout.ty.has_erasable_regions());
215215

216216
if local == mir::RETURN_PLACE && fx.fn_abi.ret.is_indirect() {
217217
debug!("alloc: {:?} (return place) -> place", local);
218-
let llretptr = bx.get_param(0);
218+
let llretptr = start_bx.get_param(0);
219219
return LocalRef::Place(PlaceRef::new_sized(llretptr, layout));
220220
}
221221

222222
if memory_locals.contains(local) {
223223
debug!("alloc: {:?} -> place", local);
224224
if layout.is_unsized() {
225-
LocalRef::UnsizedPlace(PlaceRef::alloca_unsized_indirect(&mut bx, layout))
225+
LocalRef::UnsizedPlace(PlaceRef::alloca_unsized_indirect(&mut start_bx, layout))
226226
} else {
227-
LocalRef::Place(PlaceRef::alloca(&mut bx, layout))
227+
LocalRef::Place(PlaceRef::alloca(&mut start_bx, layout))
228228
}
229229
} else {
230230
debug!("alloc: {:?} -> operand", local);
231-
LocalRef::new_operand(&mut bx, layout)
231+
LocalRef::new_operand(&mut start_bx, layout)
232232
}
233233
};
234234

@@ -240,7 +240,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
240240
};
241241

242242
// Apply debuginfo to the newly allocated locals.
243-
fx.debug_introduce_locals(&mut bx);
243+
fx.debug_introduce_locals(&mut start_bx);
244244

245245
// Codegen the body of each block using reverse postorder
246246
for (bb, _) in traversal::reverse_postorder(&mir) {

0 commit comments

Comments
 (0)