mirror of
https://github.com/ziglang/zig.git
synced 2025-12-30 10:03:21 +00:00
spirv: fix type_map use-after-realloc issues
This commit is contained in:
parent
42226fc1b7
commit
f16d1603ab
@ -947,9 +947,10 @@ pub const DeclGen = struct {
|
||||
return try self.resolveType(union_obj.enum_tag_ty.toType(), .indirect);
|
||||
}
|
||||
|
||||
// TODO: We need to add the active field to the key.
|
||||
// const entry = try self.type_map.getOrPut(self.gpa, ty.toIntern());
|
||||
// if (entry.found_existing) return entry.value_ptr.ty_ref;
|
||||
// TODO: We need to add the active field to the key, somehow.
|
||||
if (maybe_active_field == null) {
|
||||
if (self.type_map.get(ty.toIntern())) |info| return info.ty_ref;
|
||||
}
|
||||
|
||||
var member_types: [4]CacheRef = undefined;
|
||||
var member_names: [4]CacheString = undefined;
|
||||
@ -986,10 +987,9 @@ pub const DeclGen = struct {
|
||||
.member_names = member_names[0..layout.total_fields],
|
||||
} });
|
||||
|
||||
// entry.value_ptr.* = .{
|
||||
// .ty_ref = ty_ref,
|
||||
// };
|
||||
|
||||
if (maybe_active_field == null) {
|
||||
try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref });
|
||||
}
|
||||
return ty_ref;
|
||||
}
|
||||
|
||||
@ -1033,8 +1033,7 @@ pub const DeclGen = struct {
|
||||
return try self.spv.resolve(.{ .float_type = .{ .bits = bits } });
|
||||
},
|
||||
.Array => {
|
||||
const entry = try self.type_map.getOrPut(self.gpa, ty.toIntern());
|
||||
if (entry.found_existing) return entry.value_ptr.ty_ref;
|
||||
if (self.type_map.get(ty.toIntern())) |info| return info.ty_ref;
|
||||
|
||||
const elem_ty = ty.childType(mod);
|
||||
const elem_ty_ref = try self.resolveType(elem_ty, .indirect);
|
||||
@ -1042,15 +1041,12 @@ pub const DeclGen = struct {
|
||||
return self.fail("array type of {} elements is too large", .{ty.arrayLenIncludingSentinel(mod)});
|
||||
};
|
||||
const ty_ref = try self.spv.arrayType(total_len, elem_ty_ref);
|
||||
entry.value_ptr.* = .{
|
||||
.ty_ref = ty_ref,
|
||||
};
|
||||
try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref });
|
||||
return ty_ref;
|
||||
},
|
||||
.Fn => switch (repr) {
|
||||
.direct => {
|
||||
const entry = try self.type_map.getOrPut(self.gpa, ty.toIntern());
|
||||
if (entry.found_existing) return entry.value_ptr.ty_ref;
|
||||
if (self.type_map.get(ty.toIntern())) |info| return info.ty_ref;
|
||||
|
||||
const fn_info = mod.typeToFunc(ty).?;
|
||||
// TODO: Put this somewhere in Sema.zig
|
||||
@ -1069,10 +1065,7 @@ pub const DeclGen = struct {
|
||||
.parameters = param_ty_refs,
|
||||
} });
|
||||
|
||||
entry.value_ptr.* = .{
|
||||
.ty_ref = ty_ref,
|
||||
};
|
||||
|
||||
try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref });
|
||||
return ty_ref;
|
||||
},
|
||||
.indirect => {
|
||||
@ -1119,8 +1112,7 @@ pub const DeclGen = struct {
|
||||
} });
|
||||
},
|
||||
.Struct => {
|
||||
const entry = try self.type_map.getOrPut(self.gpa, ty.toIntern());
|
||||
if (entry.found_existing) return entry.value_ptr.ty_ref;
|
||||
if (self.type_map.get(ty.toIntern())) |info| return info.ty_ref;
|
||||
|
||||
const struct_type = switch (ip.indexToKey(ty.toIntern())) {
|
||||
.anon_struct_type => |tuple| {
|
||||
@ -1140,9 +1132,7 @@ pub const DeclGen = struct {
|
||||
.member_types = member_types[0..member_index],
|
||||
} });
|
||||
|
||||
entry.value_ptr.* = .{
|
||||
.ty_ref = ty_ref,
|
||||
};
|
||||
try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref });
|
||||
return ty_ref;
|
||||
},
|
||||
.struct_type => |struct_type| struct_type,
|
||||
@ -1151,6 +1141,7 @@ pub const DeclGen = struct {
|
||||
|
||||
if (struct_type.layout == .Packed) {
|
||||
return try self.resolveType(struct_type.backingIntType(ip).toType(), .direct);
|
||||
}
|
||||
|
||||
var member_types = std.ArrayList(CacheRef).init(self.gpa);
|
||||
defer member_types.deinit();
|
||||
@ -1172,9 +1163,7 @@ pub const DeclGen = struct {
|
||||
.member_names = member_names.items,
|
||||
} });
|
||||
|
||||
entry.value_ptr.* = .{
|
||||
.ty_ref = ty_ref,
|
||||
};
|
||||
try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref });
|
||||
return ty_ref;
|
||||
},
|
||||
.Optional => {
|
||||
@ -1192,8 +1181,7 @@ pub const DeclGen = struct {
|
||||
return payload_ty_ref;
|
||||
}
|
||||
|
||||
const entry = try self.type_map.getOrPut(self.gpa, ty.toIntern());
|
||||
if (entry.found_existing) return entry.value_ptr.ty_ref;
|
||||
if (self.type_map.get(ty.toIntern())) |info| return info.ty_ref;
|
||||
|
||||
const bool_ty_ref = try self.resolveType(Type.bool, .indirect);
|
||||
|
||||
@ -1205,9 +1193,7 @@ pub const DeclGen = struct {
|
||||
},
|
||||
} });
|
||||
|
||||
entry.value_ptr.* = .{
|
||||
.ty_ref = ty_ref,
|
||||
};
|
||||
try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref });
|
||||
return ty_ref;
|
||||
},
|
||||
.Union => return try self.resolveUnionType(ty, null),
|
||||
@ -1221,8 +1207,7 @@ pub const DeclGen = struct {
|
||||
return error_ty_ref;
|
||||
}
|
||||
|
||||
const entry = try self.type_map.getOrPut(self.gpa, ty.toIntern());
|
||||
if (entry.found_existing) return entry.value_ptr.ty_ref;
|
||||
if (self.type_map.get(ty.toIntern())) |info| return info.ty_ref;
|
||||
|
||||
const payload_ty_ref = try self.resolveType(payload_ty, .indirect);
|
||||
|
||||
@ -1252,9 +1237,7 @@ pub const DeclGen = struct {
|
||||
.member_names = &member_names,
|
||||
} });
|
||||
|
||||
entry.value_ptr.* = .{
|
||||
.ty_ref = ty_ref,
|
||||
};
|
||||
try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref });
|
||||
return ty_ref;
|
||||
},
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user