Skip to content

Commit 5b2cdc1

Browse files
committed
Auto merge of rust-lang#3791 - rust-lang:rustup-2024-08-06, r=RalfJung
Automatic Rustup
2 parents f6edc8a + ac3e349 commit 5b2cdc1

File tree

94 files changed

+1380
-887
lines changed

Some content is hidden

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

94 files changed

+1380
-887
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,10 +2330,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23302330
match (cast_ty_from, cast_ty_to) {
23312331
(Some(CastTy::Ptr(src)), Some(CastTy::Ptr(dst))) => {
23322332
let mut normalize = |t| self.normalize(t, location);
2333+
2334+
// N.B. `struct_tail_with_normalize` only "structurally resolves"
2335+
// the type. It is not fully normalized, so we have to normalize it
2336+
// afterwards.
23332337
let src_tail =
23342338
tcx.struct_tail_with_normalize(src.ty, &mut normalize, || ());
2339+
let src_tail = normalize(src_tail);
23352340
let dst_tail =
23362341
tcx.struct_tail_with_normalize(dst.ty, &mut normalize, || ());
2342+
let dst_tail = normalize(dst_tail);
23372343

23382344
// This checks (lifetime part of) vtable validity for pointer casts,
23392345
// which is irrelevant when there are aren't principal traits on both sides (aka only auto traits).

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,22 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
646646
}
647647
}
648648

