Rollup merge of #32347 - Amanieu:volatile_fat_ptr, r=eddyb

Fix volatile stores of fat pointers

This was previously causing an LLVM assertion.

r? @eddyb
This commit is contained in:
Eduard-Mihai Burtescu 2016-03-19 12:30:02 +02:00
commit 5bf1e58bc0
2 changed files with 35 additions and 8 deletions

View File

@ -589,15 +589,20 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
},
(_, "volatile_store") => {
let tp_ty = *substs.types.get(FnSpace, 0);
let val = if fn_ty.args[1].is_indirect() {
Load(bcx, llargs[1])
if type_is_fat_ptr(bcx.tcx(), tp_ty) {
VolatileStore(bcx, llargs[1], expr::get_dataptr(bcx, llargs[0]));
VolatileStore(bcx, llargs[2], expr::get_meta(bcx, llargs[0]));
} else {
from_immediate(bcx, llargs[1])
};
let ptr = PointerCast(bcx, llargs[0], val_ty(val).ptr_to());
let store = VolatileStore(bcx, val, ptr);
unsafe {
llvm::LLVMSetAlignment(store, type_of::align_of(ccx, tp_ty));
let val = if fn_ty.args[1].is_indirect() {
Load(bcx, llargs[1])
} else {
from_immediate(bcx, llargs[1])
};
let ptr = PointerCast(bcx, llargs[0], val_ty(val).ptr_to());
let store = VolatileStore(bcx, val, ptr);
unsafe {
llvm::LLVMSetAlignment(store, type_of::align_of(ccx, tp_ty));
}
}
C_nil(ccx)
},

View File

@ -0,0 +1,22 @@
// Copyright 2016 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.
#![feature(volatile)]
use std::ptr::{read_volatile, write_volatile};
fn main() {
let mut x: &'static str = "test";
unsafe {
let a = read_volatile(&x);
assert_eq!(a, "test");
write_volatile(&mut x, "foo");
assert_eq!(x, "foo");
}
}