Skip to content

Commit 5faf48c

Browse files
author
The rustc-dev-guide Cronjob Bot
committed
Merge from rustc
2 parents ba78fee + b440ded commit 5faf48c

Some content is hidden

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

50 files changed

+636
-436
lines changed

src/alloc/isolated_alloc.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ impl IsolatedAlloc {
145145
if pinfo.domain_size() < offset_pinfo + size_pinfo {
146146
break;
147147
}
148-
// FIXME: is there a more efficient way to check whether the entire range is unset
149-
// in the bitset?
150-
let range_avail = !(offset_pinfo..offset_pinfo + size_pinfo).any(|i| pinfo.contains(i));
151-
if range_avail {
148+
if !pinfo.contains_any(offset_pinfo..offset_pinfo + size_pinfo) {
152149
pinfo.insert_range(offset_pinfo..offset_pinfo + size_pinfo);
153150
// SAFETY: We checked the available bytes after `idx` in the call
154151
// to `domain_size` above and asserted there are at least `idx +

src/eval.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ pub fn create_ecx<'tcx>(
359359
let argvs_layout =
360360
ecx.layout_of(Ty::new_array(tcx, u8_ptr_type, u64::try_from(argvs.len()).unwrap()))?;
361361
let argvs_place = ecx.allocate(argvs_layout, MiriMemoryKind::Machine.into())?;
362-
for (idx, arg) in argvs.into_iter().enumerate() {
363-
let place = ecx.project_field(&argvs_place, idx)?;
362+
for (arg, idx) in argvs.into_iter().zip(0..) {
363+
let place = ecx.project_index(&argvs_place, idx)?;
364364
ecx.write_immediate(arg, &place)?;
365365
}
366366
ecx.mark_immutable(&argvs_place);
@@ -389,8 +389,8 @@ pub fn create_ecx<'tcx>(
389389
ecx.allocate(ecx.layout_of(cmd_type)?, MiriMemoryKind::Machine.into())?;
390390
ecx.machine.cmd_line = Some(cmd_place.ptr());
391391
// Store the UTF-16 string. We just allocated so we know the bounds are fine.
392-
for (idx, &c) in cmd_utf16.iter().enumerate() {
393-
let place = ecx.project_field(&cmd_place, idx)?;
392+
for (&c, idx) in cmd_utf16.iter().zip(0..) {
393+
let place = ecx.project_index(&cmd_place, idx)?;
394394
ecx.write_scalar(Scalar::from_u16(c), &place)?;
395395
}
396396
ecx.mark_immutable(&cmd_place);

src/helpers.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::time::Duration;
33
use std::{cmp, iter};
44

55
use rand::RngCore;
6-
use rustc_abi::{Align, ExternAbi, FieldIdx, FieldsShape, Size, Variants};
6+
use rustc_abi::{Align, CanonAbi, ExternAbi, FieldIdx, FieldsShape, Size, Variants};
77
use rustc_apfloat::Float;
88
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
99
use rustc_hir::Safety;
@@ -18,7 +18,7 @@ use rustc_middle::ty::{self, Binder, FloatTy, FnSig, IntTy, Ty, TyCtxt, UintTy};
1818
use rustc_session::config::CrateType;
1919
use rustc_span::{Span, Symbol};
2020
use rustc_symbol_mangling::mangle_internal_symbol;
21-
use rustc_target::callconv::{Conv, FnAbi};
21+
use rustc_target::callconv::FnAbi;
2222

2323
use crate::*;
2424

@@ -326,7 +326,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
326326
) -> InterpResult<'tcx, Option<P>> {
327327
let this = self.eval_context_ref();
328328
let adt = base.layout().ty.ty_adt_def().unwrap();
329-
for (idx, field) in adt.non_enum_variant().fields.iter().enumerate() {
329+
for (idx, field) in adt.non_enum_variant().fields.iter_enumerated() {
330330
if field.name.as_str() == name {
331331
return interp_ok(Some(this.project_field(base, idx)?));
332332
}
@@ -376,6 +376,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
376376
) -> InterpResult<'tcx> {
377377
let this = self.eval_context_mut();
378378
for (idx, &val) in values.iter().enumerate() {
379+
let idx = FieldIdx::from_usize(idx);
379380
let field = this.project_field(dest, idx)?;
380381
this.write_int(val, &field)?;
381382
}
@@ -763,10 +764,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
763764
/// `EINVAL` in this case.
764765
fn read_timespec(&mut self, tp: &MPlaceTy<'tcx>) -> InterpResult<'tcx, Option<Duration>> {
765766
let this = self.eval_context_mut();
766-
let seconds_place = this.project_field(tp, 0)?;
767+
let seconds_place = this.project_field(tp, FieldIdx::ZERO)?;
767768
let seconds_scalar = this.read_scalar(&seconds_place)?;
768769
let seconds = seconds_scalar.to_target_isize(this)?;
769-
let nanoseconds_place = this.project_field(tp, 1)?;
770+
let nanoseconds_place = this.project_field(tp, FieldIdx::ONE)?;
770771
let nanoseconds_scalar = this.read_scalar(&nanoseconds_place)?;
771772
let nanoseconds = nanoseconds_scalar.to_target_isize(this)?;
772773

@@ -936,11 +937,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
936937
fn check_callconv<'a>(
937938
&self,
938939
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
939-
exp_abi: Conv,
940+
exp_abi: CanonAbi,
940941
) -> InterpResult<'a, ()> {
941942
if fn_abi.conv != exp_abi {
942943
throw_ub_format!(
943-
"calling a function with calling convention {exp_abi} using caller calling convention {}",
944+
r#"calling a function with calling convention "{exp_abi}" using caller calling convention "{}""#,
944945
fn_abi.conv
945946
);
946947
}
@@ -973,7 +974,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
973974
fn check_abi_and_shim_symbol_clash(
974975
&mut self,
975976
abi: &FnAbi<'tcx, Ty<'tcx>>,
976-
exp_abi: Conv,
977+
exp_abi: CanonAbi,
977978
link_name: Symbol,
978979
) -> InterpResult<'tcx, ()> {
979980
self.check_callconv(abi, exp_abi)?;
@@ -998,7 +999,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
998999
fn check_shim<'a, const N: usize>(
9991000
&mut self,
10001001
abi: &FnAbi<'tcx, Ty<'tcx>>,
1001-
exp_abi: Conv,
1002+
exp_abi: CanonAbi,
10021003
link_name: Symbol,
10031004
args: &'a [OpTy<'tcx>],
10041005
) -> InterpResult<'tcx, &'a [OpTy<'tcx>; N]> {
@@ -1098,7 +1099,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10981099
fn check_shim_variadic<'a, const N: usize>(
10991100
&mut self,
11001101
abi: &FnAbi<'tcx, Ty<'tcx>>,
1101-
exp_abi: Conv,
1102+
exp_abi: CanonAbi,
11021103
link_name: Symbol,
11031104
args: &'a [OpTy<'tcx>],
11041105
) -> InterpResult<'tcx, (&'a [OpTy<'tcx>; N], &'a [OpTy<'tcx>])>

src/intrinsics/atomic.rs

Lines changed: 88 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -26,108 +26,131 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
2626
) -> InterpResult<'tcx, EmulateItemResult> {
2727
let this = self.eval_context_mut();
2828

29-
let intrinsic_structure: Vec<_> = intrinsic_name.split('_').collect();
29+
let get_ord_at = |i: usize| {
30+
let ordering = generic_args.const_at(i).to_value();
31+
ordering.valtree.unwrap_branch()[0].unwrap_leaf().to_atomic_ordering()
32+
};
3033

31-
fn read_ord(ord: &str) -> AtomicReadOrd {
34+
fn read_ord(ord: AtomicOrdering) -> AtomicReadOrd {
3235
match ord {
33-
"seqcst" => AtomicReadOrd::SeqCst,
34-
"acquire" => AtomicReadOrd::Acquire,
35-
"relaxed" => AtomicReadOrd::Relaxed,
36-
_ => panic!("invalid read ordering `{ord}`"),
37-
}
38-
}
39-
40-
fn read_ord_const_generic(o: AtomicOrdering) -> AtomicReadOrd {
41-
match o {
4236
AtomicOrdering::SeqCst => AtomicReadOrd::SeqCst,
4337
AtomicOrdering::Acquire => AtomicReadOrd::Acquire,
4438
AtomicOrdering::Relaxed => AtomicReadOrd::Relaxed,
45-
_ => panic!("invalid read ordering `{o:?}`"),
39+
_ => panic!("invalid read ordering `{ord:?}`"),
4640
}
4741
}
4842

49-
fn write_ord(ord: &str) -> AtomicWriteOrd {
43+
fn write_ord(ord: AtomicOrdering) -> AtomicWriteOrd {
5044
match ord {
51-
"seqcst" => AtomicWriteOrd::SeqCst,
52-
"release" => AtomicWriteOrd::Release,
53-
"relaxed" => AtomicWriteOrd::Relaxed,
54-
_ => panic!("invalid write ordering `{ord}`"),
45+
AtomicOrdering::SeqCst => AtomicWriteOrd::SeqCst,
46+
AtomicOrdering::Release => AtomicWriteOrd::Release,
47+
AtomicOrdering::Relaxed => AtomicWriteOrd::Relaxed,
48+
_ => panic!("invalid write ordering `{ord:?}`"),
5549
}
5650
}
5751

58-
fn rw_ord(ord: &str) -> AtomicRwOrd {
52+
fn rw_ord(ord: AtomicOrdering) -> AtomicRwOrd {
5953
match ord {
60-
"seqcst" => AtomicRwOrd::SeqCst,
61-
"acqrel" => AtomicRwOrd::AcqRel,
62-
"acquire" => AtomicRwOrd::Acquire,
63-
"release" => AtomicRwOrd::Release,
64-
"relaxed" => AtomicRwOrd::Relaxed,
65-
_ => panic!("invalid read-write ordering `{ord}`"),
54+
AtomicOrdering::SeqCst => AtomicRwOrd::SeqCst,
55+
AtomicOrdering::AcqRel => AtomicRwOrd::AcqRel,
56+
AtomicOrdering::Acquire => AtomicRwOrd::Acquire,
57+
AtomicOrdering::Release => AtomicRwOrd::Release,
58+
AtomicOrdering::Relaxed => AtomicRwOrd::Relaxed,
6659
}
6760
}
6861

69-
fn fence_ord(ord: &str) -> AtomicFenceOrd {
62+
fn fence_ord(ord: AtomicOrdering) -> AtomicFenceOrd {
7063
match ord {
71-
"seqcst" => AtomicFenceOrd::SeqCst,
72-
"acqrel" => AtomicFenceOrd::AcqRel,
73-
"acquire" => AtomicFenceOrd::Acquire,
74-
"release" => AtomicFenceOrd::Release,
75-
_ => panic!("invalid fence ordering `{ord}`"),
64+
AtomicOrdering::SeqCst => AtomicFenceOrd::SeqCst,
65+
AtomicOrdering::AcqRel => AtomicFenceOrd::AcqRel,
66+
AtomicOrdering::Acquire => AtomicFenceOrd::Acquire,
67+
AtomicOrdering::Release => AtomicFenceOrd::Release,
68+
_ => panic!("invalid fence ordering `{ord:?}`"),
7669
}
7770
}
7871

79-
match &*intrinsic_structure {
80-
// New-style intrinsics that use const generics
81-
["load"] => {
82-
let ordering = generic_args.const_at(1).to_value();
83-
let ordering =
84-
ordering.valtree.unwrap_branch()[0].unwrap_leaf().to_atomic_ordering();
85-
this.atomic_load(args, dest, read_ord_const_generic(ordering))?;
72+
match intrinsic_name {
73+
"load" => {
74+
let ord = get_ord_at(1);
75+
this.atomic_load(args, dest, read_ord(ord))?;
76+
}
77+
78+
"store" => {
79+
let ord = get_ord_at(1);
80+
this.atomic_store(args, write_ord(ord))?
8681
}
8782

88-
// Old-style intrinsics that have the ordering in the intrinsic name
89-
["store", ord] => this.atomic_store(args, write_ord(ord))?,
90-
91-
["fence", ord] => this.atomic_fence_intrinsic(args, fence_ord(ord))?,
92-
["singlethreadfence", ord] => this.compiler_fence_intrinsic(args, fence_ord(ord))?,
93-
94-
["xchg", ord] => this.atomic_exchange(args, dest, rw_ord(ord))?,
95-
["cxchg", ord1, ord2] =>
96-
this.atomic_compare_exchange(args, dest, rw_ord(ord1), read_ord(ord2))?,
97-
["cxchgweak", ord1, ord2] =>
98-
this.atomic_compare_exchange_weak(args, dest, rw_ord(ord1), read_ord(ord2))?,
99-
100-
["or", ord] =>
101-
this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::BitOr, false), rw_ord(ord))?,
102-
["xor", ord] =>
103-
this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::BitXor, false), rw_ord(ord))?,
104-
["and", ord] =>
105-
this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::BitAnd, false), rw_ord(ord))?,
106-
["nand", ord] =>
107-
this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::BitAnd, true), rw_ord(ord))?,
108-
["xadd", ord] =>
109-
this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::Add, false), rw_ord(ord))?,
110-
["xsub", ord] =>
111-
this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::Sub, false), rw_ord(ord))?,
112-
["min", ord] => {
83+
"fence" => {
84+
let ord = get_ord_at(0);
85+
this.atomic_fence_intrinsic(args, fence_ord(ord))?
86+
}
87+
"singlethreadfence" => {
88+
let ord = get_ord_at(0);
89+
this.compiler_fence_intrinsic(args, fence_ord(ord))?;
90+
}
91+
92+
"xchg" => {
93+
let ord = get_ord_at(1);
94+
this.atomic_exchange(args, dest, rw_ord(ord))?;
95+
}
96+
"cxchg" => {
97+
let ord1 = get_ord_at(1);
98+
let ord2 = get_ord_at(2);
99+
this.atomic_compare_exchange(args, dest, rw_ord(ord1), read_ord(ord2))?;
100+
}
101+
"cxchgweak" => {
102+
let ord1 = get_ord_at(1);
103+
let ord2 = get_ord_at(2);
104+
this.atomic_compare_exchange_weak(args, dest, rw_ord(ord1), read_ord(ord2))?;
105+
}
106+
107+
"or" => {
108+
let ord = get_ord_at(1);
109+
this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::BitOr, false), rw_ord(ord))?;
110+
}
111+
"xor" => {
112+
let ord = get_ord_at(1);
113+
this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::BitXor, false), rw_ord(ord))?;
114+
}
115+
"and" => {
116+
let ord = get_ord_at(1);
117+
this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::BitAnd, false), rw_ord(ord))?;
118+
}
119+
"nand" => {
120+
let ord = get_ord_at(1);
121+
this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::BitAnd, true), rw_ord(ord))?;
122+
}
123+
"xadd" => {
124+
let ord = get_ord_at(1);
125+
this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::Add, false), rw_ord(ord))?;
126+
}
127+
"xsub" => {
128+
let ord = get_ord_at(1);
129+
this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::Sub, false), rw_ord(ord))?;
130+
}
131+
"min" => {
132+
let ord = get_ord_at(1);
113133
// Later we will use the type to indicate signed vs unsigned,
114134
// so make sure it matches the intrinsic name.
115135
assert!(matches!(args[1].layout.ty.kind(), ty::Int(_)));
116136
this.atomic_rmw_op(args, dest, AtomicOp::Min, rw_ord(ord))?;
117137
}
118-
["umin", ord] => {
138+
"umin" => {
139+
let ord = get_ord_at(1);
119140
// Later we will use the type to indicate signed vs unsigned,
120141
// so make sure it matches the intrinsic name.
121142
assert!(matches!(args[1].layout.ty.kind(), ty::Uint(_)));
122143
this.atomic_rmw_op(args, dest, AtomicOp::Min, rw_ord(ord))?;
123144
}
124-
["max", ord] => {
145+
"max" => {
146+
let ord = get_ord_at(1);
125147
// Later we will use the type to indicate signed vs unsigned,
126148
// so make sure it matches the intrinsic name.
127149
assert!(matches!(args[1].layout.ty.kind(), ty::Int(_)));
128150
this.atomic_rmw_op(args, dest, AtomicOp::Max, rw_ord(ord))?;
129151
}
130-
["umax", ord] => {
152+
"umax" => {
153+
let ord = get_ord_at(1);
131154
// Later we will use the type to indicate signed vs unsigned,
132155
// so make sure it matches the intrinsic name.
133156
assert!(matches!(args[1].layout.ty.kind(), ty::Uint(_)));

src/shims/aarch64.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use rustc_abi::CanonAbi;
12
use rustc_middle::mir::BinOp;
23
use rustc_middle::ty::Ty;
34
use rustc_span::Symbol;
4-
use rustc_target::callconv::{Conv, FnAbi};
5+
use rustc_target::callconv::FnAbi;
56

67
use crate::*;
78

@@ -19,7 +20,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1920
let unprefixed_name = link_name.as_str().strip_prefix("llvm.aarch64.").unwrap();
2021
match unprefixed_name {
2122
"isb" => {
22-
let [arg] = this.check_shim(abi, Conv::C, link_name, args)?;
23+
let [arg] = this.check_shim(abi, CanonAbi::C, link_name, args)?;
2324
let arg = this.read_scalar(arg)?.to_i32()?;
2425
match arg {
2526
// SY ("full system scope")
@@ -37,7 +38,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
3738
// `left` input, the second half of the output from the `right` input.
3839
// https://developer.arm.com/architectures/instruction-sets/intrinsics/vpmaxq_u8
3940
"neon.umaxp.v16i8" => {
40-
let [left, right] = this.check_shim(abi, Conv::C, link_name, args)?;
41+
let [left, right] = this.check_shim(abi, CanonAbi::C, link_name, args)?;
4142

4243
let (left, left_len) = this.project_to_simd(left)?;
4344
let (right, right_len) = this.project_to_simd(right)?;

0 commit comments

Comments
 (0)