about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-01-25 18:46:33 +0000
committerbors <bors@rust-lang.org>2015-01-25 18:46:33 +0000
commitc80e556e159af38f86eea5ee2ba796d7c724c92b (patch)
tree96e77c61152fa22f7d7144da19064c738d9a0df7
parentd15192317aa025ff06faa56ca00950fb7ce6ff4b (diff)
parent75ad1161dd598ba0e61b9215a08216e744dd9f4c (diff)
downloadrust-c80e556e159af38f86eea5ee2ba796d7c724c92b.tar.gz
rust-c80e556e159af38f86eea5ee2ba796d7c724c92b.zip
Auto merge of #21519 - michaelwoerister:misc, r=eddyb
Two minor improvements that have been on my TODO list for a while:
* Clang uses a size of `-1` for arrays of unknown size and we should do that too as it will tell LLVM to omit the size information in debuginfo.
* There was no LLDB test case for handling the optimized enum representation introduced by @luqmana. This PR finally adds one.
-rw-r--r--src/librustc_trans/trans/debuginfo.rs26
-rw-r--r--src/test/debuginfo/option-like-enum.rs34
2 files changed, 48 insertions, 12 deletions
diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs
index 39413d63482..b366c7faefa 100644
--- a/src/librustc_trans/trans/debuginfo.rs
+++ b/src/librustc_trans/trans/debuginfo.rs
@@ -207,7 +207,7 @@ use session::config::{self, FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
 use util::nodemap::{DefIdMap, NodeMap, FnvHashMap, FnvHashSet};
 use util::ppaux;
 
-use libc::c_uint;
+use libc::{c_uint, c_longlong};
 use std::ffi::CString;
 use std::cell::{Cell, RefCell};
 use std::ptr;
@@ -2764,7 +2764,7 @@ fn create_struct_stub(cx: &CrateContext,
 fn fixed_vec_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
                                 unique_type_id: UniqueTypeId,
                                 element_type: Ty<'tcx>,
-                                len: uint,
+                                len: Option<u64>,
                                 span: Span)
                                 -> MetadataCreationResult {
     let element_type_metadata = type_metadata(cx, element_type, span);
@@ -2774,18 +2774,20 @@ fn fixed_vec_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
     let element_llvm_type = type_of::type_of(cx, element_type);
     let (element_type_size, element_type_align) = size_and_align_of(cx, element_llvm_type);
 
+    let (array_size_in_bytes, upper_bound) = match len {
+        Some(len) => (element_type_size * len, len as c_longlong),
+        None => (0, -1)
+    };
+
     let subrange = unsafe {
-        llvm::LLVMDIBuilderGetOrCreateSubrange(
-            DIB(cx),
-            0,
-            len as i64)
+        llvm::LLVMDIBuilderGetOrCreateSubrange(DIB(cx), 0, upper_bound)
     };
 
     let subscripts = create_DIArray(DIB(cx), &[subrange]);
     let metadata = unsafe {
         llvm::LLVMDIBuilderCreateArrayType(
             DIB(cx),
-            bytes_to_bits(element_type_size * (len as u64)),
+            bytes_to_bits(array_size_in_bytes),
             bytes_to_bits(element_type_align),
             element_type_metadata,
             subscripts)
@@ -2991,12 +2993,12 @@ fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
         ty::ty_enum(def_id, _) => {
             prepare_enum_metadata(cx, t, def_id, unique_type_id, usage_site_span).finalize(cx)
         }
-        ty::ty_vec(typ, Some(len)) => {
-            fixed_vec_metadata(cx, unique_type_id, typ, len, usage_site_span)
+        ty::ty_vec(typ, len) => {
+            fixed_vec_metadata(cx, unique_type_id, typ, len.map(|x| x as u64), usage_site_span)
+        }
+        ty::ty_str => {
+            fixed_vec_metadata(cx, unique_type_id, cx.tcx().types.i8, None, usage_site_span)
         }
-        // FIXME Can we do better than this for unsized vec/str fields?
-        ty::ty_vec(typ, None) => fixed_vec_metadata(cx, unique_type_id, typ, 0, usage_site_span),
-        ty::ty_str => fixed_vec_metadata(cx, unique_type_id, cx.tcx().types.i8, 0, usage_site_span),
         ty::ty_trait(..) => {
             MetadataCreationResult::new(
                         trait_pointer_metadata(cx, t, None, unique_type_id),
diff --git a/src/test/debuginfo/option-like-enum.rs b/src/test/debuginfo/option-like-enum.rs
index 71c235c878c..fdfbcda7421 100644
--- a/src/test/debuginfo/option-like-enum.rs
+++ b/src/test/debuginfo/option-like-enum.rs
@@ -36,6 +36,12 @@
 // gdb-command:print void_droid_gdb->internals
 // gdb-check:$6 = (isize *) 0x0
 
+// gdb-command:print nested_non_zero_yep
+// gdb-check:$7 = {RUST$ENCODED$ENUM$1$2$Nope = {10.5, {a = 10, b = 20, c = [...]}}}
+
+// gdb-command:print nested_non_zero_nope
+// gdb-check:$8 = {RUST$ENCODED$ENUM$1$2$Nope = {[...], {a = [...], b = [...], c = 0x0}}}
+
 // gdb-command:continue
 
 
@@ -67,6 +73,12 @@
 // lldb-command:print none_str
 // lldb-check:[...]$7 = None
 
+// lldb-command:print nested_non_zero_yep
+// lldb-check:[...]$8 = Yep(10.5, NestedNonZeroField { a: 10, b: 20, c: &[...] })
+
+// lldb-command:print nested_non_zero_nope
+// lldb-check:[...]$9 = Nope
+
 
 #![omit_gdb_pretty_printer_section]
 
@@ -102,6 +114,17 @@ struct NamedFieldsRepr<'a> {
     internals: &'a isize
 }
 
+struct NestedNonZeroField<'a> {
+    a: u16,
+    b: u32,
+    c: &'a char,
+}
+
+enum NestedNonZero<'a> {
+    Yep(f64, NestedNonZeroField<'a>),
+    Nope
+}
+
 fn main() {
 
     let some_str: Option<&'static str> = Some("abc");
@@ -124,6 +147,17 @@ fn main() {
     let void_droid = NamedFields::Void;
     let void_droid_gdb: &NamedFieldsRepr = unsafe { std::mem::transmute(&NamedFields::Void) };
 
+    let x = 'x';
+    let nested_non_zero_yep = NestedNonZero::Yep(
+        10.5,
+        NestedNonZeroField {
+            a: 10,
+            b: 20,
+            c: &x
+        });
+
+    let nested_non_zero_nope = NestedNonZero::Nope;
+
     zzz(); // #break
 }