authorgravatar for jonathan.haehne@hotmail.comTau <jonathan.haehne@hotmail.com> 2024-06-29 16:19:55+02:00
committergravatar for jonathan.haehne@hotmail.comTau <jonathan.haehne@hotmail.com> 2024-07-19 17:51:38+02:00
log94cf4d2d8193efb0ae642d475fb8437eb4c7e8c1
tree7e1f334cbf1941e1a9f2452bf42679cd467da9bb
parent177b3359a16016caf080ff95ba4b9359251d04b8

llvm: add pass-by-reference info to debug types

Without this data, debugger expressions try to pass structs by-value, which mostly just crashes. Also: mark enums as enum classes to prevent the enumerators from shadowing other identifiers.

2 files changed, 44 insertions(+), 3 deletions(-)

src/codegen/llvm.zig+10
......@@ -2068,6 +2068,7 @@ pub const Object = struct {
20682068 debug_ptr_type,
20692069 debug_len_type,
20702070 }),
2071 isByRef(ty, pt),
20712072 );
20722073
20732074 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_slice_type);
......@@ -2237,6 +2238,7 @@ pub const Object = struct {
22372238 debug_data_type,
22382239 debug_some_type,
22392240 }),
2241 isByRef(ty, pt),
22402242 );
22412243
22422244 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);
......@@ -2313,6 +2315,7 @@ pub const Object = struct {
23132315 ty.abiSize(pt) * 8,
23142316 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
23152317 try o.builder.debugTuple(&fields),
2318 isByRef(ty, pt),
23162319 );
23172320
23182321 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_error_union_type);
......@@ -2542,6 +2545,7 @@ pub const Object = struct {
25422545 0, // Size
25432546 0, // Align
25442547 .none, // Fields
2548 false, // ByRef
25452549 );
25462550 break :res debug_opaque_type;
25472551 },
......@@ -2601,6 +2605,7 @@ pub const Object = struct {
26012605 ty.abiSize(pt) * 8,
26022606 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
26032607 try o.builder.debugTuple(fields.items),
2608 isByRef(ty, pt),
26042609 );
26052610
26062611 break :res debug_struct_type;
......@@ -2656,6 +2661,7 @@ pub const Object = struct {
26562661 ty.abiSize(pt) * 8,
26572662 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
26582663 try o.builder.debugTuple(fields.items),
2664 isByRef(ty, pt),
26592665 );
26602666
26612667 break :res debug_struct_type;
......@@ -2683,6 +2689,7 @@ pub const Object = struct {
26832689 try o.builder.debugTuple(
26842690 &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty), required_by_runtime)},
26852691 ),
2692 isByRef(ty, pt),
26862693 );
26872694
26882695 break :res debug_union_type;
......@@ -2736,6 +2743,7 @@ pub const Object = struct {
27362743 ty.abiSize(pt) * 8,
27372744 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
27382745 try o.builder.debugTuple(fields.items),
2746 isByRef(ty, pt),
27392747 );
27402748
27412749 if (layout.tag_size == 0) {
......@@ -2791,6 +2799,7 @@ pub const Object = struct {
27912799 ty.abiSize(pt) * 8,
27922800 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
27932801 try o.builder.debugTuple(&full_fields),
2802 isByRef(ty, pt),
27942803 );
27952804
27962805 break :res debug_tagged_union_type;
......@@ -2824,6 +2833,7 @@ pub const Object = struct {
28242833 0,
28252834 0,
28262835 if (fields.len == 0) .none else try o.builder.debugTuple(fields),
2836 false, // is_byref
28272837 );
28282838 }
28292839
src/codegen/llvm/Builder.zig+34-3
......@@ -7911,6 +7911,10 @@ pub const Metadata = enum(u32) {
79117911 align_in_bits_lo: u32,
79127912 align_in_bits_hi: u32,
79137913 fields_tuple: Metadata,
7914 flags: packed struct(u32) {
7915 is_byref: bool,
7916 pad: u31 = 0,
7917 },
79147918
79157919 pub fn bitSize(self: CompositeType) u64 {
79167920 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
......@@ -11638,7 +11642,17 @@ fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item.
1163811642 u32 => value,
1163911643 MetadataString, Metadata, Variable.Index, Value => @intFromEnum(value),
1164011644 Metadata.DIFlags => @bitCast(value),
11641 else => @compileError("bad field type: " ++ @typeName(field.type)),
11645 else => blk: {
11646 switch (@typeInfo(field.type)) {
11647 .Struct => |s| {
11648 if (s.backing_integer == u32)
11649 break :blk @bitCast(value);
11650 @compileLog(s.layout, s.backing_integer);
11651 },
11652 else => {},
11653 }
11654 @compileError("bad field type: " ++ @typeName(field.type));
11655 },
1164211656 });
1164311657 }
1164411658 return result;
......@@ -11677,7 +11691,7 @@ fn metadataExtraDataTrail(
1167711691 u32 => value,
1167811692 MetadataString, Metadata, Variable.Index, Value => @enumFromInt(value),
1167911693 Metadata.DIFlags => @bitCast(value),
11680 else => @compileError("bad field type: " ++ @typeName(field.type)),
11694 else => @bitCast(value),
1168111695 };
1168211696 return .{
1168311697 .data = result,
......@@ -11844,6 +11858,7 @@ pub fn debugStructType(
1184411858 size_in_bits: u64,
1184511859 align_in_bits: u64,
1184611860 fields_tuple: Metadata,
11861 is_byref: bool,
1184711862) Allocator.Error!Metadata {
1184811863 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
1184911864 return self.debugStructTypeAssumeCapacity(
......@@ -11855,6 +11870,7 @@ pub fn debugStructType(
1185511870 size_in_bits,
1185611871 align_in_bits,
1185711872 fields_tuple,
11873 is_byref,
1185811874 );
1185911875}
1186011876
......@@ -11868,6 +11884,7 @@ pub fn debugUnionType(
1186811884 size_in_bits: u64,
1186911885 align_in_bits: u64,
1187011886 fields_tuple: Metadata,
11887 is_byref: bool,
1187111888) Allocator.Error!Metadata {
1187211889 try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
1187311890 return self.debugUnionTypeAssumeCapacity(
......@@ -11879,6 +11896,7 @@ pub fn debugUnionType(
1187911896 size_in_bits,
1188011897 align_in_bits,
1188111898 fields_tuple,
11899 is_byref,
1188211900 );
1188311901}
1188411902
......@@ -12400,6 +12418,7 @@ fn debugStructTypeAssumeCapacity(
1240012418 size_in_bits: u64,
1240112419 align_in_bits: u64,
1240212420 fields_tuple: Metadata,
12421 is_byref: bool,
1240312422) Metadata {
1240412423 assert(!self.strip);
1240512424 return self.debugCompositeTypeAssumeCapacity(
......@@ -12412,6 +12431,7 @@ fn debugStructTypeAssumeCapacity(
1241212431 size_in_bits,
1241312432 align_in_bits,
1241412433 fields_tuple,
12434 is_byref,
1241512435 );
1241612436}
1241712437
......@@ -12425,6 +12445,7 @@ fn debugUnionTypeAssumeCapacity(
1242512445 size_in_bits: u64,
1242612446 align_in_bits: u64,
1242712447 fields_tuple: Metadata,
12448 is_byref: bool,
1242812449) Metadata {
1242912450 assert(!self.strip);
1243012451 return self.debugCompositeTypeAssumeCapacity(
......@@ -12437,6 +12458,7 @@ fn debugUnionTypeAssumeCapacity(
1243712458 size_in_bits,
1243812459 align_in_bits,
1243912460 fields_tuple,
12461 is_byref,
1244012462 );
1244112463}
1244212464
......@@ -12462,6 +12484,7 @@ fn debugEnumerationTypeAssumeCapacity(
1246212484 size_in_bits,
1246312485 align_in_bits,
1246412486 fields_tuple,
12487 false, // is_byref
1246512488 );
1246612489}
1246712490
......@@ -12487,6 +12510,7 @@ fn debugArrayTypeAssumeCapacity(
1248712510 size_in_bits,
1248812511 align_in_bits,
1248912512 fields_tuple,
12513 size_in_bits > 0, // is_byref
1249012514 );
1249112515}
1249212516
......@@ -12512,6 +12536,7 @@ fn debugVectorTypeAssumeCapacity(
1251212536 size_in_bits,
1251312537 align_in_bits,
1251412538 fields_tuple,
12539 false,
1251512540 );
1251612541}
1251712542
......@@ -12526,6 +12551,7 @@ fn debugCompositeTypeAssumeCapacity(
1252612551 size_in_bits: u64,
1252712552 align_in_bits: u64,
1252812553 fields_tuple: Metadata,
12554 is_byref: bool,
1252912555) Metadata {
1253012556 assert(!self.strip);
1253112557 return self.metadataSimpleAssumeCapacity(tag, Metadata.CompositeType{
......@@ -12539,6 +12565,7 @@ fn debugCompositeTypeAssumeCapacity(
1253912565 .align_in_bits_lo = @truncate(align_in_bits),
1254012566 .align_in_bits_hi = @truncate(align_in_bits >> 32),
1254112567 .fields_tuple = fields_tuple,
12568 .flags = .{ .is_byref = is_byref },
1254212569 });
1254312570}
1254412571
......@@ -13973,7 +14000,11 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
1397314000 .underlying_type = extra.underlying_type,
1397414001 .size_in_bits = extra.bitSize(),
1397514002 .align_in_bits = extra.bitAlign(),
13976 .flags = if (kind == .composite_vector_type) .{ .Vector = true } else .{},
14003 .flags = .{
14004 .Vector = kind == .composite_vector_type,
14005 .EnumClass = kind == .composite_enumeration_type,
14006 .TypePassbyReference = extra.flags.is_byref,
14007 },
1397714008 .elements = extra.fields_tuple,
1397814009 }, metadata_adapter);
1397914010 },