Skip to content

Commit 6d9549f

Browse files
committed
Auto merge of #3383 - RalfJung:rustup, r=RalfJung
Rustup
2 parents ed9d70f + 32c734b commit 6d9549f

File tree

227 files changed

+5598
-1559
lines changed

Some content is hidden

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

227 files changed

+5598
-1559
lines changed

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub(super) fn index_hir<'hir>(
5555
OwnerNode::TraitItem(item) => collector.visit_trait_item(item),
5656
OwnerNode::ImplItem(item) => collector.visit_impl_item(item),
5757
OwnerNode::ForeignItem(item) => collector.visit_foreign_item(item),
58+
OwnerNode::AssocOpaqueTy(..) => unreachable!(),
5859
};
5960

6061
for (local_id, node) in collector.nodes.iter_enumerated() {

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -642,23 +642,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
642642
let bodies = SortedMap::from_presorted_elements(bodies);
643643

644644
// Don't hash unless necessary, because it's expensive.
645-
let (opt_hash_including_bodies, attrs_hash) = if self.tcx.needs_crate_hash() {
646-
self.tcx.with_stable_hashing_context(|mut hcx| {
647-
let mut stable_hasher = StableHasher::new();
648-
node.hash_stable(&mut hcx, &mut stable_hasher);
649-
// Bodies are stored out of line, so we need to pull them explicitly in the hash.
650-
bodies.hash_stable(&mut hcx, &mut stable_hasher);
651-
let h1 = stable_hasher.finish();
652-
653-
let mut stable_hasher = StableHasher::new();
654-
attrs.hash_stable(&mut hcx, &mut stable_hasher);
655-
let h2 = stable_hasher.finish();
656-
657-
(Some(h1), Some(h2))
658-
})
659-
} else {
660-
(None, None)
661-
};
645+
let (opt_hash_including_bodies, attrs_hash) =
646+
self.tcx.hash_owner_nodes(node, &bodies, &attrs);
662647
let num_nodes = self.item_local_id_counter.as_usize();
663648
let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes);
664649
let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies };

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
7171
// This cannot fail because we checked all required_consts in advance.
7272
let val = cv
7373
.eval(fx.tcx, ty::ParamEnv::reveal_all(), Some(constant.span))
74-
.expect("erroneous constant not captured by required_consts");
74+
.expect("erroneous constant missed by mono item collection");
7575
(val, cv.ty())
7676
}
7777

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -203,57 +203,63 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
203203
val: &'ll Value,
204204
dst: PlaceRef<'tcx, &'ll Value>,
205205
) {
206-
if self.is_ignore() {
207-
return;
208-
}
209-
if self.is_sized_indirect() {
210-
OperandValue::Ref(val, None, self.layout.align.abi).store(bx, dst)
211-
} else if self.is_unsized_indirect() {
212-
bug!("unsized `ArgAbi` must be handled through `store_fn_arg`");
213-
} else if let PassMode::Cast { cast, pad_i32: _ } = &self.mode {
214-
// FIXME(eddyb): Figure out when the simpler Store is safe, clang
215-
// uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
216-
let can_store_through_cast_ptr = false;
217-
if can_store_through_cast_ptr {
218-
bx.store(val, dst.llval, self.layout.align.abi);
219-
} else {
220-
// The actual return type is a struct, but the ABI
221-
// adaptation code has cast it into some scalar type. The
222-
// code that follows is the only reliable way I have
223-
// found to do a transform like i64 -> {i32,i32}.
224-
// Basically we dump the data onto the stack then memcpy it.
225-
//
226-
// Other approaches I tried:
227-
// - Casting rust ret pointer to the foreign type and using Store
228-
// is (a) unsafe if size of foreign type > size of rust type and
229-
// (b) runs afoul of strict aliasing rules, yielding invalid
230-
// assembly under -O (specifically, the store gets removed).
231-
// - Truncating foreign type to correct integral type and then
232-
// bitcasting to the struct type yields invalid cast errors.
233-
234-
// We instead thus allocate some scratch space...
235-
let scratch_size = cast.size(bx);
236-
let scratch_align = cast.align(bx);
237-
let llscratch = bx.alloca(cast.llvm_type(bx), scratch_align);
238-
bx.lifetime_start(llscratch, scratch_size);
239-
240-
// ... where we first store the value...
241-
bx.store(val, llscratch, scratch_align);
242-
243-
// ... and then memcpy it to the intended destination.
244-
bx.memcpy(
245-
dst.llval,
246-
self.layout.align.abi,
247-
llscratch,
248-
scratch_align,
249-
bx.const_usize(self.layout.size.bytes()),
250-
MemFlags::empty(),
251-
);
206+
match &self.mode {
207+
PassMode::Ignore => {}
208+
// Sized indirect arguments
209+
PassMode::Indirect { attrs, meta_attrs: None, on_stack: _ } => {
210+
let align = attrs.pointee_align.unwrap_or(self.layout.align.abi);
211+
OperandValue::Ref(val, None, align).store(bx, dst);
212+
}
213+
// Unsized indirect qrguments
214+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
215+
bug!("unsized `ArgAbi` must be handled through `store_fn_arg`");
216+
}
217+
PassMode::Cast { cast, pad_i32: _ } => {
218+
// FIXME(eddyb): Figure out when the simpler Store is safe, clang
219+
// uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
220+
let can_store_through_cast_ptr = false;
221+
if can_store_through_cast_ptr {
222+
bx.store(val, dst.llval, self.layout.align.abi);
223+
} else {
224+
// The actual return type is a struct, but the ABI
225+
// adaptation code has cast it into some scalar type. The
226+
// code that follows is the only reliable way I have
227+
// found to do a transform like i64 -> {i32,i32}.
228+
// Basically we dump the data onto the stack then memcpy it.
229+
//
230+
// Other approaches I tried:
231+
// - Casting rust ret pointer to the foreign type and using Store
232+
// is (a) unsafe if size of foreign type > size of rust type and
233+
// (b) runs afoul of strict aliasing rules, yielding invalid
234+
// assembly under -O (specifically, the store gets removed).
235+
// - Truncating foreign type to correct integral type and then
236+
// bitcasting to the struct type yields invalid cast errors.
237+
238+
// We instead thus allocate some scratch space...
239+
let scratch_size = cast.size(bx);
240+
let scratch_align = cast.align(bx);
241+
let llscratch = bx.alloca(cast.llvm_type(bx), scratch_align);
242+
bx.lifetime_start(llscratch, scratch_size);
243+
244+
// ... where we first store the value...
245+
bx.store(val, llscratch, scratch_align);
246+
247+
// ... and then memcpy it to the intended destination.
248+
bx.memcpy(
249+
dst.llval,
250+
self.layout.align.abi,
251+
llscratch,
252+
scratch_align,
253+
bx.const_usize(self.layout.size.bytes()),
254+
MemFlags::empty(),
255+
);
252256

253-
bx.lifetime_end(llscratch, scratch_size);
257+
bx.lifetime_end(llscratch, scratch_size);
258+
}
259+
}
260+
_ => {
261+
OperandRef::from_immediate_or_packed_pair(bx, val, self.layout).val.store(bx, dst);
254262
}
255-
} else {
256-
OperandRef::from_immediate_or_packed_pair(bx, val, self.layout).val.store(bx, dst);
257263
}
258264
}
259265

compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ impl CounterMappingRegion {
164164
end_line,
165165
end_col,
166166
),
167+
MappingKind::Branch { true_term, false_term } => Self::branch_region(
168+
Counter::from_term(true_term),
169+
Counter::from_term(false_term),
170+
local_file_id,
171+
start_line,
172+
start_col,
173+
end_line,
174+
end_col,
175+
),
167176
}
168177
}
169178

