Skip to content

Commit 7cf0aac

Browse files
debuginfo: Better support for univariant tuple-style enums.
1 parent f389bd8 commit 7cf0aac

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/librustc/middle/trans/debuginfo.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,13 +606,22 @@ fn create_enum_md(cx: &mut CrateContext,
606606
return discriminant_type_md;
607607
}
608608

609+
let is_univariant = variants.len() == 1;
610+
609611
let variants_md = do variants.map |&vi| {
610612

611613
let raw_types : &[ty::t] = vi.args;
612614
let arg_types = do raw_types.map |&raw_type| { ty::subst(cx.tcx, substs, raw_type) };
613-
let arg_llvm_types = ~[discriminant_llvm_type] + do arg_types.map |&ty| { type_of::type_of(cx, ty) };
614-
let arg_names = ~[~""] + arg_types.map(|_| ~"");
615-
let arg_md = ~[discriminant_type_md] + do arg_types.map |&ty| { get_or_create_type(cx, ty, span) };
615+
616+
let mut arg_llvm_types = do arg_types.map |&ty| { type_of::type_of(cx, ty) };
617+
let mut arg_names = arg_types.map(|_| ~"");
618+
let mut arg_md = do arg_types.map |&ty| { get_or_create_type(cx, ty, span) };
619+
620+
if !is_univariant {
621+
arg_llvm_types.insert(0, discriminant_llvm_type);
622+
arg_names.insert(0, ~"");
623+
arg_md.insert(0, discriminant_type_md);
624+
}
616625

617626
let variant_llvm_type = Type::struct_(arg_llvm_types, false);
618627
let variant_type_size = machine::llsize_of_alloc(cx, variant_llvm_type);
@@ -646,7 +655,7 @@ fn create_enum_md(cx: &mut CrateContext,
646655
let enum_type_size = machine::llsize_of_alloc(cx, enum_llvm_type);
647656
let enum_type_align = machine::llalign_of_min(cx, enum_llvm_type);
648657

649-
return do "".as_c_str |enum_name| { unsafe { llvm::LLVMDIBuilderCreateUnionType(
658+
return do enum_name.as_c_str |enum_name| { unsafe { llvm::LLVMDIBuilderCreateUnionType(
650659
DIB(cx),
651660
file_metadata,
652661
enum_name,

src/test/debug-info/tuple-style-enum.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,29 @@
1414
// debugger:run
1515
// debugger:finish
1616

17-
// debugger:print case2
18-
// check:$1 = {Case1, 0, 1}
17+
// d ebugger:print case2
18+
// c heck:$1 = {Case1, 0, 1}
1919

20-
enum Test {
20+
// debugger:print univariant
21+
// check:$1 = {{-1}}
22+
23+
24+
enum Regular {
2125
Case1(i32, i64),
2226
Case2(bool, i16, i32)
2327
}
2428

29+
enum Univariant {
30+
TheOnlyCase(i64)
31+
}
32+
2533
fn main() {
2634

2735
let case1 = Case1(110, 220);
2836
let case2 = Case2(false, 2, 3);
2937

38+
let univariant = TheOnlyCase(-1);
39+
3040
zzz();
3141
}
3242

0 commit comments

Comments
 (0)