]> git.lizzy.rs Git - rust.git/commitdiff
Fix LLVM assert with write_volatile
authorAmanieu d'Antras <amanieu@gmail.com>
Sun, 13 Mar 2016 16:40:06 +0000 (17:40 +0100)
committerAmanieu d'Antras <amanieu@gmail.com>
Sun, 13 Mar 2016 18:01:35 +0000 (19:01 +0100)
src/librustc_trans/trans/intrinsic.rs
src/test/run-pass/issue-29663.rs [new file with mode: 0644]

index 96c1d6a4d691a4ba74a0dea7cb2e3fb15268498f..ac1d34f17064eb050d991efc3b8a79ef108538a5 100644 (file)
@@ -609,7 +609,11 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
         (_, "volatile_store") => {
             let tp_ty = *substs.types.get(FnSpace, 0);
             let ptr = to_arg_ty_ptr(bcx, llargs[0], tp_ty);
-            let val = from_arg_ty(bcx, llargs[1], tp_ty);
+            let val = if type_is_immediate(bcx.ccx(), tp_ty) {
+                from_arg_ty(bcx, llargs[1], tp_ty)
+            } else {
+                Load(bcx, llargs[1])
+            };
             let store = VolatileStore(bcx, val, ptr);
             unsafe {
                 llvm::LLVMSetAlignment(store, type_of::align_of(ccx, tp_ty));
diff --git a/src/test/run-pass/issue-29663.rs b/src/test/run-pass/issue-29663.rs
new file mode 100644 (file)
index 0000000..9a77be0
--- /dev/null
@@ -0,0 +1,64 @@
+// 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.
+
+// write_volatile causes an LLVM assert with composite types
+
+#![feature(volatile)]
+use std::ptr::{read_volatile, write_volatile};
+
+#[derive(Debug, Eq, PartialEq)]
+struct A(u32);
+#[derive(Debug, Eq, PartialEq)]
+struct B(u64);
+#[derive(Debug, Eq, PartialEq)]
+struct C(u32, u32);
+#[derive(Debug, Eq, PartialEq)]
+struct D(u64, u64);
+#[derive(Debug, Eq, PartialEq)]
+struct E([u64; 32]);
+
+fn main() {
+    unsafe {
+        let mut x: u32 = 0;
+        write_volatile(&mut x, 1);
+        assert_eq!(read_volatile(&x), 1);
+        assert_eq!(x, 1);
+
+        let mut x: u64 = 0;
+        write_volatile(&mut x, 1);
+        assert_eq!(read_volatile(&x), 1);
+        assert_eq!(x, 1);
+
+        let mut x = A(0);
+        write_volatile(&mut x, A(1));
+        assert_eq!(read_volatile(&x), A(1));
+        assert_eq!(x, A(1));
+
+        let mut x = B(0);
+        write_volatile(&mut x, B(1));
+        assert_eq!(read_volatile(&x), B(1));
+        assert_eq!(x, B(1));
+
+        let mut x = C(0, 0);
+        write_volatile(&mut x, C(1, 1));
+        assert_eq!(read_volatile(&x), C(1, 1));
+        assert_eq!(x, C(1, 1));
+
+        let mut x = D(0, 0);
+        write_volatile(&mut x, D(1, 1));
+        assert_eq!(read_volatile(&x), D(1, 1));
+        assert_eq!(x, D(1, 1));
+
+        let mut x = E([0; 32]);
+        write_volatile(&mut x, E([1; 32]));
+        assert_eq!(read_volatile(&x), E([1; 32]));
+        assert_eq!(x, E([1; 32]));
+    }
+}