about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAriel Ben-Yehuda <ariel.byd@gmail.com>2015-10-27 23:02:23 +0200
committerAriel Ben-Yehuda <ariel.byd@gmail.com>2015-10-27 23:02:23 +0200
commit7f772bb84ef8ba1f986525733c505f71e876fb7c (patch)
tree559cd5f83f2cea164b6a9c8f951fa13e7b2fe021
parent2c42c9881542a0f3a8b573a56cd1c12643d4be52 (diff)
downloadrust-7f772bb84ef8ba1f986525733c505f71e876fb7c.tar.gz
rust-7f772bb84ef8ba1f986525733c505f71e876fb7c.zip
type_of: use `sizing_type_of` to check the size of arrays
when evaluating a recursive type, the type_of of the interior could be
still in progress, so we can't use that.

Fixes #19001
-rw-r--r--src/librustc_trans/trans/type_of.rs6
-rw-r--r--src/test/run-pass/issue-19001.rs19
2 files changed, 24 insertions, 1 deletions
diff --git a/src/librustc_trans/trans/type_of.rs b/src/librustc_trans/trans/type_of.rs
index 437c0d9cbc3..293c5bdcd32 100644
--- a/src/librustc_trans/trans/type_of.rs
+++ b/src/librustc_trans/trans/type_of.rs
@@ -395,8 +395,12 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
 
       ty::TyArray(ty, size) => {
           let size = size as u64;
+          // we must use `sizing_type_of` here as the type may
+          // not be fully initialized.
+          let szty = sizing_type_of(cx, ty);
+          ensure_array_fits_in_address_space(cx, szty, size, t);
+
           let llty = in_memory_type_of(cx, ty);
-          ensure_array_fits_in_address_space(cx, llty, size, t);
           Type::array(&llty, size)
       }
 
diff --git a/src/test/run-pass/issue-19001.rs b/src/test/run-pass/issue-19001.rs
new file mode 100644
index 00000000000..3340ed1ffd9
--- /dev/null
+++ b/src/test/run-pass/issue-19001.rs
@@ -0,0 +1,19 @@
+// Copyright 2015 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.
+
+// check that we handle recursive arrays correctly in `type_of`
+
+struct Loopy {
+    ptr: *mut [Loopy; 1]
+}
+
+fn main() {
+    let _t = Loopy { ptr: 0 as *mut _ };
+}