@@ -188,9 +197,6 @@ impl CounterMappingRegion {
188197
}
189198
}
190199

191-
// This function might be used in the future; the LLVM API is still evolving, as is coverage
192-
// support.
193-
#[allow(dead_code)]
194200
pub(crate) fn branch_region(
195201
counter: Counter,
196202
false_counter: Counter,

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
8888
match coverage.kind {
8989
// Marker statements have no effect during codegen,
9090
// so return early and don't create `func_coverage`.
91-
CoverageKind::SpanMarker => return,
91+
CoverageKind::SpanMarker | CoverageKind::BlockMarker { .. } => return,
9292
// Match exhaustively to ensure that newly-added kinds are classified correctly.
9393
CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. } => {}
9494
}
@@ -108,7 +108,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
108108

109109
let Coverage { kind } = coverage;
110110
match *kind {
111-
CoverageKind::SpanMarker => unreachable!(
111+
CoverageKind::SpanMarker | CoverageKind::BlockMarker { .. } => unreachable!(
112112
"unexpected marker statement {kind:?} should have caused an early return"
113113
),
114114
CoverageKind::CounterIncrement { id } => {

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,21 @@ fn link_natively<'a>(
10811081
}
10821082
}
10831083

1084+
if sess.target.is_like_aix {
1085+
let stripcmd = "/usr/bin/strip";
1086+
match strip {
1087+
Strip::Debuginfo => {
1088+
// FIXME: AIX's strip utility only offers option to strip line number information.
1089+
strip_symbols_with_external_utility(sess, stripcmd, out_filename, Some("-l"))
1090+
}
1091+
Strip::Symbols => {
1092+
// Must be noted this option might remove symbol __aix_rust_metadata and thus removes .info section which contains metadata.
1093+
strip_symbols_with_external_utility(sess, stripcmd, out_filename, Some("-r"))
1094+
}
1095+
Strip::None => {}
1096+
}
1097+
}
1098+
10841099
Ok(())
10851100
}
10861101

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,16 +1640,7 @@ impl<'a> Linker for AixLinker<'a> {
16401640

16411641
fn ehcont_guard(&mut self) {}
16421642

1643-
fn debuginfo(&mut self, strip: Strip, _: &[PathBuf]) {
1644-
match strip {
1645-
Strip::None => {}
1646-
// FIXME: -s strips the symbol table, line number information
1647-
// and relocation information.
1648-
Strip::Debuginfo | Strip::Symbols => {
1649-
self.cmd.arg("-s");
1650-
}
1651-
}
1652-
}
1643+
fn debuginfo(&mut self, _: Strip, _: &[PathBuf]) {}
16531644

16541645
fn no_crt_objects(&mut self) {}
16551646

compiler/rustc_codegen_ssa/src/mir/constant.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
2121
}
2222

