]> git.lizzy.rs Git - rust.git/commitdiff
remove the 'dereferenceable' attribute from Box
authorRalf Jung <post@ralfj.de>
Fri, 22 Nov 2019 21:04:22 +0000 (22:04 +0100)
committerRalf Jung <post@ralfj.de>
Fri, 22 Nov 2019 21:04:22 +0000 (22:04 +0100)
src/librustc/ty/layout.rs
src/librustc_target/abi/call/mod.rs
src/test/codegen/function-arguments.rs

index b6050a5caf13e996e20f0fe248e205eea91473c1..e14a78a8c44ca5aeb2e14827ca23b53360a5125c 100644 (file)
@@ -2526,9 +2526,15 @@ fn new_internal(
 
             if let Some(pointee) = layout.pointee_info_at(cx, offset) {
                 if let Some(kind) = pointee.safe {
-                    attrs.pointee_size = pointee.size;
                     attrs.pointee_align = Some(pointee.align);
 
+                    // `Box` (`UniqueBorrowed`) are not necessarily dereferencable
+                    // for the entire duration of the function, so set their size to 0.
+                    attrs.pointee_size =  match kind {
+                        PointerKind::UniqueOwned => Size::ZERO,
+                        _ => pointee.size
+                    };
+
                     // `Box` pointer parameters never alias because ownership is transferred
                     // `&mut` pointer parameters never alias other parameters,
                     // or mutable global data
index aced12aa32acba0c266d785e920907e38be0a9a8..1b55676fe4f98dd3a79f2817e5a880dfad71f24f 100644 (file)
@@ -69,6 +69,7 @@ pub struct ArgAttribute: u16 {
 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
 pub struct ArgAttributes {
     pub regular: ArgAttribute,
+    /// The dereferenceable size of the pointee.
     pub pointee_size: Size,
     pub pointee_align: Option<Align>
 }
index 7e1791cd4f296f5c3ace1b66e5736c6ceaa5f9d4..5c9aa48c0a5d6ba2e0c5e8a1ab042d03857d5e93 100644 (file)
@@ -65,7 +65,9 @@ pub fn indirect_struct(_: S) {
 pub fn borrowed_struct(_: &S) {
 }
 
-// CHECK: noalias align 4 dereferenceable(4) i32* @_box(i32* noalias align 4 dereferenceable(4) %x)
+// `Box` can get deallocated during execution of the function, so it should
+// not get `dereferenceable`.
+// CHECK: noalias nonnull align 4 i32* @_box(i32* noalias nonnull align 4 %x)
 #[no_mangle]
 pub fn _box(x: Box<i32>) -> Box<i32> {
   x