| author | |
| committer | |
| log | fd9cfc39f53fae7fad4eadf9f1d8943f7e2c03b1 |
| tree | 55910d5395d41c11b771c34057b1b16affafd9e2 |
| parent | 04fe1bfe3ceabd632183a85101cddeeec11f0745 |
| parent | 7c35070b901d9181ec3c666480a91eddf6c1abce |
| signature |
zig fmt: canonicalize nested cast builtin order30 files changed, 87 insertions(+), 46 deletions(-)
lib/build-web/fuzz.zig+1-1| ... | @@ -256,7 +256,7 @@ fn updateStats() error{OutOfMemory}!void { | ... | @@ -256,7 +256,7 @@ fn updateStats() error{OutOfMemory}!void { |
| 256 | 256 | ||
| 257 | if (recent_coverage_update.items.len == 0) return; | 257 | if (recent_coverage_update.items.len == 0) return; |
| 258 | 258 | ||
| 259 | const hdr: *abi.fuzz.CoverageUpdateHeader = @alignCast(@ptrCast( | 259 | const hdr: *abi.fuzz.CoverageUpdateHeader = @ptrCast(@alignCast( |
| 260 | recent_coverage_update.items[0..@sizeOf(abi.fuzz.CoverageUpdateHeader)], | 260 | recent_coverage_update.items[0..@sizeOf(abi.fuzz.CoverageUpdateHeader)], |
| 261 | )); | 261 | )); |
| 262 | 262 |
lib/compiler_rt/memcpy.zig+1-1| ... | @@ -110,7 +110,7 @@ inline fn copyForwards( | ... | @@ -110,7 +110,7 @@ inline fn copyForwards( |
| 110 | const d = dest + alignment_offset; | 110 | const d = dest + alignment_offset; |
| 111 | const s = src + alignment_offset; | 111 | const s = src + alignment_offset; |
| 112 | 112 | ||
| 113 | copyBlocksAlignedSource(@ptrCast(d), @alignCast(@ptrCast(s)), n); | 113 | copyBlocksAlignedSource(@ptrCast(d), @ptrCast(@alignCast(s)), n); |
| 114 | 114 | ||
| 115 | // copy last `@sizeOf(Element)` bytes unconditionally, since block copy | 115 | // copy last `@sizeOf(Element)` bytes unconditionally, since block copy |
| 116 | // methods only copy a multiple of `@sizeOf(Element)` bytes. | 116 | // methods only copy a multiple of `@sizeOf(Element)` bytes. |
lib/compiler_rt/memmove.zig+1-1| ... | @@ -157,7 +157,7 @@ inline fn copyForwards( | ... | @@ -157,7 +157,7 @@ inline fn copyForwards( |
| 157 | const d = dest + alignment_offset; | 157 | const d = dest + alignment_offset; |
| 158 | const s = src + alignment_offset; | 158 | const s = src + alignment_offset; |
| 159 | 159 | ||
| 160 | copyBlocksAlignedSource(@ptrCast(d), @alignCast(@ptrCast(s)), n); | 160 | copyBlocksAlignedSource(@ptrCast(d), @ptrCast(@alignCast(s)), n); |
| 161 | 161 | ||
| 162 | // copy last `copy_size` bytes unconditionally, since block copy | 162 | // copy last `copy_size` bytes unconditionally, since block copy |
| 163 | // methods only copy a multiple of `copy_size` bytes. | 163 | // methods only copy a multiple of `copy_size` bytes. |
lib/std/Io.zig+2-2| ... | @@ -289,7 +289,7 @@ pub fn GenericReader( | ... | @@ -289,7 +289,7 @@ pub fn GenericReader( |
| 289 | const Self = @This(); | 289 | const Self = @This(); |
| 290 | 290 | ||
| 291 | fn typeErasedReadFn(context: *const anyopaque, buffer: []u8) anyerror!usize { | 291 | fn typeErasedReadFn(context: *const anyopaque, buffer: []u8) anyerror!usize { |
| 292 | const ptr: *const Context = @alignCast(@ptrCast(context)); | 292 | const ptr: *const Context = @ptrCast(@alignCast(context)); |
| 293 | return readFn(ptr.*, buffer); | 293 | return readFn(ptr.*, buffer); |
| 294 | } | 294 | } |
| 295 | 295 | ||
| ... | @@ -382,7 +382,7 @@ pub fn GenericWriter( | ... | @@ -382,7 +382,7 @@ pub fn GenericWriter( |
| 382 | } | 382 | } |
| 383 | 383 | ||
| 384 | fn typeErasedWriteFn(context: *const anyopaque, bytes: []const u8) anyerror!usize { | 384 | fn typeErasedWriteFn(context: *const anyopaque, bytes: []const u8) anyerror!usize { |
| 385 | const ptr: *const Context = @alignCast(@ptrCast(context)); | 385 | const ptr: *const Context = @ptrCast(@alignCast(context)); |
| 386 | return writeFn(ptr.*, bytes); | 386 | return writeFn(ptr.*, bytes); |
| 387 | } | 387 | } |
| 388 | 388 |
lib/std/Io/Reader.zig+1-1| ... | @@ -1689,7 +1689,7 @@ pub fn adaptToOldInterface(r: *Reader) std.Io.AnyReader { | ... | @@ -1689,7 +1689,7 @@ pub fn adaptToOldInterface(r: *Reader) std.Io.AnyReader { |
| 1689 | } | 1689 | } |
| 1690 | 1690 | ||
| 1691 | fn derpRead(context: *const anyopaque, buffer: []u8) anyerror!usize { | 1691 | fn derpRead(context: *const anyopaque, buffer: []u8) anyerror!usize { |
| 1692 | const r: *Reader = @constCast(@alignCast(@ptrCast(context))); | 1692 | const r: *Reader = @ptrCast(@alignCast(@constCast(context))); |
| 1693 | return r.readSliceShort(buffer); | 1693 | return r.readSliceShort(buffer); |
| 1694 | } | 1694 | } |
| 1695 | 1695 |
lib/std/array_hash_map.zig+2-2| ... | @@ -2086,7 +2086,7 @@ const IndexHeader = struct { | ... | @@ -2086,7 +2086,7 @@ const IndexHeader = struct { |
| 2086 | /// Returns the attached array of indexes. I must match the type | 2086 | /// Returns the attached array of indexes. I must match the type |
| 2087 | /// returned by capacityIndexType. | 2087 | /// returned by capacityIndexType. |
| 2088 | fn indexes(header: *IndexHeader, comptime I: type) []Index(I) { | 2088 | 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))); |
| 2090 | return start_ptr[0..header.length()]; | 2090 | return start_ptr[0..header.length()]; |
| 2091 | } | 2091 | } |
| 2092 | 2092 | ||
| ... | @@ -2122,7 +2122,7 @@ const IndexHeader = struct { | ... | @@ -2122,7 +2122,7 @@ const IndexHeader = struct { |
| 2122 | const nbytes = @sizeOf(IndexHeader) + index_size * len; | 2122 | const nbytes = @sizeOf(IndexHeader) + index_size * len; |
| 2123 | const bytes = try gpa.alignedAlloc(u8, .of(IndexHeader), nbytes); | 2123 | const bytes = try gpa.alignedAlloc(u8, .of(IndexHeader), nbytes); |
| 2124 | @memset(bytes[@sizeOf(IndexHeader)..], 0xff); | 2124 | @memset(bytes[@sizeOf(IndexHeader)..], 0xff); |
| 2125 | const result: *IndexHeader = @alignCast(@ptrCast(bytes.ptr)); | 2125 | const result: *IndexHeader = @ptrCast(@alignCast(bytes.ptr)); |
| 2126 | result.* = .{ | 2126 | result.* = .{ |
| 2127 | .bit_index = new_bit_index, | 2127 | .bit_index = new_bit_index, |
| 2128 | }; | 2128 | }; |
lib/std/crypto/codecs/asn1/der/Encoder.zig+1-1| ... | @@ -37,7 +37,7 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void { | ... | @@ -37,7 +37,7 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void { |
| 37 | // > The encoding of a set value or sequence value shall not include an encoding for any | 37 | // > The encoding of a set value or sequence value shall not include an encoding for any |
| 38 | // > component value which is equal to its default value. | 38 | // > component value which is equal to its default value. |
| 39 | const is_default = if (f.is_comptime) false else if (f.default_value_ptr) |v| brk: { | 39 | 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)); |
| 41 | break :brk std.mem.eql(u8, std.mem.asBytes(default_val), std.mem.asBytes(&field_val)); | 41 | break :brk std.mem.eql(u8, std.mem.asBytes(default_val), std.mem.asBytes(&field_val)); |
| 42 | } else false; | 42 | } else false; |
| 43 | 43 |
lib/std/crypto/timing_safe.zig+1-1| ... | @@ -147,7 +147,7 @@ fn markSecret(ptr: anytype, comptime action: enum { classify, declassify }) void | ... | @@ -147,7 +147,7 @@ fn markSecret(ptr: anytype, comptime action: enum { classify, declassify }) void |
| 147 | @compileError("A pointer value is always assumed leak information via side channels"); | 147 | @compileError("A pointer value is always assumed leak information via side channels"); |
| 148 | }, | 148 | }, |
| 149 | else => { | 149 | else => { |
| 150 | const mem8: *const [@sizeOf(@TypeOf(ptr.*))]u8 = @constCast(@ptrCast(ptr)); | 150 | const mem8: *const [@sizeOf(@TypeOf(ptr.*))]u8 = @ptrCast(@constCast(ptr)); |
| 151 | if (action == .classify) { | 151 | if (action == .classify) { |
| 152 | std.valgrind.memcheck.makeMemUndefined(mem8); | 152 | std.valgrind.memcheck.makeMemUndefined(mem8); |
| 153 | } else { | 153 | } else { |
lib/std/debug.zig+1-1| ... | @@ -569,7 +569,7 @@ pub fn assertReadable(slice: []const volatile u8) void { | ... | @@ -569,7 +569,7 @@ pub fn assertReadable(slice: []const volatile u8) void { |
| 569 | /// Invokes detectable illegal behavior when the provided array is not aligned | 569 | /// Invokes detectable illegal behavior when the provided array is not aligned |
| 570 | /// to the provided amount. | 570 | /// to the provided amount. |
| 571 | pub fn assertAligned(ptr: anytype, comptime alignment: std.mem.Alignment) void { | 571 | pub 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)); |
| 573 | _ = aligned_ptr; | 573 | _ = aligned_ptr; |
| 574 | } | 574 | } |
| 575 | 575 |
lib/std/debug/SelfInfo.zig+1-1| ... | @@ -836,7 +836,7 @@ pub const WindowsModule = struct { | ... | @@ -836,7 +836,7 @@ pub const WindowsModule = struct { |
| 836 | 836 | ||
| 837 | pub fn deinit(self: @This()) void { | 837 | pub fn deinit(self: @This()) void { |
| 838 | const process_handle = windows.GetCurrentProcess(); | 838 | 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); |
| 840 | windows.CloseHandle(self.section_handle); | 840 | windows.CloseHandle(self.section_handle); |
| 841 | self.file.close(); | 841 | self.file.close(); |
| 842 | } | 842 | } |
lib/std/hash_map.zig+1-1| ... | @@ -1511,7 +1511,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1511,7 +1511,7 @@ pub fn HashMapUnmanaged( |
| 1511 | 1511 | ||
| 1512 | const total_size = std.mem.alignForward(usize, vals_end, max_align); | 1512 | const total_size = std.mem.alignForward(usize, vals_end, max_align); |
| 1513 | 1513 | ||
| 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]; |
| 1515 | allocator.free(slice); | 1515 | allocator.free(slice); |
| 1516 | 1516 | ||
| 1517 | self.metadata = null; | 1517 | self.metadata = null; |
lib/std/heap.zig+1-1| ... | @@ -151,7 +151,7 @@ const CAllocator = struct { | ... | @@ -151,7 +151,7 @@ const CAllocator = struct { |
| 151 | }; | 151 | }; |
| 152 | 152 | ||
| 153 | fn getHeader(ptr: [*]u8) *[*]u8 { | 153 | fn getHeader(ptr: [*]u8) *[*]u8 { |
| 154 | return @alignCast(@ptrCast(ptr - @sizeOf(usize))); | 154 | return @ptrCast(@alignCast(ptr - @sizeOf(usize))); |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | fn alignedAlloc(len: usize, alignment: Alignment) ?[*]u8 { | 157 | 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) | ... | @@ -205,7 +205,7 @@ fn free(context: *anyopaque, memory: []u8, alignment: mem.Alignment, ra: usize) |
| 205 | return PageAllocator.unmap(@alignCast(memory)); | 205 | return PageAllocator.unmap(@alignCast(memory)); |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | const node: *usize = @alignCast(@ptrCast(memory.ptr)); | 208 | const node: *usize = @ptrCast(@alignCast(memory.ptr)); |
| 209 | 209 | ||
| 210 | const t = Thread.lock(); | 210 | const t = Thread.lock(); |
| 211 | defer t.unlock(); | 211 | defer t.unlock(); |
lib/std/heap/debug_allocator.zig+1-1| ... | @@ -291,7 +291,7 @@ pub fn DebugAllocator(comptime config: Config) type { | ... | @@ -291,7 +291,7 @@ pub fn DebugAllocator(comptime config: Config) type { |
| 291 | 291 | ||
| 292 | fn usedBits(bucket: *BucketHeader, index: usize) *usize { | 292 | fn usedBits(bucket: *BucketHeader, index: usize) *usize { |
| 293 | const ptr: [*]u8 = @ptrCast(bucket); | 293 | const ptr: [*]u8 = @ptrCast(bucket); |
| 294 | const bits: [*]usize = @alignCast(@ptrCast(ptr + @sizeOf(BucketHeader))); | 294 | const bits: [*]usize = @ptrCast(@alignCast(ptr + @sizeOf(BucketHeader))); |
| 295 | return &bits[index]; | 295 | return &bits[index]; |
| 296 | } | 296 | } |
| 297 | 297 |
lib/std/http/Server.zig+4-4| ... | @@ -624,7 +624,7 @@ pub const Request = struct { | ... | @@ -624,7 +624,7 @@ pub const Request = struct { |
| 624 | }; | 624 | }; |
| 625 | 625 | ||
| 626 | fn read_cl(context: *const anyopaque, buffer: []u8) ReadError!usize { | 626 | 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))); |
| 628 | const s = request.server; | 628 | const s = request.server; |
| 629 | 629 | ||
| 630 | const remaining_content_length = &request.reader_state.remaining_content_length; | 630 | const remaining_content_length = &request.reader_state.remaining_content_length; |
| ... | @@ -652,7 +652,7 @@ pub const Request = struct { | ... | @@ -652,7 +652,7 @@ pub const Request = struct { |
| 652 | } | 652 | } |
| 653 | 653 | ||
| 654 | fn read_chunked(context: *const anyopaque, buffer: []u8) ReadError!usize { | 654 | 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))); |
| 656 | const s = request.server; | 656 | const s = request.server; |
| 657 | 657 | ||
| 658 | const cp = &request.reader_state.chunk_parser; | 658 | const cp = &request.reader_state.chunk_parser; |
| ... | @@ -894,7 +894,7 @@ pub const Response = struct { | ... | @@ -894,7 +894,7 @@ pub const Response = struct { |
| 894 | } | 894 | } |
| 895 | 895 | ||
| 896 | fn write_cl(context: *const anyopaque, bytes: []const u8) WriteError!usize { | 896 | 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))); |
| 898 | 898 | ||
| 899 | var trash: u64 = std.math.maxInt(u64); | 899 | var trash: u64 = std.math.maxInt(u64); |
| 900 | const len = switch (r.transfer_encoding) { | 900 | const len = switch (r.transfer_encoding) { |
| ... | @@ -944,7 +944,7 @@ pub const Response = struct { | ... | @@ -944,7 +944,7 @@ pub const Response = struct { |
| 944 | } | 944 | } |
| 945 | 945 | ||
| 946 | fn write_chunked(context: *const anyopaque, bytes: []const u8) WriteError!usize { | 946 | 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))); |
| 948 | assert(r.transfer_encoding == .chunked); | 948 | assert(r.transfer_encoding == .chunked); |
| 949 | 949 | ||
| 950 | if (r.elide_body) | 950 | if (r.elide_body) |
lib/std/os/uefi/tables.zig+1-1| ... | @@ -154,7 +154,7 @@ pub const MemoryMapSlice = struct { | ... | @@ -154,7 +154,7 @@ pub const MemoryMapSlice = struct { |
| 154 | 154 | ||
| 155 | pub fn getUnchecked(self: MemoryMapSlice, index: usize) *MemoryDescriptor { | 155 | pub fn getUnchecked(self: MemoryMapSlice, index: usize) *MemoryDescriptor { |
| 156 | const offset: usize = index * self.info.descriptor_size; | 156 | const offset: usize = index * self.info.descriptor_size; |
| 157 | return @alignCast(@ptrCast(self.ptr[offset..])); | 157 | return @ptrCast(@alignCast(self.ptr[offset..])); |
| 158 | } | 158 | } |
| 159 | }; | 159 | }; |
| 160 | 160 |
lib/std/os/uefi/tables/runtime_services.zig+1-1| ... | @@ -353,7 +353,7 @@ pub const RuntimeServices = extern struct { | ... | @@ -353,7 +353,7 @@ pub const RuntimeServices = extern struct { |
| 353 | reset_type, | 353 | reset_type, |
| 354 | reset_status, | 354 | reset_status, |
| 355 | if (data) |d| d.len else 0, | 355 | 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, |
| 357 | ); | 357 | ); |
| 358 | } | 358 | } |
| 359 | 359 |
lib/std/os/windows.zig+1-1| ... | @@ -202,7 +202,7 @@ pub fn CreatePipe(rd: *HANDLE, wr: *HANDLE, sattr: *const SECURITY_ATTRIBUTES) C | ... | @@ -202,7 +202,7 @@ pub fn CreatePipe(rd: *HANDLE, wr: *HANDLE, sattr: *const SECURITY_ATTRIBUTES) C |
| 202 | const name = UNICODE_STRING{ | 202 | const name = UNICODE_STRING{ |
| 203 | .Length = len, | 203 | .Length = len, |
| 204 | .MaximumLength = len, | 204 | .MaximumLength = len, |
| 205 | .Buffer = @constCast(@ptrCast(str)), | 205 | .Buffer = @ptrCast(@constCast(str)), |
| 206 | }; | 206 | }; |
| 207 | const attrs = OBJECT_ATTRIBUTES{ | 207 | const attrs = OBJECT_ATTRIBUTES{ |
| 208 | .ObjectName = @constCast(&name), | 208 | .ObjectName = @constCast(&name), |
lib/std/pie.zig+2-2| ... | @@ -259,7 +259,7 @@ pub fn relocate(phdrs: []const elf.Phdr) void { | ... | @@ -259,7 +259,7 @@ pub fn relocate(phdrs: []const elf.Phdr) void { |
| 259 | 259 | ||
| 260 | const rel = sorted_dynv[elf.DT_REL]; | 260 | const rel = sorted_dynv[elf.DT_REL]; |
| 261 | if (rel != 0) { | 261 | if (rel != 0) { |
| 262 | const rels: []const elf.Rel = @alignCast(@ptrCast( | 262 | const rels: []const elf.Rel = @ptrCast(@alignCast( |
| 263 | @as([*]align(@alignOf(elf.Rel)) const u8, @ptrFromInt(base_addr + rel))[0..sorted_dynv[elf.DT_RELSZ]], | 263 | @as([*]align(@alignOf(elf.Rel)) const u8, @ptrFromInt(base_addr + rel))[0..sorted_dynv[elf.DT_RELSZ]], |
| 264 | )); | 264 | )); |
| 265 | for (rels) |r| { | 265 | for (rels) |r| { |
| ... | @@ -270,7 +270,7 @@ pub fn relocate(phdrs: []const elf.Phdr) void { | ... | @@ -270,7 +270,7 @@ pub fn relocate(phdrs: []const elf.Phdr) void { |
| 270 | 270 | ||
| 271 | const rela = sorted_dynv[elf.DT_RELA]; | 271 | const rela = sorted_dynv[elf.DT_RELA]; |
| 272 | if (rela != 0) { | 272 | if (rela != 0) { |
| 273 | const relas: []const elf.Rela = @alignCast(@ptrCast( | 273 | const relas: []const elf.Rela = @ptrCast(@alignCast( |
| 274 | @as([*]align(@alignOf(elf.Rela)) const u8, @ptrFromInt(base_addr + rela))[0..sorted_dynv[elf.DT_RELASZ]], | 274 | @as([*]align(@alignOf(elf.Rela)) const u8, @ptrFromInt(base_addr + rela))[0..sorted_dynv[elf.DT_RELASZ]], |
| 275 | )); | 275 | )); |
| 276 | for (relas) |r| { | 276 | for (relas) |r| { |
lib/std/zig/Ast/Render.zig+42-1| ... | @@ -783,7 +783,48 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -783,7 +783,48 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 783 | => { | 783 | => { |
| 784 | var buf: [2]Ast.Node.Index = undefined; | 784 | var buf: [2]Ast.Node.Index = undefined; |
| 785 | const params = tree.builtinCallParams(&buf, node).?; | 785 | const params = tree.builtinCallParams(&buf, node).?; |
| 786 | return renderBuiltinCall(r, tree.nodeMainToken(node), params, space); | 786 | var builtin_token = tree.nodeMainToken(node); |
| 787 | |||
| 788 | canonicalize: { | ||
| 789 | if (params.len != 1) break :canonicalize; | ||
| 790 | |||
| 791 | const CastKind = enum { | ||
| 792 | ptrCast, | ||
| 793 | alignCast, | ||
| 794 | addrSpaceCast, | ||
| 795 | constCast, | ||
| 796 | volatileCast, | ||
| 797 | }; | ||
| 798 | const kind = meta.stringToEnum(CastKind, tree.tokenSlice(builtin_token)[1..]) orelse break :canonicalize; | ||
| 799 | |||
| 800 | var cast_map = std.EnumMap(CastKind, Ast.TokenIndex).init(.{}); | ||
| 801 | cast_map.put(kind, builtin_token); | ||
| 802 | |||
| 803 | var casts_before: usize = 0; | ||
| 804 | if (builtin_token >= 2) { | ||
| 805 | var prev_builtin_token = builtin_token - 2; | ||
| 806 | while (tree.tokenTag(prev_builtin_token) == .builtin) : (prev_builtin_token -= 2) { | ||
| 807 | const prev_kind = meta.stringToEnum(CastKind, tree.tokenSlice(prev_builtin_token)[1..]) orelse break; | ||
| 808 | if (cast_map.contains(prev_kind)) break :canonicalize; | ||
| 809 | cast_map.put(prev_kind, prev_builtin_token); | ||
| 810 | casts_before += 1; | ||
| 811 | } | ||
| 812 | } | ||
| 813 | |||
| 814 | var next_builtin_token = builtin_token + 2; | ||
| 815 | while (tree.tokenTag(next_builtin_token) == .builtin) : (next_builtin_token += 2) { | ||
| 816 | const next_kind = meta.stringToEnum(CastKind, tree.tokenSlice(next_builtin_token)[1..]) orelse break; | ||
| 817 | if (cast_map.contains(next_kind)) break :canonicalize; | ||
| 818 | cast_map.put(next_kind, next_builtin_token); | ||
| 819 | } | ||
| 820 | |||
| 821 | var it = cast_map.iterator(); | ||
| 822 | builtin_token = it.next().?.value.*; | ||
| 823 | while (casts_before > 0) : (casts_before -= 1) { | ||
| 824 | builtin_token = it.next().?.value.*; | ||
| 825 | } | ||
| 826 | } | ||
| 827 | return renderBuiltinCall(r, builtin_token, params, space); | ||
| 787 | }, | 828 | }, |
| 788 | 829 | ||
| 789 | .fn_proto_simple, | 830 | .fn_proto_simple, |
lib/std/zig/c_translation.zig+1-1| ... | @@ -71,7 +71,7 @@ fn castInt(comptime DestType: type, target: anytype) DestType { | ... | @@ -71,7 +71,7 @@ fn castInt(comptime DestType: type, target: anytype) DestType { |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | fn castPtr(comptime DestType: type, target: anytype) DestType { | 73 | fn castPtr(comptime DestType: type, target: anytype) DestType { |
| 74 | return @constCast(@volatileCast(@alignCast(@ptrCast(target)))); | 74 | return @ptrCast(@alignCast(@constCast(@volatileCast(target)))); |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | fn castToPtr(comptime DestType: type, comptime SourceType: type, target: anytype) DestType { | 77 | fn castToPtr(comptime DestType: type, comptime SourceType: type, target: anytype) DestType { |
lib/ubsan_rt.zig+7-7| ... | @@ -58,8 +58,8 @@ const Value = extern struct { | ... | @@ -58,8 +58,8 @@ const Value = extern struct { |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | return switch (size) { | 60 | return switch (size) { |
| 61 | 64 => @as(*const u64, @alignCast(@ptrCast(value.handle))).*, | 61 | 64 => @as(*const u64, @ptrCast(@alignCast(value.handle))).*, |
| 62 | 128 => @as(*const u128, @alignCast(@ptrCast(value.handle))).*, | 62 | 128 => @as(*const u128, @ptrCast(@alignCast(value.handle))).*, |
| 63 | else => @trap(), | 63 | else => @trap(), |
| 64 | }; | 64 | }; |
| 65 | } | 65 | } |
| ... | @@ -74,8 +74,8 @@ const Value = extern struct { | ... | @@ -74,8 +74,8 @@ const Value = extern struct { |
| 74 | return (handle << extra_bits) >> extra_bits; | 74 | return (handle << extra_bits) >> extra_bits; |
| 75 | } | 75 | } |
| 76 | return switch (size) { | 76 | return switch (size) { |
| 77 | 64 => @as(*const i64, @alignCast(@ptrCast(value.handle))).*, | 77 | 64 => @as(*const i64, @ptrCast(@alignCast(value.handle))).*, |
| 78 | 128 => @as(*const i128, @alignCast(@ptrCast(value.handle))).*, | 78 | 128 => @as(*const i128, @ptrCast(@alignCast(value.handle))).*, |
| 79 | else => @trap(), | 79 | else => @trap(), |
| 80 | }; | 80 | }; |
| 81 | } | 81 | } |
| ... | @@ -92,9 +92,9 @@ const Value = extern struct { | ... | @@ -92,9 +92,9 @@ const Value = extern struct { |
| 92 | }, @bitCast(@intFromPtr(value.handle))); | 92 | }, @bitCast(@intFromPtr(value.handle))); |
| 93 | } | 93 | } |
| 94 | return @floatCast(switch (size) { | 94 | return @floatCast(switch (size) { |
| 95 | 64 => @as(*const f64, @alignCast(@ptrCast(value.handle))).*, | 95 | 64 => @as(*const f64, @ptrCast(@alignCast(value.handle))).*, |
| 96 | 80 => @as(*const f80, @alignCast(@ptrCast(value.handle))).*, | 96 | 80 => @as(*const f80, @ptrCast(@alignCast(value.handle))).*, |
| 97 | 128 => @as(*const f128, @alignCast(@ptrCast(value.handle))).*, | 97 | 128 => @as(*const f128, @ptrCast(@alignCast(value.handle))).*, |
| 98 | else => @trap(), | 98 | else => @trap(), |
| 99 | }); | 99 | }); |
| 100 | } | 100 | } |
src/InternPool.zig+2-2| ... | @@ -1365,7 +1365,7 @@ const Local = struct { | ... | @@ -1365,7 +1365,7 @@ const Local = struct { |
| 1365 | capacity: u32, | 1365 | capacity: u32, |
| 1366 | }; | 1366 | }; |
| 1367 | fn header(list: ListSelf) *Header { | 1367 | fn header(list: ListSelf) *Header { |
| 1368 | return @alignCast(@ptrCast(list.bytes - bytes_offset)); | 1368 | return @ptrCast(@alignCast(list.bytes - bytes_offset)); |
| 1369 | } | 1369 | } |
| 1370 | pub fn view(list: ListSelf) View { | 1370 | pub fn view(list: ListSelf) View { |
| 1371 | const capacity = list.header().capacity; | 1371 | const capacity = list.header().capacity; |
| ... | @@ -1574,7 +1574,7 @@ const Shard = struct { | ... | @@ -1574,7 +1574,7 @@ const Shard = struct { |
| 1574 | } | 1574 | } |
| 1575 | }; | 1575 | }; |
| 1576 | fn header(map: @This()) *Header { | 1576 | 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)); |
| 1578 | } | 1578 | } |
| 1579 | 1579 | ||
| 1580 | const Entry = extern struct { | 1580 | const Entry = extern struct { |
src/Package/Fetch.zig+1-1| ... | @@ -898,7 +898,7 @@ const Resource = union(enum) { | ... | @@ -898,7 +898,7 @@ const Resource = union(enum) { |
| 898 | } | 898 | } |
| 899 | 899 | ||
| 900 | fn read(context: *const anyopaque, buffer: []u8) anyerror!usize { | 900 | 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))); |
| 902 | switch (resource.*) { | 902 | switch (resource.*) { |
| 903 | .file => |*f| return f.read(buffer), | 903 | .file => |*f| return f.read(buffer), |
| 904 | .http_request => |*r| return r.read(buffer), | 904 | .http_request => |*r| return r.read(buffer), |
src/translate_c.zig+3-3| ... | @@ -4008,11 +4008,11 @@ fn transCreateCompoundAssign( | ... | @@ -4008,11 +4008,11 @@ fn transCreateCompoundAssign( |
| 4008 | } | 4008 | } |
| 4009 | 4009 | ||
| 4010 | fn removeCVQualifiers(c: *Context, dst_type_node: Node, expr: Node) Error!Node { | 4010 | fn removeCVQualifiers(c: *Context, dst_type_node: Node, expr: Node) Error!Node { |
| 4011 | const const_casted = try Tag.const_cast.create(c.arena, expr); | 4011 | const volatile_casted = try Tag.volatile_cast.create(c.arena, expr); |
| 4012 | const volatile_casted = try Tag.volatile_cast.create(c.arena, const_casted); | 4012 | const const_casted = try Tag.const_cast.create(c.arena, volatile_casted); |
| 4013 | return Tag.as.create(c.arena, .{ | 4013 | return Tag.as.create(c.arena, .{ |
| 4014 | .lhs = dst_type_node, | 4014 | .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), |
| 4016 | }); | 4016 | }); |
| 4017 | } | 4017 | } |
| 4018 | 4018 |
test/behavior/array.zig+1-1| ... | @@ -1091,7 +1091,7 @@ test "initialize pointer to anyopaque with reference to empty array initializer" | ... | @@ -1091,7 +1091,7 @@ test "initialize pointer to anyopaque with reference to empty array initializer" |
| 1091 | const ptr: *const anyopaque = &.{}; | 1091 | const ptr: *const anyopaque = &.{}; |
| 1092 | // The above acts like an untyped initializer, since the `.{}` has no result type. | 1092 | // The above acts like an untyped initializer, since the `.{}` has no result type. |
| 1093 | // So, `ptr` points in memory to an empty tuple (`@TypeOf(.{})`). | 1093 | // 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)); |
| 1095 | const loaded = casted.*; | 1095 | const loaded = casted.*; |
| 1096 | // `val` should be a `@TypeOf(.{})`, as expected. | 1096 | // `val` should be a `@TypeOf(.{})`, as expected. |
| 1097 | // We can't check the value, but it's zero-bit, so the type matching is good enough. | 1097 | // 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( | ... | @@ -477,7 +477,7 @@ fn GenericIntApplier( |
| 477 | } | 477 | } |
| 478 | 478 | ||
| 479 | fn typeErasedApplyFn(context: *const anyopaque, arg: u32) void { | 479 | fn typeErasedApplyFn(context: *const anyopaque, arg: u32) void { |
| 480 | const ptr: *const Context = @alignCast(@ptrCast(context)); | 480 | const ptr: *const Context = @ptrCast(@alignCast(context)); |
| 481 | applyFn(ptr.*, arg); | 481 | applyFn(ptr.*, arg); |
| 482 | } | 482 | } |
| 483 | }; | 483 | }; |
test/behavior/extern.zig+1-1| ... | @@ -8,7 +8,7 @@ test "anyopaque extern symbol" { | ... | @@ -8,7 +8,7 @@ test "anyopaque extern symbol" { |
| 8 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 8 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 9 | 9 | ||
| 10 | const a = @extern(*anyopaque, .{ .name = "a_mystery_symbol" }); | 10 | const a = @extern(*anyopaque, .{ .name = "a_mystery_symbol" }); |
| 11 | const b: *i32 = @alignCast(@ptrCast(a)); | 11 | const b: *i32 = @ptrCast(@alignCast(a)); |
| 12 | try expect(b.* == 1234); | 12 | try expect(b.* == 1234); |
| 13 | } | 13 | } |
| 14 | 14 |
test/cases/compile_errors/nested_ptr_cast_bad_operand.zig+1-1| ... | @@ -6,7 +6,7 @@ export fn b() void { | ... | @@ -6,7 +6,7 @@ export fn b() void { |
| 6 | _ = @constCast(@volatileCast(123)); | 6 | _ = @constCast(@volatileCast(123)); |
| 7 | } | 7 | } |
| 8 | export fn c() void { | 8 | export fn c() void { |
| 9 | const x: ?*f32 = @constCast(@ptrCast(@addrSpaceCast(@volatileCast(p)))); | 9 | const x: ?*f32 = @ptrCast(@addrSpaceCast(@constCast(@volatileCast(p)))); |
| 10 | _ = x; | 10 | _ = x; |
| 11 | } | 11 | } |
| 12 | 12 |
test/translate_c.zig+2-2| ... | @@ -3234,12 +3234,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -3234,12 +3234,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 3234 | \\pub export fn bar(arg_a: [*c]const c_int) void { | 3234 | \\pub export fn bar(arg_a: [*c]const c_int) void { |
| 3235 | \\ var a = arg_a; | 3235 | \\ var a = arg_a; |
| 3236 | \\ _ = &a; | 3236 | \\ _ = &a; |
| 3237 | \\ foo(@as([*c]c_int, @ptrCast(@volatileCast(@constCast(a))))); | 3237 | \\ foo(@as([*c]c_int, @ptrCast(@constCast(@volatileCast(a))))); |
| 3238 | \\} | 3238 | \\} |
| 3239 | \\pub export fn baz(arg_a: [*c]volatile c_int) void { | 3239 | \\pub export fn baz(arg_a: [*c]volatile c_int) void { |
| 3240 | \\ var a = arg_a; | 3240 | \\ var a = arg_a; |
| 3241 | \\ _ = &a; | 3241 | \\ _ = &a; |
| 3242 | \\ foo(@as([*c]c_int, @ptrCast(@volatileCast(@constCast(a))))); | 3242 | \\ foo(@as([*c]c_int, @ptrCast(@constCast(@volatileCast(a))))); |
| 3243 | \\} | 3243 | \\} |
| 3244 | }); | 3244 | }); |
| 3245 | 3245 |