Skip to content

Commit 01dfd79

Browse files
committed
Auto merge of #157932 - jhpratt:rollup-OmNrNWw, r=jhpratt
Rollup of 13 pull requests Successful merges: - #152544 (Stabilize `int_format_into` feature) - #157507 (fixed: differentiation between uninitialized and possibly uninitialized) - #155750 (Document that `ManuallyDrop`'s `Box` interaction has been fixed) - #157075 (lower edition requirements for some async-closure test helpers) - #157627 (remove LLVM `va_end` calls) - #157660 (normalize instead of evaluating type const patterns) - #157692 (Don't emit `unused_parens` suggestion for proc-macro-synthesized parens around bounds) - #157908 (fix binding const argument to assoc type suggestion) - #157915 (scalable vecs size incl. num vecs + no sret for scalable vecs) - #157916 (Avoid ICE on invalid crate-level cfg_attr predicates) - #157919 (mention in the `extern "tail"` error that it's supported on x86) - #157920 (mailmap: add mu001999) - #157924 (Update books)
2 parents 42d7d52 + e1af1a0 commit 01dfd79

52 files changed

Lines changed: 712 additions & 234 deletions

File tree

Some content is hidden

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

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ Milan Landaverde <milanlandaverde@gmail.com>
491491
mjptree <michael.prantl@hotmail.de>
492492
Ms2ger <ms2ger@gmail.com> <Ms2ger@gmail.com>
493493
msizanoen1 <qtmlabs@protonmail.com>
494+
mu001999 <mu001999@outlook.com> <rcu@live.com>
494495
Mukilan Thiagarajan <mukilanthiagarajan@gmail.com>
495496
Nadrieril Feneanar <Nadrieril@users.noreply.github.com>
496497
Nadrieril Feneanar <Nadrieril@users.noreply.github.com> <nadrieril+rust@gmail.com>

