Skip to content

Commit d1dec9c

Browse files
committed
don't ICE when callee has the wrong number of arguments
1 parent 893843f commit d1dec9c

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

src/helpers.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
181181
let mut callee_args = this.frame().body.args_iter();
182182
for arg in args {
183183
let callee_arg = this.local_place(
184-
callee_args.next().expect("callee has fewer arguments than expected"),
184+
callee_args.next().ok_or_else(||
185+
err_ub_format!("callee has fewer arguments than expected")
186+
)?
185187
)?;
186188
this.write_immediate(*arg, &callee_arg)?;
187189
}
188-
assert_eq!(callee_args.next(), None, "callee has more arguments than expected");
190+
if callee_args.next().is_some() {
191+
throw_ub_format!("callee has more arguments than expected");
192+
}
189193

190194
Ok(())
191195
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// ignore-windows: Concurrency on Windows is not supported yet.
2+
// error-pattern: callee has fewer arguments than expected
3+
4+
//! The thread function must have exactly one argument.
5+
6+
#![feature(rustc_private)]
7+
8+
extern crate libc;
9+
10+
use std::{mem, ptr};
11+
12+
extern "C" fn thread_start() -> *mut libc::c_void {
13+
panic!()
14+
}
15+
16+
fn main() {
17+
unsafe {
18+
let mut native: libc::pthread_t = mem::zeroed();
19+
let attr: libc::pthread_attr_t = mem::zeroed();
20+
// assert_eq!(libc::pthread_attr_init(&mut attr), 0); FIXME: this function is not yet implemented.
21+
let thread_start: extern "C" fn() -> *mut libc::c_void = thread_start;
22+
let thread_start: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void = mem::transmute(thread_start);
23+
assert_eq!(libc::pthread_create(&mut native, &attr, thread_start, ptr::null_mut()), 0);
24+
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// ignore-windows: Concurrency on Windows is not supported yet.
2+
// error-pattern: callee has more arguments than expected
3+
4+
//! The thread function must have exactly one argument.
5+
6+
#![feature(rustc_private)]
7+
8+
extern crate libc;
9+
10+
use std::{mem, ptr};
11+
12+
extern "C" fn thread_start(_null: *mut libc::c_void, _x: i32) -> *mut libc::c_void {
13+
panic!()
14+
}
15+
16+
fn main() {
17+
unsafe {
18+
let mut native: libc::pthread_t = mem::zeroed();
19+
let attr: libc::pthread_attr_t = mem::zeroed();
20+
// assert_eq!(libc::pthread_attr_init(&mut attr), 0); FIXME: this function is not yet implemented.
21+
let thread_start: extern "C" fn(*mut libc::c_void, i32) -> *mut libc::c_void = thread_start;
22+
let thread_start: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void = mem::transmute(thread_start);
23+
assert_eq!(libc::pthread_create(&mut native, &attr, thread_start, ptr::null_mut()), 0);
24+
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
25+
}
26+
}

0 commit comments

Comments
 (0)