authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-24 21:12:01-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-24 21:21:05-05:00
log15d415e10b81a66fa3b887fb2a0c20bbcd614d94
tree10a61530b2b3d335cb8239d269b42569b8e932d8
parent34b1ebefaab2e8f5c322bc96388bb4fefec31027
signaturelock-open Commit is signed but in an unrecognized format.

make std.mem.toSlice use null terminated pointers

and fix the fallout

17 files changed, 76 insertions(+), 75 deletions(-)

lib/std/buffer.zig+2-7
...@@ -72,11 +72,11 @@ pub const Buffer = struct {...@@ -72,11 +72,11 @@ pub const Buffer = struct {
72 self.list.deinit();72 self.list.deinit();
73 }73 }
7474
75 pub fn toSlice(self: Buffer) []u8 {75 pub fn toSlice(self: Buffer) [:0]u8 {
76 return self.list.toSlice()[0..self.len()];76 return self.list.toSlice()[0..self.len()];
77 }77 }
7878
79 pub fn toSliceConst(self: Buffer) []const u8 {79 pub fn toSliceConst(self: Buffer) [:0]const u8 {
80 return self.list.toSliceConst()[0..self.len()];80 return self.list.toSliceConst()[0..self.len()];
81 }81 }
8282
...@@ -131,11 +131,6 @@ pub const Buffer = struct {...@@ -131,11 +131,6 @@ pub const Buffer = struct {
131 try self.resize(m.len);131 try self.resize(m.len);
132 mem.copy(u8, self.list.toSlice(), m);132 mem.copy(u8, self.list.toSlice(), m);
133 }133 }
134
135 /// For passing to C functions.
136 pub fn ptr(self: Buffer) [*]u8 {
137 return self.list.items.ptr;
138 }
139};134};
140135
141test "simple Buffer" {136test "simple Buffer" {
lib/std/c.zig+1-1
...@@ -110,7 +110,7 @@ pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;...@@ -110,7 +110,7 @@ pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
110pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;110pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
111pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;111pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;
112pub extern "c" fn rmdir(path: [*]const u8) c_int;112pub extern "c" fn rmdir(path: [*]const u8) c_int;
113pub extern "c" fn getenv(name: [*]const u8) ?[*]u8;113pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;
114pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;114pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
115pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;115pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
116pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;116pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
lib/std/fs.zig+1-1
...@@ -533,7 +533,7 @@ pub const Dir = struct {...@@ -533,7 +533,7 @@ pub const Dir = struct {
533 const next_index = self.index + linux_entry.reclen();533 const next_index = self.index + linux_entry.reclen();
534 self.index = next_index;534 self.index = next_index;
535535
536 const name = mem.toSlice(u8, @ptrCast([*]u8, &linux_entry.d_name));536 const name = mem.toSlice(u8, @ptrCast([*:0]u8, &linux_entry.d_name));
537537
538 // skip . and .. entries538 // skip . and .. entries
539 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {539 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {
lib/std/mem.zig+3-3
...@@ -356,17 +356,17 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool {...@@ -356,17 +356,17 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
356 return true;356 return true;
357}357}
358358
359pub fn len(comptime T: type, ptr: [*]const T) usize {359pub fn len(comptime T: type, ptr: [*:0]const T) usize {
360 var count: usize = 0;360 var count: usize = 0;
361 while (ptr[count] != 0) : (count += 1) {}361 while (ptr[count] != 0) : (count += 1) {}
362 return count;362 return count;
363}363}
364364
365pub fn toSliceConst(comptime T: type, ptr: [*]const T) []const T {365pub fn toSliceConst(comptime T: type, ptr: [*:0]const T) [:0]const T {
366 return ptr[0..len(T, ptr)];366 return ptr[0..len(T, ptr)];
367}367}
368368
369pub fn toSlice(comptime T: type, ptr: [*]T) []T {369pub fn toSlice(comptime T: type, ptr: [*:0]T) [:0]T {
370 return ptr[0..len(T, ptr)];370 return ptr[0..len(T, ptr)];
371}371}
372372
lib/std/net.zig+2-2
...@@ -360,7 +360,7 @@ pub const Address = extern union {...@@ -360,7 +360,7 @@ pub const Address = extern union {
360 unreachable;360 unreachable;
361 }361 }
362362
363 const path_len = std.mem.len(u8, &self.un.path);363 const path_len = std.mem.len(u8, @ptrCast([*:0]const u8, &self.un.path));
364 return @intCast(os.socklen_t, @sizeOf(os.sockaddr_un) - self.un.path.len + path_len);364 return @intCast(os.socklen_t, @sizeOf(os.sockaddr_un) - self.un.path.len + path_len);
365 },365 },
366 else => unreachable,366 else => unreachable,
...@@ -1271,7 +1271,7 @@ fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8)...@@ -1271,7 +1271,7 @@ fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8)
1271 var tmp: [256]u8 = undefined;1271 var tmp: [256]u8 = undefined;
1272 // Returns len of compressed name. strlen to get canon name.1272 // Returns len of compressed name. strlen to get canon name.
1273 _ = try os.dn_expand(packet, data, &tmp);1273 _ = try os.dn_expand(packet, data, &tmp);
1274 const canon_name = mem.toSliceConst(u8, &tmp);1274 const canon_name = mem.toSliceConst(u8, @ptrCast([*:0]const u8, &tmp));
1275 if (isValidHostName(canon_name)) {1275 if (isValidHostName(canon_name)) {
1276 try ctx.canon.replaceContents(canon_name);1276 try ctx.canon.replaceContents(canon_name);
1277 }1277 }
lib/std/os.zig+16-15
...@@ -66,12 +66,12 @@ pub const system = if (builtin.link_libc) std.c else switch (builtin.os) {...@@ -66,12 +66,12 @@ pub const system = if (builtin.link_libc) std.c else switch (builtin.os) {
66pub usingnamespace @import("os/bits.zig");66pub usingnamespace @import("os/bits.zig");
6767
68/// See also `getenv`. Populated by startup code before main().68/// See also `getenv`. Populated by startup code before main().
69pub var environ: [][*]u8 = undefined;69pub var environ: [][*:0]u8 = undefined;
7070
71/// Populated by startup code before main().71/// Populated by startup code before main().
72/// Not available on Windows. See `std.process.args`72/// Not available on Windows. See `std.process.args`
73/// for obtaining the process arguments.73/// for obtaining the process arguments.
74pub var argv: [][*]u8 = undefined;74pub var argv: [][*:0]u8 = undefined;
7575
76/// To obtain errno, call this function with the return value of the76/// To obtain errno, call this function with the return value of the
77/// system function call. For some systems this will obtain the value directly77/// system function call. For some systems this will obtain the value directly
...@@ -784,7 +784,7 @@ pub fn execveC(path: [*]const u8, child_argv: [*]const ?[*]const u8, envp: [*]co...@@ -784,7 +784,7 @@ pub fn execveC(path: [*]const u8, child_argv: [*]const ?[*]const u8, envp: [*]co
784/// matching the syscall API on all targets. This removes the need for an allocator.784/// matching the syscall API on all targets. This removes the need for an allocator.
785/// This function also uses the PATH environment variable to get the full path to the executable.785/// This function also uses the PATH environment variable to get the full path to the executable.
786/// If `file` is an absolute path, this is the same as `execveC`.786/// If `file` is an absolute path, this is the same as `execveC`.
787pub fn execvpeC(file: [*]const u8, child_argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) ExecveError {787pub fn execvpeC(file: [*:0]const u8, child_argv: [*]const ?[*:0]const u8, envp: [*]const ?[*:0]const u8) ExecveError {
788 const file_slice = mem.toSliceConst(u8, file);788 const file_slice = mem.toSliceConst(u8, file);
789 if (mem.indexOfScalar(u8, file_slice, '/') != null) return execveC(file, child_argv, envp);789 if (mem.indexOfScalar(u8, file_slice, '/') != null) return execveC(file, child_argv, envp);
790790
...@@ -820,8 +820,8 @@ pub fn execvpe(...@@ -820,8 +820,8 @@ pub fn execvpe(
820 argv_slice: []const []const u8,820 argv_slice: []const []const u8,
821 env_map: *const std.BufMap,821 env_map: *const std.BufMap,
822) (ExecveError || error{OutOfMemory}) {822) (ExecveError || error{OutOfMemory}) {
823 const argv_buf = try allocator.alloc(?[*]u8, argv_slice.len + 1);823 const argv_buf = try allocator.alloc(?[*:0]u8, argv_slice.len + 1);
824 mem.set(?[*]u8, argv_buf, null);824 mem.set(?[*:0]u8, argv_buf, null);
825 defer {825 defer {
826 for (argv_buf) |arg| {826 for (argv_buf) |arg| {
827 const arg_buf = if (arg) |ptr| mem.toSlice(u8, ptr) else break;827 const arg_buf = if (arg) |ptr| mem.toSlice(u8, ptr) else break;
...@@ -834,7 +834,8 @@ pub fn execvpe(...@@ -834,7 +834,8 @@ pub fn execvpe(
834 @memcpy(arg_buf.ptr, arg.ptr, arg.len);834 @memcpy(arg_buf.ptr, arg.ptr, arg.len);
835 arg_buf[arg.len] = 0;835 arg_buf[arg.len] = 0;
836836
837 argv_buf[i] = arg_buf.ptr;837 // TODO avoid @ptrCast using slice syntax with https://github.com/ziglang/zig/issues/3731
838 argv_buf[i] = @ptrCast([*:0]u8, arg_buf.ptr);
838 }839 }
839 argv_buf[argv_slice.len] = null;840 argv_buf[argv_slice.len] = null;
840841
...@@ -844,10 +845,10 @@ pub fn execvpe(...@@ -844,10 +845,10 @@ pub fn execvpe(
844 return execvpeC(argv_buf.ptr[0].?, argv_buf.ptr, envp_buf.ptr);845 return execvpeC(argv_buf.ptr[0].?, argv_buf.ptr, envp_buf.ptr);
845}846}
846847
847pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std.BufMap) ![]?[*]u8 {848pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std.BufMap) ![]?[*:0]u8 {
848 const envp_count = env_map.count();849 const envp_count = env_map.count();
849 const envp_buf = try allocator.alloc(?[*]u8, envp_count + 1);850 const envp_buf = try allocator.alloc(?[*:0]u8, envp_count + 1);
850 mem.set(?[*]u8, envp_buf, null);851 mem.set(?[*:0]u8, envp_buf, null);
851 errdefer freeNullDelimitedEnvMap(allocator, envp_buf);852 errdefer freeNullDelimitedEnvMap(allocator, envp_buf);
852 {853 {
853 var it = env_map.iterator();854 var it = env_map.iterator();
...@@ -859,7 +860,8 @@ pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std....@@ -859,7 +860,8 @@ pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std.
859 @memcpy(env_buf.ptr + pair.key.len + 1, pair.value.ptr, pair.value.len);860 @memcpy(env_buf.ptr + pair.key.len + 1, pair.value.ptr, pair.value.len);
860 env_buf[env_buf.len - 1] = 0;861 env_buf[env_buf.len - 1] = 0;
861862
862 envp_buf[i] = env_buf.ptr;863 // TODO avoid @ptrCast using slice syntax with https://github.com/ziglang/zig/issues/3731
864 envp_buf[i] = @ptrCast([*:0]u8, env_buf.ptr);
863 }865 }
864 assert(i == envp_count);866 assert(i == envp_count);
865 }867 }
...@@ -867,7 +869,7 @@ pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std....@@ -867,7 +869,7 @@ pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std.
867 return envp_buf;869 return envp_buf;
868}870}
869871
870pub fn freeNullDelimitedEnvMap(allocator: *mem.Allocator, envp_buf: []?[*]u8) void {872pub fn freeNullDelimitedEnvMap(allocator: *mem.Allocator, envp_buf: []?[*:0]u8) void {
871 for (envp_buf) |env| {873 for (envp_buf) |env| {
872 const env_buf = if (env) |ptr| ptr[0 .. mem.len(u8, ptr) + 1] else break;874 const env_buf = if (env) |ptr| ptr[0 .. mem.len(u8, ptr) + 1] else break;
873 allocator.free(env_buf);875 allocator.free(env_buf);
...@@ -896,8 +898,7 @@ pub fn getenv(key: []const u8) ?[]const u8 {...@@ -896,8 +898,7 @@ pub fn getenv(key: []const u8) ?[]const u8 {
896898
897/// Get an environment variable with a null-terminated name.899/// Get an environment variable with a null-terminated name.
898/// See also `getenv`.900/// See also `getenv`.
899/// TODO https://github.com/ziglang/zig/issues/265901pub fn getenvC(key: [*:0]const u8) ?[]const u8 {
900pub fn getenvC(key: [*]const u8) ?[]const u8 {
901 if (builtin.link_libc) {902 if (builtin.link_libc) {
902 const value = system.getenv(key) orelse return null;903 const value = system.getenv(key) orelse return null;
903 return mem.toSliceConst(u8, value);904 return mem.toSliceConst(u8, value);
...@@ -922,7 +923,7 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {...@@ -922,7 +923,7 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
922 break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));923 break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));
923 };924 };
924 switch (err) {925 switch (err) {
925 0 => return mem.toSlice(u8, out_buffer.ptr),926 0 => return mem.toSlice(u8, @ptrCast([*:0]u8, out_buffer.ptr)),
926 EFAULT => unreachable,927 EFAULT => unreachable,
927 EINVAL => unreachable,928 EINVAL => unreachable,
928 ENOENT => return error.CurrentWorkingDirectoryUnlinked,929 ENOENT => return error.CurrentWorkingDirectoryUnlinked,
...@@ -2865,7 +2866,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {...@@ -2865,7 +2866,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
2865 var uts: utsname = undefined;2866 var uts: utsname = undefined;
2866 switch (errno(system.uname(&uts))) {2867 switch (errno(system.uname(&uts))) {
2867 0 => {2868 0 => {
2868 const hostname = mem.toSlice(u8, &uts.nodename);2869 const hostname = mem.toSlice(u8, @ptrCast([*:0]u8, &uts.nodename));
2869 mem.copy(u8, name_buffer, hostname);2870 mem.copy(u8, name_buffer, hostname);
2870 return name_buffer[0..hostname.len];2871 return name_buffer[0..hostname.len];
2871 },2872 },
lib/std/os/linux/vdso.zig+4-2
...@@ -65,7 +65,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -65,7 +65,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
65 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;65 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;
66 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;66 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
67 if (0 == syms[i].st_shndx) continue;67 if (0 == syms[i].st_shndx) continue;
68 if (!mem.eql(u8, name, mem.toSliceConst(u8, strings + syms[i].st_name))) continue;68 const sym_name = @ptrCast([*:0]const u8, strings + syms[i].st_name);
69 if (!mem.eql(u8, name, mem.toSliceConst(u8, sym_name))) continue;
69 if (maybe_versym) |versym| {70 if (maybe_versym) |versym| {
70 if (!checkver(maybe_verdef.?, versym[i], vername, strings))71 if (!checkver(maybe_verdef.?, versym[i], vername, strings))
71 continue;72 continue;
...@@ -87,5 +88,6 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [...@@ -87,5 +88,6 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [
87 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);88 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);
88 }89 }
89 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);90 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);
90 return mem.eql(u8, vername, mem.toSliceConst(u8, strings + aux.vda_name));91 const vda_name = @ptrCast([*:0]const u8, strings + aux.vda_name);
92 return mem.eql(u8, vername, mem.toSliceConst(u8, vda_name));
91}93}
lib/std/special/start.zig+6-6
...@@ -123,12 +123,12 @@ fn posixCallMainAndExit() noreturn {...@@ -123,12 +123,12 @@ fn posixCallMainAndExit() noreturn {
123 @setAlignStack(16);123 @setAlignStack(16);
124 }124 }
125 const argc = starting_stack_ptr[0];125 const argc = starting_stack_ptr[0];
126 const argv = @ptrCast([*][*]u8, starting_stack_ptr + 1);126 const argv = @ptrCast([*][*:0]u8, starting_stack_ptr + 1);
127127
128 const envp_optional = @ptrCast([*]?[*]u8, argv + argc + 1);128 const envp_optional = @ptrCast([*:null]?[*:0]u8, argv + argc + 1);
129 var envp_count: usize = 0;129 var envp_count: usize = 0;
130 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}130 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}
131 const envp = @ptrCast([*][*]u8, envp_optional)[0..envp_count];131 const envp = @ptrCast([*][*:0]u8, envp_optional)[0..envp_count];
132132
133 if (builtin.os == .linux) {133 if (builtin.os == .linux) {
134 // Find the beginning of the auxiliary vector134 // Find the beginning of the auxiliary vector
...@@ -168,7 +168,7 @@ fn posixCallMainAndExit() noreturn {...@@ -168,7 +168,7 @@ fn posixCallMainAndExit() noreturn {
168 std.os.exit(@inlineCall(callMainWithArgs, argc, argv, envp));168 std.os.exit(@inlineCall(callMainWithArgs, argc, argv, envp));
169}169}
170170
171fn callMainWithArgs(argc: usize, argv: [*][*]u8, envp: [][*]u8) u8 {171fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 {
172 std.os.argv = argv[0..argc];172 std.os.argv = argv[0..argc];
173 std.os.environ = envp;173 std.os.environ = envp;
174174
...@@ -177,10 +177,10 @@ fn callMainWithArgs(argc: usize, argv: [*][*]u8, envp: [][*]u8) u8 {...@@ -177,10 +177,10 @@ fn callMainWithArgs(argc: usize, argv: [*][*]u8, envp: [][*]u8) u8 {
177 return initEventLoopAndCallMain();177 return initEventLoopAndCallMain();
178}178}
179179
180extern fn main(c_argc: i32, c_argv: [*][*]u8, c_envp: [*]?[*]u8) i32 {180extern fn main(c_argc: i32, c_argv: [*][*:0]u8, c_envp: [*:null]?[*:0]u8) i32 {
181 var env_count: usize = 0;181 var env_count: usize = 0;
182 while (c_envp[env_count] != null) : (env_count += 1) {}182 while (c_envp[env_count] != null) : (env_count += 1) {}
183 const envp = @ptrCast([*][*]u8, c_envp)[0..env_count];183 const envp = @ptrCast([*][*:0]u8, c_envp)[0..env_count];
184 return @inlineCall(callMainWithArgs, @intCast(usize, c_argc), c_argv, envp);184 return @inlineCall(callMainWithArgs, @intCast(usize, c_argc), c_argv, envp);
185}185}
186186
src-self-hosted/clang.zig+3-3
...@@ -708,7 +708,7 @@ pub const ZigClangStringLiteral_StringKind = extern enum {...@@ -708,7 +708,7 @@ pub const ZigClangStringLiteral_StringKind = extern enum {
708};708};
709709
710pub extern fn ZigClangSourceManager_getSpellingLoc(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) struct_ZigClangSourceLocation;710pub extern fn ZigClangSourceManager_getSpellingLoc(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) struct_ZigClangSourceLocation;
711pub extern fn ZigClangSourceManager_getFilename(self: *const struct_ZigClangSourceManager, SpellingLoc: struct_ZigClangSourceLocation) ?[*]const u8;711pub extern fn ZigClangSourceManager_getFilename(self: *const struct_ZigClangSourceManager, SpellingLoc: struct_ZigClangSourceLocation) ?[*:0]const u8;
712pub extern fn ZigClangSourceManager_getSpellingLineNumber(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint;712pub extern fn ZigClangSourceManager_getSpellingLineNumber(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint;
713pub extern fn ZigClangSourceManager_getSpellingColumnNumber(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint;713pub extern fn ZigClangSourceManager_getSpellingColumnNumber(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint;
714pub extern fn ZigClangSourceManager_getCharacterData(self: ?*const struct_ZigClangSourceManager, SL: struct_ZigClangSourceLocation) [*c]const u8;714pub extern fn ZigClangSourceManager_getCharacterData(self: ?*const struct_ZigClangSourceManager, SL: struct_ZigClangSourceLocation) [*c]const u8;
...@@ -746,7 +746,7 @@ pub extern fn ZigClangQualType_isRestrictQualified(self: struct_ZigClangQualType...@@ -746,7 +746,7 @@ pub extern fn ZigClangQualType_isRestrictQualified(self: struct_ZigClangQualType
746pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) ZigClangTypeClass;746pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) ZigClangTypeClass;
747pub extern fn ZigClangType_getPointeeType(self: ?*const struct_ZigClangType) struct_ZigClangQualType;747pub extern fn ZigClangType_getPointeeType(self: ?*const struct_ZigClangType) struct_ZigClangQualType;
748pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool;748pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool;
749pub extern fn ZigClangType_getTypeClassName(self: *const struct_ZigClangType) [*]const u8;749pub extern fn ZigClangType_getTypeClassName(self: *const struct_ZigClangType) [*:0]const u8;
750pub extern fn ZigClangStmt_getBeginLoc(self: *const struct_ZigClangStmt) struct_ZigClangSourceLocation;750pub extern fn ZigClangStmt_getBeginLoc(self: *const struct_ZigClangStmt) struct_ZigClangSourceLocation;
751pub extern fn ZigClangStmt_getStmtClass(self: ?*const struct_ZigClangStmt) ZigClangStmtClass;751pub extern fn ZigClangStmt_getStmtClass(self: ?*const struct_ZigClangStmt) ZigClangStmtClass;
752pub extern fn ZigClangStmt_classof_Expr(self: ?*const struct_ZigClangStmt) bool;752pub extern fn ZigClangStmt_classof_Expr(self: ?*const struct_ZigClangStmt) bool;
...@@ -904,7 +904,7 @@ pub extern fn ZigClangLoadFromCommandLine(...@@ -904,7 +904,7 @@ pub extern fn ZigClangLoadFromCommandLine(
904) ?*ZigClangASTUnit;904) ?*ZigClangASTUnit;
905905
906pub extern fn ZigClangDecl_getKind(decl: *const ZigClangDecl) ZigClangDeclKind;906pub extern fn ZigClangDecl_getKind(decl: *const ZigClangDecl) ZigClangDeclKind;
907pub extern fn ZigClangDecl_getDeclKindName(decl: *const struct_ZigClangDecl) [*]const u8;907pub extern fn ZigClangDecl_getDeclKindName(decl: *const struct_ZigClangDecl) [*:0]const u8;
908908
909pub const ZigClangCompoundStmt_const_body_iterator = [*c]const *struct_ZigClangStmt;909pub const ZigClangCompoundStmt_const_body_iterator = [*c]const *struct_ZigClangStmt;
910910
src-self-hosted/compilation.zig+3-3
...@@ -490,8 +490,8 @@ pub const Compilation = struct {...@@ -490,8 +490,8 @@ pub const Compilation = struct {
490 // LLVM creates invalid binaries on Windows sometimes.490 // LLVM creates invalid binaries on Windows sometimes.
491 // See https://github.com/ziglang/zig/issues/508491 // See https://github.com/ziglang/zig/issues/508
492 // As a workaround we do not use target native features on Windows.492 // As a workaround we do not use target native features on Windows.
493 var target_specific_cpu_args: ?[*]u8 = null;493 var target_specific_cpu_args: ?[*:0]u8 = null;
494 var target_specific_cpu_features: ?[*]u8 = null;494 var target_specific_cpu_features: ?[*:0]u8 = null;
495 defer llvm.DisposeMessage(target_specific_cpu_args);495 defer llvm.DisposeMessage(target_specific_cpu_args);
496 defer llvm.DisposeMessage(target_specific_cpu_features);496 defer llvm.DisposeMessage(target_specific_cpu_features);
497 if (target == Target.Native and !target.isWindows()) {497 if (target == Target.Native and !target.isWindows()) {
...@@ -501,7 +501,7 @@ pub const Compilation = struct {...@@ -501,7 +501,7 @@ pub const Compilation = struct {
501501
502 comp.target_machine = llvm.CreateTargetMachine(502 comp.target_machine = llvm.CreateTargetMachine(
503 comp.llvm_target,503 comp.llvm_target,
504 comp.llvm_triple.ptr(),504 comp.llvm_triple.toSliceConst(),
505 target_specific_cpu_args orelse "",505 target_specific_cpu_args orelse "",
506 target_specific_cpu_features orelse "",506 target_specific_cpu_features orelse "",
507 opt_level,507 opt_level,
src-self-hosted/llvm.zig+22-22
...@@ -83,16 +83,16 @@ pub const X86FP80TypeInContext = c.LLVMX86FP80TypeInContext;...@@ -83,16 +83,16 @@ pub const X86FP80TypeInContext = c.LLVMX86FP80TypeInContext;
83pub const X86MMXTypeInContext = c.LLVMX86MMXTypeInContext;83pub const X86MMXTypeInContext = c.LLVMX86MMXTypeInContext;
8484
85pub const AddGlobal = LLVMAddGlobal;85pub const AddGlobal = LLVMAddGlobal;
86extern fn LLVMAddGlobal(M: *Module, Ty: *Type, Name: [*]const u8) ?*Value;86extern fn LLVMAddGlobal(M: *Module, Ty: *Type, Name: [*:0]const u8) ?*Value;
8787
88pub const ConstStringInContext = LLVMConstStringInContext;88pub const ConstStringInContext = LLVMConstStringInContext;
89extern fn LLVMConstStringInContext(C: *Context, Str: [*]const u8, Length: c_uint, DontNullTerminate: Bool) ?*Value;89extern fn LLVMConstStringInContext(C: *Context, Str: [*:0]const u8, Length: c_uint, DontNullTerminate: Bool) ?*Value;
9090
91pub const ConstInt = LLVMConstInt;91pub const ConstInt = LLVMConstInt;
92extern fn LLVMConstInt(IntTy: *Type, N: c_ulonglong, SignExtend: Bool) ?*Value;92extern fn LLVMConstInt(IntTy: *Type, N: c_ulonglong, SignExtend: Bool) ?*Value;
9393
94pub const BuildLoad = LLVMBuildLoad;94pub const BuildLoad = LLVMBuildLoad;
95extern fn LLVMBuildLoad(arg0: *Builder, PointerVal: *Value, Name: [*]const u8) ?*Value;95extern fn LLVMBuildLoad(arg0: *Builder, PointerVal: *Value, Name: [*:0]const u8) ?*Value;
9696
97pub const ConstNull = LLVMConstNull;97pub const ConstNull = LLVMConstNull;
98extern fn LLVMConstNull(Ty: *Type) ?*Value;98extern fn LLVMConstNull(Ty: *Type) ?*Value;
...@@ -110,24 +110,24 @@ pub const CreateEnumAttribute = LLVMCreateEnumAttribute;...@@ -110,24 +110,24 @@ pub const CreateEnumAttribute = LLVMCreateEnumAttribute;
110extern fn LLVMCreateEnumAttribute(C: *Context, KindID: c_uint, Val: u64) ?*Attribute;110extern fn LLVMCreateEnumAttribute(C: *Context, KindID: c_uint, Val: u64) ?*Attribute;
111111
112pub const AddFunction = LLVMAddFunction;112pub const AddFunction = LLVMAddFunction;
113extern fn LLVMAddFunction(M: *Module, Name: [*]const u8, FunctionTy: *Type) ?*Value;113extern fn LLVMAddFunction(M: *Module, Name: [*:0]const u8, FunctionTy: *Type) ?*Value;
114114
115pub const CreateCompileUnit = ZigLLVMCreateCompileUnit;115pub const CreateCompileUnit = ZigLLVMCreateCompileUnit;
116extern fn ZigLLVMCreateCompileUnit(116extern fn ZigLLVMCreateCompileUnit(
117 dibuilder: *DIBuilder,117 dibuilder: *DIBuilder,
118 lang: c_uint,118 lang: c_uint,
119 difile: *DIFile,119 difile: *DIFile,
120 producer: [*]const u8,120 producer: [*:0]const u8,
121 is_optimized: bool,121 is_optimized: bool,
122 flags: [*]const u8,122 flags: [*:0]const u8,
123 runtime_version: c_uint,123 runtime_version: c_uint,
124 split_name: [*]const u8,124 split_name: [*:0]const u8,
125 dwo_id: u64,125 dwo_id: u64,
126 emit_debug_info: bool,126 emit_debug_info: bool,
127) ?*DICompileUnit;127) ?*DICompileUnit;
128128
129pub const CreateFile = ZigLLVMCreateFile;129pub const CreateFile = ZigLLVMCreateFile;
130extern fn ZigLLVMCreateFile(dibuilder: *DIBuilder, filename: [*]const u8, directory: [*]const u8) ?*DIFile;130extern fn ZigLLVMCreateFile(dibuilder: *DIBuilder, filename: [*:0]const u8, directory: [*:0]const u8) ?*DIFile;
131131
132pub const ArrayType = LLVMArrayType;132pub const ArrayType = LLVMArrayType;
133extern fn LLVMArrayType(ElementType: *Type, ElementCount: c_uint) ?*Type;133extern fn LLVMArrayType(ElementType: *Type, ElementCount: c_uint) ?*Type;
...@@ -145,7 +145,7 @@ pub const IntTypeInContext = LLVMIntTypeInContext;...@@ -145,7 +145,7 @@ pub const IntTypeInContext = LLVMIntTypeInContext;
145extern fn LLVMIntTypeInContext(C: *Context, NumBits: c_uint) ?*Type;145extern fn LLVMIntTypeInContext(C: *Context, NumBits: c_uint) ?*Type;
146146
147pub const ModuleCreateWithNameInContext = LLVMModuleCreateWithNameInContext;147pub const ModuleCreateWithNameInContext = LLVMModuleCreateWithNameInContext;
148extern fn LLVMModuleCreateWithNameInContext(ModuleID: [*]const u8, C: *Context) ?*Module;148extern fn LLVMModuleCreateWithNameInContext(ModuleID: [*:0]const u8, C: *Context) ?*Module;
149149
150pub const VoidTypeInContext = LLVMVoidTypeInContext;150pub const VoidTypeInContext = LLVMVoidTypeInContext;
151extern fn LLVMVoidTypeInContext(C: *Context) ?*Type;151extern fn LLVMVoidTypeInContext(C: *Context) ?*Type;
...@@ -157,7 +157,7 @@ pub const ContextDispose = LLVMContextDispose;...@@ -157,7 +157,7 @@ pub const ContextDispose = LLVMContextDispose;
157extern fn LLVMContextDispose(C: *Context) void;157extern fn LLVMContextDispose(C: *Context) void;
158158
159pub const CopyStringRepOfTargetData = LLVMCopyStringRepOfTargetData;159pub const CopyStringRepOfTargetData = LLVMCopyStringRepOfTargetData;
160extern fn LLVMCopyStringRepOfTargetData(TD: *TargetData) ?[*]u8;160extern fn LLVMCopyStringRepOfTargetData(TD: *TargetData) ?[*:0]u8;
161161
162pub const CreateTargetDataLayout = LLVMCreateTargetDataLayout;162pub const CreateTargetDataLayout = LLVMCreateTargetDataLayout;
163extern fn LLVMCreateTargetDataLayout(T: *TargetMachine) ?*TargetData;163extern fn LLVMCreateTargetDataLayout(T: *TargetMachine) ?*TargetData;
...@@ -165,9 +165,9 @@ extern fn LLVMCreateTargetDataLayout(T: *TargetMachine) ?*TargetData;...@@ -165,9 +165,9 @@ extern fn LLVMCreateTargetDataLayout(T: *TargetMachine) ?*TargetData;
165pub const CreateTargetMachine = ZigLLVMCreateTargetMachine;165pub const CreateTargetMachine = ZigLLVMCreateTargetMachine;
166extern fn ZigLLVMCreateTargetMachine(166extern fn ZigLLVMCreateTargetMachine(
167 T: *Target,167 T: *Target,
168 Triple: [*]const u8,168 Triple: [*:0]const u8,
169 CPU: [*]const u8,169 CPU: [*:0]const u8,
170 Features: [*]const u8,170 Features: [*:0]const u8,
171 Level: CodeGenOptLevel,171 Level: CodeGenOptLevel,
172 Reloc: RelocMode,172 Reloc: RelocMode,
173 CodeModel: CodeModel,173 CodeModel: CodeModel,
...@@ -175,10 +175,10 @@ extern fn ZigLLVMCreateTargetMachine(...@@ -175,10 +175,10 @@ extern fn ZigLLVMCreateTargetMachine(
175) ?*TargetMachine;175) ?*TargetMachine;
176176
177pub const GetHostCPUName = LLVMGetHostCPUName;177pub const GetHostCPUName = LLVMGetHostCPUName;
178extern fn LLVMGetHostCPUName() ?[*]u8;178extern fn LLVMGetHostCPUName() ?[*:0]u8;
179179
180pub const GetNativeFeatures = ZigLLVMGetNativeFeatures;180pub const GetNativeFeatures = ZigLLVMGetNativeFeatures;
181extern fn ZigLLVMGetNativeFeatures() ?[*]u8;181extern fn ZigLLVMGetNativeFeatures() ?[*:0]u8;
182182
183pub const GetElementType = LLVMGetElementType;183pub const GetElementType = LLVMGetElementType;
184extern fn LLVMGetElementType(Ty: *Type) *Type;184extern fn LLVMGetElementType(Ty: *Type) *Type;
...@@ -190,16 +190,16 @@ pub const BuildStore = LLVMBuildStore;...@@ -190,16 +190,16 @@ pub const BuildStore = LLVMBuildStore;
190extern fn LLVMBuildStore(arg0: *Builder, Val: *Value, Ptr: *Value) ?*Value;190extern fn LLVMBuildStore(arg0: *Builder, Val: *Value, Ptr: *Value) ?*Value;
191191
192pub const BuildAlloca = LLVMBuildAlloca;192pub const BuildAlloca = LLVMBuildAlloca;
193extern fn LLVMBuildAlloca(arg0: *Builder, Ty: *Type, Name: ?[*]const u8) ?*Value;193extern fn LLVMBuildAlloca(arg0: *Builder, Ty: *Type, Name: ?[*:0]const u8) ?*Value;
194194
195pub const ConstInBoundsGEP = LLVMConstInBoundsGEP;195pub const ConstInBoundsGEP = LLVMConstInBoundsGEP;
196pub extern fn LLVMConstInBoundsGEP(ConstantVal: *Value, ConstantIndices: [*]*Value, NumIndices: c_uint) ?*Value;196pub extern fn LLVMConstInBoundsGEP(ConstantVal: *Value, ConstantIndices: [*]*Value, NumIndices: c_uint) ?*Value;
197197
198pub const GetTargetFromTriple = LLVMGetTargetFromTriple;198pub const GetTargetFromTriple = LLVMGetTargetFromTriple;
199extern fn LLVMGetTargetFromTriple(Triple: [*]const u8, T: **Target, ErrorMessage: ?*[*]u8) Bool;199extern fn LLVMGetTargetFromTriple(Triple: [*:0]const u8, T: **Target, ErrorMessage: ?*[*:0]u8) Bool;
200200
201pub const VerifyModule = LLVMVerifyModule;201pub const VerifyModule = LLVMVerifyModule;
202extern fn LLVMVerifyModule(M: *Module, Action: VerifierFailureAction, OutMessage: *?[*]u8) Bool;202extern fn LLVMVerifyModule(M: *Module, Action: VerifierFailureAction, OutMessage: *?[*:0]u8) Bool;
203203
204pub const GetInsertBlock = LLVMGetInsertBlock;204pub const GetInsertBlock = LLVMGetInsertBlock;
205extern fn LLVMGetInsertBlock(Builder: *Builder) *BasicBlock;205extern fn LLVMGetInsertBlock(Builder: *Builder) *BasicBlock;
...@@ -216,7 +216,7 @@ pub const GetParam = LLVMGetParam;...@@ -216,7 +216,7 @@ pub const GetParam = LLVMGetParam;
216extern fn LLVMGetParam(Fn: *Value, Index: c_uint) *Value;216extern fn LLVMGetParam(Fn: *Value, Index: c_uint) *Value;
217217
218pub const AppendBasicBlockInContext = LLVMAppendBasicBlockInContext;218pub const AppendBasicBlockInContext = LLVMAppendBasicBlockInContext;
219extern fn LLVMAppendBasicBlockInContext(C: *Context, Fn: *Value, Name: [*]const u8) ?*BasicBlock;219extern fn LLVMAppendBasicBlockInContext(C: *Context, Fn: *Value, Name: [*:0]const u8) ?*BasicBlock;
220220
221pub const PositionBuilderAtEnd = LLVMPositionBuilderAtEnd;221pub const PositionBuilderAtEnd = LLVMPositionBuilderAtEnd;
222extern fn LLVMPositionBuilderAtEnd(Builder: *Builder, Block: *BasicBlock) void;222extern fn LLVMPositionBuilderAtEnd(Builder: *Builder, Block: *BasicBlock) void;
...@@ -278,14 +278,14 @@ pub const TargetMachineEmitToFile = ZigLLVMTargetMachineEmitToFile;...@@ -278,14 +278,14 @@ pub const TargetMachineEmitToFile = ZigLLVMTargetMachineEmitToFile;
278extern fn ZigLLVMTargetMachineEmitToFile(278extern fn ZigLLVMTargetMachineEmitToFile(
279 targ_machine_ref: *TargetMachine,279 targ_machine_ref: *TargetMachine,
280 module_ref: *Module,280 module_ref: *Module,
281 filename: [*]const u8,281 filename: [*:0]const u8,
282 output_type: EmitOutputType,282 output_type: EmitOutputType,
283 error_message: *[*]u8,283 error_message: *[*:0]u8,
284 is_debug: bool,284 is_debug: bool,
285 is_small: bool,285 is_small: bool,
286) bool;286) bool;
287287
288pub const BuildCall = ZigLLVMBuildCall;288pub const BuildCall = ZigLLVMBuildCall;
289extern fn ZigLLVMBuildCall(B: *Builder, Fn: *Value, Args: [*]*Value, NumArgs: c_uint, CC: c_uint, fn_inline: FnInline, Name: [*]const u8) ?*Value;289extern fn ZigLLVMBuildCall(B: *Builder, Fn: *Value, Args: [*]*Value, NumArgs: c_uint, CC: c_uint, fn_inline: FnInline, Name: [*:0]const u8) ?*Value;
290290
291pub const PrivateLinkage = c.LLVMLinkage.LLVMPrivateLinkage;291pub const PrivateLinkage = c.LLVMLinkage.LLVMPrivateLinkage;
src-self-hosted/stage1.zig+2-2
...@@ -144,7 +144,7 @@ export fn stage2_render_ast(tree: *ast.Tree, output_file: *FILE) Error {...@@ -144,7 +144,7 @@ export fn stage2_render_ast(tree: *ast.Tree, output_file: *FILE) Error {
144144
145// TODO: just use the actual self-hosted zig fmt. Until https://github.com/ziglang/zig/issues/2377,145// TODO: just use the actual self-hosted zig fmt. Until https://github.com/ziglang/zig/issues/2377,
146// we use a blocking implementation.146// we use a blocking implementation.
147export fn stage2_fmt(argc: c_int, argv: [*]const [*]const u8) c_int {147export fn stage2_fmt(argc: c_int, argv: [*]const [*:0]const u8) c_int {
148 if (std.debug.runtime_safety) {148 if (std.debug.runtime_safety) {
149 fmtMain(argc, argv) catch unreachable;149 fmtMain(argc, argv) catch unreachable;
150 } else {150 } else {
...@@ -156,7 +156,7 @@ export fn stage2_fmt(argc: c_int, argv: [*]const [*]const u8) c_int {...@@ -156,7 +156,7 @@ export fn stage2_fmt(argc: c_int, argv: [*]const [*]const u8) c_int {
156 return 0;156 return 0;
157}157}
158158
159fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {159fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
160 const allocator = std.heap.c_allocator;160 const allocator = std.heap.c_allocator;
161 var args_list = std.ArrayList([]const u8).init(allocator);161 var args_list = std.ArrayList([]const u8).init(allocator);
162 const argc_usize = @intCast(usize, argc);162 const argc_usize = @intCast(usize, argc);
src-self-hosted/translate_c.zig+1-1
...@@ -113,7 +113,7 @@ const Context = struct {...@@ -113,7 +113,7 @@ const Context = struct {
113 }113 }
114114
115 /// Convert a null-terminated C string to a slice allocated in the arena115 /// Convert a null-terminated C string to a slice allocated in the arena
116 fn str(c: *Context, s: [*]const u8) ![]u8 {116 fn str(c: *Context, s: [*:0]const u8) ![]u8 {
117 return std.mem.dupe(c.a(), u8, std.mem.toSliceConst(u8, s));117 return std.mem.dupe(c.a(), u8, std.mem.toSliceConst(u8, s));
118 }118 }
119119
src-self-hosted/util.zig+3-3
...@@ -172,9 +172,9 @@ pub fn getDarwinArchString(self: Target) []const u8 {...@@ -172,9 +172,9 @@ pub fn getDarwinArchString(self: Target) []const u8 {
172172
173pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target {173pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target {
174 var result: *llvm.Target = undefined;174 var result: *llvm.Target = undefined;
175 var err_msg: [*]u8 = undefined;175 var err_msg: [*:0]u8 = undefined;
176 if (llvm.GetTargetFromTriple(triple.ptr(), &result, &err_msg) != 0) {176 if (llvm.GetTargetFromTriple(triple.toSlice(), &result, &err_msg) != 0) {
177 std.debug.warn("triple: {s} error: {s}\n", triple.ptr(), err_msg);177 std.debug.warn("triple: {s} error: {s}\n", triple.toSlice(), err_msg);
178 return error.UnsupportedTarget;178 return error.UnsupportedTarget;
179 }179 }
180 return result;180 return result;
src/analyze.cpp+4-2
...@@ -7792,7 +7792,8 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa...@@ -7792,7 +7792,8 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa
77927792
7793 bool done = false;7793 bool done = false;
7794 if (ptr_type->data.pointer.is_const || ptr_type->data.pointer.is_volatile ||7794 if (ptr_type->data.pointer.is_const || ptr_type->data.pointer.is_volatile ||
7795 ptr_type->data.pointer.explicit_alignment != 0 || ptr_type->data.pointer.allow_zero)7795 ptr_type->data.pointer.explicit_alignment != 0 || ptr_type->data.pointer.allow_zero ||
7796 ptr_type->data.pointer.sentinel != nullptr)
7796 {7797 {
7797 ZigType *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false,7798 ZigType *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false,
7798 PtrLenUnknown, 0, 0, 0, false);7799 PtrLenUnknown, 0, 0, 0, false);
...@@ -7811,7 +7812,8 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa...@@ -7811,7 +7812,8 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa
7811 ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index]->type_entry;7812 ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index]->type_entry;
7812 assert(child_ptr_type->id == ZigTypeIdPointer);7813 assert(child_ptr_type->id == ZigTypeIdPointer);
7813 if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile ||7814 if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile ||
7814 child_ptr_type->data.pointer.explicit_alignment != 0 || child_ptr_type->data.pointer.allow_zero)7815 child_ptr_type->data.pointer.explicit_alignment != 0 || child_ptr_type->data.pointer.allow_zero ||
7816 child_ptr_type->data.pointer.sentinel != nullptr)
7815 {7817 {
7816 ZigType *grand_child_type = child_ptr_type->data.pointer.child_type;7818 ZigType *grand_child_type = child_ptr_type->data.pointer.child_type;
7817 ZigType *bland_child_ptr_type = get_pointer_to_type_extra(g, grand_child_type, false, false,7819 ZigType *bland_child_ptr_type = get_pointer_to_type_extra(g, grand_child_type, false, false,
test/stage1/behavior/cast.zig+1-1
...@@ -348,7 +348,7 @@ fn testCastPtrOfArrayToSliceAndPtr() void {...@@ -348,7 +348,7 @@ fn testCastPtrOfArrayToSliceAndPtr() void {
348test "cast *[1][*]const u8 to [*]const ?[*]const u8" {348test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
349 const window_name = [1][*]const u8{"window name"};349 const window_name = [1][*]const u8{"window name"};
350 const x: [*]const ?[*]const u8 = &window_name;350 const x: [*]const ?[*]const u8 = &window_name;
351 expect(mem.eql(u8, std.mem.toSliceConst(u8, x[0].?), "window name"));351 expect(mem.eql(u8, std.mem.toSliceConst(u8, @ptrCast([*:0]const u8, x[0].?)), "window name"));
352}352}
353353
354test "@intCast comptime_int" {354test "@intCast comptime_int" {
test/stage1/behavior/pointers.zig+2-1
...@@ -207,7 +207,8 @@ test "null terminated pointer" {...@@ -207,7 +207,8 @@ test "null terminated pointer" {
207 var array_with_zero = [_:0]u8{'h', 'e', 'l', 'l', 'o'};207 var array_with_zero = [_:0]u8{'h', 'e', 'l', 'l', 'o'};
208 var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero);208 var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero);
209 var no_zero_ptr: [*]const u8 = zero_ptr;209 var no_zero_ptr: [*]const u8 = zero_ptr;
210 expect(std.mem.eql(u8, std.mem.toSliceConst(u8, no_zero_ptr), "hello"));210 var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr);
211 expect(std.mem.eql(u8, std.mem.toSliceConst(u8, zero_ptr_again), "hello"));
211 }212 }
212 };213 };
213 S.doTheTest();214 S.doTheTest();