Skip to content

Commit d9d6df9

Browse files
committed
Auto merge of #881 - RalfJung:rustup, r=RalfJung
adjust for rustc changes
2 parents d0e8850 + a41ec9a commit d9d6df9

12 files changed

+40
-69
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8e917f48382c6afaf50568263b89d35fba5d98e4
1+
a45743345659c775b01484574af2818c46a2cb03

src/eval.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
4141
let main_mir = ecx.load_mir(main_instance.def)?;
4242

4343
if !main_mir.return_ty().is_unit() || main_mir.arg_count != 0 {
44-
throw_unsup!(Unimplemented(
44+
throw_unsup_format!(
4545
"miri does not support main functions without `fn()` type signatures"
46-
.to_owned(),
47-
));
46+
);
4847
}
4948

5049
let start_id = tcx.lang_items().start_fn().unwrap();
@@ -60,10 +59,10 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
6059
let start_mir = ecx.load_mir(start_instance.def)?;
6160

6261
if start_mir.arg_count != 3 {
63-
throw_unsup!(AbiViolation(format!(
62+
bug!(
6463
"'start' lang item should have three arguments, but has {}",
6564
start_mir.arg_count
66-
)));
65+
);
6766
}
6867

6968
// Return value (in static memory so that it does not count as leak).

src/machine.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
247247
let data = vec![0; size.bytes() as usize];
248248
Allocation::from_bytes(&data, tcx.data_layout.pointer_align.abi)
249249
}
250-
_ => throw_unsup!(Unimplemented(
251-
format!("can't access foreign static: {}", link_name),
252-
)),
250+
_ => throw_unsup_format!("can't access foreign static: {}", link_name),
253251
};
254252
Ok(Cow::Owned(alloc))
255253
}

src/shims/dlsym.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ impl Dlsym {
1616
"getentropy" => Some(GetEntropy),
1717
"__pthread_get_minstack" => None,
1818
_ =>
19-
throw_unsup!(Unimplemented(format!(
20-
"Unsupported dlsym: {}", name
21-
))),
19+
throw_unsup_format!("Unsupported dlsym: {}", name),
2220
})
2321
}
2422
}

src/shims/foreign_items.rs

+14-29
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
141141
// First: functions that diverge.
142142
match link_name {
143143
"__rust_start_panic" | "panic_impl" => {
144-
throw_unsup!(MachineError("the evaluated program panicked".to_string()));
144+
throw_unsup_format!("the evaluated program panicked");
145145
}
146146
"exit" | "ExitProcess" => {
147147
// it's really u32 for ExitProcess, but we have to put it into the `Exit` error variant anyway
148148
let code = this.read_scalar(args[0])?.to_i32()?;
149149
return Err(InterpError::Exit(code).into());
150150
}
151151
_ => if dest.is_none() {
152-
throw_unsup!(Unimplemented(
153-
format!("can't call diverging foreign function: {}", link_name),
154-
));
152+
throw_unsup_format!("can't call (diverging) foreign function: {}", link_name);
155153
}
156154
}
157155

@@ -179,16 +177,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
179177
if !align.is_power_of_two() {
180178
throw_unsup!(HeapAllocNonPowerOfTwoAlignment(align));
181179
}
182-
/*
183-
FIXME: This check is disabled because rustc violates it.
184-
See <https://github.com/rust-lang/rust/issues/62251>.
185180
if align < this.pointer_size().bytes() {
186-
throw_unsup!(MachineError(format!(
181+
throw_ub_format!(
187182
"posix_memalign: alignment must be at least the size of a pointer, but is {}",
188183
align,
189-
)));
184+
);
190185
}
191-
*/
186+
192187
if size == 0 {
193188
this.write_null(ret.into())?;
194189
} else {
@@ -309,9 +304,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
309304
this.write_scalar(Scalar::from_uint(len, dest.layout.size), dest)?;
310305
}
311306
id => {
312-
throw_unsup!(Unimplemented(
313-
format!("miri does not support syscall ID {}", id),
314-
))
307+
throw_unsup_format!("miri does not support syscall ID {}", id)
315308
}
316309
}
317310
}
@@ -359,12 +352,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
359352
)?;
360353
let mut args = this.frame().body.args_iter();
361354

362-
let arg_local = args.next().ok_or_else(||
363-
err_unsup!(AbiViolation(
364-
"Argument to __rust_maybe_catch_panic does not take enough arguments."
365-
.to_owned(),
366-
)),
367-
)?;
355+
let arg_local = args.next()
356+
.expect("Argument to __rust_maybe_catch_panic does not take enough arguments.");
368357
let arg_dest = this.local_place(arg_local)?;
369358
this.write_scalar(data, arg_dest)?;
370359

