Skip to content

Commit 2593070

Browse files
committed
rollup merge of #19581: luqmana/duc
Fixes #19575.
2 parents 39b5711 + 8ebc1c9 commit 2593070

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

src/librustc_trans/trans/closure.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ fn load_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
288288
debuginfo::create_captured_var_metadata(
289289
bcx,
290290
def_id.node,
291-
cdata_ty,
292291
env_pointer_alloca,
293292
i,
294293
captured_by_ref,
@@ -328,7 +327,7 @@ fn load_unboxed_closure_environment<'blk, 'tcx>(
328327
// Store the pointer to closure data in an alloca for debug info because that's what the
329328
// llvm.dbg.declare intrinsic expects
330329
let env_pointer_alloca = if bcx.sess().opts.debuginfo == FullDebugInfo {
331-
let alloc = alloc_ty(bcx, ty::mk_mut_ptr(bcx.tcx(), self_type), "__debuginfo_env_ptr");
330+
let alloc = alloca(bcx, val_ty(llenv), "__debuginfo_env_ptr");
332331
Store(bcx, llenv, alloc);
333332
Some(alloc)
334333
} else {
@@ -357,7 +356,6 @@ fn load_unboxed_closure_environment<'blk, 'tcx>(
357356
debuginfo::create_captured_var_metadata(
358357
bcx,
359358
def_id.node,
360-
self_type,
361359
env_pointer_alloca,
362360
i,
363361
captured_by_ref,

src/librustc_trans/trans/debuginfo.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,6 @@ pub fn create_local_var_metadata(bcx: Block, local: &ast::Local) {
884884
/// Adds the created metadata nodes directly to the crate's IR.
885885
pub fn create_captured_var_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
886886
node_id: ast::NodeId,
887-
env_data_type: Ty<'tcx>,
888887
env_pointer: ValueRef,
889888
env_index: uint,
890889
captured_by_ref: bool,
@@ -930,7 +929,10 @@ pub fn create_captured_var_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
930929
let variable_type = node_id_type(bcx, node_id);
931930
let scope_metadata = bcx.fcx.debug_context.get_ref(cx, span).fn_metadata;
932931

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

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

Lines changed: 43 additions & 6 deletions
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)