Skip to content

Commit e5791df

Browse files
committed
Auto merge of #143715 - tgross35:rollup-5cuwrql, r=tgross35
Rollup of 9 pull requests Successful merges: - #141996 (Fix `proc_macro::Ident`'s handling of `$crate`) - #142911 (Remove support for dynamic allocas) - #142950 (mbe: Rework diagnostics for metavariable expressions) - #143270 (tests/codegen/enum/enum-match.rs: accept negative range attribute) - #143298 (`tests/ui`: A New Order [23/N]) - #143398 (tidy: add support for `--extra-checks=auto:` feature) - #143632 (fix: correct parameter names in LLVMRustBuildMinNum and LLVMRustBuildMaxNum FFI declarations) - #143644 (Add triagebot stdarch mention ping) - #143651 (Win: Use exceptions with empty data for SEH panic exception copies instead of a new panic) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 32cd911 + 9ec2968 commit e5791df

File tree

59 files changed

+1709
-453
lines changed

Some content is hidden

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

59 files changed

+1709
-453
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -926,10 +926,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
926926
.get_address(self.location)
927927
}
928928

929-
fn dynamic_alloca(&mut self, _len: RValue<'gcc>, _align: Align) -> RValue<'gcc> {
930-
unimplemented!();
931-
}
932-
933929
fn load(&mut self, pointee_ty: Type<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValue<'gcc> {
934930
let block = self.llbb();
935931
let function = block.get_function();

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -538,16 +538,6 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
538538
}
539539
}
540540

541-
fn dynamic_alloca(&mut self, size: &'ll Value, align: Align) -> &'ll Value {
542-
unsafe {
543-
let alloca =
544-
llvm::LLVMBuildArrayAlloca(self.llbuilder, self.cx().type_i8(), size, UNNAMED);
545-
llvm::LLVMSetAlignment(alloca, align.bytes() as c_uint);
546-
// Cast to default addrspace if necessary
547-
llvm::LLVMBuildPointerCast(self.llbuilder, alloca, self.cx().type_ptr(), UNNAMED)
548-
}
549-
}
550-
551541
fn load(&mut self, ty: &'ll Type, ptr: &'ll Value, align: Align) -> &'ll Value {
552542
unsafe {
553543
let load = llvm::LLVMBuildLoad2(self.llbuilder, ty, ptr, UNNAMED);

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,12 +1492,6 @@ unsafe extern "C" {
14921492
Ty: &'a Type,
14931493
Name: *const c_char,
14941494
) -> &'a Value;
1495-
pub(crate) fn LLVMBuildArrayAlloca<'a>(
1496-
B: &Builder<'a>,
1497-
Ty: &'a Type,
1498-
Val: &'a Value,
1499-
Name: *const c_char,
1500-
) -> &'a Value;
15011495
pub(crate) fn LLVMBuildLoad2<'a>(
15021496
B: &Builder<'a>,
15031497
Ty: &'a Type,
@@ -1980,12 +1974,12 @@ unsafe extern "C" {
19801974
pub(crate) fn LLVMRustBuildMinNum<'a>(
19811975
B: &Builder<'a>,
19821976
LHS: &'a Value,
1983-
LHS: &'a Value,
1977+
RHS: &'a Value,
19841978
) -> &'a Value;
19851979
pub(crate) fn LLVMRustBuildMaxNum<'a>(
19861980
B: &Builder<'a>,
19871981
LHS: &'a Value,
1988-
LHS: &'a Value,
1982+
RHS: &'a Value,
19891983
) -> &'a Value;
19901984

19911985
// Atomic Operations