@@ -641,9 +630,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
641630
if let Some(result) = result {
642631
this.write_scalar(result, dest)?;
643632
} else {
644-
throw_unsup!(Unimplemented(
645-
format!("Unimplemented sysconf name: {}", name),
646-
));
633+
throw_unsup_format!("Unimplemented sysconf name: {}", name)
647634
}
648635
}
649636

@@ -670,9 +657,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
670657
// This is `libc::pthread_key_t`.
671658
let key_type = args[0].layout.ty
672659
.builtin_deref(true)
673-
.ok_or_else(|| err_unsup!(
674-
AbiViolation("wrong signature used for `pthread_key_create`: first argument must be a raw pointer.".to_owned())
675-
))?
660+
.ok_or_else(|| err_ub!(Ub(format!(
661+
"wrong signature used for `pthread_key_create`: first argument must be a raw pointer."
662+
))))?
676663
.ty;
677664
let key_layout = this.layout_of(key_type)?;
678665

@@ -738,7 +725,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
738725

739726
// We don't support threading. (Also for Windows.)
740727
"pthread_create" | "CreateThread" => {
741-
throw_unsup!(Unimplemented(format!("Miri does not support threading")));
728+
throw_unsup_format!("Miri does not support threading");
742729
}
743730

744731
// Stub out calls for condvar, mutex and rwlock, to just return `0`.
@@ -957,9 +944,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
957944

958945
// We can't execute anything else.
959946
_ => {
960-
throw_unsup!(Unimplemented(
961-
format!("can't call foreign function: {}", link_name),
962-
));
947+
throw_unsup_format!("can't call foreign function: {}", link_name)
963948
}
964949
}
965950

src/shims/intrinsics.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
133133
"atomic_xsub_relaxed" => {
134134
let ptr = this.deref_operand(args[0])?;
135135
if !ptr.layout.ty.is_integral() {
136-
throw_unsup!(Unimplemented(format!("Atomic arithmetic operations only work on integer types")));
136+
bug!("Atomic arithmetic operations only work on integer types");
137137
}
138138
let rhs = this.read_immediate(args[1])?;
139139
let old = this.read_immediate(ptr.into())?;
@@ -279,9 +279,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
279279
// Check if `b` is -1, which is the "min_value / -1" case.
280280
let minus1 = Scalar::from_int(-1, dest.layout.size);
281281
return Err(if b.to_scalar().unwrap() == minus1 {
282-
err_unsup!(Intrinsic(format!("exact_div: result of dividing MIN by -1 cannot be represented")))
282+
err_ub!(Ub(format!("exact_div: result of dividing MIN by -1 cannot be represented")))
283283
} else {
284-
err_unsup!(Intrinsic(format!("exact_div: {:?} cannot be divided by {:?} without remainder", *a, *b)))
284+
err_ub!(Ub(format!("exact_div: {:?} cannot be divided by {:?} without remainder", *a, *b)))
285285
}.into());
286286
}
287287
this.binop_ignore_overflow(mir::BinOp::Div, a, b, dest)?;
@@ -350,7 +350,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
350350
let ty = substs.type_at(0);
351351
let layout = this.layout_of(ty)?;
352352
if layout.abi.is_uninhabited() {
353-
throw_unsup!(Intrinsic(format!("Trying to instantiate uninhabited type {}", ty)))
353+
throw_ub_format!("Trying to instantiate uninhabited type {}", ty)
354354
}
355355
}
356356

@@ -444,7 +444,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
444444
let r = this.read_immediate(args[1])?;
445445
let rval = r.to_scalar()?.to_bits(args[1].layout.size)?;
446446
if rval == 0 {
447-
throw_unsup!(Intrinsic(format!("Division by 0 in unchecked_div")));
447+
throw_ub_format!("Division by 0 in unchecked_div");
448448
}
449449
this.binop_ignore_overflow(
450450
mir::BinOp::Div,
@@ -459,7 +459,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
459459
let r = this.read_immediate(args[1])?;
460460
let rval = r.to_scalar()?.to_bits(args[1].layout.size)?;
461461
if rval == 0 {
462-
throw_unsup!(Intrinsic(format!("Division by 0 in unchecked_rem")));
462+
throw_ub_format!("Division by 0 in unchecked_rem");
463463
}
464464
this.binop_ignore_overflow(
465465
mir::BinOp::Rem,
@@ -480,7 +480,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
480480
};
481481
let (res, overflowed) = this.binary_op(op, l, r)?;
482482
if overflowed {
483-
throw_unsup!(Intrinsic(format!("Overflowing arithmetic in {}", intrinsic_name.get())));
483+
throw_ub_format!("Overflowing arithmetic in {}", intrinsic_name.get());
484484
}
485485
this.write_scalar(res, dest)?;
486486
}
@@ -504,7 +504,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
504504
}
505505
}
506506

