Skip to content

Commit 81d128b

Browse files
committed
Merge branch 'generic-enum-disr-fix' of https://github.com/michaelwoerister/rust into update-llvm
2 parents 958d563 + f9a20bb commit 81d128b

File tree

3 files changed

+98
-9
lines changed

3 files changed

+98
-9
lines changed

Diff for: src/librustc_trans/trans/debuginfo/metadata.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1606,13 +1606,10 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
16061606
.collect();
16071607

16081608
let discriminant_type_metadata = |inttype| {
1609-
// We can reuse the type of the discriminant for all monomorphized
1610-
// instances of an enum because it doesn't depend on any type
1611-
// parameters. The def_id, uniquely identifying the enum's polytype acts
1612-
// as key in this cache.
1609+
let disr_type_key = (enum_def_id, inttype);
16131610
let cached_discriminant_type_metadata = debug_context(cx).created_enum_disr_types
16141611
.borrow()
1615-
.get(&enum_def_id).cloned();
1612+
.get(&disr_type_key).cloned();
16161613
match cached_discriminant_type_metadata {
16171614
Some(discriminant_type_metadata) => discriminant_type_metadata,
16181615
None => {
@@ -1641,7 +1638,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
16411638

16421639
debug_context(cx).created_enum_disr_types
16431640
.borrow_mut()
1644-
.insert(enum_def_id, discriminant_type_metadata);
1641+
.insert(disr_type_key, discriminant_type_metadata);
16451642

16461643
discriminant_type_metadata
16471644
}

Diff for: src/librustc_trans/trans/debuginfo/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use trans;
3232
use trans::monomorphize;
3333
use middle::ty::Ty;
3434
use session::config::{self, FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
35-
use util::nodemap::{DefIdMap, NodeMap, FnvHashMap, FnvHashSet};
35+
use util::nodemap::{NodeMap, FnvHashMap, FnvHashSet};
3636

3737
use libc::c_uint;
3838
use std::cell::{Cell, RefCell};
@@ -41,6 +41,7 @@ use std::ptr;
4141
use std::rc::Rc;
4242
use syntax::codemap::{Span, Pos};
4343
use syntax::{ast, codemap, ast_util};
44+
use syntax::attr::IntType;
4445
use syntax::parse::token::{self, special_idents};
4546

4647
pub mod gdb;
@@ -73,7 +74,7 @@ pub struct CrateDebugContext<'tcx> {
7374
builder: DIBuilderRef,
7475
current_debug_location: Cell<InternalDebugLocation>,
7576
created_files: RefCell<FnvHashMap<String, DIFile>>,
76-
created_enum_disr_types: RefCell<DefIdMap<DIType>>,
77+
created_enum_disr_types: RefCell<FnvHashMap<(ast::DefId, IntType), DIType>>,
7778

7879
type_map: RefCell<TypeMap<'tcx>>,
7980
namespace_map: RefCell<FnvHashMap<Vec<ast::Name>, Rc<NamespaceTreeNode>>>,
@@ -94,7 +95,7 @@ impl<'tcx> CrateDebugContext<'tcx> {
9495
builder: builder,
9596
current_debug_location: Cell::new(InternalDebugLocation::UnknownLocation),
9697
created_files: RefCell::new(FnvHashMap()),
97-
created_enum_disr_types: RefCell::new(DefIdMap()),
98+
created_enum_disr_types: RefCell::new(FnvHashMap()),
9899
type_map: RefCell::new(TypeMap::new()),
99100
namespace_map: RefCell::new(FnvHashMap()),
100101
composite_types_completed: RefCell::new(FnvHashSet()),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-tidy-linelength
12+
// min-lldb-version: 310
13+
14+
// compile-flags:-g
15+
16+
// === GDB TESTS ===================================================================================
17+
// gdb-command:run
18+
19+
// gdb-command:print eight_bytes1
20+
// gdb-check:$1 = {{RUST$ENUM$DISR = Variant1, __0 = 100}, {RUST$ENUM$DISR = Variant1, __0 = 100}}
21+
// gdb-command:print four_bytes1
22+
// gdb-check:$2 = {{RUST$ENUM$DISR = Variant1, __0 = 101}, {RUST$ENUM$DISR = Variant1, __0 = 101}}
23+
// gdb-command:print two_bytes1
24+
// gdb-check:$3 = {{RUST$ENUM$DISR = Variant1, __0 = 102}, {RUST$ENUM$DISR = Variant1, __0 = 102}}
25+
// gdb-command:print one_byte1
26+
// gdb-check:$4 = {{RUST$ENUM$DISR = Variant1, __0 = 65 'A'}, {RUST$ENUM$DISR = Variant1, __0 = 65 'A'}}
27+
28+
// gdb-command:print eight_bytes2
29+
// gdb-check:$5 = {{RUST$ENUM$DISR = Variant2, __0 = 100}, {RUST$ENUM$DISR = Variant2, __0 = 100}}
30+
// gdb-command:print four_bytes2
31+
// gdb-check:$6 = {{RUST$ENUM$DISR = Variant2, __0 = 101}, {RUST$ENUM$DISR = Variant2, __0 = 101}}
32+
// gdb-command:print two_bytes2
33+
// gdb-check:$7 = {{RUST$ENUM$DISR = Variant2, __0 = 102}, {RUST$ENUM$DISR = Variant2, __0 = 102}}
34+
// gdb-command:print one_byte2
35+
// gdb-check:$8 = {{RUST$ENUM$DISR = Variant2, __0 = 65 'A'}, {RUST$ENUM$DISR = Variant2, __0 = 65 'A'}}
36+
37+
// gdb-command:continue
38+
39+
// === LLDB TESTS ==================================================================================
40+
// lldb-command:run
41+
42+
// lldb-command:print eight_bytes1
43+
// lldb-check:[...]$0 = Variant1(100)
44+
// lldb-command:print four_bytes1
45+
// lldb-check:[...]$1 = Variant1(101)
46+
// lldb-command:print two_bytes1
47+
// lldb-check:[...]$2 = Variant1(102)
48+
// lldb-command:print one_byte1
49+
// lldb-check:[...]$3 = Variant1('A')
50+
51+
// lldb-command:print eight_bytes2
52+
// lldb-check:[...]$4 = Variant2(100)
53+
// lldb-command:print four_bytes2
54+
// lldb-check:[...]$5 = Variant2(101)
55+
// lldb-command:print two_bytes2
56+
// lldb-check:[...]$6 = Variant2(102)
57+
// lldb-command:print one_byte2
58+
// lldb-check:[...]$7 = Variant2('A')
59+
60+
// lldb-command:continue
61+
62+
#![allow(unused_variables)]
63+
#![allow(dead_code)]
64+
#![omit_gdb_pretty_printer_section]
65+
66+
// This test case makes sure that we get correct type descriptions for the enum
67+
// discriminant of different instantiations of the same generic enum type where,
68+
// dependending on the generic type parameter(s), the discriminant has a
69+
// different size in memory.
70+
71+
enum Enum<T> {
72+
Variant1(T),
73+
Variant2(T)
74+
}
75+
76+
fn main() {
77+
// These are ordered for descending size on purpose
78+
let eight_bytes1 = Enum::Variant1(100.0f64);
79+
let four_bytes1 = Enum::Variant1(101i32);
80+
let two_bytes1 = Enum::Variant1(102i16);
81+
let one_byte1 = Enum::Variant1(65u8);
82+
83+
let eight_bytes2 = Enum::Variant2(100.0f64);
84+
let four_bytes2 = Enum::Variant2(101i32);
85+
let two_bytes2 = Enum::Variant2(102i16);
86+
let one_byte2 = Enum::Variant2(65u8);
87+
88+
zzz(); // #break
89+
}
90+
91+
fn zzz() { () }

0 commit comments

Comments
 (0)