aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-05-29 08:21:47 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:47:56 -0700
commita702af062bb65673ba554dba330b4c5ca8d50f3e (patch)
tree042542e3bc6359b739e70af5b8bd3f2a3b9b0932 /src/codegen.zig
parent4f70863a55e699c13731325f8c52870119479c02 (diff)
downloadzig-a702af062bb65673ba554dba330b4c5ca8d50f3e.tar.gz
zig-a702af062bb65673ba554dba330b4c5ca8d50f3e.zip
x86_64: fix InternPool regressions
Diffstat (limited to 'src/codegen.zig')
-rw-r--r--src/codegen.zig94
1 files changed, 52 insertions, 42 deletions
diff --git a/src/codegen.zig b/src/codegen.zig
index 0034e96e35..983d895991 100644
--- a/src/codegen.zig
+++ b/src/codegen.zig
@@ -387,22 +387,24 @@ pub fn generateSymbol(
},
.aggregate => |aggregate| switch (mod.intern_pool.indexToKey(typed_value.ty.toIntern())) {
.array_type => |array_type| {
- var index: u64 = 0;
- while (index < array_type.len) : (index += 1) {
- switch (aggregate.storage) {
- .bytes => |bytes| try code.appendSlice(bytes),
- .elems, .repeated_elem => switch (try generateSymbol(bin_file, src_loc, .{
- .ty = array_type.child.toType(),
- .val = switch (aggregate.storage) {
- .bytes => unreachable,
- .elems => |elems| elems[@intCast(usize, index)],
- .repeated_elem => |elem| elem,
- }.toValue(),
- }, code, debug_output, reloc_info)) {
- .ok => {},
- .fail => |em| return .{ .fail = em },
- },
- }
+ switch (aggregate.storage) {
+ .bytes => |bytes| try code.appendSlice(bytes),
+ .elems, .repeated_elem => {
+ var index: u64 = 0;
+ while (index < array_type.len) : (index += 1) {
+ switch (try generateSymbol(bin_file, src_loc, .{
+ .ty = array_type.child.toType(),
+ .val = switch (aggregate.storage) {
+ .bytes => unreachable,
+ .elems => |elems| elems[@intCast(usize, index)],
+ .repeated_elem => |elem| elem,
+ }.toValue(),
+ }, code, debug_output, reloc_info)) {
+ .ok => {},
+ .fail => |em| return .{ .fail = em },
+ }
+ }
+ },
}
if (array_type.sentinel != .none) {
@@ -416,22 +418,24 @@ pub fn generateSymbol(
}
},
.vector_type => |vector_type| {
- var index: u32 = 0;
- while (index < vector_type.len) : (index += 1) {
- switch (aggregate.storage) {
- .bytes => |bytes| try code.appendSlice(bytes),
- .elems, .repeated_elem => switch (try generateSymbol(bin_file, src_loc, .{
- .ty = vector_type.child.toType(),
- .val = switch (aggregate.storage) {
- .bytes => unreachable,
- .elems => |elems| elems[@intCast(usize, index)],
- .repeated_elem => |elem| elem,
- }.toValue(),
- }, code, debug_output, reloc_info)) {
- .ok => {},
- .fail => |em| return .{ .fail = em },
- },
- }
+ switch (aggregate.storage) {
+ .bytes => |bytes| try code.appendSlice(bytes),
+ .elems, .repeated_elem => {
+ var index: u64 = 0;
+ while (index < vector_type.len) : (index += 1) {
+ switch (try generateSymbol(bin_file, src_loc, .{
+ .ty = vector_type.child.toType(),
+ .val = switch (aggregate.storage) {
+ .bytes => unreachable,
+ .elems => |elems| elems[@intCast(usize, index)],
+ .repeated_elem => |elem| elem,
+ }.toValue(),
+ }, code, debug_output, reloc_info)) {
+ .ok => {},
+ .fail => |em| return .{ .fail = em },
+ }
+ }
+ },
}
const padding = math.cast(usize, typed_value.ty.abiSize(mod) -
@@ -669,7 +673,7 @@ fn lowerParentPtr(
mod.intern_pool.typeOf(elem.base).toType().elemType2(mod).abiSize(mod))),
),
.field => |field| {
- const base_type = mod.intern_pool.typeOf(field.base);
+ const base_type = mod.intern_pool.indexToKey(mod.intern_pool.typeOf(field.base)).ptr_type.elem_type;
return lowerParentPtr(
bin_file,
src_loc,
@@ -688,7 +692,7 @@ fn lowerParentPtr(
.struct_type,
.anon_struct_type,
.union_type,
- => @intCast(u32, base_type.toType().childType(mod).structFieldOffset(
+ => @intCast(u32, base_type.toType().structFieldOffset(
@intCast(u32, field.index),
mod,
)),
@@ -989,17 +993,23 @@ pub fn genTypedValue(
return GenResult.mcv(.{ .immediate = error_index });
},
.ErrorUnion => {
- const error_type = typed_value.ty.errorUnionSet(mod);
+ const err_type = typed_value.ty.errorUnionSet(mod);
const payload_type = typed_value.ty.errorUnionPayload(mod);
- const is_pl = typed_value.val.errorUnionIsPayload(mod);
-
if (!payload_type.hasRuntimeBitsIgnoreComptime(mod)) {
// We use the error type directly as the type.
- const err_val = if (!is_pl) typed_value.val else try mod.intValue(error_type, 0);
- return genTypedValue(bin_file, src_loc, .{
- .ty = error_type,
- .val = err_val,
- }, owner_decl_index);
+ switch (mod.intern_pool.indexToKey(typed_value.val.toIntern()).error_union.val) {
+ .err_name => |err_name| return genTypedValue(bin_file, src_loc, .{
+ .ty = err_type,
+ .val = (try mod.intern(.{ .err = .{
+ .ty = err_type.toIntern(),
+ .name = err_name,
+ } })).toValue(),
+ }, owner_decl_index),
+ .payload => return genTypedValue(bin_file, src_loc, .{
+ .ty = Type.err_int,
+ .val = try mod.intValue(Type.err_int, 0),
+ }, owner_decl_index),
+ }
}
},