Skip to content

Commit 8ad3066

Browse files
committed
[DebugInfo] Fix implicit deref on arithmetic expressions
1 parent c2c16f5 commit 8ad3066

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

docs/HowToUpdateDebugInfo.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ debug_value %0 : $Builtin.Int64, var, name "next", type $Int, expr op_consts:1:o
206206
```
207207

208208
> [!Caution]
209-
> This currently doesn't work, an implicit op_deref is added.
209+
> This currently doesn't work if a fragment is present.
210210
211211
#### Constants
212212

@@ -219,7 +219,7 @@ debug_value undef : $Int, let, name "x", expr op_consts:1:op_fragment:#Int._valu
219219
```
220220

221221
> [!Caution]
222-
> This currently doesn't work, an implicit op_deref is added.
222+
> This currently doesn't work, these variables are dropped by IRGen.
223223
224224
### Undef variables
225225

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,6 +3138,9 @@ bool IRGenDebugInfoImpl::buildDebugInfoExpression(
31383138
return false;
31393139
}
31403140
}
3141+
if (Operands.size() && Operands.back() != llvm::dwarf::DW_OP_deref) {
3142+
Operands.push_back(llvm::dwarf::DW_OP_stack_value);
3143+
}
31413144
return true;
31423145
}
31433146

test/DebugInfo/irgen_undef.sil

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,20 @@ debug_value undef : $Builtin.Int64, var, name "optimizedout"
1212
return %0 : $Builtin.Int64
1313
}
1414

15+
// CHECK-LABEL: define {{.*}} @arithmetic
16+
sil @arithmetic : $@convention(thin) (Builtin.Int64) -> (Builtin.Int64) {
17+
bb0(%0 : $Builtin.Int64):
18+
// CHECK: call void @llvm.dbg.value(metadata i64 %0, metadata ![[CURRENT_VAR:[0-9]+]], metadata !DIExpression())
19+
debug_value %0 : $Builtin.Int64, var, name "current", type $Int, expr op_fragment:#Int._value
20+
// FIXME: It should work with the fragment, as it should be noop.
21+
// CHECK: call void @llvm.dbg.value(metadata i64 %0, metadata ![[PREVIOUS_VAR:[0-9]+]], metadata !DIExpression(DW_OP_consts, 1, DW_OP_minus, DW_OP_stack_value))
22+
debug_value %0 : $Builtin.Int64, var, name "previous", type $Int, expr op_consts:1:op_minus //:op_fragment:#Int._value
23+
// CHECK: call void @llvm.dbg.value(metadata i64 %0, metadata ![[NEXT_VAR:[0-9]+]], metadata !DIExpression(DW_OP_constu, 12, DW_OP_plus, DW_OP_stack_value))
24+
debug_value %0 : $Builtin.Int64, var, name "next", type $Int, expr op_constu:12:op_plus //:op_fragment:#Int._value
25+
return %0 : $Builtin.Int64
26+
}
27+
1528
// CHECK: ![[JUST_UNDEF_VAR]] = !DILocalVariable(name: "optimizedout"
29+
// CHECK: ![[CURRENT_VAR]] = !DILocalVariable(name: "current"
30+
// CHECK: ![[PREVIOUS_VAR]] = !DILocalVariable(name: "previous"
31+
// CHECK: ![[NEXT_VAR]] = !DILocalVariable(name: "next"

0 commit comments

Comments
 (0)