diff --git a/doc/langref.md b/doc/langref.md index e1d2dbccb5..dcbf3b03df 100644 --- a/doc/langref.md +++ b/doc/langref.md @@ -623,7 +623,7 @@ calls the public `panic` function exposed in the root source file, or if there is not one specified, invokes the one provided in `std/special/panic.zig`. -### @ptrcast(comptime DestType: type, value: var) -> DestType +### @ptrCast(comptime DestType: type, value: var) -> DestType Converts a pointer of one type to a pointer of another type. diff --git a/src/codegen.cpp b/src/codegen.cpp index d8c3e0e2d6..c0131e6a5e 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -4551,7 +4551,7 @@ static void define_builtin_fns(CodeGen *g) { create_builtin_fn(g, BuiltinFnIdSetGlobalSection, "setGlobalSection", 2); create_builtin_fn(g, BuiltinFnIdSetGlobalLinkage, "setGlobalLinkage", 2); create_builtin_fn(g, BuiltinFnIdPanic, "panic", 1); - create_builtin_fn(g, BuiltinFnIdPtrCast, "ptrcast", 2); + create_builtin_fn(g, BuiltinFnIdPtrCast, "ptrCast", 2); create_builtin_fn(g, BuiltinFnIdIntToPtr, "intToPtr", 2); create_builtin_fn(g, BuiltinFnIdEnumTagName, "enumTagName", 1); create_builtin_fn(g, BuiltinFnIdFieldParentPtr, "fieldParentPtr", 3); diff --git a/std/buf_map.zig b/std/buf_map.zig index 81834c6782..3f7787a7c3 100644 --- a/std/buf_map.zig +++ b/std/buf_map.zig @@ -58,7 +58,7 @@ pub const BufMap = struct { fn free(self: &BufMap, value: []const u8) { // remove the const - const mut_value = @ptrcast(&u8, value.ptr)[0...value.len]; + const mut_value = @ptrCast(&u8, value.ptr)[0...value.len]; self.hash_map.allocator.free(mut_value); } diff --git a/std/buf_set.zig b/std/buf_set.zig index 7c9f0f9058..dfda99e15b 100644 --- a/std/buf_set.zig +++ b/std/buf_set.zig @@ -47,7 +47,7 @@ pub const BufSet = struct { fn free(self: &BufSet, value: []const u8) { // remove the const - const mut_value = @ptrcast(&u8, value.ptr)[0...value.len]; + const mut_value = @ptrCast(&u8, value.ptr)[0...value.len]; self.hash_map.allocator.free(mut_value); } diff --git a/std/debug.zig b/std/debug.zig index 529c459992..a37f8749cf 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -74,7 +74,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream) -> %void { const name = %return compile_unit.die.getAttrString(st, DW.AT_name); %return out_stream.printf("{} -> {}\n", return_address, name); - maybe_fp = *@ptrcast(&const ?&const u8, fp); + maybe_fp = *@ptrCast(&const ?&const u8, fp); } }, ObjectFormat.coff => { diff --git a/std/hash_map.zig b/std/hash_map.zig index 3e99dde47b..fdb7e65e8f 100644 --- a/std/hash_map.zig +++ b/std/hash_map.zig @@ -250,7 +250,7 @@ test "basicHashMapTest" { } fn hash_i32(x: i32) -> u32 { - *@ptrcast(&u32, &x) + *@ptrCast(&u32, &x) } fn eql_i32(a: i32, b: i32) -> bool { diff --git a/std/os/darwin.zig b/std/os/darwin.zig index 12a4c56167..90e8c3fb0a 100644 --- a/std/os/darwin.zig +++ b/std/os/darwin.zig @@ -59,7 +59,7 @@ pub fn exit(status: usize) -> noreturn { /// Get the errno from a syscall return value, or 0 for no error. pub fn getErrno(r: usize) -> usize { - const signed_r = *@ptrcast(&const isize, &r); + const signed_r = *@ptrCast(&const isize, &r); if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0 } diff --git a/std/os/index.zig b/std/os/index.zig index 52e26d9e2b..60e3c9a9b8 100644 --- a/std/os/index.zig +++ b/std/os/index.zig @@ -752,7 +752,7 @@ pub const Dir = struct { break; } } - const linux_entry = @ptrcast(&LinuxEntry, &self.buf[self.index]); + const linux_entry = @ptrCast(&LinuxEntry, &self.buf[self.index]); const next_index = self.index + linux_entry.d_reclen; self.index = next_index; diff --git a/std/os/linux.zig b/std/os/linux.zig index 1ebade3baf..86a37e1b1c 100644 --- a/std/os/linux.zig +++ b/std/os/linux.zig @@ -251,8 +251,8 @@ pub const DT_LNK = 10; pub const DT_SOCK = 12; pub const DT_WHT = 14; -fn unsigned(s: i32) -> u32 { *@ptrcast(&u32, &s) } -fn signed(s: u32) -> i32 { *@ptrcast(&i32, &s) } +fn unsigned(s: i32) -> u32 { *@ptrCast(&u32, &s) } +fn signed(s: u32) -> i32 { *@ptrCast(&i32, &s) } pub fn WEXITSTATUS(s: i32) -> i32 { signed((unsigned(s) & 0xff00) >> 8) } pub fn WTERMSIG(s: i32) -> i32 { signed(unsigned(s) & 0x7f) } pub fn WSTOPSIG(s: i32) -> i32 { WEXITSTATUS(s) } @@ -262,7 +262,7 @@ pub fn WIFSIGNALED(s: i32) -> bool { (unsigned(s)&0xffff)-%1 < 0xff } /// Get the errno from a syscall return value, or 0 for no error. pub fn getErrno(r: usize) -> usize { - const signed_r = *@ptrcast(&const isize, &r); + const signed_r = *@ptrCast(&const isize, &r); if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0 } diff --git a/std/special/bootstrap.zig b/std/special/bootstrap.zig index d2a7703144..3fa9bcaf0d 100644 --- a/std/special/bootstrap.zig +++ b/std/special/bootstrap.zig @@ -31,8 +31,8 @@ export nakedcc fn _start() -> noreturn { fn callMainAndExit() -> noreturn { const argc = *argc_ptr; - const argv = @ptrcast(&&u8, &argc_ptr[1]); - const envp = @ptrcast(&?&u8, &argv[argc + 1]); + const argv = @ptrCast(&&u8, &argc_ptr[1]); + const envp = @ptrCast(&?&u8, &argv[argc + 1]); callMain(argc, argv, envp) %% exit(1); exit(0); } @@ -42,7 +42,7 @@ fn callMain(argc: usize, argv: &&u8, envp: &?&u8) -> %void { var env_count: usize = 0; while (envp[env_count] != null; env_count += 1) {} - std.os.environ_raw = @ptrcast(&&u8, envp)[0...env_count]; + std.os.environ_raw = @ptrCast(&&u8, envp)[0...env_count]; return root.main(); } diff --git a/std/special/compiler_rt.zig b/std/special/compiler_rt.zig index 1ad408beb9..1fdec3f157 100644 --- a/std/special/compiler_rt.zig +++ b/std/special/compiler_rt.zig @@ -15,7 +15,7 @@ export fn __udivdi3(a: du_int, b: du_int) -> du_int { fn du_int_to_udwords(x: du_int) -> udwords { @setDebugSafety(this, false); - return *@ptrcast(&udwords, &x); + return *@ptrCast(&udwords, &x); } export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { @@ -66,7 +66,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { if (var rem ?= maybe_rem) { r[high] = n[high] % d[high]; r[low] = 0; - *rem = *@ptrcast(&du_int, &r[0]); + *rem = *@ptrCast(&du_int, &r[0]); } return n[high] / d[high]; } @@ -78,7 +78,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { if (var rem ?= maybe_rem) { r[low] = n[low]; r[high] = n[high] & (d[high] - 1); - *rem = *@ptrcast(&du_int, &r[0]); + *rem = *@ptrCast(&du_int, &r[0]); } return n[high] >> @ctz(d[high]); } @@ -89,7 +89,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { // 0 <= sr <= n_uword_bits - 2 or sr large if (sr > n_uword_bits - 2) { if (var rem ?= maybe_rem) { - *rem = *@ptrcast(&du_int, &n[0]); + *rem = *@ptrCast(&du_int, &n[0]); } return 0; } @@ -113,12 +113,12 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { *rem = n[low] & (d[low] - 1); } if (d[low] == 1) { - return *@ptrcast(&du_int, &n[0]); + return *@ptrCast(&du_int, &n[0]); } sr = @ctz(d[low]); q[high] = n[high] >> sr; q[low] = (n[high] << (n_uword_bits - sr)) | (n[low] >> sr); - return *@ptrcast(&du_int, &q[0]); + return *@ptrCast(&du_int, &q[0]); } // K X // --- @@ -154,7 +154,7 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { // 0 <= sr <= n_uword_bits - 1 or sr large if (sr > n_uword_bits - 1) { if (var rem ?= maybe_rem) { - *rem = *@ptrcast(&du_int, &n[0]); + *rem = *@ptrCast(&du_int, &n[0]); } return 0; } @@ -191,17 +191,17 @@ export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int { // r.all -= d.all; // carry = 1; // } - const s: di_int = (di_int)(*@ptrcast(&du_int, &d[0]) - *@ptrcast(&du_int, &r[0]) - 1) >> (n_udword_bits - 1); + const s: di_int = (di_int)(*@ptrCast(&du_int, &d[0]) - *@ptrCast(&du_int, &r[0]) - 1) >> (n_udword_bits - 1); carry = su_int(s & 1); - *@ptrcast(&du_int, &r[0]) -= *@ptrcast(&du_int, &d[0]) & u64(s); + *@ptrCast(&du_int, &r[0]) -= *@ptrCast(&du_int, &d[0]) & u64(s); sr -= 1; } - *@ptrcast(&du_int, &q[0]) = (*@ptrcast(&du_int, &q[0]) << 1) | u64(carry); + *@ptrCast(&du_int, &q[0]) = (*@ptrCast(&du_int, &q[0]) << 1) | u64(carry); if (var rem ?= maybe_rem) { - *rem = *@ptrcast(&du_int, &r[0]); + *rem = *@ptrCast(&du_int, &r[0]); } - return *@ptrcast(&du_int, &q[0]); + return *@ptrCast(&du_int, &q[0]); } export fn __umoddi3(a: du_int, b: du_int) -> du_int { diff --git a/test/cases/cast.zig b/test/cases/cast.zig index 6a07b27a23..9f0d5f330b 100644 --- a/test/cases/cast.zig +++ b/test/cases/cast.zig @@ -16,7 +16,7 @@ test "numLitIntToPtrCast" { test "pointerReinterpretConstFloatToInt" { const float: f64 = 5.99999999999994648725e-01; const float_ptr = &float; - const int_ptr = @ptrcast(&i32, float_ptr); + const int_ptr = @ptrCast(&i32, float_ptr); const int_val = *int_ptr; assert(int_val == 858993411); } diff --git a/test/cases/generics.zig b/test/cases/generics.zig index dfae572054..7668e6a43b 100644 --- a/test/cases/generics.zig +++ b/test/cases/generics.zig @@ -121,5 +121,5 @@ test "genericFnWithImplicitCast" { } fn getByte(ptr: ?&const u8) -> u8 {*??ptr} fn getFirstByte(comptime T: type, mem: []const T) -> u8 { - getByte(@ptrcast(&const u8, &mem[0])) + getByte(@ptrCast(&const u8, &mem[0])) } diff --git a/test/cases/misc.zig b/test/cases/misc.zig index 4bcd59e1f5..6bd8cc6cb1 100644 --- a/test/cases/misc.zig +++ b/test/cases/misc.zig @@ -246,15 +246,15 @@ test "typeEquality" { const global_a: i32 = 1234; const global_b: &const i32 = &global_a; -const global_c: &const f32 = @ptrcast(&const f32, global_b); +const global_c: &const f32 = @ptrCast(&const f32, global_b); test "compileTimeGlobalReinterpret" { - const d = @ptrcast(&const i32, global_c); + const d = @ptrCast(&const i32, global_c); assert(*d == 1234); } test "explicitCastMaybePointers" { const a: ?&i32 = undefined; - const b: ?&f32 = @ptrcast(?&f32, a); + const b: ?&f32 = @ptrCast(?&f32, a); } test "genericMallocFree" { @@ -263,7 +263,7 @@ test "genericMallocFree" { } const some_mem : [100]u8 = undefined; fn memAlloc(comptime T: type, n: usize) -> %[]T { - return @ptrcast(&T, &some_mem[0])[0...n]; + return @ptrCast(&T, &some_mem[0])[0...n]; } fn memFree(comptime T: type, memory: []T) { } diff --git a/test/cases/struct.zig b/test/cases/struct.zig index 99039df654..d088fb8180 100644 --- a/test/cases/struct.zig +++ b/test/cases/struct.zig @@ -41,7 +41,7 @@ const VoidStructFieldsFoo = struct { test "fn" { var foo: StructFoo = undefined; - @memset(@ptrcast(&u8, &foo), 0, @sizeOf(StructFoo)); + @memset(@ptrCast(&u8, &foo), 0, @sizeOf(StructFoo)); foo.a += 1; foo.b = foo.a == 1; testFoo(foo); diff --git a/test/compare_output.zig b/test/compare_output.zig index 33ec04995d..bf2255881b 100644 --- a/test/compare_output.zig +++ b/test/compare_output.zig @@ -262,8 +262,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) { \\const c = @cImport(@cInclude("stdlib.h")); \\ \\export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int { - \\ const a_int = @ptrcast(&i32, a ?? unreachable); - \\ const b_int = @ptrcast(&i32, b ?? unreachable); + \\ const a_int = @ptrCast(&i32, a ?? unreachable); + \\ const b_int = @ptrCast(&i32, b ?? unreachable); \\ if (*a_int < *b_int) { \\ -1 \\ } else if (*a_int > *b_int) { @@ -276,7 +276,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) { \\export fn main() -> c_int { \\ var array = []u32 { 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 }; \\ - \\ c.qsort(@ptrcast(&c_void, &array[0]), c_ulong(array.len), @sizeOf(i32), compare_fn); + \\ c.qsort(@ptrCast(&c_void, &array[0]), c_ulong(array.len), @sizeOf(i32), compare_fn); \\ \\ for (array) |item, i| { \\ if (item != i) { diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 5880eebbf1..1f6c519d1a 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -1475,7 +1475,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { cases.add("ptrcast to non-pointer", \\export fn entry(a: &i32) -> usize { - \\ return @ptrcast(usize, a); + \\ return @ptrCast(usize, a); \\} , ".tmp_source.zig:2:21: error: expected pointer, found 'usize'");