Skip to content

[MIR] Handle FatPtr in mir::constant::trans_constval. #30482

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

Merged
merged 1 commit into from
Dec 21, 2015
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: 5 additions & 0 deletions src/librustc_trans/trans/mir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use back::abi;
use middle::ty::{Ty, HasTypeFlags};
use rustc::middle::const_eval::ConstVal;
use rustc::mir::repr as mir;
Expand All @@ -29,6 +30,10 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
let val = consts::trans_constval(bcx, cv, ty, bcx.fcx.param_substs);
let val = if common::type_is_immediate(ccx, ty) {
OperandValue::Immediate(val)
} else if common::type_is_fat_ptr(bcx.tcx(), ty) {
let data = common::const_get_elt(ccx, val, &[abi::FAT_PTR_ADDR as u32]);
let extra = common::const_get_elt(ccx, val, &[abi::FAT_PTR_EXTRA as u32]);
OperandValue::FatPtr(data, extra)
} else {
OperandValue::Ref(val)
};
Expand Down
7 changes: 7 additions & 0 deletions src/test/run-pass/mir_fat_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ fn fat_ptr_store_to<'a>(a: &'a [u8], b: &mut &'a [u8]) {
*b = a;
}

#[rustc_mir]
fn fat_ptr_constant() -> &'static str {
"HELLO"
}

fn main() {
let a = Wrapper(4, [7,6,5]);

Expand All @@ -60,4 +65,6 @@ fn main() {
let mut target : &[u8] = &[42];
fat_ptr_store_to(p, &mut target);
assert_eq!(target, &a.1);

assert_eq!(fat_ptr_constant(), "HELLO");
}