Skip to content

Commit b820c76

Browse files
committed
Auto merge of #62428 - Centril:rollup-2udow5e, r=Centril
Rollup of 7 pull requests Successful merges: - #62151 (Update linked OpenSSL version) - #62245 (Miri engine: support extra function (pointer) values) - #62257 (forward read_c_str method from Memory to Alloc) - #62264 (Fix perf regression from Miri Machine trait changes) - #62296 (request at least ptr-size alignment from posix_memalign) - #62329 (Remove support for 1-token lookahead from the lexer) - #62377 (Add test for ICE #62375) Failed merges: r? @ghost
2 parents 481068a + 46edb51 commit b820c76

25 files changed

+511
-385
lines changed

Cargo.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -1835,7 +1835,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
18351835

18361836
[[package]]
18371837
name = "openssl-src"
1838-
version = "111.1.0+1.1.1a"
1838+
version = "111.3.0+1.1.1c"
18391839
source = "registry+https://github.com/rust-lang/crates.io-index"
18401840
dependencies = [
18411841
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1848,7 +1848,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
18481848
dependencies = [
18491849
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
18501850
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
1851-
"openssl-src 111.1.0+1.1.1a (registry+https://github.com/rust-lang/crates.io-index)",
1851+
"openssl-src 111.3.0+1.1.1c (registry+https://github.com/rust-lang/crates.io-index)",
18521852
"pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
18531853
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
18541854
"vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -4384,7 +4384,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
43844384
"checksum opener 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "998c59e83d9474c01127a96e023b7a04bb061dd286bf8bb939d31dc8d31a7448"
43854385
"checksum openssl 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ec7bd7ca4cce6dbdc77e7c1230682740d307d1218a87fb0349a571272be749f9"
43864386
"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
4387-
"checksum openssl-src 111.1.0+1.1.1a (registry+https://github.com/rust-lang/crates.io-index)" = "26bb632127731bf4ac49bf86a5dde12d2ca0918c2234fc39d79d4da2ccbc6da7"
4387+
"checksum openssl-src 111.3.0+1.1.1c (registry+https://github.com/rust-lang/crates.io-index)" = "53ed5f31d294bdf5f7a4ba0a206c2754b0f60e9a63b7e3076babc5317873c797"
43884388
"checksum openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)" = "33c86834957dd5b915623e94f2f4ab2c70dd8f6b70679824155d5ae21dbd495d"
43894389
"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
43904390
"checksum ordslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dd20eec3dbe4376829cb7d80ae6ac45e0a766831dca50202ff2d40db46a8a024"

src/liballoc/tests/heap.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::alloc::{Global, Alloc, Layout, System};
22

3-
/// Issue #45955.
3+
/// Issue #45955 and #62251.
44
#[test]
55
fn alloc_system_overaligned_request() {
66
check_overalign_requests(System)
@@ -12,21 +12,23 @@ fn std_heap_overaligned_request() {
1212
}
1313

1414
fn check_overalign_requests<T: Alloc>(mut allocator: T) {
15-
let size = 8;
16-
let align = 16; // greater than size
17-
let iterations = 100;
18-
unsafe {
19-
let pointers: Vec<_> = (0..iterations).map(|_| {
20-
allocator.alloc(Layout::from_size_align(size, align).unwrap()).unwrap()
21-
}).collect();
22-
for &ptr in &pointers {
23-
assert_eq!((ptr.as_ptr() as usize) % align, 0,
24-
"Got a pointer less aligned than requested")
25-
}
15+
for &align in &[4, 8, 16, 32] { // less than and bigger than `MIN_ALIGN`
16+
for &size in &[align/2, align-1] { // size less than alignment
17+
let iterations = 128;
18+
unsafe {
19+
let pointers: Vec<_> = (0..iterations).map(|_| {
20+
allocator.alloc(Layout::from_size_align(size, align).unwrap()).unwrap()
21+
}).collect();
22+
for &ptr in &pointers {
23+
assert_eq!((ptr.as_ptr() as usize) % align, 0,
24+
"Got a pointer less aligned than requested")
25+
}
2626

27-
// Clean up
28-
for &ptr in &pointers {
29-
allocator.dealloc(ptr, Layout::from_size_align(size, align).unwrap())
27+
// Clean up
28+
for &ptr in &pointers {
29+
allocator.dealloc(ptr, Layout::from_size_align(size, align).unwrap())
30+
}
31+
}
3032
}
3133
}
3234
}

src/librustc_mir/const_eval.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc::hir::def::DefKind;
1111
use rustc::hir::def_id::DefId;
1212
use rustc::mir::interpret::{ConstEvalErr, ErrorHandled, ScalarMaybeUndef};
1313
use rustc::mir;
14-
use rustc::ty::{self, TyCtxt, query::TyCtxtAt};
14+
use rustc::ty::{self, TyCtxt};
1515
use rustc::ty::layout::{self, LayoutOf, VariantIdx};
1616
use rustc::ty::subst::Subst;
1717
use rustc::traits::Reveal;
@@ -23,7 +23,7 @@ use crate::interpret::{self,
2323
PlaceTy, MPlaceTy, OpTy, ImmTy, Immediate, Scalar,
2424
RawConst, ConstValue,
2525
InterpResult, InterpErrorInfo, InterpError, GlobalId, InterpCx, StackPopCleanup,
26-
Allocation, AllocId, MemoryKind, Memory,
26+
Allocation, AllocId, MemoryKind,
2727
snapshot, RefTracking, intern_const_alloc_recursive,
2828
};
2929

@@ -316,6 +316,7 @@ impl interpret::MayLeak for ! {
316316
impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, 'tcx> {
317317
type MemoryKinds = !;
318318
type PointerTag = ();
319+
type ExtraFnVal = !;
319320

320321
type FrameExtra = ();
321322
type MemoryExtra = ();
@@ -370,6 +371,16 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
370371
}))
371372
}
372373

374+
fn call_extra_fn(
375+
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
376+
fn_val: !,
377+
_args: &[OpTy<'tcx>],
378+
_dest: Option<PlaceTy<'tcx>>,
379+
_ret: Option<mir::BasicBlock>,
380+
) -> InterpResult<'tcx> {
381+
match fn_val {}
382+
}
383+
373384
fn call_intrinsic(
374385
ecx: &mut InterpCx<'mir, 'tcx, Self>,
375386
instance: ty::Instance<'tcx>,
@@ -398,27 +409,27 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
398409
}
399410

400411
fn find_foreign_static(
412+
_tcx: TyCtxt<'tcx>,
401413
_def_id: DefId,
402-
_tcx: TyCtxtAt<'tcx>,
403414
) -> InterpResult<'tcx, Cow<'tcx, Allocation<Self::PointerTag>>> {
404415
err!(ReadForeignStatic)
405416
}
406417

407418
#[inline(always)]
408419
fn tag_allocation<'b>(
420+
_memory_extra: &(),
409421
_id: AllocId,
410422
alloc: Cow<'b, Allocation>,
411423
_kind: Option<MemoryKind<!>>,
412-
_memory: &Memory<'mir, 'tcx, Self>,
413424
) -> (Cow<'b, Allocation<Self::PointerTag>>, Self::PointerTag) {
414425
// We do not use a tag so we can just cheaply forward the allocation
415426
(alloc, ())
416427
}
417428

418429
#[inline(always)]
419430
fn tag_static_base_pointer(
431+
_memory_extra: &(),
420432
_id: AllocId,
421-
_memory: &Memory<'mir, 'tcx, Self>,
422433
) -> Self::PointerTag {
423434
()
424435
}

src/librustc_mir/interpret/cast.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc::mir::interpret::{
1111
};
1212
use rustc::mir::CastKind;
1313

14-
use super::{InterpCx, Machine, PlaceTy, OpTy, Immediate};
14+
use super::{InterpCx, Machine, PlaceTy, OpTy, Immediate, FnVal};
1515

1616
impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1717
fn type_is_fat_ptr(&self, ty: Ty<'tcx>) -> bool {
@@ -86,7 +86,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
8686
def_id,
8787
substs,
8888
).ok_or_else(|| InterpError::TooGeneric.into());
89-
let fn_ptr = self.memory.create_fn_alloc(instance?);
89+
let fn_ptr = self.memory.create_fn_alloc(FnVal::Instance(instance?));
9090
self.write_scalar(Scalar::Ptr(fn_ptr.into()), dest)?;
9191
}
9292
_ => bug!("reify fn pointer on {:?}", src.layout.ty),
@@ -115,7 +115,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
115115
substs,
116116
ty::ClosureKind::FnOnce,
117117
);
118-
let fn_ptr = self.memory.create_fn_alloc(instance);
118+
let fn_ptr = self.memory.create_fn_alloc(FnVal::Instance(instance));
119119
let val = Immediate::Scalar(Scalar::Ptr(fn_ptr.into()).into());
120120
self.write_immediate(val, dest)?;
121121
}

