Fix type encoding/decoding for unions
Fix union debuginfo test on lldb
This commit is contained in:
parent
93067ca089
commit
436cfe5653
7 changed files with 48 additions and 52 deletions
|
|
@ -291,7 +291,7 @@ fn maybe_item_name(item: rbml::Doc) -> Option<ast::Name> {
|
|||
|
||||
fn family_to_variant_kind<'tcx>(family: Family) -> Option<ty::VariantKind> {
|
||||
match family {
|
||||
Struct(VariantKind::Struct) | Variant(VariantKind::Struct) =>
|
||||
Struct(VariantKind::Struct) | Variant(VariantKind::Struct) | Union =>
|
||||
Some(ty::VariantKind::Struct),
|
||||
Struct(VariantKind::Tuple) | Variant(VariantKind::Tuple) =>
|
||||
Some(ty::VariantKind::Tuple),
|
||||
|
|
|
|||
|
|
@ -472,6 +472,14 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
|
|||
let def = self.tcx.lookup_adt_def(did);
|
||||
return self.tcx.mk_struct(def, substs);
|
||||
}
|
||||
'U' => {
|
||||
assert_eq!(self.next(), '[');
|
||||
let did = self.parse_def();
|
||||
let substs = self.parse_substs();
|
||||
assert_eq!(self.next(), ']');
|
||||
let def = self.tcx.lookup_adt_def(did);
|
||||
return self.tcx.mk_union(def, substs);
|
||||
}
|
||||
'k' => {
|
||||
assert_eq!(self.next(), '[');
|
||||
let did = self.parse_def();
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Cursor<Vec<u8>>, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx
|
|||
write!(w, "]");
|
||||
}
|
||||
ty::TyUnion(def, substs) => {
|
||||
write!(w, "u[{}|", (cx.ds)(cx.tcx, def.did));
|
||||
write!(w, "U[{}|", (cx.ds)(cx.tcx, def.did));
|
||||
enc_substs(w, cx, substs);
|
||||
write!(w, "]");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@
|
|||
// === LLDB TESTS ==================================================================================
|
||||
|
||||
// lldb-command:run
|
||||
// lldb-command:print a
|
||||
// lldb-check:[...]$0 = {a = {__0 = 2 '\002', __1 = 2 '\002'}, b = 514}
|
||||
// lldb-command:print u
|
||||
// lldb-check:[...]$0 = { a = ('\x02', '\x02') b = 514 }
|
||||
// lldb-command:print union_smoke::SU
|
||||
// lldb-check:[...]$1 = {a = {__0 = 1 '\001', __1 = 1 '\001'}, b = 257}
|
||||
// lldb-check:[...]$1 = 257
|
||||
|
||||
#![allow(unused)]
|
||||
#![feature(omit_gdb_pretty_printer_section)]
|
||||
|
|
|
|||
|
|
@ -12,5 +12,5 @@
|
|||
|
||||
pub union U {
|
||||
pub a: u8,
|
||||
b: u16,
|
||||
pub b: u16,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,38 +8,21 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// aux-build:union.rs
|
||||
|
||||
#![feature(untagged_unions)]
|
||||
|
||||
extern crate union;
|
||||
use std::mem::{size_of, align_of, zeroed};
|
||||
|
||||
union U {
|
||||
a: u8,
|
||||
b: u16
|
||||
}
|
||||
|
||||
union U64 {
|
||||
a: u64,
|
||||
}
|
||||
|
||||
union W {
|
||||
a: u8,
|
||||
b: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
union Y {
|
||||
f1: u16,
|
||||
f2: [u8; 4],
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(size_of::<U>(), 1);
|
||||
assert_eq!(size_of::<U64>(), 8);
|
||||
assert_eq!(size_of::<W>(), 8);
|
||||
assert_eq!(align_of::<U>(), 1);
|
||||
assert_eq!(align_of::<U64>(), align_of::<u64>());
|
||||
assert_eq!(align_of::<W>(), align_of::<u64>());
|
||||
assert_eq!(size_of::<Y>(), 4);
|
||||
assert_eq!(align_of::<Y>(), 2);
|
||||
fn local() {
|
||||
assert_eq!(size_of::<U>(), 2);
|
||||
assert_eq!(align_of::<U>(), 2);
|
||||
|
||||
let u = U { a: 10 };
|
||||
unsafe {
|
||||
|
|
@ -48,7 +31,7 @@ fn main() {
|
|||
assert_eq!(a, 10);
|
||||
}
|
||||
|
||||
let mut w = W { b: 0 };
|
||||
let mut w = U { b: 0 };
|
||||
unsafe {
|
||||
assert_eq!(w.a, 0);
|
||||
assert_eq!(w.b, 0);
|
||||
|
|
@ -57,3 +40,29 @@ fn main() {
|
|||
assert_eq!(w.b, 1);
|
||||
}
|
||||
}
|
||||
|
||||
fn xcrate() {
|
||||
assert_eq!(size_of::<union::U>(), 2);
|
||||
assert_eq!(align_of::<union::U>(), 2);
|
||||
|
||||
let u = union::U { a: 10 };
|
||||
unsafe {
|
||||
assert_eq!(u.a, 10);
|
||||
let union::U { a } = u;
|
||||
assert_eq!(a, 10);
|
||||
}
|
||||
|
||||
let mut w = union::U { b: 0 };
|
||||
unsafe {
|
||||
assert_eq!(w.a, 0);
|
||||
assert_eq!(w.b, 0);
|
||||
w.a = 1;
|
||||
assert_eq!(w.a, 1);
|
||||
assert_eq!(w.b, 1);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
local();
|
||||
xcrate();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
// 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.
|
||||
|
||||
// aux-build:union.rs
|
||||
|
||||
// #![feature(untagged_unions)]
|
||||
|
||||
extern crate union;
|
||||
|
||||
type A = union::U;
|
||||
|
||||
fn main() {
|
||||
assert_eq!(std::mem::size_of::<A>(), 8);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue