authorgravatar for justus@klausecker.deJustus Klausecker <justus@klausecker.de> 2025-08-03 14:53:52+02:00
committergravatar for justus@klausecker.deJustus Klausecker <justus@klausecker.de> 2025-08-03 14:59:56+02:00
log7c35070b901d9181ec3c666480a91eddf6c1abce
tree74f6eddb4386054ad74aa04b9a506d1ccfb717dc
parent81219493f87b8345446e387e71279d74f35b6824

zig fmt: apply new cast builtin order


29 files changed, 45 insertions(+), 45 deletions(-)

lib/build-web/fuzz.zig+1-1
......@@ -256,7 +256,7 @@ fn updateStats() error{OutOfMemory}!void {
256256
257257 if (recent_coverage_update.items.len == 0) return;
258258
259 const hdr: *abi.fuzz.CoverageUpdateHeader = @alignCast(@ptrCast(
259 const hdr: *abi.fuzz.CoverageUpdateHeader = @ptrCast(@alignCast(
260260 recent_coverage_update.items[0..@sizeOf(abi.fuzz.CoverageUpdateHeader)],
261261 ));
262262
lib/compiler_rt/memcpy.zig+1-1
......@@ -110,7 +110,7 @@ inline fn copyForwards(
110110 const d = dest + alignment_offset;
111111 const s = src + alignment_offset;
112112
113 copyBlocksAlignedSource(@ptrCast(d), @alignCast(@ptrCast(s)), n);
113 copyBlocksAlignedSource(@ptrCast(d), @ptrCast(@alignCast(s)), n);
114114
115115 // copy last `@sizeOf(Element)` bytes unconditionally, since block copy
116116 // methods only copy a multiple of `@sizeOf(Element)` bytes.
lib/compiler_rt/memmove.zig+1-1
......@@ -157,7 +157,7 @@ inline fn copyForwards(
157157 const d = dest + alignment_offset;
158158 const s = src + alignment_offset;
159159
160 copyBlocksAlignedSource(@ptrCast(d), @alignCast(@ptrCast(s)), n);
160 copyBlocksAlignedSource(@ptrCast(d), @ptrCast(@alignCast(s)), n);
161161
162162 // copy last `copy_size` bytes unconditionally, since block copy
163163 // methods only copy a multiple of `copy_size` bytes.
lib/std/Io.zig+2-2
......@@ -304,7 +304,7 @@ pub fn GenericReader(
304304 const Self = @This();
305305
306306 fn typeErasedReadFn(context: *const anyopaque, buffer: []u8) anyerror!usize {
307 const ptr: *const Context = @alignCast(@ptrCast(context));
307 const ptr: *const Context = @ptrCast(@alignCast(context));
308308 return readFn(ptr.*, buffer);
309309 }
310310
......@@ -397,7 +397,7 @@ pub fn GenericWriter(
397397 }
398398
399399 fn typeErasedWriteFn(context: *const anyopaque, bytes: []const u8) anyerror!usize {
400 const ptr: *const Context = @alignCast(@ptrCast(context));
400 const ptr: *const Context = @ptrCast(@alignCast(context));
401401 return writeFn(ptr.*, bytes);
402402 }
403403
lib/std/Io/Reader.zig+1-1
......@@ -1698,7 +1698,7 @@ pub fn adaptToOldInterface(r: *Reader) std.Io.AnyReader {
16981698}
16991699
17001700fn derpRead(context: *const anyopaque, buffer: []u8) anyerror!usize {
1701 const r: *Reader = @constCast(@alignCast(@ptrCast(context)));
1701 const r: *Reader = @ptrCast(@alignCast(@constCast(context)));
17021702 return r.readSliceShort(buffer);
17031703}
17041704
lib/std/array_hash_map.zig+2-2
......@@ -2086,7 +2086,7 @@ const IndexHeader = struct {
20862086 /// Returns the attached array of indexes. I must match the type
20872087 /// returned by capacityIndexType.
20882088 fn indexes(header: *IndexHeader, comptime I: type) []Index(I) {
2089 const start_ptr: [*]Index(I) = @alignCast(@ptrCast(@as([*]u8, @ptrCast(header)) + @sizeOf(IndexHeader)));
2089 const start_ptr: [*]Index(I) = @ptrCast(@alignCast(@as([*]u8, @ptrCast(header)) + @sizeOf(IndexHeader)));
20902090 return start_ptr[0..header.length()];
20912091 }
20922092
......@@ -2122,7 +2122,7 @@ const IndexHeader = struct {
21222122 const nbytes = @sizeOf(IndexHeader) + index_size * len;
21232123 const bytes = try gpa.alignedAlloc(u8, .of(IndexHeader), nbytes);
21242124 @memset(bytes[@sizeOf(IndexHeader)..], 0xff);
2125 const result: *IndexHeader = @alignCast(@ptrCast(bytes.ptr));
2125 const result: *IndexHeader = @ptrCast(@alignCast(bytes.ptr));
21262126 result.* = .{
21272127 .bit_index = new_bit_index,
21282128 };
lib/std/crypto/codecs/asn1/der/Encoder.zig+1-1
......@@ -37,7 +37,7 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void {
3737 // > The encoding of a set value or sequence value shall not include an encoding for any
3838 // > component value which is equal to its default value.
3939 const is_default = if (f.is_comptime) false else if (f.default_value_ptr) |v| brk: {
40 const default_val: *const f.type = @alignCast(@ptrCast(v));
40 const default_val: *const f.type = @ptrCast(@alignCast(v));
4141 break :brk std.mem.eql(u8, std.mem.asBytes(default_val), std.mem.asBytes(&field_val));
4242 } else false;
4343
lib/std/crypto/timing_safe.zig+1-1
......@@ -147,7 +147,7 @@ fn markSecret(ptr: anytype, comptime action: enum { classify, declassify }) void
147147 @compileError("A pointer value is always assumed leak information via side channels");
148148 },
149149 else => {
150 const mem8: *const [@sizeOf(@TypeOf(ptr.*))]u8 = @constCast(@ptrCast(ptr));
150 const mem8: *const [@sizeOf(@TypeOf(ptr.*))]u8 = @ptrCast(@constCast(ptr));
151151 if (action == .classify) {
152152 std.valgrind.memcheck.makeMemUndefined(mem8);
153153 } else {
lib/std/debug.zig+1-1
......@@ -569,7 +569,7 @@ pub fn assertReadable(slice: []const volatile u8) void {
569569/// Invokes detectable illegal behavior when the provided array is not aligned
570570/// to the provided amount.
571571pub fn assertAligned(ptr: anytype, comptime alignment: std.mem.Alignment) void {
572 const aligned_ptr: *align(alignment.toByteUnits()) anyopaque = @alignCast(@ptrCast(ptr));
572 const aligned_ptr: *align(alignment.toByteUnits()) anyopaque = @ptrCast(@alignCast(ptr));
573573 _ = aligned_ptr;
574574}
575575
lib/std/debug/SelfInfo.zig+1-1
......@@ -836,7 +836,7 @@ pub const WindowsModule = struct {
836836
837837 pub fn deinit(self: @This()) void {
838838 const process_handle = windows.GetCurrentProcess();
839 assert(windows.ntdll.NtUnmapViewOfSection(process_handle, @constCast(@ptrCast(self.section_view.ptr))) == .SUCCESS);
839 assert(windows.ntdll.NtUnmapViewOfSection(process_handle, @ptrCast(@constCast(self.section_view.ptr))) == .SUCCESS);
840840 windows.CloseHandle(self.section_handle);
841841 self.file.close();
842842 }
lib/std/hash_map.zig+1-1
......@@ -1511,7 +1511,7 @@ pub fn HashMapUnmanaged(
15111511
15121512 const total_size = std.mem.alignForward(usize, vals_end, max_align);
15131513
1514 const slice = @as([*]align(max_align) u8, @alignCast(@ptrCast(self.header())))[0..total_size];
1514 const slice = @as([*]align(max_align) u8, @ptrCast(@alignCast(self.header())))[0..total_size];
15151515 allocator.free(slice);
15161516
15171517 self.metadata = null;
lib/std/heap.zig+1-1
......@@ -151,7 +151,7 @@ const CAllocator = struct {
151151 };
152152
153153 fn getHeader(ptr: [*]u8) *[*]u8 {
154 return @alignCast(@ptrCast(ptr - @sizeOf(usize)));
154 return @ptrCast(@alignCast(ptr - @sizeOf(usize)));
155155 }
156156
157157 fn alignedAlloc(len: usize, alignment: Alignment) ?[*]u8 {
lib/std/heap/SmpAllocator.zig+1-1
......@@ -205,7 +205,7 @@ fn free(context: *anyopaque, memory: []u8, alignment: mem.Alignment, ra: usize)
205205 return PageAllocator.unmap(@alignCast(memory));
206206 }
207207
208 const node: *usize = @alignCast(@ptrCast(memory.ptr));
208 const node: *usize = @ptrCast(@alignCast(memory.ptr));
209209
210210 const t = Thread.lock();
211211 defer t.unlock();
lib/std/heap/debug_allocator.zig+1-1
......@@ -291,7 +291,7 @@ pub fn DebugAllocator(comptime config: Config) type {
291291
292292 fn usedBits(bucket: *BucketHeader, index: usize) *usize {
293293 const ptr: [*]u8 = @ptrCast(bucket);
294 const bits: [*]usize = @alignCast(@ptrCast(ptr + @sizeOf(BucketHeader)));
294 const bits: [*]usize = @ptrCast(@alignCast(ptr + @sizeOf(BucketHeader)));
295295 return &bits[index];
296296 }
297297
lib/std/http/Server.zig+4-4
......@@ -624,7 +624,7 @@ pub const Request = struct {
624624 };
625625
626626 fn read_cl(context: *const anyopaque, buffer: []u8) ReadError!usize {
627 const request: *Request = @constCast(@alignCast(@ptrCast(context)));
627 const request: *Request = @ptrCast(@alignCast(@constCast(context)));
628628 const s = request.server;
629629
630630 const remaining_content_length = &request.reader_state.remaining_content_length;
......@@ -652,7 +652,7 @@ pub const Request = struct {
652652 }
653653
654654 fn read_chunked(context: *const anyopaque, buffer: []u8) ReadError!usize {
655 const request: *Request = @constCast(@alignCast(@ptrCast(context)));
655 const request: *Request = @ptrCast(@alignCast(@constCast(context)));
656656 const s = request.server;
657657
658658 const cp = &request.reader_state.chunk_parser;
......@@ -894,7 +894,7 @@ pub const Response = struct {
894894 }
895895
896896 fn write_cl(context: *const anyopaque, bytes: []const u8) WriteError!usize {
897 const r: *Response = @constCast(@alignCast(@ptrCast(context)));
897 const r: *Response = @ptrCast(@alignCast(@constCast(context)));
898898
899899 var trash: u64 = std.math.maxInt(u64);
900900 const len = switch (r.transfer_encoding) {
......@@ -944,7 +944,7 @@ pub const Response = struct {
944944 }
945945
946946 fn write_chunked(context: *const anyopaque, bytes: []const u8) WriteError!usize {
947 const r: *Response = @constCast(@alignCast(@ptrCast(context)));
947 const r: *Response = @ptrCast(@alignCast(@constCast(context)));
948948 assert(r.transfer_encoding == .chunked);
949949
950950 if (r.elide_body)
lib/std/os/uefi/tables.zig+1-1
......@@ -154,7 +154,7 @@ pub const MemoryMapSlice = struct {
154154
155155 pub fn getUnchecked(self: MemoryMapSlice, index: usize) *MemoryDescriptor {
156156 const offset: usize = index * self.info.descriptor_size;
157 return @alignCast(@ptrCast(self.ptr[offset..]));
157 return @ptrCast(@alignCast(self.ptr[offset..]));
158158 }
159159};
160160
lib/std/os/uefi/tables/runtime_services.zig+1-1
......@@ -353,7 +353,7 @@ pub const RuntimeServices = extern struct {
353353 reset_type,
354354 reset_status,
355355 if (data) |d| d.len else 0,
356 if (data) |d| @alignCast(@ptrCast(d.ptr)) else null,
356 if (data) |d| @ptrCast(@alignCast(d.ptr)) else null,
357357 );
358358 }
359359
lib/std/os/windows.zig+1-1
......@@ -202,7 +202,7 @@ pub fn CreatePipe(rd: *HANDLE, wr: *HANDLE, sattr: *const SECURITY_ATTRIBUTES) C
202202 const name = UNICODE_STRING{
203203 .Length = len,
204204 .MaximumLength = len,
205 .Buffer = @constCast(@ptrCast(str)),
205 .Buffer = @ptrCast(@constCast(str)),
206206 };
207207 const attrs = OBJECT_ATTRIBUTES{
208208 .ObjectName = @constCast(&name),
lib/std/pie.zig+2-2
......@@ -259,7 +259,7 @@ pub fn relocate(phdrs: []const elf.Phdr) void {
259259
260260 const rel = sorted_dynv[elf.DT_REL];
261261 if (rel != 0) {
262 const rels: []const elf.Rel = @alignCast(@ptrCast(
262 const rels: []const elf.Rel = @ptrCast(@alignCast(
263263 @as([*]align(@alignOf(elf.Rel)) const u8, @ptrFromInt(base_addr + rel))[0..sorted_dynv[elf.DT_RELSZ]],
264264 ));
265265 for (rels) |r| {
......@@ -270,7 +270,7 @@ pub fn relocate(phdrs: []const elf.Phdr) void {
270270
271271 const rela = sorted_dynv[elf.DT_RELA];
272272 if (rela != 0) {
273 const relas: []const elf.Rela = @alignCast(@ptrCast(
273 const relas: []const elf.Rela = @ptrCast(@alignCast(
274274 @as([*]align(@alignOf(elf.Rela)) const u8, @ptrFromInt(base_addr + rela))[0..sorted_dynv[elf.DT_RELASZ]],
275275 ));
276276 for (relas) |r| {
lib/std/zig/c_translation.zig+1-1
......@@ -71,7 +71,7 @@ fn castInt(comptime DestType: type, target: anytype) DestType {
7171}
7272
7373fn castPtr(comptime DestType: type, target: anytype) DestType {
74 return @constCast(@volatileCast(@alignCast(@ptrCast(target))));
74 return @ptrCast(@alignCast(@constCast(@volatileCast(target))));
7575}
7676
7777fn castToPtr(comptime DestType: type, comptime SourceType: type, target: anytype) DestType {
lib/ubsan_rt.zig+7-7
......@@ -58,8 +58,8 @@ const Value = extern struct {
5858 }
5959
6060 return switch (size) {
61 64 => @as(*const u64, @alignCast(@ptrCast(value.handle))).*,
62 128 => @as(*const u128, @alignCast(@ptrCast(value.handle))).*,
61 64 => @as(*const u64, @ptrCast(@alignCast(value.handle))).*,
62 128 => @as(*const u128, @ptrCast(@alignCast(value.handle))).*,
6363 else => @trap(),
6464 };
6565 }
......@@ -74,8 +74,8 @@ const Value = extern struct {
7474 return (handle << extra_bits) >> extra_bits;
7575 }
7676 return switch (size) {
77 64 => @as(*const i64, @alignCast(@ptrCast(value.handle))).*,
78 128 => @as(*const i128, @alignCast(@ptrCast(value.handle))).*,
77 64 => @as(*const i64, @ptrCast(@alignCast(value.handle))).*,
78 128 => @as(*const i128, @ptrCast(@alignCast(value.handle))).*,
7979 else => @trap(),
8080 };
8181 }
......@@ -92,9 +92,9 @@ const Value = extern struct {
9292 }, @bitCast(@intFromPtr(value.handle)));
9393 }
9494 return @floatCast(switch (size) {
95 64 => @as(*const f64, @alignCast(@ptrCast(value.handle))).*,
96 80 => @as(*const f80, @alignCast(@ptrCast(value.handle))).*,
97 128 => @as(*const f128, @alignCast(@ptrCast(value.handle))).*,
95 64 => @as(*const f64, @ptrCast(@alignCast(value.handle))).*,
96 80 => @as(*const f80, @ptrCast(@alignCast(value.handle))).*,
97 128 => @as(*const f128, @ptrCast(@alignCast(value.handle))).*,
9898 else => @trap(),
9999 });
100100 }
src/InternPool.zig+2-2
......@@ -1365,7 +1365,7 @@ const Local = struct {
13651365 capacity: u32,
13661366 };
13671367 fn header(list: ListSelf) *Header {
1368 return @alignCast(@ptrCast(list.bytes - bytes_offset));
1368 return @ptrCast(@alignCast(list.bytes - bytes_offset));
13691369 }
13701370 pub fn view(list: ListSelf) View {
13711371 const capacity = list.header().capacity;
......@@ -1574,7 +1574,7 @@ const Shard = struct {
15741574 }
15751575 };
15761576 fn header(map: @This()) *Header {
1577 return @alignCast(@ptrCast(@as([*]u8, @ptrCast(map.entries)) - entries_offset));
1577 return @ptrCast(@alignCast(@as([*]u8, @ptrCast(map.entries)) - entries_offset));
15781578 }
15791579
15801580 const Entry = extern struct {
src/Package/Fetch.zig+1-1
......@@ -898,7 +898,7 @@ const Resource = union(enum) {
898898 }
899899
900900 fn read(context: *const anyopaque, buffer: []u8) anyerror!usize {
901 const resource: *Resource = @constCast(@ptrCast(@alignCast(context)));
901 const resource: *Resource = @ptrCast(@alignCast(@constCast(context)));
902902 switch (resource.*) {
903903 .file => |*f| return f.read(buffer),
904904 .http_request => |*r| return r.read(buffer),
src/translate_c.zig+3-3
......@@ -4008,11 +4008,11 @@ fn transCreateCompoundAssign(
40084008}
40094009
40104010fn removeCVQualifiers(c: *Context, dst_type_node: Node, expr: Node) Error!Node {
4011 const const_casted = try Tag.const_cast.create(c.arena, expr);
4012 const volatile_casted = try Tag.volatile_cast.create(c.arena, const_casted);
4011 const volatile_casted = try Tag.volatile_cast.create(c.arena, expr);
4012 const const_casted = try Tag.const_cast.create(c.arena, volatile_casted);
40134013 return Tag.as.create(c.arena, .{
40144014 .lhs = dst_type_node,
4015 .rhs = try Tag.ptr_cast.create(c.arena, volatile_casted),
4015 .rhs = try Tag.ptr_cast.create(c.arena, const_casted),
40164016 });
40174017}
40184018
test/behavior/array.zig+1-1
......@@ -1091,7 +1091,7 @@ test "initialize pointer to anyopaque with reference to empty array initializer"
10911091 const ptr: *const anyopaque = &.{};
10921092 // The above acts like an untyped initializer, since the `.{}` has no result type.
10931093 // So, `ptr` points in memory to an empty tuple (`@TypeOf(.{})`).
1094 const casted: *const @TypeOf(.{}) = @alignCast(@ptrCast(ptr));
1094 const casted: *const @TypeOf(.{}) = @ptrCast(@alignCast(ptr));
10951095 const loaded = casted.*;
10961096 // `val` should be a `@TypeOf(.{})`, as expected.
10971097 // We can't check the value, but it's zero-bit, so the type matching is good enough.
test/behavior/comptime_memory.zig+1-1
......@@ -477,7 +477,7 @@ fn GenericIntApplier(
477477 }
478478
479479 fn typeErasedApplyFn(context: *const anyopaque, arg: u32) void {
480 const ptr: *const Context = @alignCast(@ptrCast(context));
480 const ptr: *const Context = @ptrCast(@alignCast(context));
481481 applyFn(ptr.*, arg);
482482 }
483483 };
test/behavior/extern.zig+1-1
......@@ -8,7 +8,7 @@ test "anyopaque extern symbol" {
88 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
99
1010 const a = @extern(*anyopaque, .{ .name = "a_mystery_symbol" });
11 const b: *i32 = @alignCast(@ptrCast(a));
11 const b: *i32 = @ptrCast(@alignCast(a));
1212 try expect(b.* == 1234);
1313}
1414
test/cases/compile_errors/nested_ptr_cast_bad_operand.zig+1-1
......@@ -6,7 +6,7 @@ export fn b() void {
66 _ = @constCast(@volatileCast(123));
77}
88export fn c() void {
9 const x: ?*f32 = @constCast(@ptrCast(@addrSpaceCast(@volatileCast(p))));
9 const x: ?*f32 = @ptrCast(@addrSpaceCast(@constCast(@volatileCast(p))));
1010 _ = x;
1111}
1212
test/translate_c.zig+2-2
......@@ -3234,12 +3234,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
32343234 \\pub export fn bar(arg_a: [*c]const c_int) void {
32353235 \\ var a = arg_a;
32363236 \\ _ = &a;
3237 \\ foo(@as([*c]c_int, @ptrCast(@volatileCast(@constCast(a)))));
3237 \\ foo(@as([*c]c_int, @ptrCast(@constCast(@volatileCast(a)))));
32383238 \\}
32393239 \\pub export fn baz(arg_a: [*c]volatile c_int) void {
32403240 \\ var a = arg_a;
32413241 \\ _ = &a;
3242 \\ foo(@as([*c]c_int, @ptrCast(@volatileCast(@constCast(a)))));
3242 \\ foo(@as([*c]c_int, @ptrCast(@constCast(@volatileCast(a)))));
32433243 \\}
32443244 });
32453245