Skip to content

Commit ebc83dd

Browse files
committed
fixup! codegen: Generate dbg_value for the ref statement
Add a test case for the index projection.
1 parent c23e3b1 commit ebc83dd

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

compiler/rustc_codegen_ssa/src/mir/statement.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
131131
});
132132
matches!(local_ref_pass_mode, Some(&PassMode::Indirect {..}) | None) &&
133133
// Drop unsupported projections.
134-
// FIXME: Add a test case.
135134
place.projection.iter().all(|p| p.can_use_in_debuginfo()) &&
136135
// Only pointers can be calculated addresses.
137136
bx.type_kind(bx.val_ty(place_ref.val.llval)) == TypeKind::Pointer

tests/codegen-llvm/debuginfo-dse.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ pub fn tuple(foo: (i32, &Foo)) -> i32 {
103103
foo.1.0
104104
}
105105

106+
#[no_mangle]
107+
fn index(slice: &[i32; 4], idx: usize) -> i32 {
108+
// CHECK-LABEL: define {{.*}} i32 @index
109+
// CHECK: bb1:
110+
// CHECK-NEXT: #dbg_value(ptr poison, [[VAR_index_from_var:![0-9]+]], !DIExpression()
111+
// CODEGEN: bb3:
112+
// CHECK-NEXT: #dbg_value(ptr %slice, [[VAR_const_index_from_start:![0-9]+]], !DIExpression()
113+
// CHECK-NEXT: #dbg_value(ptr poison, [[VAR_const_index_from_end:![0-9]+]], !DIExpression()
114+
let index_from_var = &slice[idx];
115+
let [ref const_index_from_start, .., ref const_index_from_end] = slice[..] else {
116+
return 0;
117+
};
118+
slice[0]
119+
}
120+
106121
// CHECK-DAG: [[VAR_invalid_ref_of_ref_foo]] = !DILocalVariable(name: "invalid_ref_of_ref_foo"
107122
// OPTIMIZED-DAG: [[VAR_ref_foo]] = !DILocalVariable(name: "ref_foo"
108123
// CHECK-DAG: [[VAR_ref_v0]] = !DILocalVariable(name: "ref_v0"
@@ -116,5 +131,8 @@ pub fn tuple(foo: (i32, &Foo)) -> i32 {
116131
// CHECK-DAG: [[VAR_fragment_f]] = !DILocalVariable(name: "fragment_f"
117132
// CHECK-DAG: [[VAR_tuple_dead]] = !DILocalVariable(name: "tuple_dead"
118133
// CHECK-DAG: [[VAR_deref_dead]] = !DILocalVariable(name: "deref_dead"
119-
// CHECK-DAG: [[ARG_dead_first_foo]] = !DILocalVariable(name: "dead_first_foo", arg: 1
134+
// CHECK-DAG: [[ARG_dead_first_foo]] = !DILocalVariable(name: "dead_first_foo"
120135
// CHECK-DAG: [[VAR_dead_first_v0]] = !DILocalVariable(name: "dead_first_v0"
136+
// CHECK-DAG: [[VAR_index_from_var]] = !DILocalVariable(name: "index_from_var"
137+
// CHECK-DAG: [[VAR_const_index_from_start]] = !DILocalVariable(name: "const_index_from_start"
138+
// CHECK-DAG: [[VAR_const_index_from_end]] = !DILocalVariable(name: "const_index_from_end"

0 commit comments

Comments
 (0)