authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-18 01:02:55+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-18 01:02:55+01:00
logf8997aca8f62eef4968e4abf817ece4eb4e91c38
tree727f3d0fb0581aa5e5d77652f84e832dda90879e
parent032319c94257e650abc7a4743298154c218dba89
parent85837de476a919e42da101d42da848a5f181fb38

Merge pull request 'llvm: some random fixes' (#31552) from llvm-fixes into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31552 Reviewed-by: Andrew Kelley <andrew@ziglang.org>

1 files changed, 116 insertions(+), 99 deletions(-)

src/codegen/llvm.zig+116-99
......@@ -1438,8 +1438,7 @@ pub const Object = struct {
14381438 const param = wip.arg(llvm_arg_i);
14391439 llvm_arg_i += 1;
14401440 const field_ptr = try wip.gepStruct(llvm_ty, arg_ptr, field_i, "");
1441 const alignment =
1442 Builder.Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));
1441 const alignment = Builder.Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));
14431442 _ = try wip.store(.normal, param, field_ptr, alignment);
14441443 }
14451444
......@@ -1625,13 +1624,7 @@ pub const Object = struct {
16251624 .pt = pt,
16261625 .err_msg = null,
16271626 };
1628 ng.genDecl() catch |err| switch (err) {
1629 error.CodegenFail => switch (pt.zcu.codegenFailMsg(nav_index, ng.err_msg.?)) {
1630 error.CodegenFail => return,
1631 error.OutOfMemory => |e| return e,
1632 },
1633 else => |e| return e,
1634 };
1627 try ng.genDecl();
16351628 try self.flushTypePool(pt);
16361629 }
16371630
......@@ -1713,10 +1706,7 @@ pub const Object = struct {
17131706 const global_index = variable_index.ptrConst(&o.builder).global;
17141707 gop.value_ptr.* = global_index;
17151708 // This line invalidates `gop`.
1716 const init_val = o.lowerValue(pt, exported_value) catch |err| switch (err) {
1717 error.OutOfMemory => return error.OutOfMemory,
1718 error.CodegenFail => return error.AnalysisFail,
1719 };
1709 const init_val = try o.lowerValue(pt, exported_value);
17201710 try variable_index.setInitializer(init_val, &o.builder);
17211711 break :i global_index;
17221712 };
......@@ -1834,6 +1824,9 @@ pub const Object = struct {
18341824
18351825 pub fn updateContainerType(o: *Object, pt: Zcu.PerThread, ty: InternPool.Index, success: bool) Allocator.Error!void {
18361826 try o.type_pool.updateContainerType(pt, .{ .llvm = o }, ty, success);
1827 if (o.named_enum_map.get(ty)) |function_index| {
1828 try o.updateIsNamedEnumValueFunction(pt, .fromInterned(ty), function_index);
1829 }
18371830 }
18381831
18391832 /// Should only be called by the `link.ConstPool` implementation.
......@@ -2907,7 +2900,7 @@ pub const Object = struct {
29072900 uav: InternPool.Index,
29082901 llvm_addr_space: Builder.AddrSpace,
29092902 alignment: InternPool.Alignment,
2910 ) Error!Builder.Variable.Index {
2903 ) Allocator.Error!Builder.Variable.Index {
29112904 assert(alignment != .none);
29122905 // TODO: Add address space to the anon_decl_map
29132906 const gop = try o.uav_map.getOrPut(o.gpa, uav);
......@@ -3506,7 +3499,7 @@ pub const Object = struct {
35063499 );
35073500 }
35083501
3509 fn lowerValue(o: *Object, pt: Zcu.PerThread, arg_val: InternPool.Index) Error!Builder.Constant {
3502 fn lowerValue(o: *Object, pt: Zcu.PerThread, arg_val: InternPool.Index) Allocator.Error!Builder.Constant {
35103503 const zcu = pt.zcu;
35113504 const ip = &zcu.intern_pool;
35123505 const target = zcu.getTarget();
......@@ -4019,7 +4012,7 @@ pub const Object = struct {
40194012 pt: Zcu.PerThread,
40204013 ptr_val: InternPool.Index,
40214014 prev_offset: u64,
4022 ) Error!Builder.Constant {
4015 ) Allocator.Error!Builder.Constant {
40234016 const zcu = pt.zcu;
40244017 const ptr = zcu.intern_pool.indexToKey(ptr_val).ptr;
40254018 const offset: u64 = prev_offset + ptr.byte_offset;
......@@ -4086,7 +4079,7 @@ pub const Object = struct {
40864079 o: *Object,
40874080 pt: Zcu.PerThread,
40884081 uav: InternPool.Key.Ptr.BaseAddr.Uav,
4089 ) Error!Builder.Constant {
4082 ) Allocator.Error!Builder.Constant {
40904083 const zcu = pt.zcu;
40914084 const ip = &zcu.intern_pool;
40924085 const uav_val = uav.val;
......@@ -4363,6 +4356,58 @@ pub const Object = struct {
43634356 const index = try o.type_pool.get(pt, .{ .llvm = o }, ty.toIntern());
43644357 return o.lazy_abi_aligns.items[@intFromEnum(index)];
43654358 }
4359
4360 fn updateIsNamedEnumValueFunction(
4361 o: *Object,
4362 pt: Zcu.PerThread,
4363 enum_ty: Type,
4364 function_index: Builder.Function.Index,
4365 ) Allocator.Error!void {
4366 const zcu = pt.zcu;
4367 const builder = &o.builder;
4368 const loaded_enum = zcu.intern_pool.loadEnumType(enum_ty.toIntern());
4369 function_index.ptrConst(builder).global.ptr(builder).type = try builder.fnType(
4370 .i1,
4371 &.{try o.lowerType(pt, .fromInterned(loaded_enum.int_tag_type))},
4372 .normal,
4373 );
4374
4375 var attributes: Builder.FunctionAttributes.Wip = .{};
4376 defer attributes.deinit(builder);
4377 try o.addCommonFnAttributes(&attributes, zcu.root_mod, zcu.root_mod.omit_frame_pointer);
4378
4379 function_index.setLinkage(.internal, builder);
4380 function_index.setCallConv(.fastcc, builder);
4381 function_index.setAttributes(try attributes.finish(builder), builder);
4382
4383 var wip: Builder.WipFunction = try .init(builder, .{
4384 .function = function_index,
4385 .strip = true,
4386 });
4387 defer wip.deinit();
4388 wip.cursor = .{ .block = try wip.block(0, "Entry") };
4389
4390 const named_block = try wip.block(@intCast(loaded_enum.field_names.len), "Named");
4391 const unnamed_block = try wip.block(1, "Unnamed");
4392 const tag_int_value = wip.arg(0);
4393 var wip_switch = try wip.@"switch"(tag_int_value, unnamed_block, @intCast(loaded_enum.field_names.len), .none);
4394 defer wip_switch.finish(&wip);
4395
4396 for (0..loaded_enum.field_names.len) |field_index| {
4397 const this_tag_int_value = try o.lowerValue(
4398 pt,
4399 (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(),
4400 );
4401 try wip_switch.addCase(this_tag_int_value, named_block, &wip);
4402 }
4403 wip.cursor = .{ .block = named_block };
4404 _ = try wip.ret(.true);
4405
4406 wip.cursor = .{ .block = unnamed_block };
4407 _ = try wip.ret(.false);
4408
4409 try wip.finish();
4410 }
43664411};
43674412
43684413pub const NavGen = struct {
......@@ -6105,7 +6150,7 @@ pub const FuncGen = struct {
61056150 const body = unwrapped_try.else_body;
61066151 const err_union_ty = self.typeOf(unwrapped_try.error_union);
61076152 const is_unused = self.liveness.isUnused(inst);
6108 return lowerTry(self, err_union, body, err_union_ty, false, false, is_unused, err_cold);
6153 return lowerTry(self, err_union, body, err_union_ty, false, .none, false, is_unused, err_cold);
61096154 }
61106155
61116156 fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index, err_cold: bool) !Builder.Value {
......@@ -6113,12 +6158,13 @@ pub const FuncGen = struct {
61136158 const unwrapped_try = self.air.unwrapTryPtr(inst);
61146159 const err_union_ptr = try self.resolveInst(unwrapped_try.error_union_ptr);
61156160 const body = unwrapped_try.else_body;
6116 const err_union_ty = self.typeOf(unwrapped_try.error_union_ptr).childType(zcu);
6161 const err_union_ptr_ty = self.typeOf(unwrapped_try.error_union_ptr);
6162 const err_union_ty = err_union_ptr_ty.childType(zcu);
61176163 const is_unused = self.liveness.isUnused(inst);
61186164
61196165 self.maybeMarkAllowZeroAccess(self.typeOf(unwrapped_try.error_union_ptr).ptrInfo(zcu));
61206166
6121 return lowerTry(self, err_union_ptr, body, err_union_ty, true, true, is_unused, err_cold);
6167 return lowerTry(self, err_union_ptr, body, err_union_ty, true, err_union_ptr_ty.ptrAlignment(zcu), true, is_unused, err_cold);
61226168 }
61236169
61246170 fn lowerTry(
......@@ -6127,6 +6173,7 @@ pub const FuncGen = struct {
61276173 body: []const Air.Inst.Index,
61286174 err_union_ty: Type,
61296175 operand_is_ptr: bool,
6176 operand_ptr_align: InternPool.Alignment,
61306177 can_elide_load: bool,
61316178 is_unused: bool,
61326179 err_cold: bool,
......@@ -6139,15 +6186,19 @@ pub const FuncGen = struct {
61396186 const err_union_llvm_ty = try o.lowerType(pt, err_union_ty);
61406187 const error_type = try o.errorIntType(pt);
61416188
6189 const err_set_align: InternPool.Alignment, const payload_align: InternPool.Alignment = if (operand_is_ptr) .{
6190 operand_ptr_align.minStrict(Type.anyerror.abiAlignment(zcu)),
6191 operand_ptr_align.minStrict(payload_ty.abiAlignment(zcu)),
6192 } else .{ .none, .none };
6193
61426194 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
61436195 const loaded = loaded: {
61446196 const access_kind: Builder.MemoryAccessKind =
61456197 if (err_union_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
61466198
61476199 if (!payload_has_bits) {
6148 // TODO add alignment to this load
61496200 break :loaded if (operand_is_ptr)
6150 try fg.wip.load(access_kind, error_type, err_union, .default, "")
6201 try fg.wip.load(access_kind, error_type, err_union, err_set_align.toLlvm(), "")
61516202 else
61526203 err_union;
61536204 }
......@@ -6155,12 +6206,11 @@ pub const FuncGen = struct {
61556206 if (operand_is_ptr or isByRef(err_union_ty, zcu)) {
61566207 const err_field_ptr =
61576208 try fg.wip.gepStruct(err_union_llvm_ty, err_union, err_field_index, "");
6158 // TODO add alignment to this load
61596209 break :loaded try fg.wip.load(
61606210 if (operand_is_ptr) access_kind else .normal,
61616211 error_type,
61626212 err_field_ptr,
6163 .default,
6213 err_set_align.toLlvm(),
61646214 "",
61656215 );
61666216 }
......@@ -6186,15 +6236,14 @@ pub const FuncGen = struct {
61866236 return fg.wip.gepStruct(err_union_llvm_ty, err_union, offset, "");
61876237 } else if (isByRef(err_union_ty, zcu)) {
61886238 const payload_ptr = try fg.wip.gepStruct(err_union_llvm_ty, err_union, offset, "");
6189 const payload_alignment = payload_ty.abiAlignment(zcu).toLlvm();
61906239 if (isByRef(payload_ty, zcu)) {
61916240 if (can_elide_load)
61926241 return payload_ptr;
61936242
6194 return fg.loadByRef(payload_ptr, payload_ty, payload_alignment, .normal);
6243 return fg.loadByRef(payload_ptr, payload_ty, payload_align.toLlvm(), .normal);
61956244 }
61966245 const load_ty = err_union_llvm_ty.structFields(&o.builder)[offset];
6197 return fg.wip.load(.normal, load_ty, payload_ptr, payload_alignment, "");
6246 return fg.wip.load(.normal, load_ty, payload_ptr, payload_align.toLlvm(), "");
61986247 }
61996248 return fg.wip.extractValue(err_union, &.{offset}, "");
62006249 }
......@@ -6667,20 +6716,20 @@ pub const FuncGen = struct {
66676716 const slice_ty = self.typeOf(bin_op.lhs);
66686717 const slice = try self.resolveInst(bin_op.lhs);
66696718 const index = try self.resolveInst(bin_op.rhs);
6670 const elem_ty = slice_ty.childType(zcu);
6719 const slice_info = slice_ty.ptrInfo(zcu);
6720 assert(slice_info.flags.size == .slice);
6721 const elem_ty: Type = .fromInterned(slice_info.child);
66716722 const llvm_elem_ty = try o.lowerType(pt, elem_ty);
66726723 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");
66736724 const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");
6725 const elem_align = slice_ty.ptrAlignment(zcu).min(elem_ty.abiAlignment(zcu));
6726 const access_kind: Builder.MemoryAccessKind = if (slice_info.flags.is_volatile) .@"volatile" else .normal;
6727 self.maybeMarkAllowZeroAccess(slice_info);
66746728 if (isByRef(elem_ty, zcu)) {
6675 self.maybeMarkAllowZeroAccess(slice_ty.ptrInfo(zcu));
6676
6677 const slice_align = (slice_ty.ptrAlignment(zcu).min(elem_ty.abiAlignment(zcu))).toLlvm();
6678 return self.loadByRef(ptr, elem_ty, slice_align, if (slice_ty.isVolatilePtr(zcu)) .@"volatile" else .normal);
6729 return self.loadByRef(ptr, elem_ty, elem_align.toLlvm(), access_kind);
6730 } else {
6731 return self.loadTruncate(access_kind, elem_ty, ptr, elem_align.toLlvm());
66796732 }
6680
6681 self.maybeMarkAllowZeroAccess(slice_ty.ptrInfo(zcu));
6682
6683 return self.load(ptr, slice_ty);
66846733 }
66856734
66866735 fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
......@@ -7461,7 +7510,7 @@ pub const FuncGen = struct {
74617510
74627511 if (optional_ty.optionalReprIsPayload(zcu)) {
74637512 const loaded = if (operand_is_ptr)
7464 try self.wip.load(access_kind, optional_llvm_ty, operand, .default, "")
7513 try self.wip.load(access_kind, optional_llvm_ty, operand, operand_ty.ptrAlignment(zcu).toLlvm(), "")
74657514 else
74667515 operand;
74677516 if (payload_ty.isSlice(zcu)) {
......@@ -7479,7 +7528,7 @@ pub const FuncGen = struct {
74797528
74807529 if (!payload_ty.hasRuntimeBits(zcu)) {
74817530 const loaded = if (operand_is_ptr)
7482 try self.wip.load(access_kind, optional_llvm_ty, operand, .default, "")
7531 try self.wip.load(access_kind, optional_llvm_ty, operand, operand_ty.ptrAlignment(zcu).toLlvm(), "")
74837532 else
74847533 operand;
74857534 return self.wip.icmp(cond, loaded, try o.builder.intValue(.i8, 0), "");
......@@ -7522,7 +7571,7 @@ pub const FuncGen = struct {
75227571
75237572 if (!payload_ty.hasRuntimeBits(zcu)) {
75247573 const loaded = if (operand_is_ptr)
7525 try self.wip.load(access_kind, try o.lowerType(pt, err_union_ty), operand, .default, "")
7574 try self.wip.load(access_kind, try o.lowerType(pt, err_union_ty), operand, operand_ty.ptrAlignment(zcu).toLlvm(), "")
75267575 else
75277576 operand;
75287577 return self.wip.icmp(cond, loaded, zero, "");
......@@ -7532,9 +7581,13 @@ pub const FuncGen = struct {
75327581
75337582 const loaded = if (operand_is_ptr or isByRef(err_union_ty, zcu)) loaded: {
75347583 const err_union_llvm_ty = try o.lowerType(pt, err_union_ty);
7584 const err_alignment = if (operand_is_ptr)
7585 operand_ty.ptrAlignment(zcu).minStrict(Type.anyerror.abiAlignment(zcu))
7586 else
7587 .none;
75357588 const err_field_ptr =
75367589 try self.wip.gepStruct(err_union_llvm_ty, operand, err_field_index, "");
7537 break :loaded try self.wip.load(access_kind, error_type, err_field_ptr, .default, "");
7590 break :loaded try self.wip.load(access_kind, error_type, err_field_ptr, err_alignment.toLlvm(), "");
75387591 } else try self.wip.extractValue(operand, &.{err_field_index}, "");
75397592 return self.wip.icmp(cond, loaded, zero, "");
75407593 }
......@@ -7579,6 +7632,7 @@ pub const FuncGen = struct {
75797632 self.maybeMarkAllowZeroAccess(optional_ptr_ty.ptrInfo(zcu));
75807633
75817634 // We have a pointer to a i8. We need to set it to 1 and then return the same pointer.
7635 // Default alignment store because align of the non null bit is 1 anyway.
75827636 _ = try self.wip.store(access_kind, non_null_bit, operand, .default);
75837637 return operand;
75847638 }
......@@ -7594,7 +7648,7 @@ pub const FuncGen = struct {
75947648
75957649 self.maybeMarkAllowZeroAccess(optional_ptr_ty.ptrInfo(zcu));
75967650
7597 // TODO set alignment on this store
7651 // Default alignment store because align of the non null bit is 1 anyway.
75987652 _ = try self.wip.store(access_kind, non_null_bit, non_null_ptr, .default);
75997653
76007654 // Then return the payload pointer (only if it's used).
......@@ -7682,7 +7736,7 @@ pub const FuncGen = struct {
76827736
76837737 self.maybeMarkAllowZeroAccess(operand_ty.ptrInfo(zcu));
76847738
7685 return self.wip.load(access_kind, error_type, operand, .default, "");
7739 return self.wip.load(access_kind, error_type, operand, operand_ty.ptrAlignment(zcu).toLlvm(), "");
76867740 }
76877741
76887742 const offset = try errUnionErrorOffset(payload_ty, pt);
......@@ -7706,6 +7760,7 @@ pub const FuncGen = struct {
77067760 const operand = try self.resolveInst(ty_op.operand);
77077761 const err_union_ptr_ty = self.typeOf(ty_op.operand);
77087762 const err_union_ty = err_union_ptr_ty.childType(zcu);
7763 const err_union_ptr_align = err_union_ptr_ty.ptrAlignment(zcu);
77097764
77107765 const payload_ty = err_union_ty.errorUnionPayload(zcu);
77117766 const non_error_val = try o.builder.intValue(try o.errorIntType(pt), 0);
......@@ -7715,8 +7770,7 @@ pub const FuncGen = struct {
77157770
77167771 if (!payload_ty.hasRuntimeBits(zcu)) {
77177772 self.maybeMarkAllowZeroAccess(err_union_ptr_ty.ptrInfo(zcu));
7718
7719 _ = try self.wip.store(access_kind, non_error_val, operand, .default);
7773 _ = try self.wip.store(access_kind, non_error_val, operand, err_union_ptr_align.toLlvm());
77207774 return operand;
77217775 }
77227776 const err_union_llvm_ty = try o.lowerType(pt, err_union_ty);
......@@ -7724,7 +7778,7 @@ pub const FuncGen = struct {
77247778 self.maybeMarkAllowZeroAccess(err_union_ptr_ty.ptrInfo(zcu));
77257779
77267780 const err_int_ty = try pt.errorIntType();
7727 const error_alignment = err_int_ty.abiAlignment(zcu).toLlvm();
7781 const error_alignment = err_int_ty.abiAlignment(zcu).minStrict(err_union_ptr_align).toLlvm();
77287782 const error_offset = try errUnionErrorOffset(payload_ty, pt);
77297783 // First set the non-error value.
77307784 const non_null_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, error_offset, "");
......@@ -8405,9 +8459,8 @@ pub const FuncGen = struct {
84058459 _ = try self.wip.store(.normal, result_val, field_ptr, result_alignment);
84068460 }
84078461 {
8408 const overflow_alignment = comptime Builder.Alignment.fromByteUnits(1);
84098462 const field_ptr = try self.wip.gepStruct(llvm_inst_ty, alloca_inst, overflow_index, "");
8410 _ = try self.wip.store(.normal, overflow_bit, field_ptr, overflow_alignment);
8463 _ = try self.wip.store(.normal, overflow_bit, field_ptr, comptime .fromByteUnits(1));
84118464 }
84128465
84138466 return alloca_inst;
......@@ -8767,9 +8820,8 @@ pub const FuncGen = struct {
87678820 _ = try self.wip.store(.normal, result, field_ptr, result_alignment);
87688821 }
87698822 {
8770 const field_alignment = comptime Builder.Alignment.fromByteUnits(1);
87718823 const field_ptr = try self.wip.gepStruct(llvm_dest_ty, alloca_inst, overflow_index, "");
8772 _ = try self.wip.store(.normal, overflow_bit, field_ptr, field_alignment);
8824 _ = try self.wip.store(.normal, overflow_bit, field_ptr, comptime .fromByteUnits(1));
87738825 }
87748826 return alloca_inst;
87758827 }
......@@ -9925,15 +9977,18 @@ pub const FuncGen = struct {
99259977
99269978 const union_ptr = try self.resolveInst(bin_op.lhs);
99279979 const new_tag = try self.resolveInst(bin_op.rhs);
9980 const union_ptr_align = un_ptr_ty.ptrAlignment(zcu);
99289981 if (layout.payload_size == 0) {
9929 // TODO alignment on this store
9930 _ = try self.wip.store(access_kind, new_tag, union_ptr, .default);
9982 _ = try self.wip.store(access_kind, new_tag, union_ptr, union_ptr_align.toLlvm());
99319983 return .none;
99329984 }
99339985 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));
99349986 const tag_field_ptr = try self.wip.gepStruct(try o.lowerType(pt, un_ty), union_ptr, tag_index, "");
9935 // TODO alignment on this store
9936 _ = try self.wip.store(access_kind, new_tag, tag_field_ptr, .default);
9987 const tag_ptr_align: InternPool.Alignment = switch (layout.tagOffset()) {
9988 0 => union_ptr_align,
9989 else => |off| .minStrict(union_ptr_align, .fromLog2Units(@ctz(off))),
9990 };
9991 _ = try self.wip.store(access_kind, new_tag, tag_field_ptr, tag_ptr_align.toLlvm());
99379992 return .none;
99389993 }
99399994
......@@ -10106,56 +10161,19 @@ pub const FuncGen = struct {
1010610161 const pt = self.ng.pt;
1010710162 const zcu = pt.zcu;
1010810163 const ip = &zcu.intern_pool;
10109 const enum_type = ip.loadEnumType(enum_ty.toIntern());
1011010164
10111 // TODO: detect when the type changes (`updateContainerType` will be called) and re-emit this function
1011210165 const gop = try o.named_enum_map.getOrPut(o.gpa, enum_ty.toIntern());
1011310166 if (gop.found_existing) return gop.value_ptr.*;
1011410167 errdefer assert(o.named_enum_map.remove(enum_ty.toIntern()));
10115
10116 const target = &zcu.root_mod.resolved_target.result;
1011710168 const function_index = try o.builder.addFunction(
10118 try o.builder.fnType(.i1, &.{try o.lowerType(pt, Type.fromInterned(enum_type.int_tag_type))}, .normal),
10119 try o.builder.strtabStringFmt("__zig_is_named_enum_value_{f}", .{enum_type.name.fmt(ip)}),
10120 toLlvmAddressSpace(.generic, target),
10169 // Dummy function type; `updateIsNamedEnumValue` will replace it with the correct type.
10170 // TODO: change the builder API so we don't need to do this.
10171 try o.builder.fnType(.void, &.{}, .normal),
10172 try o.builder.strtabStringFmt("__zig_is_named_enum_value_{f}", .{enum_ty.containerTypeName(ip).fmt(ip)}),
10173 toLlvmAddressSpace(.generic, zcu.getTarget()),
1012110174 );
10122
10123 var attributes: Builder.FunctionAttributes.Wip = .{};
10124 defer attributes.deinit(&o.builder);
10125 try o.addCommonFnAttributes(&attributes, zcu.root_mod, zcu.root_mod.omit_frame_pointer);
10126
10127 function_index.setLinkage(.internal, &o.builder);
10128 function_index.setCallConv(.fastcc, &o.builder);
10129 function_index.setAttributes(try attributes.finish(&o.builder), &o.builder);
1013010175 gop.value_ptr.* = function_index;
10131
10132 var wip = try Builder.WipFunction.init(&o.builder, .{
10133 .function = function_index,
10134 .strip = true,
10135 });
10136 defer wip.deinit();
10137 wip.cursor = .{ .block = try wip.block(0, "Entry") };
10138
10139 const named_block = try wip.block(@intCast(enum_type.field_names.len), "Named");
10140 const unnamed_block = try wip.block(1, "Unnamed");
10141 const tag_int_value = wip.arg(0);
10142 var wip_switch = try wip.@"switch"(tag_int_value, unnamed_block, @intCast(enum_type.field_names.len), .none);
10143 defer wip_switch.finish(&wip);
10144
10145 for (0..enum_type.field_names.len) |field_index| {
10146 const this_tag_int_value = try o.lowerValue(
10147 pt,
10148 (try pt.enumValueFieldIndex(enum_ty, @intCast(field_index))).toIntern(),
10149 );
10150 try wip_switch.addCase(this_tag_int_value, named_block, &wip);
10151 }
10152 wip.cursor = .{ .block = named_block };
10153 _ = try wip.ret(.true);
10154
10155 wip.cursor = .{ .block = unnamed_block };
10156 _ = try wip.ret(.false);
10157
10158 try wip.finish();
10176 try o.updateIsNamedEnumValueFunction(pt, enum_ty, function_index);
1015910177 return function_index;
1016010178 }
1016110179
......@@ -10824,9 +10842,8 @@ pub const FuncGen = struct {
1082410842 comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Rw.read) == 0);
1082510843 comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Rw.write) == 1);
1082610844
10827 // TODO these two asserts should be able to be comptime because the type is a u2
10828 assert(prefetch.locality >= 0);
10829 assert(prefetch.locality <= 3);
10845 comptime assert(prefetch.locality >= 0);
10846 comptime assert(prefetch.locality <= 3);
1083010847
1083110848 comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Cache.instruction) == 0);
1083210849 comptime assert(@intFromEnum(std.builtin.PrefetchOptions.Cache.data) == 1);