Files
swift-mirror/test/DebugInfo/sroa_debug_value.sil
Emil Pedersen abfae78aeb [DebugInfo] Fix address-only type handling in debug blocks
Address-only types in SIL cannot be loaded, but op_deref is supported:
the type layout is unknown at compile time, but LLDB supports them.

When adding a debug reconstruction block, the op_deref was changed into
a load, which doesn't work. Those types can't be manipulated in DWARF
or by debug blocks, so supporting loads in the middle of a block wouldn't
work either.

Instead, keep op_deref when handling address-only types. Any operation
prepending or stripping a deref is invalid, as their object types don't
exist: the operand gets killed if it cannot be salvaged.
2026-06-04 16:08:48 +01:00

96 lines
5.4 KiB
Plaintext

// RUN: %target-sil-opt -sil-print-types -enable-sil-verify-all -sil-print-debuginfo -sroa %s | %FileCheck --check-prefix=CHECK-SROA %s
// RUN: %target-sil-opt -sil-print-types -enable-sil-verify-all -sil-print-debuginfo -sroa -mem2reg %s | %FileCheck --check-prefix=CHECK-MEM2REG %s
sil_stage canonical
import Builtin
import Swift
struct MyStruct {
@_hasStorage var x: Int64 { get set }
@_hasStorage var y: Int64 { get set }
init(x: Int64, y: Int64)
}
sil_scope 1 { loc "sroa.swift":2:8 parent @MyStructInit : $@convention(method) (Int64, Int64, @thin MyStruct.Type) -> MyStruct }
// MyStruct.init(x:y:)
sil hidden @MyStructInit : $@convention(method) (Int64, Int64, @thin MyStruct.Type) -> MyStruct {
bb0(%0 : $Int64, %1 : $Int64, %2 : $@thin MyStruct.Type):
%3 = struct $MyStruct (%0 : $Int64, %1 : $Int64), loc "sroa.swift":2:8, scope 1
return %3 : $MyStruct, loc "sroa.swift":2:8, scope 1
} // end sil function 'MyStructInit'
sil_scope 2 { loc "sroa.swift":7:6 parent @foo : $@convention(thin) (Int64, Int64) -> Int64 }
// CHECK-SROA-LABEL: sil {{.+}} @foo
// foo(in_x:in_y:)
sil hidden @foo : $@convention(thin) (Int64, Int64) -> Int64 {
bb0(%0 : $Int64, %1 : $Int64):
%4 = alloc_stack $MyStruct, var, name "my_struct", loc "sroa.swift":8:9, scope 2
debug_value %4 : $*MyStruct, let, name "my_copy", expr op_deref, loc "sroa.swift":7:10, scope 2
// Make sure SROA propagate the debug info to the splitted alloc_stack/debug_value instructions
// CHECK-SROA: %[[ALLOC_X:[0-9]+]] = alloc_stack $Int64
// CHECK-SROA-SAME: loc * "<compiler-generated>":0:0
// CHECK-SROA: debug_value %[[ALLOC_X]] : $*Int64, var
// CHECK-SROA-SAME: (name "my_struct", loc "sroa.swift":8:9
// CHECK-SROA-SAME: type $MyStruct, expr op_deref:op_fragment:#MyStruct.x
// CHECK-SROA: %[[ALLOC_Y:[0-9]+]] = alloc_stack $Int64
// CHECK-SROA-SAME: loc * "<compiler-generated>":0:0
// CHECK-SROA: debug_value %[[ALLOC_Y]] : $*Int64, var
// CHECK-SROA-SAME: (name "my_struct", loc "sroa.swift":8:9
// CHECK-SROA-SAME: type $MyStruct, expr op_deref:op_fragment:#MyStruct.y
// CHECK-SROA: debug_value %[[ALLOC_X]] : $*Int64, let
// CHECK-SROA-SAME: name "my_copy",
// CHECK-SROA-SAME: type $MyStruct, expr op_deref:op_fragment:#MyStruct.x
// CHECK-SROA-SAME: loc "sroa.swift":7:10
// CHECK-SROA: debug_value %[[ALLOC_Y]] : $*Int64, let
// CHECK-SROA-SAME: name "my_copy",
// CHECK-SROA-SAME: type $MyStruct, expr op_deref:op_fragment:#MyStruct.y
// CHECK-SROA-SAME: loc "sroa.swift":7:10
%13 = struct_element_addr %4 : $*MyStruct, #MyStruct.x, loc "sroa.swift":9:17, scope 2
store %0 to %13 : $*Int64, loc "sroa.swift":9:17, scope 2
// CHECK-SROA: store %0 to %[[ALLOC_X]]
%15 = struct_element_addr %4 : $*MyStruct, #MyStruct.y, loc "sroa.swift":10:17, scope 2
store %1 to %15 : $*Int64, loc "sroa.swift":10:17, scope 2
// CHECK-SROA: store %1 to %[[ALLOC_Y]]
dealloc_stack %4 : $*MyStruct, loc "sroa.swift":8:9, scope 2
// Make sure function arguments' SSA values are properly connected to both source variables
// CHECK-MEM2REG: debug_value %0 : $Int64, let, (name "my_copy", loc "sroa.swift":7:10
// CHECK-MEM2REG-SAME: type $MyStruct, expr op_fragment:#MyStruct.x
// CHECK-MEM2REG: debug_value %0 : $Int64, var, (name "my_struct", loc "sroa.swift":8:9
// CHECK-MEM2REG-SAME: type $MyStruct, expr op_fragment:#MyStruct.x
// CHECK-MEM2REG: debug_value %1 : $Int64, let, (name "my_copy", loc "sroa.swift":7:10
// CHECK-MEM2REG-SAME: type $MyStruct, expr op_fragment:#MyStruct.y
// CHECK-MEM2REG: debug_value %1 : $Int64, var, (name "my_struct", loc "sroa.swift":8:9
// CHECK-MEM2REG-SAME: type $MyStruct, expr op_fragment:#MyStruct.y
return %0 : $Int64, loc "sroa.swift":11:5, scope 2
} // end sil function 'foo'
sil_scope 3 { loc "sroa.swift":20:6 parent @sroa_kills_debug_reconstruction_block : $@convention(thin) (Int64, Int64) -> Int64 }
// CHECK-SROA-LABEL: sil {{.+}} @sroa_kills_debug_reconstruction_block
// When a debug_value has a reconstruction block, SROA cannot append fragments.
// Instead it kills the operand (replaces with undef) and preserves the block.
// CHECK-SROA: debug_value undef : {{.+}}, let, name "ptr", type $Builtin.RawPointer, transform {
// CHECK-SROA: bb0:
// CHECK-SROA: address_to_pointer undef : $*MyStruct to $Builtin.RawPointer
// CHECK-SROA: return
// CHECK-SROA: }
sil hidden @sroa_kills_debug_reconstruction_block : $@convention(thin) (Int64, Int64) -> Int64 {
bb0(%0 : $Int64, %1 : $Int64):
%4 = alloc_stack $MyStruct, var, name "my_struct", loc "sroa.swift":21:9, scope 3
debug_value %4 : $*MyStruct, let, name "ptr", type $Builtin.RawPointer, transform {
bb0(%0 : $*MyStruct):
%1 = address_to_pointer %0 : $*MyStruct to $Builtin.RawPointer
return %1 : $Builtin.RawPointer
}, loc "sroa.swift":22:10, scope 3
%5 = struct_element_addr %4 : $*MyStruct, #MyStruct.x, loc "sroa.swift":23:17, scope 3
store %0 to %5 : $*Int64, loc "sroa.swift":23:17, scope 3
%7 = struct_element_addr %4 : $*MyStruct, #MyStruct.y, loc "sroa.swift":24:17, scope 3
store %1 to %7 : $*Int64, loc "sroa.swift":24:17, scope 3
%9 = struct_element_addr %4 : $*MyStruct, #MyStruct.x, loc "sroa.swift":25:10, scope 3
%10 = load %9 : $*Int64, loc "sroa.swift":25:10, scope 3
dealloc_stack %4 : $*MyStruct, loc "sroa.swift":21:9, scope 3
return %10 : $Int64, loc "sroa.swift":26:5, scope 3
}