aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-12-02 18:51:26 +0200
committerVeikka Tuominen <git@vexu.eu>2022-12-03 00:09:23 +0200
commit7f9e841f746bb3eaf6ac205092a30bc7ed12a068 (patch)
tree14b168089558d7c1c27a0ea2f6f69b8d1fbc1813 /src
parent59dad43de26a89ca72a97224a171d724dcc6ee41 (diff)
downloadzig-7f9e841f746bb3eaf6ac205092a30bc7ed12a068.tar.gz
zig-7f9e841f746bb3eaf6ac205092a30bc7ed12a068.zip
Sema: do not forcibly canonicalize unresolved pointer element type
Closes #13308
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig12
-rw-r--r--src/type.zig12
2 files changed, 12 insertions, 12 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 73ebf3d0aa..cc6e5e95d2 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -16825,7 +16825,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
const bitoffset_src: LazySrcLoc = .{ .node_offset_ptr_bitoffset = extra.data.src_node };
const hostsize_src: LazySrcLoc = .{ .node_offset_ptr_hostsize = extra.data.src_node };
- const unresolved_elem_ty = blk: {
+ const elem_ty = blk: {
const air_inst = try sema.resolveInst(extra.data.elem_type);
const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| {
if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer()) {
@@ -16854,7 +16854,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
// Check if this happens to be the lazy alignment of our element type, in
// which case we can make this 0 without resolving it.
if (val.castTag(.lazy_align)) |payload| {
- if (payload.data.eql(unresolved_elem_ty, sema.mod)) {
+ if (payload.data.eql(elem_ty, sema.mod)) {
break :blk 0;
}
}
@@ -16887,14 +16887,6 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
return sema.fail(block, bitoffset_src, "bit offset starts after end of host integer", .{});
}
- const elem_ty = if (abi_align == 0)
- unresolved_elem_ty
- else t: {
- const elem_ty = try sema.resolveTypeFields(unresolved_elem_ty);
- try sema.resolveTypeLayout(elem_ty);
- break :t elem_ty;
- };
-
if (elem_ty.zigTypeTag() == .NoReturn) {
return sema.fail(block, elem_ty_src, "pointer to noreturn not allowed", .{});
} else if (elem_ty.zigTypeTag() == .Fn) {
diff --git a/src/type.zig b/src/type.zig
index 5fcd0f6a26..46b33a34fa 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -6491,8 +6491,16 @@ pub const Type = extern union {
// 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 (d.@"align" != 0 and d.@"align" == d.pointee_type.abiAlignment(target)) {
- d.@"align" = 0;
+ if (d.@"align" != 0) canonicalize: {
+ if (d.pointee_type.castTag(.@"struct")) |struct_ty| {
+ if (!struct_ty.data.haveLayout()) break :canonicalize;
+ }
+ if (d.pointee_type.cast(Payload.Union)) |union_ty| {
+ if (!union_ty.data.haveLayout()) break :canonicalize;
+ }
+ if (d.@"align" == d.pointee_type.abiAlignment(target)) {
+ d.@"align" = 0;
+ }
}
// Canonicalize host_size. If it matches the bit size of the pointee type,