Skip to content

Commit f463621

Browse files
committed
Auto merge of #878 - RalfJung:rustup, r=RalfJung
Rustup for error changes
2 parents 079b53e + 312b546 commit f463621

File tree

11 files changed

+78
-78
lines changed

11 files changed

+78
-78
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8b94e9e9188b65df38a5f1ae723617dc2dfb3155
1+
d7270712cb446aad0817040bbca73a8d024f67b0

src/eval.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ 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-
return err!(Unimplemented(
44+
throw_unsup!(Unimplemented(
4545
"miri does not support main functions without `fn()` type signatures"
4646
.to_owned(),
4747
));
@@ -60,7 +60,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
6060
let start_mir = ecx.load_mir(start_instance.def)?;
6161

6262
if start_mir.arg_count != 3 {
63-
return err!(AbiViolation(format!(
63+
throw_unsup!(AbiViolation(format!(
6464
"'start' lang item should have three arguments, but has {}",
6565
start_mir.arg_count
6666
)));
@@ -200,7 +200,7 @@ pub fn eval_main<'tcx>(
200200
// Special treatment for some error kinds
201201
let msg = match e.kind {
202202
InterpError::Exit(code) => std::process::exit(code),
203-
InterpError::NoMirFor(..) =>
203+
err_unsup!(NoMirFor(..)) =>
204204
format!("{}. Did you set `MIRI_SYSROOT` to a Miri-enabled sysroot? You can prepare one with `cargo miri setup`.", e),
205205
_ => e.to_string()
206206
};

src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
4242
})
4343
.ok_or_else(|| {
4444
let path = path.iter().map(|&s| s.to_owned()).collect();
45-
InterpError::PathNotFound(path).into()
45+
err_unsup!(PathNotFound(path)).into()
4646
})
4747
}
4848

src/intptrcast.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ impl<'mir, 'tcx> GlobalState {
4343
memory: &Memory<'mir, 'tcx, Evaluator<'tcx>>,
4444
) -> InterpResult<'tcx, Pointer<Tag>> {
4545
if int == 0 {
46-
return err!(InvalidNullPointerUsage);
46+
throw_unsup!(InvalidNullPointerUsage);
4747
}
4848

4949
let global_state = memory.extra.intptrcast.borrow();
5050

51-
match global_state.int_to_ptr_map.binary_search_by_key(&int, |(addr, _)| *addr) {
51+
Ok(match global_state.int_to_ptr_map.binary_search_by_key(&int, |(addr, _)| *addr) {
5252
Ok(pos) => {
5353
let (_, alloc_id) = global_state.int_to_ptr_map[pos];
5454
// `int` is equal to the starting address for an allocation, the offset should be
5555
// zero. The pointer is untagged because it was created from a cast
56-
Ok(Pointer::new_with_tag(alloc_id, Size::from_bytes(0), Tag::Untagged))
56+
Pointer::new_with_tag(alloc_id, Size::from_bytes(0), Tag::Untagged)
5757
},
58-
Err(0) => err!(DanglingPointerDeref),
58+
Err(0) => throw_unsup!(DanglingPointerDeref),
5959
Err(pos) => {
6060
// This is the largest of the adresses smaller than `int`,
6161
// i.e. the greatest lower bound (glb)
@@ -65,12 +65,12 @@ impl<'mir, 'tcx> GlobalState {
6565
// If the offset exceeds the size of the allocation, this access is illegal
6666
if offset <= memory.get(alloc_id)?.bytes.len() as u64 {
6767
// This pointer is untagged because it was created from a cast
68-
Ok(Pointer::new_with_tag(alloc_id, Size::from_bytes(offset), Tag::Untagged))
68+
Pointer::new_with_tag(alloc_id, Size::from_bytes(offset), Tag::Untagged)
6969
} else {
70-
err!(DanglingPointerDeref)
70+
throw_unsup!(DanglingPointerDeref)
7171
}
7272
}
73-
}
73+
})
7474
}
7575

7676
pub fn ptr_to_int(

src/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +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-
_ => return err!(Unimplemented(
250+
_ => throw_unsup!(Unimplemented(
251251
format!("can't access foreign static: {}", link_name),
252252
)),
253253
};

src/operator.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
9494
let right = right.to_scalar()?;
9595
debug_assert!(left.is_ptr() || right.is_ptr() || bin_op == Offset);
9696

97-
match bin_op {
97+
Ok(match bin_op {
9898
Offset => {
9999
let pointee_ty = left_layout.ty
100100
.builtin_deref(true)
@@ -105,7 +105,7 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
105105
pointee_ty,
106106
right.to_isize(self)?,
107107
)?;
108-
Ok((ptr, false))
108+
(ptr, false)
109109
}
110110
// These need both to be pointer, and fail if they are not in the same location
111111
Lt | Le | Gt | Ge | Sub if left.is_ptr() && right.is_ptr() => {
@@ -130,10 +130,10 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
130130
}
131131
_ => bug!("We already established it has to be one of these operators."),
132132
};
133-
Ok((Scalar::from_bool(res), false))
133+
(Scalar::from_bool(res), false)
134134
} else {
135135
// Both are pointers, but from different allocations.
136-
err!(InvalidPointerMath)
136+
throw_unsup!(InvalidPointerMath)
137137
}
138138
}
139139
Gt | Ge if left.is_ptr() && right.is_bits() => {
@@ -151,10 +151,10 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
151151
};
152152
if result {
153153
// Definitely true!
154-
Ok((Scalar::from_bool(true), false))
154+
(Scalar::from_bool(true), false)
155155
} else {
156156
// Sorry, can't tell.
157-
err!(InvalidPointerMath)
157+
throw_unsup!(InvalidPointerMath)
158158
}
159159
}
160160
// These work if the left operand is a pointer, and the right an integer
@@ -165,7 +165,7 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
165165
left.to_ptr().expect("we checked is_ptr"),
166166
right.to_bits(self.memory().pointer_size()).expect("we checked is_bits"),
167167
right_layout.abi.is_signed(),
168-
)
168+
)?
169169
}
170170
// Commutative operators also work if the integer is on the left
171171
Add | BitAnd if left.is_bits() && right.is_ptr() => {
@@ -175,11 +175,11 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
175175
right.to_ptr().expect("we checked is_ptr"),
176176
left.to_bits(self.memory().pointer_size()).expect("we checked is_bits"),
177177
left_layout.abi.is_signed(),
178-
)
178+
)?
179179
}
180180
// Nothing else works
181-
_ => err!(InvalidPointerMath),
182-
}
181+
_ => throw_unsup!(InvalidPointerMath),
182+
})
183183
}
184184

