Skip to content

Commit 8ebc1c9

Browse files
committed
librustc: Fix debuginfo for captured variables in non-FnOnce unboxed closures.
1 parent 6f4c11b commit 8ebc1c9

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

src/librustc_trans/trans/closure.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ fn load_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
286286
debuginfo::create_captured_var_metadata(
287287
bcx,
288288
def_id.node,
289-
cdata_ty,
290289
env_pointer_alloca,
291290
i,
292291
captured_by_ref,
@@ -326,7 +325,7 @@ fn load_unboxed_closure_environment<'blk, 'tcx>(
326325
// Store the pointer to closure data in an alloca for debug info because that's what the
327326
// llvm.dbg.declare intrinsic expects
328327
let env_pointer_alloca = if bcx.sess().opts.debuginfo == FullDebugInfo {
329-
let alloc = alloc_ty(bcx, ty::mk_mut_ptr(bcx.tcx(), self_type), "__debuginfo_env_ptr");
328+
let alloc = alloca(bcx, val_ty(llenv), "__debuginfo_env_ptr");
330329
Store(bcx, llenv, alloc);
331330
Some(alloc)
332331
} else {
@@ -355,7 +354,6 @@ fn load_unboxed_closure_environment<'blk, 'tcx>(
355354
debuginfo::create_captured_var_metadata(
356355
bcx,
357356
def_id.node,
358-
self_type,
359357
env_pointer_alloca,
360358
i,
361359
captured_by_ref,

src/librustc_trans/trans/debuginfo.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,6 @@ pub fn create_local_var_metadata(bcx: Block, local: &ast::Local) {
882882
/// Adds the created metadata nodes directly to the crate's IR.
883883
pub fn create_captured_var_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
884884
node_id: ast::NodeId,
885-
env_data_type: Ty<'tcx>,
886885
env_pointer: ValueRef,
887886
env_index: uint,
888887
captured_by_ref: bool,
@@ -928,7 +927,10 @@ pub fn create_captured_var_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
928927
let variable_type = node_id_type(bcx, node_id);
929928
let scope_metadata = bcx.fcx.debug_context.get_ref(cx, span).fn_metadata;
930929

931-
let llvm_env_data_type = type_of::type_of(cx, env_data_type);
930+
// env_pointer is the alloca containing the pointer to the environment,
931+
// so it's type is **EnvironmentType. In order to find out the type of
932+
// the environment we have to "dereference" two times.
933+
let llvm_env_data_type = val_ty(env_pointer).element_type().element_type();
932934
let byte_offset_of_var_in_env = machine::llelement_offset(cx,
933935
llvm_env_data_type,
934936
env_index);

src/test/debuginfo/var-captured-in-stack-closure.rs

+43-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@
2828
// gdb-command:print *owned
2929
// gdb-check:$5 = 6
3030

31+
// gdb-command:continue
32+
33+
// gdb-command:print variable
34+
// gdb-check:$6 = 2
35+
// gdb-command:print constant
36+
// gdb-check:$7 = 2
37+
// gdb-command:print a_struct
38+
// gdb-check:$8 = {a = -3, b = 4.5, c = 5}
39+
// gdb-command:print *struct_ref
40+
// gdb-check:$9 = {a = -3, b = 4.5, c = 5}
41+
// gdb-command:print *owned
42+
// gdb-check:$10 = 6
43+
3144

3245
// === LLDB TESTS ==================================================================================
3346

@@ -44,6 +57,20 @@
4457
// lldb-command:print *owned
4558
// lldb-check:[...]$4 = 6
4659

60+
// lldb-command:continue
61+
62+
// lldb-command:print variable
63+
// lldb-check:[...]$5 = 2
64+
// lldb-command:print constant
65+
// lldb-check:[...]$6 = 2
66+
// lldb-command:print a_struct
67+
// lldb-check:[...]$7 = Struct { a: -3, b: 4.5, c: 5 }
68+
// lldb-command:print *struct_ref
69+
// lldb-check:[...]$8 = Struct { a: -3, b: 4.5, c: 5 }
70+
// lldb-command:print *owned
71+
// lldb-check:[...]$9 = 6
72+
73+
#![feature(unboxed_closures)]
4774
#![allow(unused_variables)]
4875

4976
struct Struct {
@@ -65,12 +92,22 @@ fn main() {
6592
let struct_ref = &a_struct;
6693
let owned = box 6;
6794

68-
let closure = || {
69-
zzz(); // #break
70-
variable = constant + a_struct.a + struct_ref.a + *owned;
71-
};
72-
73-
closure();
95+
{
96+
let closure = || {
97+
zzz(); // #break
98+
variable = constant + a_struct.a + struct_ref.a + *owned;
99+
};
100+
101+
closure();
102+
}
103+
104+
{
105+
let mut unboxed_closure = |&mut:| {
106+
zzz(); // #break
107+
variable = constant + a_struct.a + struct_ref.a + *owned;
108+
};
109+
unboxed_closure();
110+
}
74111
}
75112

76113
fn zzz() {()}

0 commit comments

Comments
 (0)