Skip to content

Commit

Permalink
disallow stores to element types with no comptime size
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexicon226 committed Dec 15, 2024
1 parent af89bb0 commit 3ac8bc2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31958,6 +31958,14 @@ fn storePtr2(
});
}

// Don't allow stores to element types that have no comptime size.
switch (elem_ty.zigTypeTag(zcu)) {
.@"fn",
.@"opaque",
=> return sema.fail(block, ptr_src, "pointer element type must have a comptime-known size", .{}),
else => std.debug.print("{} {}", .{ elem_ty.fmt(pt), elem_ty.zigTypeTag(zcu) }),
}

const store_inst = if (is_ret)
try block.addBinOp(.store, ptr, operand)
else
Expand Down
15 changes: 15 additions & 0 deletions test/cases/compile_errors/store_no_comptime_size.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export fn a() void {
const x: *fn () void = @ptrFromInt(4);
x.* = undefined;
}

export fn b(x: *anyopaque) void {
x.* = undefined;
}

// error
// backend=stage2
// target=native
//
// :3:6: error: pointer element type must have a comptime-known size
// :7:6: error: pointer element type must have a comptime-known size

0 comments on commit 3ac8bc2

Please sign in to comment.