2323
pub fn eval_mir_constant(&self, constant: &mir::ConstOperand<'tcx>) -> mir::ConstValue<'tcx> {
24-
// `MirUsedCollector` visited all constants before codegen began, so if we got here there
25-
// can be no more constants that fail to evaluate.
24+
// `MirUsedCollector` visited all required_consts before codegen began, so if we got here
25+
// there can be no more constants that fail to evaluate.
2626
self.monomorphize(constant.const_)
2727
.eval(self.cx.tcx(), ty::ParamEnv::reveal_all(), Some(constant.span))
28-
.expect("erroneous constant not captured by required_consts")
28+
.expect("erroneous constant missed by mono item collection")
2929
}
3030

3131
/// This is a convenience helper for `simd_shuffle_indices`. It has the precondition

compiler/rustc_codegen_ssa/src/mir/mod.rs

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
211211

212212
// It may seem like we should iterate over `required_consts` to ensure they all successfully
213213
// evaluate; however, the `MirUsedCollector` already did that during the collection phase of
214-
// monomorphization so we don't have to do it again.
214+
// monomorphization, and if there is an error during collection then codegen never starts -- so
215+
// we don't have to do it again.
215216

216217
fx.per_local_var_debug_info = fx.compute_per_local_var_debug_info(&mut start_bx);
217218

@@ -376,29 +377,45 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
376377
}
377378
}
378379

379-
if arg.is_sized_indirect() {
380-
// Don't copy an indirect argument to an alloca, the caller
381-
// already put it in a temporary alloca and gave it up.
382-
// FIXME: lifetimes
383-
let llarg = bx.get_param(llarg_idx);
384-
llarg_idx += 1;
385-
LocalRef::Place(PlaceRef::new_sized(llarg, arg.layout))
386-
} else if arg.is_unsized_indirect() {
387-
// As the storage for the indirect argument lives during
388-
// the whole function call, we just copy the fat pointer.
389-
let llarg = bx.get_param(llarg_idx);
390-
llarg_idx += 1;
391-
let llextra = bx.get_param(llarg_idx);
392-
llarg_idx += 1;
393-
let indirect_operand = OperandValue::Pair(llarg, llextra);
394-
395-
let tmp = PlaceRef::alloca_unsized_indirect(bx, arg.layout);
396-
indirect_operand.store(bx, tmp);
397-
LocalRef::UnsizedPlace(tmp)
398-
} else {
399-
let tmp = PlaceRef::alloca(bx, arg.layout);
400-
bx.store_fn_arg(arg, &mut llarg_idx, tmp);
401-
LocalRef::Place(tmp)
380+
match arg.mode {
381+
// Sized indirect arguments
382+
PassMode::Indirect { attrs, meta_attrs: None, on_stack: _ } => {
383+
// Don't copy an indirect argument to an alloca, the caller already put it
384+
// in a temporary alloca and gave it up.
385+
// FIXME: lifetimes
386+
if let Some(pointee_align) = attrs.pointee_align
387+
&& pointee_align < arg.layout.align.abi
388+
{
389+
// ...unless the argument is underaligned, then we need to copy it to
390+
// a higher-aligned alloca.
391+
let tmp = PlaceRef::alloca(bx, arg.layout);
392+
bx.store_fn_arg(arg, &mut llarg_idx, tmp);
393+
LocalRef::Place(tmp)
394+
} else {
395+
let llarg = bx.get_param(llarg_idx);
396+
llarg_idx += 1;
397+
LocalRef::Place(PlaceRef::new_sized(llarg, arg.layout))
398+
}
399+
}
400+
// Unsized indirect qrguments
401+
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
402+
// As the storage for the indirect argument lives during
403+
// the whole function call, we just copy the fat pointer.
404+
let llarg = bx.get_param(llarg_idx);
405+
llarg_idx += 1;
406+
let llextra = bx.get_param(llarg_idx);
407+
llarg_idx += 1;
408+
let indirect_operand = OperandValue::Pair(llarg, llextra);
409+
410+
let tmp = PlaceRef::alloca_unsized_indirect(bx, arg.layout);
411+
indirect_operand.store(bx, tmp);
412+
LocalRef::UnsizedPlace(tmp)
413+
}
414+
_ => {
415+
let tmp = PlaceRef::alloca(bx, arg.layout);
416+
bx.store_fn_arg(arg, &mut llarg_idx, tmp);
417+
LocalRef::Place(tmp)
418+
}
402419
}
403420
})
404421
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)