Skip to content

Commit 1dbc0c9

Browse files
committed
remove hack for panics
1 parent b819493 commit 1dbc0c9

File tree

5 files changed

+37
-31
lines changed

5 files changed

+37
-31
lines changed

src/shims/foreign_items.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
170170
};
171171

172172
// Next: functions that return.
173-
match link_name {
174-
"__rust_maybe_catch_panic" => {
175-
this.handle_catch_panic(args, dest, ret)?;
176-
return Ok(None);
177-
}
178-
179-
_ => this.emulate_foreign_item_by_name(link_name, args, dest)?,
180-
};
181-
182-
this.dump_place(*dest);
183-
this.go_to_block(ret);
173+
if this.emulate_foreign_item_by_name(link_name, args, dest, ret)? {
174+
this.dump_place(*dest);
175+
this.go_to_block(ret);
176+
}
184177

185178
Ok(None)
186179
}
@@ -190,7 +183,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
190183
link_name: &str,
191184
args: &[OpTy<'tcx, Tag>],
192185
dest: PlaceTy<'tcx, Tag>,
193-
) -> InterpResult<'tcx> {
186+
ret: mir::BasicBlock,
187+
) -> InterpResult<'tcx, bool> {
194188
let this = self.eval_context_mut();
195189

196190
// Here we dispatch all the shims for foreign functions. If you have a platform specific
@@ -293,6 +287,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
293287
this.write_scalar(new_ptr, dest)?;
294288
}
295289

290+
"__rust_maybe_catch_panic" => {
291+
this.handle_catch_panic(args, dest, ret)?;
292+
return Ok(false);
293+
}
294+
296295
"memcmp" => {
297296
let left = this.read_scalar(args[0])?.not_undef()?;
298297
let right = this.read_scalar(args[1])?.not_undef()?;
@@ -330,12 +329,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
330329
}
331330
}
332331

333-
334-
"rename" => {
335-
let result = this.rename(args[0], args[1])?;
336-
this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
337-
}
338-
339332
"strlen" => {
340333
let ptr = this.read_scalar(args[0])?.not_undef()?;
341334
let n = this.memory.read_c_str(ptr)?.len();
@@ -442,13 +435,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
442435
}
443436

444437
_ => match this.tcx.sess.target.target.target_os.to_lowercase().as_str() {
445-
"linux" | "macos" => posix::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest)?,
446-
"windows" => windows::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest)?,
438+
"linux" | "macos" => return posix::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret),
439+
"windows" => return windows::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret),
447440
target => throw_unsup_format!("The {} target platform is not supported", target),
448441
}
449442
};
450443

451-
Ok(())
444+
Ok(true)
452445
}
453446

454447
/// Evaluates the scalar at the specified path. Returns Some(val)

src/shims/foreign_items/posix.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mod linux;
22
mod macos;
33

44
use crate::*;
5+
use rustc::mir;
56
use rustc::ty::layout::{Align, LayoutOf, Size};
67

78
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
@@ -11,7 +12,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1112
link_name: &str,
1213
args: &[OpTy<'tcx, Tag>],
1314
dest: PlaceTy<'tcx, Tag>,
14-
) -> InterpResult<'tcx> {
15+
ret: mir::BasicBlock,
16+
) -> InterpResult<'tcx, bool> {
1517
let this = self.eval_context_mut();
1618
let tcx = &{ this.tcx.tcx };
1719

@@ -97,6 +99,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
9799
this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
98100
}
99101

102+
"rename" => {
103+
let result = this.rename(args[0], args[1])?;
104+
this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
105+
}
106+
100107
"posix_memalign" => {
101108
let ret = this.deref_operand(args[0])?;
102109
let align = this.read_scalar(args[1])?.to_machine_usize(this)?;
@@ -325,14 +332,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
325332

326333
_ => {
327334
match this.tcx.sess.target.target.target_os.to_lowercase().as_str() {
328-
"linux" => linux::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest)?,
329-
"macos" => macos::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest)?,
335+
"linux" => return linux::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret),
336+
"macos" => return macos::EvalContextExt::emulate_foreign_item_by_name(this, link_name, args, dest, ret),
330337
_ => unreachable!(),
331338
}
332339
}
333340
};
334341

335-
Ok(())
342+
Ok(true)
336343
}
337344
}
338345

src/shims/foreign_items/posix/linux.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::*;
2+
use rustc::mir;
23

34
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
45
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
@@ -7,7 +8,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
78
link_name: &str,
89
args: &[OpTy<'tcx, Tag>],
910
dest: PlaceTy<'tcx, Tag>,
10-
) -> InterpResult<'tcx> {
11+
_ret: mir::BasicBlock,
12+
) -> InterpResult<'tcx, bool> {
1113
let this = self.eval_context_mut();
1214

1315
match link_name {
@@ -83,6 +85,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
8385
_ => throw_unsup_format!("can't call foreign function: {}", link_name),
8486
};
8587

86-
Ok(())
88+
Ok(true)
8789
}
8890
}

src/shims/foreign_items/posix/macos.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::*;
2+
use rustc::mir;
23

34
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
45
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
@@ -7,7 +8,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
78
link_name: &str,
89
args: &[OpTy<'tcx, Tag>],
910
dest: PlaceTy<'tcx, Tag>,
10-
) -> InterpResult<'tcx> {
11+
_ret: mir::BasicBlock,
12+
) -> InterpResult<'tcx, bool> {
1113
let this = self.eval_context_mut();
1214

1315
match link_name {
@@ -108,7 +110,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
108110
_ => throw_unsup_format!("can't call foreign function: {}", link_name),
109111
};
110112

111-
Ok(())
113+
Ok(true)
112114
}
113115
}
114116

src/shims/foreign_items/windows.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::*;
2+
use rustc::mir;
23
use rustc::ty::layout::Size;
34
use std::iter;
45

@@ -9,7 +10,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
910
link_name: &str,
1011
args: &[OpTy<'tcx, Tag>],
1112
dest: PlaceTy<'tcx, Tag>,
12-
) -> InterpResult<'tcx> {
13+
_ret: mir::BasicBlock,
14+
) -> InterpResult<'tcx, bool> {
1315
let this = self.eval_context_mut();
1416
let tcx = &{ this.tcx.tcx };
1517

@@ -197,7 +199,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
197199
_ => throw_unsup_format!("can't call foreign function: {}", link_name),
198200
}
199201

200-
Ok(())
202+
Ok(true)
201203
}
202204
}
203205

0 commit comments

Comments
 (0)