Fix volatile stores of fat pointers
This commit is contained in:
parent
235d77457d
commit
135d24dd03
@ -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)
|
||||
},
|
||||
|
22
src/test/run-pass/volatile-fat-ptr.rs
Normal file
22
src/test/run-pass/volatile-fat-ptr.rs
Normal 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");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user