Skip to content

Commit ae96420

Browse files
committed
Auto merge of #1739 - RalfJung:rustup, r=RalfJung
rustup
2 parents a653993 + 98f28ac commit ae96420

File tree

8 files changed

+29
-26
lines changed

8 files changed

+29
-26
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a4d9624242df6bfe6c0a298867dd2bd527263424
1+
b3ac52646f7591a811fa9bf55995b24fd17ece08

src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ pub fn check_abi<'a>(abi: Abi, exp_abi: Abi) -> InterpResult<'a, ()> {
559559
if abi == exp_abi {
560560
Ok(())
561561
} else {
562-
throw_ub_format!("calling a function with ABI {:?} using caller ABI {:?}", exp_abi, abi)
562+
throw_ub_format!("calling a function with ABI {} using caller ABI {}", exp_abi.name(), abi.name())
563563
}
564564
}
565565

src/shims/foreign_items.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
146146
| "exit"
147147
| "ExitProcess"
148148
=> {
149-
check_abi(abi, if link_name == "exit" { Abi::C } else { Abi::System })?;
149+
check_abi(abi, if link_name == "exit" { Abi::C { unwind: false } } else { Abi::System { unwind: false } })?;
150150
let &[ref code] = check_arg_count(args)?;
151151
// it's really u32 for ExitProcess, but we have to put it into the `Exit` variant anyway
152152
let code = this.read_scalar(code)?.to_i32()?;
153153
throw_machine_stop!(TerminationInfo::Exit(code.into()));
154154
}
155155
"abort" => {
156-
check_abi(abi, Abi::C)?;
156+
check_abi(abi, Abi::C { unwind: false })?;
157157
throw_machine_stop!(TerminationInfo::Abort("the program aborted execution".to_owned()))
158158
}
159159
_ => throw_unsup_format!("can't call (diverging) foreign function: {}", link_name),
@@ -170,7 +170,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
170170
// Normally, this will be either `libpanic_unwind` or `libpanic_abort`, but it could
171171
// also be a custom user-provided implementation via `#![feature(panic_runtime)]`
172172
"__rust_start_panic" | "__rust_panic_cleanup" => {
173-
check_abi(abi, Abi::C)?;
173+
check_abi(abi, Abi::C { unwind: false })?;
174174
// This replicates some of the logic in `inject_panic_runtime`.
175175
// FIXME: is there a way to reuse that logic?
176176
let panic_runtime = match this.tcx.sess.panic_strategy() {
@@ -236,14 +236,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
236236

237237
// Standard C allocation
238238
"malloc" => {
239-
check_abi(abi, Abi::C)?;
239+
check_abi(abi, Abi::C { unwind: false })?;
240240
let &[ref size] = check_arg_count(args)?;
241241
let size = this.read_scalar(size)?.to_machine_usize(this)?;
242242
let res = this.malloc(size, /*zero_init:*/ false, MiriMemoryKind::C);
243243
this.write_scalar(res, dest)?;
244244
}
245245
"calloc" => {
246-
check_abi(abi, Abi::C)?;
246+
check_abi(abi, Abi::C { unwind: false })?;
247247
let &[ref items, ref len] = check_arg_count(args)?;
248248
let items = this.read_scalar(items)?.to_machine_usize(this)?;
249249
let len = this.read_scalar(len)?.to_machine_usize(this)?;
@@ -253,13 +253,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
253253
this.write_scalar(res, dest)?;
254254
}
255255
"free" => {
256-
check_abi(abi, Abi::C)?;
256+
check_abi(abi, Abi::C { unwind: false })?;
257257
let &[ref ptr] = check_arg_count(args)?;
258258
let ptr = this.read_scalar(ptr)?.check_init()?;
259259
this.free(ptr, MiriMemoryKind::C)?;
260260
}
261261
"realloc" => {
262-
check_abi(abi, Abi::C)?;
262+
check_abi(abi, Abi::C { unwind: false })?;
263263
let &[ref old_ptr, ref new_size] = check_arg_count(args)?;
264264
let old_ptr = this.read_scalar(old_ptr)?.check_init()?;
265265
let new_size = this.read_scalar(new_size)?.to_machine_usize(this)?;
@@ -334,7 +334,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
334334

335335
// C memory handling functions
336336
"memcmp" => {
337-
check_abi(abi, Abi::C)?;
337+
check_abi(abi, Abi::C { unwind: false })?;
338338
let &[ref left, ref right, ref n] = check_arg_count(args)?;
339339
let left = this.read_scalar(left)?.check_init()?;
340340
let right = this.read_scalar(right)?.check_init()?;
@@ -355,7 +355,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
355355
this.write_scalar(Scalar::from_i32(result), dest)?;
356356
}
357357
"memrchr" => {
358-
check_abi(abi, Abi::C)?;
358+
check_abi(abi, Abi::C { unwind: false })?;
359359
let &[ref ptr, ref val, ref num] = check_arg_count(args)?;
360360
let ptr = this.read_scalar(ptr)?.check_init()?;
361361
let val = this.read_scalar(val)?.to_i32()? as u8;
@@ -374,7 +374,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
374374
}
375375
}
376376
"memchr" => {
377-
check_abi(abi, Abi::C)?;
377+
check_abi(abi, Abi::C { unwind: false })?;
378378
let &[ref ptr, ref val, ref num] = check_arg_count(args)?;
379379
let ptr = this.read_scalar(ptr)?.check_init()?;
380380
let val = this.read_scalar(val)?.to_i32()? as u8;
@@ -392,7 +392,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
392392
}
393393
}
394394
"strlen" => {
395-
check_abi(abi, Abi::C)?;
395+
check_abi(abi, Abi::C { unwind: false })?;
396396
let &[ref ptr] = check_arg_count(args)?;
397397
let ptr = this.read_scalar(ptr)?.check_init()?;
398398
let n = this.memory.read_c_str(ptr)?.len();
@@ -408,7 +408,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
408408
| "asinf"
409409
| "atanf"
410410
=> {
411-
check_abi(abi, Abi::C)?;
411+
check_abi(abi, Abi::C { unwind: false })?;
412412
let &[ref f] = check_arg_count(args)?;
413413
// FIXME: Using host floats.
414414
let f = f32::from_bits(this.read_scalar(f)?.to_u32()?);
@@ -428,7 +428,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
428428
| "hypotf"
429429
| "atan2f"
430430
=> {
431-
check_abi(abi, Abi::C)?;
431+
check_abi(abi, Abi::C { unwind: false })?;
432432
let &[ref f1, ref f2] = check_arg_count(args)?;
433433
// underscore case for windows, here and below
434434
// (see https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/floating-point-primitives?view=vs-2019)
@@ -450,7 +450,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
450450
| "asin"
451451
| "atan"
452452
=> {
453-
check_abi(abi, Abi::C)?;
453+
check_abi(abi, Abi::C { unwind: false })?;
454454
let &[ref f] = check_arg_count(args)?;
455455
// FIXME: Using host floats.
456456
let f = f64::from_bits(this.read_scalar(f)?.to_u64()?);
@@ -470,7 +470,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
470470
| "hypot"
471471
| "atan2"
472472
=> {
473-
check_abi(abi, Abi::C)?;
473+
check_abi(abi, Abi::C { unwind: false })?;
474474
let &[ref f1, ref f2] = check_arg_count(args)?;
475475
// FIXME: Using host floats.
476476
let f1 = f64::from_bits(this.read_scalar(f1)?.to_u64()?);
@@ -486,7 +486,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
486486
| "ldexp"
487487
| "scalbn"
488488
=> {
489-
check_abi(abi, Abi::C)?;
489+
check_abi(abi, Abi::C { unwind: false })?;
490490
let &[ref x, ref exp] = check_arg_count(args)?;
491491
// For radix-2 (binary) systems, `ldexp` and `scalbn` are the same.
492492
let x = this.read_scalar(x)?.to_f64()?;
@@ -508,12 +508,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
508508

509509
// Architecture-specific shims
510510
"llvm.x86.sse2.pause" if this.tcx.sess.target.arch == "x86" || this.tcx.sess.target.arch == "x86_64" => {
511-
check_abi(abi, Abi::C)?;
511+
check_abi(abi, Abi::C { unwind: false })?;
512512
let &[] = check_arg_count(args)?;
513513
this.yield_active_thread();
514514
}
515515
"llvm.aarch64.hint" if this.tcx.sess.target.arch == "aarch64" => {
516-
check_abi(abi, Abi::C)?;
516+
check_abi(abi, Abi::C { unwind: false })?;
517517
let &[ref hint] = check_arg_count(args)?;
518518
let hint = this.read_scalar(hint)?.to_i32()?;
519519
match hint {

src/shims/posix/dlsym.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
3535
) -> InterpResult<'tcx> {
3636
let this = self.eval_context_mut();
3737

38-
check_abi(abi, Abi::C)?;
38+
check_abi(abi, Abi::C { unwind: false })?;
3939

4040
match dlsym {
4141
Dlsym::Linux(dlsym) => linux::EvalContextExt::call_dlsym(this, dlsym, args, ret),

src/shims/posix/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2222
) -> InterpResult<'tcx, bool> {
2323
let this = self.eval_context_mut();
2424

25-
check_abi(abi, Abi::C)?;
25+
check_abi(abi, Abi::C { unwind: false })?;
2626

2727
match link_name {
2828
// Environment related shims

src/shims/windows/dlsym.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
3232
let (_dest, _ret) = ret.expect("we don't support any diverging dlsym");
3333
assert!(this.tcx.sess.target.os == "windows");
3434

35-
check_abi(abi, Abi::System)?;
35+
check_abi(abi, Abi::System { unwind: false })?;
3636

3737
match dlsym {}
3838
}

src/shims/windows/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2020
) -> InterpResult<'tcx, bool> {
2121
let this = self.eval_context_mut();
2222

23-
check_abi(abi, Abi::System)?;
23+
check_abi(abi, Abi::System { unwind: false })?;
2424

2525
// Windows API stubs.
2626
// HANDLE = isize

tests/compile-fail/concurrency/unwind_top_of_stack.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
//! Unwinding past the top frame of a stack is Undefined Behavior.
55
6-
#![feature(rustc_private)]
6+
#![feature(rustc_private, c_unwind)]
77

88
extern crate libc;
99

1010
use std::{mem, ptr};
1111

12-
extern "C" fn thread_start(_null: *mut libc::c_void) -> *mut libc::c_void {
12+
extern "C-unwind" fn thread_start(_null: *mut libc::c_void) -> *mut libc::c_void {
1313
panic!()
1414
}
1515

@@ -18,6 +18,9 @@ fn main() {
1818
let mut native: libc::pthread_t = mem::zeroed();
1919
let attr: libc::pthread_attr_t = mem::zeroed();
2020
// assert_eq!(libc::pthread_attr_init(&mut attr), 0); FIXME: this function is not yet implemented.
21+
// Cast to avoid inserting abort-on-unwind.
22+
let thread_start: extern "C-unwind" fn(*mut libc::c_void) -> *mut libc::c_void = thread_start;
23+
let thread_start: extern "C" fn(*mut libc::c_void) -> *mut libc::c_void = mem::transmute(thread_start);
2124
assert_eq!(libc::pthread_create(&mut native, &attr, thread_start, ptr::null_mut()), 0);
2225
assert_eq!(libc::pthread_join(native, ptr::null_mut()), 0);
2326
}

0 commit comments

Comments
 (0)