mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[DebugInfo] Add support for constant debug values
This commit is contained in:
@@ -218,9 +218,6 @@ value.
|
||||
debug_value undef : $Int, let, name "x", expr op_consts:1:op_fragment:#Int._value
|
||||
```
|
||||
|
||||
> [!Caution]
|
||||
> This currently doesn't work, these variables are dropped by IRGen.
|
||||
|
||||
### Undef variables
|
||||
|
||||
If the value of the variable cannot be recovered as the value is entirely
|
||||
|
||||
@@ -3432,6 +3432,16 @@ void IRGenDebugInfoImpl::emitDbgIntrinsic(
|
||||
// /always/ emit an llvm.dbg.value of undef.
|
||||
// If we have undef, always emit a llvm.dbg.value in the current position.
|
||||
if (isa<llvm::UndefValue>(Storage)) {
|
||||
if (Expr->getNumElements() &&
|
||||
(Expr->getElement(0) == llvm::dwarf::DW_OP_consts
|
||||
|| Expr->getElement(0) == llvm::dwarf::DW_OP_constu)) {
|
||||
/// Convert `undef, expr op_consts:N:...` to `N, expr ...`
|
||||
Storage = llvm::ConstantInt::get(
|
||||
llvm::IntegerType::getInt64Ty(Builder.getContext()),
|
||||
Expr->getElement(1));
|
||||
Expr = llvm::DIExpression::get(Builder.getContext(),
|
||||
Expr->getElements().drop_front(2));
|
||||
}
|
||||
DBuilder.insertDbgValueIntrinsic(Storage, Var, Expr, DL, ParentBlock);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,16 +16,33 @@ return %0 : $Builtin.Int64
|
||||
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
|
||||
debug_value %0 : $Builtin.Int64, var, name "current", type $Int64, expr op_fragment:#Int64._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
|
||||
debug_value %0 : $Builtin.Int64, var, name "previous", type $Int64, expr op_consts:1:op_minus //:op_fragment:#Int64._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
|
||||
debug_value %0 : $Builtin.Int64, var, name "next", type $Int64, expr op_constu:12:op_plus //:op_fragment:#Int64._value
|
||||
return %0 : $Builtin.Int64
|
||||
}
|
||||
|
||||
// CHECK-LABEL: define {{.*}} @constant
|
||||
sil @constant : $@convention(thin) (Builtin.Int64) -> (Builtin.Int64) {
|
||||
bb0(%0 : $Builtin.Int64):
|
||||
// CHECK: call void @llvm.dbg.value(metadata i64 42, metadata ![[CONST_VAR:[0-9]+]], metadata !DIExpression(DW_OP_stack_value))
|
||||
debug_value undef : $Builtin.Int64, var, name "const", expr op_consts:42
|
||||
// CHECK: call void @llvm.dbg.value(metadata i64 3645, metadata ![[CONSTINT_VAR:[0-9]+]], metadata !DIExpression(DW_OP_stack_value))
|
||||
debug_value undef : $Builtin.Int64, var, name "constint", type $Int64, expr op_constu:3645:op_fragment:#Int64._value
|
||||
// CHECK: call void @llvm.dbg.value(metadata i64 6, metadata ![[CONSTUPLE_VAR:[0-9]+]], metadata !DIExpression(DW_OP_LLVM_fragment, 0, 64))
|
||||
debug_value undef : $Builtin.Int64, var, name "constuple", type $(Int64, Int64), expr op_consts:6:op_tuple_fragment:$(Int64, Int64):0:op_fragment:#Int64._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"
|
||||
// CHECK: ![[CONST_VAR]] = !DILocalVariable(name: "const"
|
||||
// CHECK: ![[CONSTINT_VAR]] = !DILocalVariable(name: "constint"
|
||||
// CHECK: ![[CONSTUPLE_VAR]] = !DILocalVariable(name: "constuple"
|
||||
|
||||
Reference in New Issue
Block a user