compiler/rustc_codegen_ssa/src/mir/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,13 @@ enum LocalRef<'tcx, V> {
140140
Place(PlaceRef<'tcx, V>),
141141
/// `UnsizedPlace(p)`: `p` itself is a thin pointer (indirect place).
142142
/// `*p` is the wide pointer that references the actual unsized place.
143-
/// Every time it is initialized, we have to reallocate the place
144-
/// and update the wide pointer. That's the reason why it is indirect.
143+
///
144+
/// MIR only supports unsized args, not dynamically-sized locals, so
145+
/// new unsized temps don't exist and we must reuse the referred-to place.
146+
///
147+
/// FIXME: Since the removal of unsized locals in <https://github.com/rust-lang/rust/pull/142911>,
148+
/// can we maybe use `Place` here? Or refactor it in another way? There are quite a few
149+
/// `UnsizedPlace => bug` branches now.
145150
UnsizedPlace(PlaceRef<'tcx, V>),
146151
/// The backend [`OperandValue`] has already been generated.
147152
Operand(OperandRef<'tcx, V>),
@@ -498,7 +503,7 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
498503
LocalRef::Place(PlaceRef::new_sized(llarg, arg.layout))
499504
}
500505
}
501-
// Unsized indirect qrguments
506+
// Unsized indirect arguments
502507
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
503508
// As the storage for the indirect argument lives during
504509
// the whole function call, we just copy the wide pointer.

compiler/rustc_codegen_ssa/src/mir/operand.rs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use tracing::{debug, instrument};
1616
use super::place::{PlaceRef, PlaceValue};
1717
use super::rvalue::transmute_scalar;
1818
use super::{FunctionCx, LocalRef};
19+
use crate::MemFlags;
1920
use crate::common::IntPredicate;
2021
use crate::traits::*;
21-
use crate::{MemFlags, size_of_val};
2222

2323
/// The representation of a Rust value. The enum variant is in fact
2424
/// uniquely determined by the value's type, but is kept as a
@@ -861,44 +861,6 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue<V> {
861861
}
862862
}
863863
}
864-
865-
pub fn store_unsized<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
866-
self,
867-
bx: &mut Bx,
868-
indirect_dest: PlaceRef<'tcx, V>,
869-
) {
870-
debug!("OperandRef::store_unsized: operand={:?}, indirect_dest={:?}", self, indirect_dest);
871-
// `indirect_dest` must have `*mut T` type. We extract `T` out of it.
872-
let unsized_ty = indirect_dest
873-
.layout
874-
.ty
875-
.builtin_deref(true)
876-
.unwrap_or_else(|| bug!("indirect_dest has non-pointer type: {:?}", indirect_dest));
877-
878-
let OperandValue::Ref(PlaceValue { llval: llptr, llextra: Some(llextra), .. }) = self
879-
else {
880-
bug!("store_unsized called with a sized value (or with an extern type)")
881-
};
882-
883-
// Allocate an appropriate region on the stack, and copy the value into it. Since alloca
884-
// doesn't support dynamic alignment, we allocate an extra align - 1 bytes, and align the
885-
// pointer manually.
886-
let (size, align) = size_of_val::size_and_align_of_dst(bx, unsized_ty, Some(llextra));
887-
let one = bx.const_usize(1);
888-
let align_minus_1 = bx.sub(align, one);
889-
let size_extra = bx.add(size, align_minus_1);
890-
let min_align = Align::ONE;
891-
let alloca = bx.dynamic_alloca(size_extra, min_align);
892-
let address = bx.ptrtoint(alloca, bx.type_isize());
893-
let neg_address = bx.neg(address);
894-
let offset = bx.and(neg_address, align_minus_1);
895-
let dst = bx.inbounds_ptradd(alloca, offset);
896-
bx.memcpy(dst, min_align, llptr, min_align, size, MemFlags::empty());
897-
898-
// Store the allocated region and the extra to the indirect place.
899-
let indirect_operand = OperandValue::Pair(dst, llextra);
900-
indirect_operand.store(bx, indirect_dest);
901-
}
902864
}
903865

904866
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -327,27 +327,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
327327
Some(imm)
328328
}
329329

