Skip to content

Commit af34f91

Browse files
committed
Fix debuginfo for unsized struct members
The member was given the size of a fat pointer, which caused llvm to emit DWARF attributes for a 128-bit bitfield.
1 parent c217ab6 commit af34f91

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/librustc_trans/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ impl<'tcx> StructMemberDescriptionFactory<'tcx> {
906906

907907
MemberDescription {
908908
name: name,
909-
llvm_type: type_of::type_of(cx, fty),
909+
llvm_type: type_of::in_memory_type_of(cx, fty),
910910
type_metadata: type_metadata(cx, fty, self.span),
911911
offset: offset,
912912
flags: DIFlags::FlagZero,

src/test/debuginfo/unsized.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2016 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+
// compile-flags:-g
12+
13+
// === GDB TESTS ===================================================================================
14+
15+
// gdb-command:run
16+
17+
// gdb-command:print *a
18+
// gdbg-check:$1 = {value = [...] "abc"}
19+
// gdbr-check:$1 = unsized::Foo<[u8]> {value: [...]}
20+
21+
// gdb-command:print *b
22+
// gdbg-check:$2 = {value = {value = [...] "abc"}}
23+
// gdbr-check:$2 = unsized::Foo<unsized::Foo<[u8]>> {value: unsized::Foo<[u8]> {value: [...]}}
24+
25+
26+
#![feature(omit_gdb_pretty_printer_section)]
27+
#![omit_gdb_pretty_printer_section]
28+
29+
struct Foo<T: ?Sized> {
30+
value: T
31+
}
32+
33+
fn main() {
34+
let foo: Foo<Foo<[u8; 4]>> = Foo {
35+
value: Foo {
36+
value: *b"abc\0"
37+
}
38+
};
39+
let a: &Foo<[u8]> = &foo.value;
40+
let b: &Foo<Foo<[u8]>> = &foo;
41+
42+
zzz(); // #break
43+
}
44+
45+
fn zzz() { () }

0 commit comments

Comments
 (0)