185185
fn ptr_eq(
@@ -248,7 +248,7 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
248248
let v = Scalar::from_uint((left.offset.bytes() as u128) & right, ptr_size);
249249
(v, false)
250250
} else {
251-
return err!(ReadPointerAsBytes);
251+
throw_unsup!(ReadPointerAsBytes);
252252
}
253253
}
254254

@@ -271,7 +271,7 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
271271
false,
272272
)
273273
} else {
274-
return err!(ReadPointerAsBytes);
274+
throw_unsup!(ReadPointerAsBytes);
275275
}
276276
}
277277

@@ -283,7 +283,7 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
283283
right,
284284
if signed { "signed" } else { "unsigned" }
285285
);
286-
return err!(Unimplemented(msg));
286+
throw_unsup!(Unimplemented(msg));
287287
}
288288
})
289289
}
@@ -298,12 +298,11 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
298298
pointee_ty: Ty<'tcx>,
299299
offset: i64,
300300
) -> InterpResult<'tcx, Scalar<Tag>> {
301-
use rustc::mir::interpret::InterpError::Panic;
302301
// FIXME: assuming here that type size is less than `i64::max_value()`.
303302
let pointee_size = self.layout_of(pointee_ty)?.size.bytes() as i64;
304303
let offset = offset
305304
.checked_mul(pointee_size)
306-
.ok_or_else(|| Panic(PanicMessage::Overflow(mir::BinOp::Mul)))?;
305+
.ok_or_else(|| err_panic!(Overflow(mir::BinOp::Mul)))?;
307306
// Now let's see what kind of pointer this is.
308307
let ptr = if offset == 0 {
309308
match ptr {

src/shims/dlsym.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Dlsym {
1616
"getentropy" => Some(GetEntropy),
1717
"__pthread_get_minstack" => None,
1818
_ =>
19-
return err!(Unimplemented(format!(
19+
throw_unsup!(Unimplemented(format!(
2020
"Unsupported dlsym: {}", name
2121
))),
2222
})

src/shims/foreign_items.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
128128
dest: Option<PlaceTy<'tcx, Tag>>,
129129
ret: Option<mir::BasicBlock>,
130130
) -> InterpResult<'tcx> {
131-
use rustc::mir::interpret::InterpError::Panic;
132131
let this = self.eval_context_mut();
133132
let attrs = this.tcx.get_attrs(def_id);
134133
let link_name = match attr::first_attr_value_str_by_name(&attrs, sym::link_name) {
@@ -142,15 +141,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
142141
// First: functions that diverge.
143142
match link_name {
144143
"__rust_start_panic" | "panic_impl" => {
145-
return err!(MachineError("the evaluated program panicked".to_string()));
144+
throw_unsup!(MachineError("the evaluated program panicked".to_string()));
146145
}
147146
"exit" | "ExitProcess" => {
148147
// it's really u32 for ExitProcess, but we have to put it into the `Exit` error variant anyway
149148
let code = this.read_scalar(args[0])?.to_i32()?;
150-
return err!(Exit(code));
149+
return Err(InterpError::Exit(code).into());
151150
}
152151
_ => if dest.is_none() {
153-
return err!(Unimplemented(
152+
throw_unsup!(Unimplemented(
154153
format!("can't call diverging foreign function: {}", link_name),
155154
));
156155
}
@@ -168,7 +167,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
168167
"calloc" => {
169168
let items = this.read_scalar(args[0])?.to_usize(this)?;
170169
let len = this.read_scalar(args[1])?.to_usize(this)?;
171-
let size = items.checked_mul(len).ok_or_else(|| Panic(PanicMessage::Overflow(mir::BinOp::Mul)))?;
170+
let size = items.checked_mul(len).ok_or_else(|| err_panic!(Overflow(mir::BinOp::Mul)))?;
172171
let res = this.malloc(size, /*zero_init:*/ true, MiriMemoryKind::C);
173172
this.write_scalar(res, dest)?;
174173
}
@@ -178,13 +177,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
178177
let size = this.read_scalar(args[2])?.to_usize(this)?;
179178
// Align must be power of 2, and also at least ptr-sized (POSIX rules).
180179
if !align.is_power_of_two() {
181-
return err!(HeapAllocNonPowerOfTwoAlignment(align));
180+
throw_unsup!(HeapAllocNonPowerOfTwoAlignment(align));
182181
}
183182
/*
184183
FIXME: This check is disabled because rustc violates it.
185184
See <https://github.com/rust-lang/rust/issues/62251>.
186185
if align < this.pointer_size().bytes() {
187-
return err!(MachineError(format!(
186+
throw_unsup!(MachineError(format!(
188187
"posix_memalign: alignment must be at least the size of a pointer, but is {}",
189188
align,
190189
)));
@@ -217,10 +216,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
217216
let size = this.read_scalar(args[0])?.to_usize(this)?;
218217
let align = this.read_scalar(args[1])?.to_usize(this)?;
219218
if size == 0 {
220-
return err!(HeapAllocZeroBytes);
219+
throw_unsup!(HeapAllocZeroBytes);
221220
}
222221
if !align.is_power_of_two() {
223-
return err!(HeapAllocNonPowerOfTwoAlignment(align));
222+
throw_unsup!(HeapAllocNonPowerOfTwoAlignment(align));
224223
}
225224
let ptr = this.memory_mut()
226225
.allocate(
@@ -234,10 +233,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
234233
let size = this.read_scalar(args[0])?.to_usize(this)?;
235234
let align = this.read_scalar(args[1])?.to_usize(this)?;
236235
if size == 0 {
237-
return err!(HeapAllocZeroBytes);
236+
throw_unsup!(HeapAllocZeroBytes);
238237
}
239238
if !align.is_power_of_two() {
240-
return err!(HeapAllocNonPowerOfTwoAlignment(align));
239+
throw_unsup!(HeapAllocNonPowerOfTwoAlignment(align));
241240
}
242241
let ptr = this.memory_mut()
243242
.allocate(
@@ -256,10 +255,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
256255
let old_size = this.read_scalar(args[1])?.to_usize(this)?;
257256
let align = this.read_scalar(args[2])?.to_usize(this)?;
258257
if old_size == 0 {
259-
return err!(HeapAllocZeroBytes);
258+
throw_unsup!(HeapAllocZeroBytes);
260259
}
261260
if !align.is_power_of_two() {
262-
return err!(HeapAllocNonPowerOfTwoAlignment(align));
261+
throw_unsup!(HeapAllocNonPowerOfTwoAlignment(align));
263262
}
264263
let ptr = this.force_ptr(ptr)?;
265264
this.memory_mut().deallocate(
@@ -274,10 +273,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
274273
let align = this.read_scalar(args[2])?.to_usize(this)?;
275274
let new_size = this.read_scalar(args[3])?.to_usize(this)?;
276275
if old_size == 0 || new_size == 0 {
277-
return err!(HeapAllocZeroBytes);
276+
throw_unsup!(HeapAllocZeroBytes);
278277
}
279278
if !align.is_power_of_two() {
280-
return err!(HeapAllocNonPowerOfTwoAlignment(align));
279+
throw_unsup!(HeapAllocNonPowerOfTwoAlignment(align));
281280
}
282281
let align = Align::from_bytes(align).unwrap();
283282
let new_ptr = this.memory_mut().reallocate(
@@ -310,7 +309,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
310309
this.write_scalar(Scalar::from_uint(len, dest.layout.size), dest)?;
311310
}
312311
id => {
313-
return err!(Unimplemented(
312+
throw_unsup!(Unimplemented(
314313
format!("miri does not support syscall ID {}", id),
315314
))
316315
}
@@ -361,10 +360,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
361360
let mut args = this.frame().body.args_iter();
362361

363362
let arg_local = args.next().ok_or_else(||
364-
InterpError::AbiViolation(
363+
err_unsup!(AbiViolation(
365364
"Argument to __rust_maybe_catch_panic does not take enough arguments."
366365
.to_owned(),
367-
),
366+
)),
368367
)?;
369368
let arg_dest = this.local_place(arg_local)?;
370369
this.write_scalar(data, arg_dest)?;
@@ -633,7 +632,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
633632
if let Some(result) = result {
634633
this.write_scalar(result, dest)?;
635634
} else {
636-
return err!(Unimplemented(
635+
throw_unsup!(Unimplemented(
637636
format!("Unimplemented sysconf name: {}", name),
638637
));
639638
}
@@ -662,14 +661,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
662661
// This is `libc::pthread_key_t`.
663662
let key_type = args[0].layout.ty
664663
.builtin_deref(true)
665-
.ok_or_else(|| InterpError::AbiViolation("wrong signature used for `pthread_key_create`: first argument must be a raw pointer.".to_owned()))?
664+
.ok_or_else(|| err_unsup!(
665+
AbiViolation("wrong signature used for `pthread_key_create`: first argument must be a raw pointer.".to_owned())
666+
))?
666667
.ty;
667668
let key_layout = this.layout_of(key_type)?;
668669

669670
// Create key and write it into the memory where `key_ptr` wants it.
670671
let key = this.machine.tls.create_tls_key(dtor) as u128;
671672
if key_layout.size.bits() < 128 && key >= (1u128 << key_layout.size.bits() as u128) {
672-
return err!(OutOfTls);
673+
throw_unsup!(OutOfTls);
673674
}
674675

675676
let key_ptr = this.memory().check_ptr_access(key_ptr, key_layout.size, key_layout.align.abi)?
@@ -728,7 +729,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
728729

729730
// We don't support threading. (Also for Windows.)
730731
"pthread_create" | "CreateThread" => {
731-
return err!(Unimplemented(format!("Miri does not support threading")));
732+
throw_unsup!(Unimplemented(format!("Miri does not support threading")));
732733
}
733734

734735
// Stub out calls for condvar, mutex and rwlock, to just return `0`.
@@ -869,7 +870,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
869870
// Figure out how large a TLS key actually is. This is `c::DWORD`.
870871
if dest.layout.size.bits() < 128
871872
&& key >= (1u128 << dest.layout.size.bits() as u128) {
872-
return err!(OutOfTls);
873+
throw_unsup!(OutOfTls);
873874
}
874875
this.write_scalar(Scalar::from_uint(key, dest.layout.size), dest)?;
875876
}
@@ -947,7 +948,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
947948

948949
// We can't execute anything else.
949950
_ => {
950-
return err!(Unimplemented(
951+
throw_unsup!(Unimplemented(
951952
format!("can't call foreign function: {}", link_name),
952953
));
953954
}

0 commit comments

Comments
 (0)