src/librustc_mir/interpret/eval_context.rs

+38-36
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,23 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
222222
&mut self.memory
223223
}
224224

225+
#[inline(always)]
226+
pub fn force_ptr(
227+
&self,
228+
scalar: Scalar<M::PointerTag>,
229+
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
230+
self.memory.force_ptr(scalar)
231+
}
232+
233+
#[inline(always)]
234+
pub fn force_bits(
235+
&self,
236+
scalar: Scalar<M::PointerTag>,
237+
size: Size
238+
) -> InterpResult<'tcx, u128> {
239+
self.memory.force_bits(scalar, size)
240+
}
241+
225242
#[inline(always)]
226243
pub fn tag_static_base_pointer(&self, ptr: Pointer) -> Pointer<M::PointerTag> {
227244
self.memory.tag_static_base_pointer(ptr)
@@ -253,6 +270,27 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
253270
self.frame().body
254271
}
255272

273+
#[inline(always)]
274+
pub fn sign_extend(&self, value: u128, ty: TyLayout<'_>) -> u128 {
275+
assert!(ty.abi.is_signed());
276+
sign_extend(value, ty.size)
277+
}
278+
279+
#[inline(always)]
280+
pub fn truncate(&self, value: u128, ty: TyLayout<'_>) -> u128 {
281+
truncate(value, ty.size)
282+
}
283+
284+
#[inline]
285+
pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
286+
ty.is_sized(self.tcx, self.param_env)
287+
}
288+
289+
#[inline]
290+
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
291+
ty.is_freeze(*self.tcx, self.param_env, DUMMY_SP)
292+
}
293+
256294
pub(super) fn subst_and_normalize_erasing_regions<T: TypeFoldable<'tcx>>(
257295
&self,
258296
substs: T,
@@ -288,14 +326,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
288326
).ok_or_else(|| InterpError::TooGeneric.into())
289327
}
290328

