Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix thinning pointers to extern types in miri #50530

Merged
merged 1 commit into from
May 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,21 +654,24 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
if self.type_is_fat_ptr(src.ty) {
match (src.value, self.type_is_fat_ptr(dest_ty)) {
(Value::ByRef { .. }, _) |
// pointers to extern types
(Value::ByVal(_),_) |
// slices and trait objects to other slices/trait objects
(Value::ByValPair(..), true) => {
let valty = ValTy {
value: src.value,
ty: dest_ty,
};
self.write_value(valty, dest)?;
}
// slices and trait objects to thin pointers (dropping the metadata)
(Value::ByValPair(data, _), false) => {
let valty = ValTy {
value: Value::ByVal(data),
ty: dest_ty,
};
self.write_value(valty, dest)?;
}
(Value::ByVal(_), _) => bug!("expected fat ptr"),
}
} else {
let src_layout = self.layout_of(src.ty)?;
Expand Down
23 changes: 23 additions & 0 deletions src/test/ui/const-eval/extern_fat_pointer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-pass

#![feature(extern_types)]

extern {
type Opaque;
}

const FOO: *const u8 = &42 as *const _ as *const Opaque as *const u8;

fn main() {
let _foo = FOO;
}
2 changes: 1 addition & 1 deletion src/tools/miri
Submodule miri updated from f48fed to e0e1bd