649+
// This is a workaround for a LLVM bug that doesn't implicitly enable
650+
// `simd128` when `relaxed-simd` is.
651+
// See <https://github.com/llvm/llvm-project/pull/99803>, which didn't make
652+
// it into a released version of LLVM yet.
653+
//
654+
// This doesn't use the "implicit target feature" system because it is only
655+
// used for function attributes in other targets, which fixes this bug as
656+
// well on the function attribute level.
657+
if sess.target.families.contains(&"wasm".into()) {
658+
if features.iter().any(|f| f == "+relaxed-simd")
659+
&& !features.iter().any(|f| f == "+simd128")
660+
{
661+
features.push("+simd128".into());
662+
}
663+
}
664+
649665
if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) {
650666
sess.dcx().emit_err(TargetFeatureDisableOrEnable {
651667
features: f,

compiler/rustc_codegen_ssa/src/common.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::Span;
88

99
use crate::traits::*;
1010

11-
#[derive(Copy, Clone)]
11+
#[derive(Copy, Clone, Debug)]
1212
pub enum IntPredicate {
1313
IntEQ,
1414
IntNE,
@@ -22,7 +22,7 @@ pub enum IntPredicate {
2222
IntSLE,
2323
}
2424

25-
#[derive(Copy, Clone)]
25+
#[derive(Copy, Clone, Debug)]
2626
pub enum RealPredicate {
2727
RealPredicateFalse,
2828
RealOEQ,
@@ -42,7 +42,7 @@ pub enum RealPredicate {
4242
RealPredicateTrue,
4343
}
4444

45-
#[derive(Copy, Clone, PartialEq)]
45+
#[derive(Copy, Clone, PartialEq, Debug)]
4646
pub enum AtomicRmwBinOp {
4747
AtomicXchg,
4848
AtomicAdd,
@@ -57,7 +57,7 @@ pub enum AtomicRmwBinOp {
5757
AtomicUMin,
5858
}
5959

60-
#[derive(Copy, Clone)]
60+
#[derive(Copy, Clone, Debug)]
6161
pub enum AtomicOrdering {
6262
Unordered,
6363
Relaxed,
@@ -67,7 +67,7 @@ pub enum AtomicOrdering {
6767
SequentiallyConsistent,
6868
}
6969

70-
#[derive(Copy, Clone)]
70+
#[derive(Copy, Clone, Debug)]
7171
pub enum SynchronizationScope {
7272
SingleThread,
7373
CrossThread,

compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ pub fn from_target_feature(
9797
Some(Symbol::intern(feature))
9898
}));
9999
}
100+
101+
for (feature, requires) in tcx.sess.target.implicit_target_features() {
102+
if target_features.iter().any(|f| f.as_str() == *feature)
103+
&& !target_features.iter().any(|f| f.as_str() == *requires)
104+
{
105+
target_features.push(Symbol::intern(requires));
106+
}
107+
}
100108
}
101109

102110
/// Computes the set of target features used in a function for the purposes of

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::mir::operand::{OperandRef, OperandValue};
2323
use crate::mir::place::{PlaceRef, PlaceValue};
2424
use crate::MemFlags;
2525

26-
#[derive(Copy, Clone)]
26+
#[derive(Copy, Clone, Debug)]
2727
pub enum OverflowOp {
2828
Add,
2929
Sub,

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
458458
_unwind: mir::UnwindAction,
459459
) -> InterpResult<'tcx, Option<ty::Instance<'tcx>>> {
460460
// Shared intrinsics.
461-
if ecx.emulate_intrinsic(instance, args, dest, target)? {
461+
if ecx.eval_intrinsic(instance, args, dest, target)? {
462462
return Ok(None);
463463
}
464464
let intrinsic_name = ecx.tcx.item_name(instance.def_id());

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
9797
/// Returns `true` if emulation happened.
9898
/// Here we implement the intrinsics that are common to all Miri instances; individual machines can add their own
9999
/// intrinsic handling.
100-
pub fn emulate_intrinsic(
100+
pub fn eval_intrinsic(
101101
&mut self,
102102
instance: ty::Instance<'tcx>,
103103
args: &[OpTy<'tcx, M::Provenance>],
@@ -447,7 +447,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
447447
Ok(true)
448448
}
449449

450-
pub(super) fn emulate_nondiverging_intrinsic(
450+
pub(super) fn eval_nondiverging_intrinsic(
451451
&mut self,
452452
intrinsic: &NonDivergingIntrinsic<'tcx>,
453453
) -> InterpResult<'tcx> {

compiler/rustc_const_eval/src/interpret/operator.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use either::Either;
22
use rustc_apfloat::{Float, FloatConvert};
33
use rustc_middle::mir::interpret::{InterpResult, Scalar};
4+
use rustc_middle::mir::NullOp;
45
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
5-
use rustc_middle::ty::{self, FloatTy, ScalarInt};
6+
use rustc_middle::ty::{self, FloatTy, ScalarInt, Ty};
67
use rustc_middle::{bug, mir, span_bug};
78
use rustc_span::symbol::sym;
89
use tracing::trace;
@@ -480,4 +481,38 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
480481
}
481482
}
482483
}
484+
485+
pub fn nullary_op(
486+
&self,
487+
null_op: NullOp<'tcx>,
488+
arg_ty: Ty<'tcx>,
489+
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
490+
use rustc_middle::mir::NullOp::*;
491+
492+
let layout = self.layout_of(arg_ty)?;
493+
let usize_layout = || self.layout_of(self.tcx.types.usize).unwrap();
494+
495+
Ok(match null_op {
496+
SizeOf => {
497+
if !layout.abi.is_sized() {
498+
span_bug!(self.cur_span(), "unsized type for `NullaryOp::SizeOf`");
499+
}
500+
let val = layout.size.bytes();
501+
ImmTy::from_uint(val, usize_layout())
502+
}
503+
AlignOf => {
504+
if !layout.abi.is_sized() {
505+
span_bug!(self.cur_span(), "unsized type for `NullaryOp::AlignOf`");
506+
}
507+
let val = layout.align.abi.bytes();
508+
ImmTy::from_uint(val, usize_layout())
509+
}
510+
OffsetOf(fields) => {
511+
let val =
512+
self.tcx.offset_of_subfield(self.param_env, layout, fields.iter()).bytes();
513+
ImmTy::from_uint(val, usize_layout())
514+
}
515+
UbChecks => ImmTy::from_bool(self.tcx.sess.ub_checks(), *self.tcx),
516+
})
517+
}
483518
}

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
55
use either::Either;
66
use rustc_index::IndexSlice;
7-
use rustc_middle::ty::layout::LayoutOf;
8-
use rustc_middle::{bug, mir, span_bug};
7+
use rustc_middle::{bug, mir};
98
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
109
use tracing::{info, instrument, trace};
1110

@@ -94,7 +93,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
9493
M::retag_place_contents(self, *kind, &dest)?;
9594
}
9695

97-
Intrinsic(box intrinsic) => self.emulate_nondiverging_intrinsic(intrinsic)?,
96+
Intrinsic(box intrinsic) => self.eval_nondiverging_intrinsic(intrinsic)?,
9897

9998
// Evaluate the place expression, without reading from it.
10099
PlaceMention(box place) => {
@@ -179,6 +178,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
179178
self.write_immediate(*result, &dest)?;
180179
}
181180

181+
NullaryOp(null_op, ty) => {
182+
let ty = self.instantiate_from_current_frame_and_normalize_erasing_regions(ty)?;
183+
let val = self.nullary_op(null_op, ty)?;
184+
self.write_immediate(*val, &dest)?;
185+
}
186+
182187
Aggregate(box ref kind, ref operands) => {
183188
self.write_aggregate(kind, operands, &dest)?;
184189
}
@@ -230,38 +235,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
230235
self.write_immediate(*val, &dest)?;
231236
}
232237

233-
NullaryOp(ref null_op, ty) => {
234-
let ty = self.instantiate_from_current_frame_and_normalize_erasing_regions(ty)?;
235-
let layout = self.layout_of(ty)?;
236-
if let mir::NullOp::SizeOf | mir::NullOp::AlignOf = null_op
237-
&& layout.is_unsized()
238-
{
239-
span_bug!(
240-
self.frame().current_span(),
241-
"{null_op:?} MIR operator called for unsized type {ty}",
242-
);
243-
}
244-
let val = match null_op {
245-
mir::NullOp::SizeOf => {
246-
let val = layout.size.bytes();
247-
Scalar::from_target_usize(val, self)
248-
}
249-
mir::NullOp::AlignOf => {
250-
let val = layout.align.abi.bytes();
251-
Scalar::from_target_usize(val, self)
252-
}
253-
mir::NullOp::OffsetOf(fields) => {
254-
let val = self
255-
.tcx
256-
.offset_of_subfield(self.param_env, layout, fields.iter())
257-
.bytes();
258-
Scalar::from_target_usize(val, self)
259-
}
260-
mir::NullOp::UbChecks => Scalar::from_bool(self.tcx.sess.ub_checks()),
261-
};
262-
self.write_scalar(val, &dest)?;
263-
}
264-
265238
ShallowInitBox(ref operand, _) => {
266239
let src = self.eval_operand(operand, None)?;
267240
let v = self.read_immediate(&src)?;

compiler/rustc_hir_analysis/src/check/intrinsicck.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_ast::InlineAsmTemplatePiece;
22
use rustc_data_structures::fx::FxIndexSet;
33
use rustc_hir::{self as hir, LangItem};
44
use rustc_middle::bug;
5-
use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitableExt, UintTy};
5+
use rustc_middle::ty::{self, FloatTy, IntTy, Ty, TyCtxt, TypeVisitableExt, UintTy};
66
use rustc_session::lint;
77
use rustc_span::def_id::LocalDefId;
88
use rustc_span::Symbol;
@@ -455,32 +455,22 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
455455
);
456456
}
457457
}
458-
// No special checking is needed for these:
459-
// - Typeck has checked that Const operands are integers.
460-
// - AST lowering guarantees that SymStatic points to a static.
461-
hir::InlineAsmOperand::Const { .. } | hir::InlineAsmOperand::SymStatic { .. } => {}
462-
// Check that sym actually points to a function. Later passes
463-
// depend on this.
458+
// Typeck has checked that Const operands are integers.
459+
hir::InlineAsmOperand::Const { anon_const } => {
460+
debug_assert!(matches!(
461+
self.tcx.type_of(anon_const.def_id).instantiate_identity().kind(),
462+
ty::Error(_) | ty::Int(_) | ty::Uint(_)
463+
));
464+
}
465+
// Typeck has checked that SymFn refers to a function.
464466
hir::InlineAsmOperand::SymFn { anon_const } => {
465-
let ty = self.tcx.type_of(anon_const.def_id).instantiate_identity();
466-
match ty.kind() {
467-
ty::Never | ty::Error(_) => {}
468-
ty::FnDef(..) => {}
469-
_ => {
470-
self.tcx
471-
.dcx()
472-
.struct_span_err(*op_sp, "invalid `sym` operand")
473-
.with_span_label(
474-
self.tcx.def_span(anon_const.def_id),
475-
format!("is {} `{}`", ty.kind().article(), ty),
476-
)
477-
.with_help(
478-
"`sym` operands must refer to either a function or a static",
479-
)
480-
.emit();
481-
}
482-
};
467+
debug_assert!(matches!(
468+
self.tcx.type_of(anon_const.def_id).instantiate_identity().kind(),
469+
ty::Error(_) | ty::FnDef(..)
470+
));
483471
}
472+
// AST lowering guarantees that SymStatic points to a static.
473+
hir::InlineAsmOperand::SymStatic { .. } => {}
484474
// No special checking is needed for labels.
485475
hir::InlineAsmOperand::Label { .. } => {}
486476
}

0 commit comments

Comments
 (0)