Skip to content

Commit b540e5d

Browse files
committed
Reserve fides for stdio and fix merge issues
2 parents ca3a917 + b625812 commit b540e5d

File tree

13 files changed

+97
-64
lines changed

13 files changed

+97
-64
lines changed

.appveyor.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,21 @@ cache:
1717
- '%USERPROFILE%\.rustup'
1818

1919
install:
20+
# Compute the rust version we use
21+
- set /p RUSTC_HASH=<rust-version
2022
# Install Rust
2123
- curl -sSf --retry 3 -o rustup-init.exe https://win.rustup.rs/
2224
- rustup-init.exe -y --default-host %TARGET% --default-toolchain stable
2325
- set PATH=%USERPROFILE%\.cargo\bin;%PATH%
26+
- rustup default stable
27+
- rustup uninstall beta
28+
- rustup update
2429
# Install "master" toolchain
2530
- cargo install rustup-toolchain-install-master & exit 0
26-
- set /p RUSTC_HASH=<rust-version
2731
- rustup-toolchain-install-master -f -n master %RUSTC_HASH% -c cargo -c rust-src
2832
- rustup default master
2933
- rustc --version
34+
- cargo --version
3035

3136
build_script:
3237
- set RUSTFLAGS=-C debug-assertions

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ before_script:
3333
# Install Rust ("stable" toolchain for better caching, it is just used to build rustup-toolchain-install-master)
3434
- curl https://build.travis-ci.org/files/rustup-init.sh -sSf | sh -s -- -y --default-toolchain stable
3535
- export PATH=$HOME/.cargo/bin:$PATH
36+
- rustup default stable
37+
- rustup uninstall beta
3638
- rustup update
3739
# Install "master" toolchain
3840
- cargo install rustup-toolchain-install-master || echo "rustup-toolchain-install-master already installed"
3941
- travis_retry rustup-toolchain-install-master -f -n master $RUSTC_HASH -c rust-src
4042
- rustup default master
4143
- rustc --version
44+
- cargo --version
4245

4346
script:
4447
- ./travis.sh

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ cargo_miri = ["cargo_metadata", "directories", "rustc_version"]
5959
rustc_tests = []
6060

6161
[dev-dependencies]
62-
compiletest_rs = { version = "0.3.22", features = ["tmp", "stable"] }
62+
compiletest_rs = { version = "0.3.23", features = ["tmp"] }
6363
colored = "1.6"

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ea3ba36f3f4b7f0168a27d23c499efeb2304e2d5
1+
084beb83e0e87d673d5fabc844d28e8e8ae2ab4c

