Files
swift-mirror/test/DebugInfo/generic_tuple_size.swift
T
Raphael Isemann b772384527 [DebugInfo] No longer assign non-fixed-size types the size of a pointer
`CompletedDebugTypeInfo::getFromTypeInfo` currently uses the storage type as
the preferred source of size information.
For address-only types (and any other type that has no fixed size at compile
time), the storage type is always changed to a pointer.

This currently causes that some non-fixed-size types (e.g., generics)
are assigned the size of a pointer as their actual size in the generated
debug information.

For example:

```
protocol P {
associatedtype S
}

func foo<B: P>(_ b: B) {
let x: (aaa: Int, bbb: B.S?) = (aaa: 0, bbb: nil)
_ = x
let y: (Fx: Int, Fy: Int) = (Fx: 0, Fy: 0)
_ = y
}
```

results in the following DWARF output where the first struct
is given size 8 (= the size of a pointer).

```
0x000000d4:   DW_TAG_structure_type
                DW_AT_name	("$sSi3aaa_1S4main1PPQzSg3bbbtD")
                DW_AT_linkage_name	("$sSi3aaa_1S4main1PPQzSg3bbbtD")
                DW_AT_byte_size	(0x08)
                DW_AT_APPLE_runtime_class	(DW_LANG_Swift)

0x000000f3:   DW_TAG_structure_type
                DW_AT_name	("$sSi2Fx_Si2FytD")
                DW_AT_linkage_name	("$sSi2Fx_Si2FytD")
                DW_AT_byte_size	(0x10)
                DW_AT_APPLE_runtime_class	(DW_LANG_Swift)
```

This change modifies `CompletedDebugTypeInfo::getFromTypeInfo` to ignore the
storage size for types that do not have fixed size. Generics now have no
specified size or 0 in DWARF. FixedArray<A, B> without substituted type/size
is now also emitted using the dedicated FixedArray code.
2026-03-13 13:42:05 +00:00

16 lines
509 B
Swift

// RUN: %target-swift-frontend %s -emit-ir -gdwarf-types -o - | %FileCheck %s
// Tests that tuples with no known size are not given a size in DWARF.
protocol Prot {
associatedtype Associated
}
func generic_func<B: Prot>(_ b: B) {
let x: (first: Int, optionalSecond: B.Associated?) = (first: 0, optionalSecond: nil)
_ = x
}
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, {{.*}}name: "$sSi5first_10Associated18generic_tuple_size4ProtPQzSg14optionalSecondtD"
// CHECK-NOT: size:
// CHECK-SAME:)