about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc/middle/trans/expr.rs8
-rw-r--r--src/test/run-pass/empty-allocation-rvalue-non-null.rs13
2 files changed, 19 insertions, 2 deletions
diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs
index 95bf2a7f275..e47362e8d9e 100644
--- a/src/librustc/middle/trans/expr.rs
+++ b/src/librustc/middle/trans/expr.rs
@@ -1802,11 +1802,15 @@ fn deref_once<'a>(bcx: &'a Block<'a>,
             RvalueExpr(Rvalue { mode: ByRef }) => {
                 let scope = cleanup::temporary_scope(bcx.tcx(), expr.id);
                 let ptr = Load(bcx, datum.val);
-                bcx.fcx.schedule_free_value(scope, ptr, cleanup::HeapExchange);
+                if !type_is_zero_size(bcx.ccx(), content_ty) {
+                    bcx.fcx.schedule_free_value(scope, ptr, cleanup::HeapExchange);
+                }
             }
             RvalueExpr(Rvalue { mode: ByValue }) => {
                 let scope = cleanup::temporary_scope(bcx.tcx(), expr.id);
-                bcx.fcx.schedule_free_value(scope, datum.val, cleanup::HeapExchange);
+                if !type_is_zero_size(bcx.ccx(), content_ty) {
+                    bcx.fcx.schedule_free_value(scope, datum.val, cleanup::HeapExchange);
+                }
             }
             LvalueExpr => { }
         }
diff --git a/src/test/run-pass/empty-allocation-rvalue-non-null.rs b/src/test/run-pass/empty-allocation-rvalue-non-null.rs
new file mode 100644
index 00000000000..a5fc8425cf6
--- /dev/null
+++ b/src/test/run-pass/empty-allocation-rvalue-non-null.rs
@@ -0,0 +1,13 @@
+// Copyright 2014 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.
+
+pub fn main() {
+    let x = *~();
+}