aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-05-29 00:10:36 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:47:56 -0700
commit32692569656d9a178abb24f8fb7893395700cb62 (patch)
treec2f10d2ed2d1d5e0e6c1cd2d532c6d76d401a466 /src/Module.zig
parent3064d2aa7b9a8ea836cb70884b0640fe902ecc29 (diff)
downloadzig-32692569656d9a178abb24f8fb7893395700cb62.tar.gz
zig-32692569656d9a178abb24f8fb7893395700cb62.zip
behavior: fix more compiler crashes
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig29
1 files changed, 6 insertions, 23 deletions
diff --git a/src/Module.zig b/src/Module.zig
index d11a11cf08..36037bb49c 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -6678,14 +6678,14 @@ pub fn optionalType(mod: *Module, child_type: InternPool.Index) Allocator.Error!
pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type {
var canon_info = info;
+ const have_elem_layout = info.elem_type.toType().layoutIsResolved(mod);
// Canonicalize non-zero alignment. If it matches the ABI alignment of the pointee
// type, we change it to 0 here. If this causes an assertion trip because the
// pointee type needs to be resolved more, that needs to be done before calling
// this ptr() function.
if (info.alignment.toByteUnitsOptional()) |info_align| {
- const elem_align = info.elem_type.toType().abiAlignment(mod);
- if (info.elem_type.toType().layoutIsResolved(mod) and info_align == elem_align) {
+ if (have_elem_layout and info_align == info.elem_type.toType().abiAlignment(mod)) {
canon_info.alignment = .none;
}
}
@@ -6694,7 +6694,7 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type
// Canonicalize host_size. If it matches the bit size of the pointee type,
// we change it to 0 here. If this causes an assertion trip, the pointee type
// needs to be resolved before calling this ptr() function.
- .none => if (info.host_size != 0) {
+ .none => if (have_elem_layout and info.host_size != 0) {
const elem_bit_size = info.elem_type.toType().bitSize(mod);
assert(info.bit_offset + elem_bit_size <= info.host_size * 8);
if (info.host_size * 8 == elem_bit_size) {
@@ -6782,21 +6782,7 @@ pub fn errorSetFromUnsortedNames(
/// Supports optionals in addition to pointers.
pub fn ptrIntValue(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
- if (ty.isPtrLikeOptional(mod)) {
- const i = try intern(mod, .{ .opt = .{
- .ty = ty.toIntern(),
- .val = try intern(mod, .{ .ptr = .{
- .ty = ty.childType(mod).toIntern(),
- .addr = .{ .int = try intern(mod, .{ .int = .{
- .ty = .usize_type,
- .storage = .{ .u64 = x },
- } }) },
- } }),
- } });
- return i.toValue();
- } else {
- return ptrIntValue_ptronly(mod, ty, x);
- }
+ return mod.getCoerced(try mod.intValue_u64(Type.usize, x), ty);
}
/// Supports only pointers. See `ptrIntValue` for pointer-like optional support.
@@ -6804,10 +6790,7 @@ pub fn ptrIntValue_ptronly(mod: *Module, ty: Type, x: u64) Allocator.Error!Value
assert(ty.zigTypeTag(mod) == .Pointer);
const i = try intern(mod, .{ .ptr = .{
.ty = ty.toIntern(),
- .addr = .{ .int = try intern(mod, .{ .int = .{
- .ty = .usize_type,
- .storage = .{ .u64 = x },
- } }) },
+ .addr = .{ .int = try mod.intValue_u64(Type.usize, x) },
} });
return i.toValue();
}
@@ -6954,7 +6937,7 @@ pub fn intBitsForValue(mod: *Module, val: Value, sign: bool) u16 {
const key = mod.intern_pool.indexToKey(val.toIntern());
switch (key.int.storage) {
.i64 => |x| {
- if (std.math.cast(u64, x)) |casted| return Type.smallestUnsignedBits(casted);
+ if (std.math.cast(u64, x)) |casted| return Type.smallestUnsignedBits(casted) + @boolToInt(sign);
assert(sign);
// Protect against overflow in the following negation.
if (x == std.math.minInt(i64)) return 64;