507-
name => throw_unsup!(Unimplemented(format!("unimplemented intrinsic: {}", name))),
507+
name => throw_unsup_format!("unimplemented intrinsic: {}", name),
508508
}
509509

510510
Ok(())

src/shims/tls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
158158
StackPopCleanup::None { cleanup: true },
159159
)?;
160160
let arg_local = this.frame().body.args_iter().next().ok_or_else(
161-
|| err_unsup!(AbiViolation("TLS dtor does not take enough arguments.".to_owned())),
161+
|| err_ub!(Ub(format!("TLS dtor does not take enough arguments."))),
162162
)?;
163163
let dest = this.local_place(arg_local)?;
164164
this.write_scalar(ptr, dest)?;

src/stacked_borrows.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,14 @@ impl<'tcx> Stack {
273273
if let Some(call) = item.protector {
274274
if global.is_active(call) {
275275
if let Some(tag) = tag {
276-
throw_unsup!(MachineError(format!(
276+
throw_ub_format!(
277277
"not granting access to tag {:?} because incompatible item is protected: {:?}",
278278
tag, item
279-
)));
279+
);
280280
} else {
281-
throw_unsup!(MachineError(format!(
281+
throw_ub_format!(
282282
"deallocating while item is protected: {:?}", item
283-
)));
283+
);
284284
}
285285
}
286286
}
@@ -299,7 +299,7 @@ impl<'tcx> Stack {
299299

300300
// Step 1: Find granting item.
301301
let granting_idx = self.find_granting(access, tag)
302-
.ok_or_else(|| err_unsup!(MachineError(format!(
302+
.ok_or_else(|| err_ub!(Ub(format!(
303303
"no item granting {} to tag {:?} found in borrow stack",
304304
access, tag,
305305
))))?;
@@ -346,7 +346,7 @@ impl<'tcx> Stack {
346346
) -> InterpResult<'tcx> {
347347
// Step 1: Find granting item.
348348
self.find_granting(AccessKind::Write, tag)
349-
.ok_or_else(|| err_unsup!(MachineError(format!(
349+
.ok_or_else(|| err_ub!(Ub(format!(
350350
"no item granting write access for deallocation to tag {:?} found in borrow stack",
351351
tag,
352352
))))?;
@@ -378,7 +378,7 @@ impl<'tcx> Stack {
378378
// Now we figure out which item grants our parent (`derived_from`) this kind of access.
379379
// We use that to determine where to put the new item.
380380
let granting_idx = self.find_granting(access, derived_from)
381-
.ok_or_else(|| err_unsup!(MachineError(format!(
381+
.ok_or_else(|| err_ub!(Ub(format!(
382382
"trying to reborrow for {:?}, but parent tag {:?} does not have an appropriate item in the borrow stack", new.perm, derived_from,
383383
))))?;
384384

tests/compile-fail/atomic_non_integer_arithmetic.rs

-9
This file was deleted.

tests/compile-fail/ctlz_nonzero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ pub fn main() {
1010
unsafe {
1111
use crate::rusti::*;
1212

13-
ctlz_nonzero(0u8); //~ ERROR ctlz_nonzero called on 0
13+
ctlz_nonzero(0u8); //~ ERROR `ctlz_nonzero` called on 0
1414
}
1515
}

tests/compile-fail/cttz_nonzero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ pub fn main() {
1010
unsafe {
1111
use crate::rusti::*;
1212

13-
cttz_nonzero(0u8); //~ ERROR cttz_nonzero called on 0
13+
cttz_nonzero(0u8); //~ ERROR `cttz_nonzero` called on 0
1414
}
1515
}

tests/compile-fail/overflowing-unchecked-rsh.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::intrinsics::*;
44

5-
//error-pattern: Overflowing shift by 64 in unchecked_shr
5+
//error-pattern: Overflowing shift by 64 in `unchecked_shr`
66

77
fn main() {
88
unsafe {

0 commit comments

Comments
 (0)