291-
pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
292-
ty.is_sized(self.tcx, self.param_env)
293-
}
294-
295-
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
296-
ty.is_freeze(*self.tcx, self.param_env, DUMMY_SP)
297-
}
298-
299329
pub fn load_mir(
300330
&self,
301331
instance: ty::InstanceDef<'tcx>,
@@ -766,32 +796,4 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
766796
trace!("generate stacktrace: {:#?}, {:?}", frames, explicit_span);
767797
frames
768798
}
769-
770-
#[inline(always)]
771-
pub fn sign_extend(&self, value: u128, ty: TyLayout<'_>) -> u128 {
772-
assert!(ty.abi.is_signed());
773-
sign_extend(value, ty.size)
774-
}
775-
776-
#[inline(always)]
777-
pub fn truncate(&self, value: u128, ty: TyLayout<'_>) -> u128 {
778-
truncate(value, ty.size)
779-
}
780-
781-
#[inline(always)]
782-
pub fn force_ptr(
783-
&self,
784-
scalar: Scalar<M::PointerTag>,
785-
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
786-
self.memory.force_ptr(scalar)
787-
}
788-
789-
#[inline(always)]
790-
pub fn force_bits(
791-
&self,
792-
scalar: Scalar<M::PointerTag>,
793-
size: Size
794-
) -> InterpResult<'tcx, u128> {
795-
self.memory.force_bits(scalar, size)
796-
}
797799
}

src/librustc_mir/interpret/machine.rs

+29-12
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use std::hash::Hash;
77

88
use rustc::hir::def_id::DefId;
99
use rustc::mir;
10-
use rustc::ty::{self, query::TyCtxtAt};
10+
use rustc::ty::{self, TyCtxt};
1111

1212
use super::{
13-
Allocation, AllocId, InterpResult, Scalar, AllocationExtra,
14-
InterpCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer, Memory
13+
Allocation, AllocId, InterpResult, InterpError, Scalar, AllocationExtra,
14+
InterpCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer, Memory,
1515
};
1616