src/bin/miri-rustc-tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
4646
struct Visitor<'tcx>(TyCtxt<'tcx>);
4747
impl<'tcx, 'hir> itemlikevisit::ItemLikeVisitor<'hir> for Visitor<'tcx> {
4848
fn visit_item(&mut self, i: &'hir hir::Item) {
49-
if let hir::ItemKind::Fn(.., body_id) = i.node {
49+
if let hir::ItemKind::Fn(.., body_id) = i.kind {
5050
if i.attrs.iter().any(|attr| attr.check_name(syntax::symbol::sym::test)) {
5151
let config = MiriConfig {
5252
validate: true,

src/eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
6363
ty::ParamEnv::reveal_all(),
6464
start_id,
6565
ecx.tcx.mk_substs(
66-
::std::iter::once(ty::subst::Kind::from(main_ret_ty)))
66+
::std::iter::once(ty::subst::GenericArg::from(main_ret_ty)))
6767
).unwrap();
6868
let start_mir = ecx.load_mir(start_instance.def, None)?;
6969

src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
211211
fn visit_value(&mut self, v: MPlaceTy<'tcx, Tag>) -> InterpResult<'tcx>
212212
{
213213
trace!("UnsafeCellVisitor: {:?} {:?}", *v, v.layout.ty);
214-
let is_unsafe_cell = match v.layout.ty.sty {
214+
let is_unsafe_cell = match v.layout.ty.kind {
215215
ty::Adt(adt, _) => Some(adt.did) == self.ecx.tcx.lang_items().unsafe_cell_type(),
216216
_ => false,
217217
};

src/shims/io.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ use std::io::Read;
55
use crate::stacked_borrows::Tag;
66
use crate::*;
77

8-
#[derive(Default)]
98
pub struct FileHandler {
109
files: HashMap<i32, File>,
1110
flags: HashMap<i32, i32>,
1211
low: i32,
1312
}
1413

14+
impl Default for FileHandler {
15+
fn default() -> Self {
16+
FileHandler {
17+
files: Default::default(),
18+
flags: Default::default(),
19+
// 0, 1 and 2 are reserved for stdin, stdout and stderr
20+
low: 3,
21+
}
22+
}
23+
}
24+
1525
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
1626
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
1727
fn open(

src/shims/mod.rs

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
pub mod dlsym;
2+
pub mod env;
13
pub mod foreign_items;
24
pub mod intrinsics;
35
pub mod tls;
4-
pub mod dlsym;
5-
pub mod env;
66
pub mod io;
77

8-
use rustc::{ty, mir};
8+
use rustc::{mir, ty};
99

1010
use crate::*;
1111

@@ -19,7 +19,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1919
ret: Option<mir::BasicBlock>,
2020
) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> {
2121
let this = self.eval_context_mut();
22-
trace!("eval_fn_call: {:#?}, {:?}", instance, dest.map(|place| *place));
22+
trace!(
23+
"eval_fn_call: {:#?}, {:?}",
24+
instance,
25+
dest.map(|place| *place)
26+
);
2327

2428
// First, run the common hooks also supported by CTFE.
2529
if this.hook_fn(instance, args, dest)? {
@@ -28,27 +32,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2832
}
2933
// There are some more lang items we want to hook that CTFE does not hook (yet).
3034
if this.tcx.lang_items().align_offset_fn() == Some(instance.def.def_id()) {
31-
32-
let n = {
33-
let ptr = this.force_ptr(this.read_scalar(args[0])?.not_undef()?)?;
34-
let align = this.force_bits(
35-
this.read_scalar(args[1])?.not_undef()?,
36-
this.pointer_size()
37-
)? as usize;
38-
39-
let stride = this.memory().get(ptr.alloc_id)?.align.bytes() as usize;
40-
// if the allocation alignment is at least the required alignment, we use the
41-
// libcore implementation
42-
if stride >= align {
43-
((stride + ptr.offset.bytes() as usize) as *const ())
44-
.align_offset(align) as u128
45-
} else {
46-
u128::max_value()
47-
}
48-
};
49-
5035
let dest = dest.unwrap();
51-
let n = this.truncate(n, dest.layout);
36+
let n = this
37+
.align_offset(args[0], args[1])?
38+
.unwrap_or_else(|| this.truncate(u128::max_value(), dest.layout));
5239
this.write_scalar(Scalar::from_uint(n, dest.layout.size), dest)?;
5340
this.goto_block(ret)?;
5441
return Ok(None);
@@ -66,4 +53,39 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6653
// Otherwise, load the MIR.
6754
Ok(Some(this.load_mir(instance.def, None)?))
6855
}
56+
57+
fn align_offset(
58+
&mut self,
59+
ptr_op: OpTy<'tcx, Tag>,
60+
align_op: OpTy<'tcx, Tag>,
61+
) -> InterpResult<'tcx, Option<u128>> {
62+
let this = self.eval_context_mut();
63+
64+
let req_align = this.force_bits(
65+
this.read_scalar(align_op)?.not_undef()?,
66+
this.pointer_size(),
67+
)? as usize;
68+
69+
// FIXME: This should actually panic in the interpreted program
70+
if !req_align.is_power_of_two() {
71+
throw_unsup_format!("Required alignment should always be a power of two")
72+
}
73+
74+
let ptr_scalar = this.read_scalar(ptr_op)?.not_undef()?;
75+
76+
if let Ok(ptr) = this.force_ptr(ptr_scalar) {
77+
let cur_align = this.memory().get(ptr.alloc_id)?.align.bytes() as usize;
78+
if cur_align >= req_align {
79+
// if the allocation alignment is at least the required alignment we use the
80+
// libcore implementation
81+
return Ok(Some(
82+
(this.force_bits(ptr_scalar, this.pointer_size())? as *const i8)
83+
.align_offset(req_align) as u128,
84+
));
85+
}
86+
}
87+
// If the allocation alignment is smaller than then required alignment or the pointer was
88+
// actually an integer, we return `None`
89+
Ok(None)
90+
}
6991
}

src/stacked_borrows.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ impl<'tcx> Stacks {
435435

436436
Stacks {
437437
stacks: RefCell::new(RangeMap::new(size, stack)),
438-
global: extra,
438+
global: extra,
439439
}
440440
}
441441

@@ -460,7 +460,7 @@ impl Stacks {
460460
pub fn new_allocation(
461461
id: AllocId,
462462
size: Size,
463-
extra: MemoryExtra,
463+
extra: MemoryExtra,
464464
kind: MemoryKind<MiriMemoryKind>,
465465
) -> (Self, Tag) {
466466
let (tag, perm) = match kind {
@@ -616,7 +616,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
616616
// Cannot use `builtin_deref` because that reports *immutable* for `Box`,
617617
// making it useless.
618618
fn qualify(ty: ty::Ty<'_>, kind: RetagKind) -> Option<(RefKind, bool)> {
619-
match ty.sty {
619+
match ty.kind {
620620
// References are simple.
621621
ty::Ref(_, _, MutMutable) =>
622622
Some((RefKind::Unique { two_phase: kind == RetagKind::TwoPhase}, kind == RetagKind::FnEntry)),

0 commit comments

Comments
 (0)