authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-09-15 13:54:23+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-09-15 16:03:56+01:00
log8ff2f1057a9e9cc258f335e4a26101866be987a9
treed6174b1f09ef8d4745dea53e58b988737d8bd33e
parentbab6bf4194511c609210624d53b6601268719ac9
signaturelock-open Commit is signed but in an unrecognized format.

Revert "Dwarf: prevent crash on missing field inits"

This reverts commit faafc4132731e854a471ad4c4bb231efb525ea9a.

1 files changed, 27 insertions(+), 51 deletions(-)

src/link/Dwarf.zig+27-51
......@@ -2643,10 +2643,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
26432643 try uleb128(diw, nav_val.toType().abiAlignment(zcu).toByteUnits().?);
26442644 for (0..loaded_struct.field_types.len) |field_index| {
26452645 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
2646 const field_init = if (loaded_struct.haveFieldInits(ip))
2647 loaded_struct.fieldInit(ip, field_index)
2648 else
2649 .none;
2646 const field_init = loaded_struct.fieldInit(ip, field_index);
2647 assert(!(is_comptime and field_init == .none));
26502648 try wip_nav.abbrevCode(if (is_comptime)
26512649 .struct_field_comptime
26522650 else if (field_init != .none)
......@@ -2658,20 +2656,14 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
26582656 defer dwarf.gpa.free(field_name);
26592657 try wip_nav.strp(field_name);
26602658 }
2661 if (is_comptime and field_init == .none) {
2662 // workaround frontend bug
2663 try wip_nav.refType(Type.void);
2664 try wip_nav.blockValue(nav_src_loc, Value.void);
2665 } else {
2666 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
2667 try wip_nav.refType(field_type);
2668 if (!is_comptime) {
2669 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
2670 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
2671 field_type.abiAlignment(zcu).toByteUnits().?);
2672 }
2673 if (field_init != .none) try wip_nav.blockValue(nav_src_loc, Value.fromInterned(field_init));
2659 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
2660 try wip_nav.refType(field_type);
2661 if (!is_comptime) {
2662 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
2663 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
2664 field_type.abiAlignment(zcu).toByteUnits().?);
26742665 }
2666 if (field_init != .none) try wip_nav.blockValue(nav_src_loc, Value.fromInterned(field_init));
26752667 }
26762668 try uleb128(diw, @intFromEnum(AbbrevCode.null));
26772669 }
......@@ -3511,10 +3503,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
35113503 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
35123504 for (0..loaded_struct.field_types.len) |field_index| {
35133505 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
3514 const field_init = if (loaded_struct.haveFieldInits(ip))
3515 loaded_struct.fieldInit(ip, field_index)
3516 else
3517 .none;
3506 const field_init = loaded_struct.fieldInit(ip, field_index);
3507 assert(!(is_comptime and field_init == .none));
35183508 try wip_nav.abbrevCode(if (is_comptime)
35193509 .struct_field_comptime
35203510 else if (field_init != .none)
......@@ -3526,20 +3516,14 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
35263516 defer dwarf.gpa.free(field_name);
35273517 try wip_nav.strp(field_name);
35283518 }
3529 if (is_comptime and field_init == .none) {
3530 // workaround frontend bug
3531 try wip_nav.refType(Type.void);
3532 try wip_nav.blockValue(ty_src_loc, Value.void);
3533 } else {
3534 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
3535 try wip_nav.refType(field_type);
3536 if (!is_comptime) {
3537 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
3538 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
3539 field_type.abiAlignment(zcu).toByteUnits().?);
3540 }
3541 if (field_init != .none) try wip_nav.blockValue(ty_src_loc, Value.fromInterned(field_init));
3519 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
3520 try wip_nav.refType(field_type);
3521 if (!is_comptime) {
3522 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
3523 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
3524 field_type.abiAlignment(zcu).toByteUnits().?);
35423525 }
3526 if (field_init != .none) try wip_nav.blockValue(ty_src_loc, Value.fromInterned(field_init));
35433527 }
35443528 try uleb128(diw, @intFromEnum(AbbrevCode.null));
35453529 }
......@@ -3595,10 +3579,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
35953579 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
35963580 for (0..loaded_struct.field_types.len) |field_index| {
35973581 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
3598 const field_init = if (loaded_struct.haveFieldInits(ip))
3599 loaded_struct.fieldInit(ip, field_index)
3600 else
3601 .none;
3582 const field_init = loaded_struct.fieldInit(ip, field_index);
3583 assert(!(is_comptime and field_init == .none));
36023584 try wip_nav.abbrevCode(if (is_comptime)
36033585 .struct_field_comptime
36043586 else if (field_init != .none)
......@@ -3610,20 +3592,14 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
36103592 defer dwarf.gpa.free(field_name);
36113593 try wip_nav.strp(field_name);
36123594 }
3613 if (is_comptime and field_init == .none) {
3614 // workaround frontend bug
3615 try wip_nav.refType(Type.void);
3616 try wip_nav.blockValue(ty_src_loc, Value.void);
3617 } else {
3618 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
3619 try wip_nav.refType(field_type);
3620 if (!is_comptime) {
3621 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
3622 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
3623 field_type.abiAlignment(zcu).toByteUnits().?);
3624 }
3625 if (field_init != .none) try wip_nav.blockValue(ty_src_loc, Value.fromInterned(field_init));
3595 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
3596 try wip_nav.refType(field_type);
3597 if (!is_comptime) {
3598 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
3599 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
3600 field_type.abiAlignment(zcu).toByteUnits().?);
36263601 }
3602 if (field_init != .none) try wip_nav.blockValue(ty_src_loc, Value.fromInterned(field_init));
36273603 }
36283604 try uleb128(diw, @intFromEnum(AbbrevCode.null));
36293605 }