1717
/// Whether this kind of memory is allowed to leak
@@ -67,6 +67,11 @@ pub trait Machine<'mir, 'tcx>: Sized {
6767
/// The `default()` is used for pointers to consts, statics, vtables and functions.
6868
type PointerTag: ::std::fmt::Debug + Copy + Eq + Hash + 'static;
6969

70+
/// Machines can define extra (non-instance) things that represent values of function pointers.
71+
/// For example, Miri uses this to return a fucntion pointer from `dlsym`
72+
/// that can later be called to execute the right thing.
73+
type ExtraFnVal: ::std::fmt::Debug + Copy;
74+
7075
/// Extra data stored in every call frame.
7176
type FrameExtra;
7277

@@ -119,6 +124,16 @@ pub trait Machine<'mir, 'tcx>: Sized {
119124
ret: Option<mir::BasicBlock>,
120125
) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>>;
121126

127+
/// Execute `fn_val`. it is the hook's responsibility to advance the instruction
128+
/// pointer as appropriate.
129+
fn call_extra_fn(
130+
ecx: &mut InterpCx<'mir, 'tcx, Self>,
131+
fn_val: Self::ExtraFnVal,
132+
args: &[OpTy<'tcx, Self::PointerTag>],
133+
dest: Option<PlaceTy<'tcx, Self::PointerTag>>,
134+
ret: Option<mir::BasicBlock>,
135+
) -> InterpResult<'tcx>;
136+
122137
/// Directly process an intrinsic without pushing a stack frame.
123138
/// If this returns successfully, the engine will take care of jumping to the next block.
124139
fn call_intrinsic(
@@ -136,8 +151,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
136151
///
137152
/// This allocation will then be fed to `tag_allocation` to initialize the "extra" state.
138153
fn find_foreign_static(
154+
tcx: TyCtxt<'tcx>,
139155
def_id: DefId,
140-
tcx: TyCtxtAt<'tcx>,
141156
) -> InterpResult<'tcx, Cow<'tcx, Allocation>>;
142157

143158
/// Called for all binary operations on integer(-like) types when one operand is a pointer
@@ -174,10 +189,10 @@ pub trait Machine<'mir, 'tcx>: Sized {
174189
/// For static allocations, the tag returned must be the same as the one returned by
175190
/// `tag_static_base_pointer`.
176191
fn tag_allocation<'b>(
192+
memory_extra: &Self::MemoryExtra,
177193
id: AllocId,
178194
alloc: Cow<'b, Allocation>,
179195
kind: Option<MemoryKind<Self::MemoryKinds>>,
180-
memory: &Memory<'mir, 'tcx, Self>,
181196
) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, Self::PointerTag);
182197

183198
/// Return the "base" tag for the given static allocation: the one that is used for direct
@@ -186,8 +201,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
186201
/// Be aware that requesting the `Allocation` for that `id` will lead to cycles
187202
/// for cyclic statics!
188203
fn tag_static_base_pointer(
204+
memory_extra: &Self::MemoryExtra,
189205
id: AllocId,
190-
memory: &Memory<'mir, 'tcx, Self>,
191206
) -> Self::PointerTag;
192207

193208
/// Executes a retagging operation
@@ -209,20 +224,22 @@ pub trait Machine<'mir, 'tcx>: Sized {
209224
extra: Self::FrameExtra,
210225
) -> InterpResult<'tcx>;
211226

227+
#[inline(always)]
212228
fn int_to_ptr(
213-
int: u64,
214229
_mem: &Memory<'mir, 'tcx, Self>,
230+
int: u64,
215231
) -> InterpResult<'tcx, Pointer<Self::PointerTag>> {
216-
if int == 0 {
217-
err!(InvalidNullPointerUsage)
232+
Err((if int == 0 {
233+
InterpError::InvalidNullPointerUsage
218234
} else {
219-
err!(ReadBytesAsPointer)
220-
}
235+
InterpError::ReadBytesAsPointer
236+
}).into())
221237
}
222238

239+
#[inline(always)]
223240
fn ptr_to_int(
224-
_ptr: Pointer<Self::PointerTag>,
225241
_mem: &Memory<'mir, 'tcx, Self>,
242+
_ptr: Pointer<Self::PointerTag>,
226243
) -> InterpResult<'tcx, u64> {
227244
err!(ReadPointerAsBytes)
228245
}

0 commit comments

Comments
 (0)