330-
pub(crate) fn codegen_rvalue_unsized(
331-
&mut self,
332-
bx: &mut Bx,
333-
indirect_dest: PlaceRef<'tcx, Bx::Value>,
334-
rvalue: &mir::Rvalue<'tcx>,
335-
) {
336-
debug!(
337-
"codegen_rvalue_unsized(indirect_dest.llval={:?}, rvalue={:?})",
338-
indirect_dest.val.llval, rvalue
339-
);
340-
341-
match *rvalue {
342-
mir::Rvalue::Use(ref operand) => {
343-
let cg_operand = self.codegen_operand(bx, operand);
344-
cg_operand.val.store_unsized(bx, indirect_dest);
345-
}
346-
347-
_ => bug!("unsized assignment other than `Rvalue::Use`"),
348-
}
349-
}
350-
351330
pub(crate) fn codegen_rvalue_operand(
352331
&mut self,
353332
bx: &mut Bx,

compiler/rustc_codegen_ssa/src/mir/statement.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1515
match self.locals[index] {
1616
LocalRef::Place(cg_dest) => self.codegen_rvalue(bx, cg_dest, rvalue),
1717
LocalRef::UnsizedPlace(cg_indirect_dest) => {
18-
self.codegen_rvalue_unsized(bx, cg_indirect_dest, rvalue)
18+
let ty = cg_indirect_dest.layout.ty;
19+
span_bug!(
20+
statement.source_info.span,
21+
"cannot reallocate from `UnsizedPlace({ty})` \
22+
into `{rvalue:?}`; dynamic alloca is not supported",
23+
);
1924
}
2025
LocalRef::PendingOperand => {
2126
let operand = self.codegen_rvalue_operand(bx, rvalue);

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ pub trait BuilderMethods<'a, 'tcx>:
224224
fn to_immediate_scalar(&mut self, val: Self::Value, scalar: Scalar) -> Self::Value;
225225

226226
fn alloca(&mut self, size: Size, align: Align) -> Self::Value;
227-
fn dynamic_alloca(&mut self, size: Self::Value, align: Align) -> Self::Value;
228227

229228
fn load(&mut self, ty: Self::Type, ptr: Self::Value, align: Align) -> Self::Value;
230229
fn volatile_load(&mut self, ty: Self::Type, ptr: Self::Value) -> Self::Value;

compiler/rustc_expand/messages.ftl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,32 @@ expand_module_multiple_candidates =
133133
expand_must_repeat_once =
134134
this must repeat at least once
135135
136+
expand_mve_extra_tokens =
137+
unexpected trailing tokens
138+
.label = for this metavariable expression
139+
.range = the `{$name}` metavariable expression takes between {$min_or_exact_args} and {$max_args} arguments
140+
.exact = the `{$name}` metavariable expression takes {$min_or_exact_args ->
141+
[zero] no arguments
142+
[one] a single argument
143+
*[other] {$min_or_exact_args} arguments
144+
}
145+
.suggestion = try removing {$extra_count ->
146+
[one] this token
147+
*[other] these tokens
148+
}
149+
150+
expand_mve_missing_paren =
151+
expected `(`
152+
.label = for this this metavariable expression
153+
.unexpected = unexpected token
154+
.note = metavariable expressions use function-like parentheses syntax
155+
.suggestion = try adding parentheses
156+
157+
expand_mve_unrecognized_expr =
158+
unrecognized metavariable expression
159+
.label = not a valid metavariable expression
160+
.note = valid metavariable expressions are {$valid_expr_list}
161+
136162
expand_mve_unrecognized_var =
137163
variable `{$key}` is not recognized in meta-variable expression
138164

compiler/rustc_expand/src/errors.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,50 @@ pub(crate) use metavar_exprs::*;
496496
mod metavar_exprs {
497497
use super::*;
498498

499+
#[derive(Diagnostic, Default)]
500+
#[diag(expand_mve_extra_tokens)]
501+
pub(crate) struct MveExtraTokens {
502+
#[primary_span]
503+
#[suggestion(code = "", applicability = "machine-applicable")]
504+
pub span: Span,
505+
#[label]
506+
pub ident_span: Span,
507+
pub extra_count: usize,
508+
509+
// The rest is only used for specific diagnostics and can be default if neither
510+
// `note` is `Some`.
511+
#[note(expand_exact)]
512+
pub exact_args_note: Option<()>,
513+
#[note(expand_range)]
514+
pub range_args_note: Option<()>,
515+
pub min_or_exact_args: usize,
516+
pub max_args: usize,
517+
pub name: String,
518+
}
519+
520+
#[derive(Diagnostic)]
521+
#[note]
522+
#[diag(expand_mve_missing_paren)]
523+
pub(crate) struct MveMissingParen {
524+
#[primary_span]
525+
#[label]
526+
pub ident_span: Span,
527+
#[label(expand_unexpected)]
528+
pub unexpected_span: Option<Span>,
529+
#[suggestion(code = "( /* ... */ )", applicability = "has-placeholders")]
530+
pub insert_span: Option<Span>,
531+
}
532+
533+
#[derive(Diagnostic)]
534+
#[note]
535+
#[diag(expand_mve_unrecognized_expr)]
536+
pub(crate) struct MveUnrecognizedExpr {
537+
#[primary_span]
538+
#[label]
539+
pub span: Span,
540+
pub valid_expr_list: &'static str,
541+
}
542+
499543
#[derive(Diagnostic)]
500544
#[diag(expand_mve_unrecognized_var)]
501545
pub(crate) struct MveUnrecognizedVar {

0 commit comments

Comments
 (0)