aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-03-17 15:19:54 -0700
committerGitHub <noreply@github.com>2024-03-17 15:19:54 -0700
commitd981549d65849591749d8d9db12ddf2bf7361399 (patch)
treeced0941ad568c7bb7cddc57759e8d320a71ab7fc /lib/std
parent294f51814f491ae4a09348d9e7221ae3e550c16f (diff)
parentedeed592eeed151780ae8a0b13c3d4d17c3f93b2 (diff)
downloadzig-d981549d65849591749d8d9db12ddf2bf7361399.tar.gz
zig-d981549d65849591749d8d9db12ddf2bf7361399.zip
Merge pull request #19323 from jacobly0/rm-fn-type-align
AstGen: disallow alignment on function types
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/builtin.zig1
-rw-r--r--lib/std/c/darwin.zig10
-rw-r--r--lib/std/c/dragonfly.zig8
-rw-r--r--lib/std/c/freebsd.zig8
-rw-r--r--lib/std/c/haiku.zig8
-rw-r--r--lib/std/c/netbsd.zig8
-rw-r--r--lib/std/c/openbsd.zig12
-rw-r--r--lib/std/c/solaris.zig10
-rw-r--r--lib/std/meta.zig9
-rw-r--r--lib/std/os/emscripten.zig8
-rw-r--r--lib/std/os/linux.zig41
-rw-r--r--lib/std/zig/AstGen.zig14
12 files changed, 65 insertions, 72 deletions
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig
index d9e72f2019..0238d35c7d 100644
--- a/lib/std/builtin.zig
+++ b/lib/std/builtin.zig
@@ -420,7 +420,6 @@ pub const Type = union(enum) {
/// therefore must be kept in sync with the compiler implementation.
pub const Fn = struct {
calling_convention: CallingConvention,
- alignment: comptime_int,
is_generic: bool,
is_var_args: bool,
/// TODO change the language spec to make this not optional.
diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig
index 8dd122c3ba..8442ac9fe0 100644
--- a/lib/std/c/darwin.zig
+++ b/lib/std/c/darwin.zig
@@ -1053,10 +1053,10 @@ pub const sigset_t = u32;
pub const empty_sigset: sigset_t = 0;
pub const SIG = struct {
- pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
- pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
- pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
- pub const HOLD = @as(?Sigaction.handler_fn, @ptrFromInt(5));
+ pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
+ pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
+ pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
+ pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(5);
/// block specified signal set
pub const BLOCK = 1;
@@ -1150,7 +1150,7 @@ pub const siginfo_t = extern struct {
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
pub const Sigaction = extern struct {
- pub const handler_fn = *const fn (c_int) align(1) callconv(.C) void;
+ pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
handler: extern union {
diff --git a/lib/std/c/dragonfly.zig b/lib/std/c/dragonfly.zig
index 8cbdd22c40..183a81bba2 100644
--- a/lib/std/c/dragonfly.zig
+++ b/lib/std/c/dragonfly.zig
@@ -616,9 +616,9 @@ pub const S = struct {
pub const BADSIG = SIG.ERR;
pub const SIG = struct {
- pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
- pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
- pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
+ pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
+ pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
+ pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
pub const BLOCK = 1;
pub const UNBLOCK = 2;
@@ -690,7 +690,7 @@ pub const empty_sigset = sigset_t{ .__bits = [_]c_uint{0} ** _SIG_WORDS };
pub const sig_atomic_t = c_int;
pub const Sigaction = extern struct {
- pub const handler_fn = *const fn (c_int) align(1) callconv(.C) void;
+ pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
/// signal handler
diff --git a/lib/std/c/freebsd.zig b/lib/std/c/freebsd.zig
index 94854cf090..a89ca30968 100644
--- a/lib/std/c/freebsd.zig
+++ b/lib/std/c/freebsd.zig
@@ -695,9 +695,9 @@ pub const SIG = struct {
pub const UNBLOCK = 2;
pub const SETMASK = 3;
- pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
- pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
- pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
+ pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
+ pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
+ pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
pub const WORDS = 4;
pub const MAXSIG = 128;
@@ -1171,7 +1171,7 @@ const NSIG = 32;
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
- pub const handler_fn = *const fn (c_int) align(1) callconv(.C) void;
+ pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
/// signal handler
diff --git a/lib/std/c/haiku.zig b/lib/std/c/haiku.zig
index 723d953d2d..12b5201acd 100644
--- a/lib/std/c/haiku.zig
+++ b/lib/std/c/haiku.zig
@@ -441,9 +441,9 @@ pub const SA = struct {
};
pub const SIG = struct {
- pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
- pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
- pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
+ pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
+ pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
+ pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
pub const HUP = 1;
pub const INT = 2;
@@ -690,7 +690,7 @@ const NSIG = 32;
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
- pub const handler_fn = *const fn (i32) align(1) callconv(.C) void;
+ pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
/// signal handler
__sigaction_u: extern union {
diff --git a/lib/std/c/netbsd.zig b/lib/std/c/netbsd.zig
index 475fd55e22..c06857787a 100644
--- a/lib/std/c/netbsd.zig
+++ b/lib/std/c/netbsd.zig
@@ -800,9 +800,9 @@ pub const winsize = extern struct {
const NSIG = 32;
pub const SIG = struct {
- pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
- pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
- pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
+ pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
+ pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
+ pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
pub const WORDS = 4;
pub const MAXSIG = 128;
@@ -864,7 +864,7 @@ pub const SIG = struct {
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
- pub const handler_fn = *const fn (c_int) align(1) callconv(.C) void;
+ pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
/// signal handler
diff --git a/lib/std/c/openbsd.zig b/lib/std/c/openbsd.zig
index 75a4d6e0e8..4fd450cd5c 100644
--- a/lib/std/c/openbsd.zig
+++ b/lib/std/c/openbsd.zig
@@ -795,11 +795,11 @@ pub const winsize = extern struct {
const NSIG = 33;
pub const SIG = struct {
- pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
- pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
- pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
- pub const CATCH = @as(?Sigaction.handler_fn, @ptrFromInt(2));
- pub const HOLD = @as(?Sigaction.handler_fn, @ptrFromInt(3));
+ pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
+ pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
+ pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
+ pub const CATCH: ?Sigaction.handler_fn = @ptrFromInt(2);
+ pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);
pub const HUP = 1;
pub const INT = 2;
@@ -842,7 +842,7 @@ pub const SIG = struct {
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
- pub const handler_fn = *const fn (c_int) align(1) callconv(.C) void;
+ pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
/// signal handler
diff --git a/lib/std/c/solaris.zig b/lib/std/c/solaris.zig
index ef64acd43b..838b6985cc 100644
--- a/lib/std/c/solaris.zig
+++ b/lib/std/c/solaris.zig
@@ -798,10 +798,10 @@ pub const winsize = extern struct {
const NSIG = 75;
pub const SIG = struct {
- pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
- pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
- pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
- pub const HOLD = @as(?Sigaction.handler_fn, @ptrFromInt(2));
+ pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
+ pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
+ pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
+ pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(2);
pub const WORDS = 4;
pub const MAXSIG = 75;
@@ -874,7 +874,7 @@ pub const SIG = struct {
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
- pub const handler_fn = *const fn (c_int) align(1) callconv(.C) void;
+ pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
/// signal options
diff --git a/lib/std/meta.zig b/lib/std/meta.zig
index f7b418d71d..da0f629748 100644
--- a/lib/std/meta.zig
+++ b/lib/std/meta.zig
@@ -57,10 +57,9 @@ test stringToEnum {
}
/// Returns the alignment of type T.
-/// Note that if T is a pointer or function type the result is different than
-/// the one returned by @alignOf(T).
+/// Note that if T is a pointer type the result is different than the one
+/// returned by @alignOf(T).
/// If T is a pointer type the alignment of the type it points to is returned.
-/// If T is a function type the alignment a target-dependent value is returned.
pub fn alignment(comptime T: type) comptime_int {
return switch (@typeInfo(T)) {
.Optional => |info| switch (@typeInfo(info.child)) {
@@ -68,7 +67,6 @@ pub fn alignment(comptime T: type) comptime_int {
else => @alignOf(T),
},
.Pointer => |info| info.alignment,
- .Fn => |info| info.alignment,
else => @alignOf(T),
};
}
@@ -80,7 +78,8 @@ test alignment {
try testing.expect(alignment([]align(1) u8) == 1);
try testing.expect(alignment([]align(2) u8) == 2);
try testing.expect(alignment(fn () void) > 0);
- try testing.expect(alignment(fn () align(128) void) == 128);
+ try testing.expect(alignment(*const fn () void) > 0);
+ try testing.expect(alignment(*align(128) const fn () void) == 128);
}
/// Given a parameterized type (array, vector, pointer, optional), returns the "child type".
diff --git a/lib/std/os/emscripten.zig b/lib/std/os/emscripten.zig
index 04c3996f15..924b2dd0b2 100644
--- a/lib/std/os/emscripten.zig
+++ b/lib/std/os/emscripten.zig
@@ -689,13 +689,13 @@ pub const SIG = struct {
pub const SYS = 31;
pub const UNUSED = SIG.SYS;
- pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(std.math.maxInt(usize)));
- pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
- pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
+ pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(std.math.maxInt(usize));
+ pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
+ pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
};
pub const Sigaction = extern struct {
- pub const handler_fn = *const fn (c_int) align(1) callconv(.C) void;
+ pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
handler: extern union {
diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig
index 3892e4326a..a5cdab18ce 100644
--- a/lib/std/os/linux.zig
+++ b/lib/std/os/linux.zig
@@ -1327,16 +1327,14 @@ pub fn flock(fd: fd_t, operation: i32) usize {
return syscall2(.flock, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, operation))));
}
-var vdso_clock_gettime = @as(?*const anyopaque, @ptrCast(&init_vdso_clock_gettime));
-
// We must follow the C calling convention when we call into the VDSO
-const vdso_clock_gettime_ty = *align(1) const fn (i32, *timespec) callconv(.C) usize;
+const VdsoClockGettime = *align(1) const fn (i32, *timespec) callconv(.C) usize;
+var vdso_clock_gettime: ?VdsoClockGettime = &init_vdso_clock_gettime;
pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
if (@hasDecl(VDSO, "CGT_SYM")) {
- const ptr = @atomicLoad(?*const anyopaque, &vdso_clock_gettime, .unordered);
- if (ptr) |fn_ptr| {
- const f = @as(vdso_clock_gettime_ty, @ptrCast(fn_ptr));
+ const ptr = @atomicLoad(?VdsoClockGettime, &vdso_clock_gettime, .unordered);
+ if (ptr) |f| {
const rc = f(clk_id, tp);
switch (rc) {
0, @as(usize, @bitCast(-@as(isize, @intFromEnum(E.INVAL)))) => return rc,
@@ -1348,15 +1346,12 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
}
fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize {
- const ptr = @as(?*const anyopaque, @ptrFromInt(vdso.lookup(VDSO.CGT_VER, VDSO.CGT_SYM)));
+ const ptr: ?VdsoClockGettime = @ptrFromInt(vdso.lookup(VDSO.CGT_VER, VDSO.CGT_SYM));
// Note that we may not have a VDSO at all, update the stub address anyway
// so that clock_gettime will fall back on the good old (and slow) syscall
- @atomicStore(?*const anyopaque, &vdso_clock_gettime, ptr, .monotonic);
+ @atomicStore(?VdsoClockGettime, &vdso_clock_gettime, ptr, .monotonic);
// Call into the VDSO if available
- if (ptr) |fn_ptr| {
- const f = @as(vdso_clock_gettime_ty, @ptrCast(fn_ptr));
- return f(clk, ts);
- }
+ if (ptr) |f| return f(clk, ts);
return @as(usize, @bitCast(-@as(isize, @intFromEnum(E.NOSYS))));
}
@@ -2516,9 +2511,9 @@ pub const SIG = if (is_mips) struct {
pub const SYS = 31;
pub const UNUSED = SIG.SYS;
- pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
- pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
- pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
+ pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
+ pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
+ pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
} else if (is_sparc) struct {
pub const BLOCK = 1;
pub const UNBLOCK = 2;
@@ -2560,9 +2555,9 @@ pub const SIG = if (is_mips) struct {
pub const PWR = LOST;
pub const IO = SIG.POLL;
- pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
- pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
- pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
+ pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
+ pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
+ pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
} else struct {
pub const BLOCK = 0;
pub const UNBLOCK = 1;
@@ -2603,9 +2598,9 @@ pub const SIG = if (is_mips) struct {
pub const SYS = 31;
pub const UNUSED = SIG.SYS;
- pub const ERR = @as(?Sigaction.handler_fn, @ptrFromInt(maxInt(usize)));
- pub const DFL = @as(?Sigaction.handler_fn, @ptrFromInt(0));
- pub const IGN = @as(?Sigaction.handler_fn, @ptrFromInt(1));
+ pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
+ pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
+ pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
};
pub const kernel_rwf = u32;
@@ -3709,7 +3704,7 @@ pub const all_mask: sigset_t = [_]u32{0xffffffff} ** @typeInfo(sigset_t).Array.l
pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30;
const k_sigaction_funcs = struct {
- const handler = ?*const fn (c_int) align(1) callconv(.C) void;
+ const handler = ?*align(1) const fn (c_int) callconv(.C) void;
const restorer = *const fn () callconv(.C) void;
};
@@ -3736,7 +3731,7 @@ pub const k_sigaction = switch (native_arch) {
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
- pub const handler_fn = *const fn (c_int) align(1) callconv(.C) void;
+ pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
handler: extern union {
diff --git a/lib/std/zig/AstGen.zig b/lib/std/zig/AstGen.zig
index 364e49ae8f..54efe22b8d 100644
--- a/lib/std/zig/AstGen.zig
+++ b/lib/std/zig/AstGen.zig
@@ -1369,16 +1369,16 @@ fn fnProtoExpr(
break :is_var_args false;
};
- const align_ref: Zir.Inst.Ref = if (fn_proto.ast.align_expr == 0) .none else inst: {
- break :inst try expr(&block_scope, scope, coerced_align_ri, fn_proto.ast.align_expr);
- };
+ if (fn_proto.ast.align_expr != 0) {
+ return astgen.failNode(fn_proto.ast.align_expr, "function type cannot have an alignment", .{});
+ }
if (fn_proto.ast.addrspace_expr != 0) {
- return astgen.failNode(fn_proto.ast.addrspace_expr, "addrspace not allowed on function prototypes", .{});
+ return astgen.failNode(fn_proto.ast.addrspace_expr, "function type cannot have an addrspace", .{});
}
if (fn_proto.ast.section_expr != 0) {
- return astgen.failNode(fn_proto.ast.section_expr, "linksection not allowed on function prototypes", .{});
+ return astgen.failNode(fn_proto.ast.section_expr, "function type cannot have a linksection", .{});
}
const cc: Zir.Inst.Ref = if (fn_proto.ast.callconv_expr != 0)
@@ -1394,7 +1394,7 @@ fn fnProtoExpr(
const maybe_bang = tree.firstToken(fn_proto.ast.return_type) - 1;
const is_inferred_error = token_tags[maybe_bang] == .bang;
if (is_inferred_error) {
- return astgen.failTok(maybe_bang, "function prototype may not have inferred error set", .{});
+ return astgen.failTok(maybe_bang, "function type cannot have an inferred error set", .{});
}
const ret_ty = try expr(&block_scope, scope, coerced_type_ri, fn_proto.ast.return_type);
@@ -1403,7 +1403,7 @@ fn fnProtoExpr(
.cc_ref = cc,
.cc_gz = null,
- .align_ref = align_ref,
+ .align_ref = .none,
.align_gz = null,
.ret_ref = ret_ty,
.ret_gz = null,