Skip to content

Commit

Permalink
[DebugInfo] Fix implicit deref on arithmetic expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowy1803 committed Apr 26, 2024
1 parent a21394f commit 655de5c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/HowToUpdateDebugInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ debug_value %0 : $Builtin.Int64, var, name "current", type $Int, expr op_fragmen
```

> [!Caution]
> This currently doesn't work, an implicit op_deref is added.
> This currently doesn't work if a fragment is present.
#### Constants

Expand All @@ -218,7 +218,7 @@ debug_value undef : $Int, let, name "x", expr op_consts:1:op_fragment:#Int._valu
```

> [!Caution]
> This currently doesn't work, an implicit op_deref is added.
> This currently doesn't work, these variables are dropped by IRGen.
### Undef variables

Expand Down
3 changes: 3 additions & 0 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3138,6 +3138,9 @@ bool IRGenDebugInfoImpl::buildDebugInfoExpression(
return false;
}
}
if (Operands.size() && Operands.back() != llvm::dwarf::DW_OP_deref) {
Operands.push_back(llvm::dwarf::DW_OP_stack_value);
}
return true;
}

Expand Down
16 changes: 16 additions & 0 deletions test/DebugInfo/irgen_undef.sil
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,20 @@ debug_value undef : $Builtin.Int64, var, name "optimizedout"
return %0 : $Builtin.Int64
}

// CHECK-LABEL: define {{.*}} @arithmetic
sil @arithmetic : $@convention(thin) (Builtin.Int64) -> (Builtin.Int64) {
bb0(%0 : $Builtin.Int64):
// CHECK: call void @llvm.dbg.value(metadata i64 %0, metadata ![[CURRENT_VAR:[0-9]+]], metadata !DIExpression())
debug_value %0 : $Builtin.Int64, var, name "current", type $Int, expr op_fragment:#Int._value
// FIXME: It should work with the fragment, as it should be noop.
// 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))
debug_value %0 : $Builtin.Int64, var, name "previous", type $Int, expr op_consts:1:op_minus //:op_fragment:#Int._value
// 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))
debug_value %0 : $Builtin.Int64, var, name "next", type $Int, expr op_constu:12:op_plus //:op_fragment:#Int._value
return %0 : $Builtin.Int64
}

// CHECK: ![[JUST_UNDEF_VAR]] = !DILocalVariable(name: "optimizedout"
// CHECK: ![[CURRENT_VAR]] = !DILocalVariable(name: "current"
// CHECK: ![[PREVIOUS_VAR]] = !DILocalVariable(name: "previous"
// CHECK: ![[NEXT_VAR]] = !DILocalVariable(name: "next"

0 comments on commit 655de5c

Please sign in to comment.