compiler/rustc_abi/src/layout.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,19 +1498,21 @@ where
14981498
// Compute the size and alignment of the vector
14991499
let size =
15001500
elt.size.checked_mul(count, dl).ok_or_else(|| LayoutCalculatorError::SizeOverflow)?;
1501-
let (repr, align) = match kind {
1501+
let (repr, size, align) = match kind {
15021502
SimdVectorKind::Scalable(number_of_vectors) => (
15031503
BackendRepr::SimdScalableVector { element, count, number_of_vectors },
1504+
size.checked_mul(number_of_vectors.0 as u64, dl)
1505+
.ok_or_else(|| LayoutCalculatorError::SizeOverflow)?,
15041506
dl.llvmlike_vector_align(size),
15051507
),
15061508
// Non-power-of-two vectors have padding up to the next power-of-two.
15071509
// If we're a packed repr, remove the padding while keeping the alignment as close
15081510
// to a vector as possible.
15091511
SimdVectorKind::PackedFixed if !count.is_power_of_two() => {
1510-
(BackendRepr::Memory { sized: true }, Align::max_aligned_factor(size))
1512+
(BackendRepr::Memory { sized: true }, size, Align::max_aligned_factor(size))
15111513
}
15121514
SimdVectorKind::PackedFixed | SimdVectorKind::Fixed => {
1513-
(BackendRepr::SimdVector { element, count }, dl.llvmlike_vector_align(size))
1515+
(BackendRepr::SimdVector { element, count }, size, dl.llvmlike_vector_align(size))
15141516
}
15151517
};
15161518
let size = size.align_to(align);

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn parse_cfg_entry(
104104
Some(sym::version) => parse_cfg_entry_version(cx, list, meta.span())?,
105105
_ => {
106106
let mut possibilities = vec![sym::any, sym::all, sym::not, sym::target];
107-
if cx.features().cfg_version() {
107+
if cx.features_option().is_some_and(Features::cfg_version) {
108108
possibilities.push(sym::version);
109109
}
110110
return Err(cx.adcx().expected_specific_argument(meta.span(), &possibilities));

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_hir::intravisit::{Visitor, walk_block, walk_expr};
1515
use rustc_hir::{
1616
CoroutineDesugaring, CoroutineKind, CoroutineSource, LangItem, PatField, find_attr,
1717
};
18+
use rustc_index::bit_set::DenseBitSet;
1819
use rustc_middle::bug;
1920
use rustc_middle::hir::nested_filter::OnlyBodies;
2021
use rustc_middle::mir::{
@@ -28,7 +29,7 @@ use rustc_middle::ty::{
2829
self, PredicateKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor, Upcast,
2930
suggest_constraining_type_params,
3031
};
31-
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
32+
use rustc_mir_dataflow::move_paths::{Init, InitKind, InitLocation, MoveOutIndex, MovePathIndex};
3233
use rustc_span::def_id::{DefId, LocalDefId};
3334
use rustc_span::hygiene::DesugaringKind;
3435
use rustc_span::{BytePos, ExpnKind, Ident, MacroKind, Span, Symbol, kw, sym};
@@ -110,6 +111,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
110111
used_place,
111112
moved_place,
112113
desired_action,
114+
location,
113115
span,
114116
use_spans,
115117
);
@@ -769,12 +771,61 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
769771
}
770772
}
771773

774+
/// Returns `true` if the given initialization can reach the error location.
775+
///
776+
/// This is used to determine whether an initialization should be considered
777+
/// when reporting diagnostics at `err_location`.
778+
///
779+
/// The check proceeds in two stages:
780+
///
781+
/// 1. If the initialization originates from a function argument, it is
782+
/// considered reachable by definition.
783+
/// 2. If the initialization's basic block dominates the error block, then
784+
/// every path to the error must pass through the initialization, so it is
785+
/// reachable.
786+
/// 3. Otherwise, perform a graph traversal over the MIR control-flow graph to
787+
/// determine whether any path exists from the initialization block to the
788+
/// error block.
789+
///
790+
/// The dominance check acts as a fast path for the common case, while the CFG
791+
/// traversal handles cases where the initialization does not dominate the
792+
/// error location but can still reach it through an alternate control-flow
793+
/// path.
794+
fn is_init_reachable(&self, init: &Init, err_location: mir::Location) -> bool {
795+
let dominators = self.body.basic_blocks.dominators();
796+
let init_block = match init.location {
797+
InitLocation::Argument(_) => return true,
798+
InitLocation::Statement(location) => location.block,
799+
};
800+
let err_block = err_location.block;
801+
if dominators.dominates(init_block, err_block) {
802+
return true;
803+
}
804+
// If init_block doesn't dominate error_block, check if there is any valid path from the
805+
// initialization block to the error block in the Control Flow Graph.
806+
let mut visited = DenseBitSet::new_empty(self.body.basic_blocks.len());
807+
let mut stack = vec![init_block];
808+
while let Some(block) = stack.pop() {
809+
if block == err_block {
810+
return true;
811+
}
812+
if visited.insert(block) {
813+
let data = &self.body.basic_blocks[block];
814+
for successor in data.terminator().successors() {
815+
stack.push(successor);
816+
}
817+
}
818+
}
819+
false
820+
}
821+
772822
fn report_use_of_uninitialized(
773823
&self,
774824
mpi: MovePathIndex,
775825
used_place: PlaceRef<'tcx>,
776826
moved_place: PlaceRef<'tcx>,
777827
desired_action: InitializationRequiringAction,
828+
location: Location,
778829
span: Span,
779830
use_spans: UseSpans<'tcx>,
780831
) -> Diag<'infcx> {
@@ -783,15 +834,20 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
783834
let inits = &self.move_data.init_path_map[mpi];
784835
let move_path = &self.move_data.move_paths[mpi];
785836
let decl_span = self.body.local_decls[move_path.place.local].source_info.span;
786-
let mut spans_set = FxIndexSet::default();
837+
let mut all_init_spans_set = FxIndexSet::default();
838+
let mut reachable_spans_set = FxIndexSet::default();
787839
for init_idx in inits {
788840
let init = &self.move_data.inits[*init_idx];
789841
let span = init.span(self.body);
790842
if !span.is_dummy() {
791-
spans_set.insert(span);
843+
all_init_spans_set.insert(span);
844+
if self.is_init_reachable(init, location) {
845+
reachable_spans_set.insert(span);
846+
}
792847
}
793848
}
794-
let spans: Vec<_> = spans_set.into_iter().collect();
849+
let all_init_spans: Vec<_> = all_init_spans_set.into_iter().collect();
850+
let reachable_spans: Vec<_> = reachable_spans_set.into_iter().collect();
795851

796852
let (name, desc) = match self.describe_place_with_options(
797853
moved_place,
@@ -812,9 +868,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
812868
// for the branching codepaths that aren't covered, to point at them.
813869
let tcx = self.infcx.tcx;
814870
let body = tcx.hir_body_owned_by(self.mir_def_id());
815-
let mut visitor = ConditionVisitor { tcx, spans, name, errors: vec![] };
871+
let mut visitor =
872+
ConditionVisitor { tcx, spans: all_init_spans.clone(), name, errors: vec![] };
816873
visitor.visit_body(&body);
817-
let spans = visitor.spans;
818874

819875
let mut show_assign_sugg = false;
820876
let isnt_initialized = if let InitializationRequiringAction::PartialAssignment
@@ -824,7 +880,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
824880
// that are *partially* initialized by assigning to a field of an uninitialized
825881
// binding. We differentiate between them for more accurate wording here.
826882
"isn't fully initialized"
827-
} else if !spans.iter().any(|i| {
883+
} else if !reachable_spans.iter().any(|i| {
828884
// We filter these to avoid misleading wording in cases like the following,
829885
// where `x` has an `init`, but it is in the same place we're looking at:
830886
// ```
@@ -840,7 +896,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
840896
.any(|sp| span < sp && !sp.contains(span))
841897
}) {
842898
show_assign_sugg = true;
843-
"isn't initialized"
899+
if all_init_spans.iter().any(|init_span| !init_span.contains(span))
900+
&& reachable_spans.is_empty()
901+
{
902+
"isn't initialized on any path leading to this point"
903+
} else {
904+
"isn't initialized"
905+
}
844906
} else {
845907
"is possibly-uninitialized"
846908
};
@@ -887,7 +949,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
887949
}
888950
}
889951
if !shown {
890-
for sp in &spans {
952+
for sp in &reachable_spans {
891953
if *sp < span && !sp.overlaps(span) {
892954
err.span_label(*sp, "binding initialized here in some conditions");
893955
}

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
15121512
}
15131513

15141514
// FIXME implement variadics in cranelift
1515-
sym::va_arg | sym::va_end => {
1515+
sym::va_arg => {
15161516
fx.tcx.dcx().span_fatal(
15171517
source_info.span,
15181518
"Defining variadic functions is not yet supported by Cranelift",

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,10 +705,6 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
705705
unimplemented!();
706706
}
707707

708-
fn va_end(&mut self, _va_list: RValue<'gcc>) {
709-
// FIXME(antoyo): implement.
710-
}
711-
712708
fn retag_reg(&mut self, _ptr: Self::Value, _info: &RetagInfo<Self::Value>) -> Self::Value {
713709
unimplemented!()
714710
}

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ pub(crate) fn to_llvm_calling_convention(sess: &Session, abi: CanonAbi) -> llvm:
725725
},
726726
CanonAbi::RustTail => match &sess.target.arch {
727727
Arch::X86 | Arch::X86_64 | Arch::AArch64 => llvm::Tail,
728-
_ => sess.dcx().fatal("extern \"tail\" is only supported on x86_64 and aarch64"),
728+
_ => sess.dcx().fatal("extern \"tail\" is only supported on x86, x86_64 and aarch64"),
729729
},
730730
// Functions with this calling convention can only be called from assembly, but it is
731731
// possible to declare an `extern "custom"` block, so the backend still needs a calling

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,10 +1070,6 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
10701070
self.call_intrinsic("llvm.va_start", &[self.val_ty(va_list)], &[va_list]);
10711071
}
10721072

1073-
fn va_end(&mut self, va_list: &'ll Value) {
1074-
self.call_intrinsic("llvm.va_end", &[self.val_ty(va_list)], &[va_list]);
1075-
}
1076-
10771073
fn retag_reg(&mut self, ptr: Self::Value, info: &RetagInfo<Self::Value>) -> Self::Value {
10781074
codegen_retag_inner(self, "__rust_retag_reg", ptr, info)
10791075
}

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
525525
}
526526

527527
fn codegen_return_terminator(&mut self, bx: &mut Bx) {
528-
// Call `va_end` if this is the definition of a C-variadic function.
528+
// Explicitly end the lifetime of the VaList if this function is c-variadic. We explicitly
529+
// start the lifetime when desugaring `...`. Ending the lifetime meaningfully improves
530+
// codegen.
529531
if self.fn_abi.c_variadic {
530532
// The `VaList` "spoofed" argument is just after all the real arguments.
531533
let va_list_arg_idx = self.fn_abi.args.len();
532534
match self.locals[mir::Local::arg(va_list_arg_idx)] {
533535
LocalRef::Place(va_list) => {
534-
bx.va_end(va_list.val.llval);
536+
// NOTE: we don't actually call LLVM's va_end here. We know it's a no-op for
537+
// all current targets and hence don't bother
538+
// (as permitted by https://llvm.org/docs/LangRef.html#llvm-va-end-intrinsic).
535539

536540
// Explicitly end the lifetime of the `va_list`, improves LLVM codegen.
537541
bx.lifetime_end(va_list.val.llval, va_list.layout.size);

compiler/rustc_codegen_ssa/src/traits/intrinsic.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ pub trait IntrinsicCallBuilderMethods<'tcx>: BackendTypes {
5252
/// Trait method used to inject `va_start` on the "spoofed" `VaList` in
5353
/// Rust defined C-variadic functions.
5454
fn va_start(&mut self, val: Self::Value);
55-
/// Trait method used to inject `va_end` on the "spoofed" `VaList` before
56-
/// Rust defined C-variadic functions return.
57-
fn va_end(&mut self, val: Self::Value);
5855
/// Trait method used to retag a pointer stored within a place.
5956
fn retag_mem(&mut self, place: Self::Value, info: &RetagInfo<Self::Value>);
6057
/// Trait method used to retag a pointer that has been loaded into a register.

0 commit comments

Comments
 (0)