| author | |
| committer | |
| log | fdac89d6cd65fa19bd5c6d381b62d980d97e5852 |
| tree | a8c8ac71faef3ae20f87ad49cda692679cbb97db |
| parent | 57634b7809d07c8a07a015bec55829937d5795e1 |
| signature |
In preparation for its removal as accepted in
https://github.com/ziglang/zig/issues/24738.154 files changed, 892 insertions(+), 866 deletions(-)
lib/compiler/build_runner.zig+1-1| ... | @@ -1557,7 +1557,7 @@ fn printUsage(b: *std.Build, w: *Writer) !void { | ... | @@ -1557,7 +1557,7 @@ fn printUsage(b: *std.Build, w: *Writer) !void { |
| 1557 | const name = try fmt.allocPrint(arena, " -D{s}=[{t}]", .{ option.name, option.type_id }); | 1557 | const name = try fmt.allocPrint(arena, " -D{s}=[{t}]", .{ option.name, option.type_id }); |
| 1558 | try w.print("{s:<30} {s}\n", .{ name, option.description }); | 1558 | try w.print("{s:<30} {s}\n", .{ name, option.description }); |
| 1559 | if (option.enum_options) |enum_options| { | 1559 | if (option.enum_options) |enum_options| { |
| 1560 | const padding = " " ** 33; | 1560 | const padding: [33]u8 = @splat(' '); |
| 1561 | try w.writeAll(padding ++ "Supported Values:\n"); | 1561 | try w.writeAll(padding ++ "Supported Values:\n"); |
| 1562 | for (enum_options) |enum_option| { | 1562 | for (enum_options) |enum_option| { |
| 1563 | try w.print(padding ++ " {s}\n", .{enum_option}); | 1563 | try w.print(padding ++ " {s}\n", .{enum_option}); |
lib/compiler/resinator/cvtres.zig+4-4| ... | @@ -321,7 +321,7 @@ pub fn writeCoff( | ... | @@ -321,7 +321,7 @@ pub fn writeCoff( |
| 321 | .checksum = 0, | 321 | .checksum = 0, |
| 322 | .number = 0, | 322 | .number = 0, |
| 323 | .selection = .NONE, | 323 | .selection = .NONE, |
| 324 | .unused = .{0} ** 3, | 324 | .unused = @splat(0), |
| 325 | }); | 325 | }); |
| 326 | 326 | ||
| 327 | try writeSymbol(writer, .{ | 327 | try writeSymbol(writer, .{ |
| ... | @@ -342,7 +342,7 @@ pub fn writeCoff( | ... | @@ -342,7 +342,7 @@ pub fn writeCoff( |
| 342 | .checksum = 0, | 342 | .checksum = 0, |
| 343 | .number = 0, | 343 | .number = 0, |
| 344 | .selection = .NONE, | 344 | .selection = .NONE, |
| 345 | .unused = .{0} ** 3, | 345 | .unused = @splat(0), |
| 346 | }); | 346 | }); |
| 347 | 347 | ||
| 348 | for (resource_symbols) |resource_symbol| { | 348 | for (resource_symbols) |resource_symbol| { |
| ... | @@ -353,11 +353,11 @@ pub fn writeCoff( | ... | @@ -353,11 +353,11 @@ pub fn writeCoff( |
| 353 | const name_bytes: [8]u8 = name_bytes: { | 353 | const name_bytes: [8]u8 = name_bytes: { |
| 354 | if (external_symbol_name.len > 8) { | 354 | if (external_symbol_name.len > 8) { |
| 355 | const string_table_offset: u32 = try string_table.put(allocator, external_symbol_name); | 355 | const string_table_offset: u32 = try string_table.put(allocator, external_symbol_name); |
| 356 | var bytes = [_]u8{0} ** 8; | 356 | var bytes: [8]u8 = @splat(0); |
| 357 | std.mem.writeInt(u32, bytes[4..8], string_table_offset, .little); | 357 | std.mem.writeInt(u32, bytes[4..8], string_table_offset, .little); |
| 358 | break :name_bytes bytes; | 358 | break :name_bytes bytes; |
| 359 | } else { | 359 | } else { |
| 360 | var symbol_shortname = [_]u8{0} ** 8; | 360 | var symbol_shortname: [8]u8 = @splat(0); |
| 361 | @memcpy(symbol_shortname[0..external_symbol_name.len], external_symbol_name); | 361 | @memcpy(symbol_shortname[0..external_symbol_name.len], external_symbol_name); |
| 362 | break :name_bytes symbol_shortname; | 362 | break :name_bytes symbol_shortname; |
| 363 | } | 363 | } |
lib/compiler/resinator/ico.zig+4-4| ... | @@ -183,7 +183,7 @@ pub const Entry = struct { | ... | @@ -183,7 +183,7 @@ pub const Entry = struct { |
| 183 | }; | 183 | }; |
| 184 | 184 | ||
| 185 | test "icon" { | 185 | test "icon" { |
| 186 | const data = "\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x00\x00\x00\x16\x00\x00\x00" ++ [_]u8{0} ** 16; | 186 | const data = "\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x00\x00\x00\x16\x00\x00\x00" ++ @as([16]u8, @splat(0)); |
| 187 | var fbs: std.Io.Reader = .fixed(data); | 187 | var fbs: std.Io.Reader = .fixed(data); |
| 188 | const icon = try read(std.testing.allocator, &fbs, data.len); | 188 | const icon = try read(std.testing.allocator, &fbs, data.len); |
| 189 | defer icon.deinit(); | 189 | defer icon.deinit(); |
| ... | @@ -196,19 +196,19 @@ test "icon too many images" { | ... | @@ -196,19 +196,19 @@ test "icon too many images" { |
| 196 | // Note that with verifying that all data sizes are within the file bounds and >= 16, | 196 | // Note that with verifying that all data sizes are within the file bounds and >= 16, |
| 197 | // it's not possible to hit EOF when looking for more RESDIR structures, since they are | 197 | // it's not possible to hit EOF when looking for more RESDIR structures, since they are |
| 198 | // themselves 16 bytes long, so we'll always hit ImpossibleDataSize instead. | 198 | // themselves 16 bytes long, so we'll always hit ImpossibleDataSize instead. |
| 199 | const data = "\x00\x00\x01\x00\x02\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x00\x00\x00\x16\x00\x00\x00" ++ [_]u8{0} ** 16; | 199 | const data = "\x00\x00\x01\x00\x02\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x00\x00\x00\x16\x00\x00\x00" ++ @as([16]u8, @splat(0)); |
| 200 | var fbs: std.Io.Reader = .fixed(data); | 200 | var fbs: std.Io.Reader = .fixed(data); |
| 201 | try std.testing.expectError(error.ImpossibleDataSize, read(std.testing.allocator, &fbs, data.len)); | 201 | try std.testing.expectError(error.ImpossibleDataSize, read(std.testing.allocator, &fbs, data.len)); |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | test "icon data size past EOF" { | 204 | test "icon data size past EOF" { |
| 205 | const data = "\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x01\x00\x00\x16\x00\x00\x00" ++ [_]u8{0} ** 16; | 205 | const data = "\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x01\x00\x00\x16\x00\x00\x00" ++ @as([16]u8, @splat(0)); |
| 206 | var fbs: std.Io.Reader = .fixed(data); | 206 | var fbs: std.Io.Reader = .fixed(data); |
| 207 | try std.testing.expectError(error.ImpossibleDataSize, read(std.testing.allocator, &fbs, data.len)); | 207 | try std.testing.expectError(error.ImpossibleDataSize, read(std.testing.allocator, &fbs, data.len)); |
| 208 | } | 208 | } |
| 209 | 209 | ||
| 210 | test "icon data offset past EOF" { | 210 | test "icon data offset past EOF" { |
| 211 | const data = "\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x00\x00\x00\x17\x00\x00\x00" ++ [_]u8{0} ** 16; | 211 | const data = "\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x00\x00\x00\x17\x00\x00\x00" ++ @as([16]u8, @splat(0)); |
| 212 | var fbs: std.Io.Reader = .fixed(data); | 212 | var fbs: std.Io.Reader = .fixed(data); |
| 213 | try std.testing.expectError(error.ImpossibleDataSize, read(std.testing.allocator, &fbs, data.len)); | 213 | try std.testing.expectError(error.ImpossibleDataSize, read(std.testing.allocator, &fbs, data.len)); |
| 214 | } | 214 | } |
lib/compiler/resinator/parse.zig+2-2| ... | @@ -138,8 +138,8 @@ pub const Parser = struct { | ... | @@ -138,8 +138,8 @@ pub const Parser = struct { |
| 138 | var optional_statements: std.ArrayList(*Node) = .empty; | 138 | var optional_statements: std.ArrayList(*Node) = .empty; |
| 139 | 139 | ||
| 140 | const num_statement_types = @typeInfo(rc.OptionalStatements).@"enum".fields.len; | 140 | const num_statement_types = @typeInfo(rc.OptionalStatements).@"enum".fields.len; |
| 141 | var statement_type_has_duplicates = [_]bool{false} ** num_statement_types; | 141 | var statement_type_has_duplicates: [num_statement_types]bool = @splat(false); |
| 142 | var last_statement_per_type = [_]?*Node{null} ** num_statement_types; | 142 | var last_statement_per_type: [num_statement_types]?*Node = @splat(null); |
| 143 | 143 | ||
| 144 | while (true) { | 144 | while (true) { |
| 145 | const lookahead_token = try self.lookaheadToken(.normal); | 145 | const lookahead_token = try self.lookaheadToken(.normal); |
lib/compiler/resinator/res.zig+1-1| ... | @@ -1068,7 +1068,7 @@ pub const FixedFileInfo = struct { | ... | @@ -1068,7 +1068,7 @@ pub const FixedFileInfo = struct { |
| 1068 | pub const key = std.unicode.utf8ToUtf16LeStringLiteral("VS_VERSION_INFO"); | 1068 | pub const key = std.unicode.utf8ToUtf16LeStringLiteral("VS_VERSION_INFO"); |
| 1069 | 1069 | ||
| 1070 | pub const Version = struct { | 1070 | pub const Version = struct { |
| 1071 | parts: [4]u16 = [_]u16{0} ** 4, | 1071 | parts: [4]u16 = @splat(0), |
| 1072 | 1072 | ||
| 1073 | pub fn mostSignificantCombinedParts(self: Version) u32 { | 1073 | pub fn mostSignificantCombinedParts(self: Version) u32 { |
| 1074 | return (@as(u32, self.parts[0]) << 16) + self.parts[1]; | 1074 | return (@as(u32, self.parts[0]) << 16) + self.parts[1]; |
lib/compiler/translate-c/ast.zig+11-21| ... | @@ -242,7 +242,7 @@ pub const Node = extern union { | ... | @@ -242,7 +242,7 @@ pub const Node = extern union { |
| 242 | 242 | ||
| 243 | /// array_type{} | 243 | /// array_type{} |
| 244 | empty_array, | 244 | empty_array, |
| 245 | /// [1]type{val} ** count | 245 | /// @as([count]type, @splat(val)) |
| 246 | array_filler, | 246 | array_filler, |
| 247 | 247 | ||
| 248 | /// comptime { if (!(lhs)) @compileError(rhs); } | 248 | /// comptime { if (!(lhs)) @compileError(rhs); } |
| ... | @@ -1976,28 +1976,18 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { | ... | @@ -1976,28 +1976,18 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { |
| 1976 | .array_filler => { | 1976 | .array_filler => { |
| 1977 | const payload = node.castTag(.array_filler).?.data; | 1977 | const payload = node.castTag(.array_filler).?.data; |
| 1978 | 1978 | ||
| 1979 | const type_expr = try renderArrayType(c, 1, payload.type); | 1979 | const as_tok = try c.addToken(.builtin, "@as"); |
| 1980 | const l_brace = try c.addToken(.l_brace, "{"); | 1980 | _ = try c.addToken(.l_paren, "("); |
| 1981 | const val = try renderNode(c, payload.filler); | 1981 | const type_node = try renderArrayType(c, payload.count, payload.type); |
| 1982 | _ = try c.addToken(.r_brace, "}"); | 1982 | _ = try c.addToken(.comma, ","); |
| 1983 | const splat_node = try renderBuiltinCall(c, "@splat", &.{payload.filler}); | ||
| 1984 | _ = try c.addToken(.r_paren, ")"); | ||
| 1983 | 1985 | ||
| 1984 | const init = try c.addNode(.{ | ||
| 1985 | .tag = .array_init_one, | ||
| 1986 | .main_token = l_brace, | ||
| 1987 | .data = .{ .node_and_node = .{ | ||
| 1988 | type_expr, val, | ||
| 1989 | } }, | ||
| 1990 | }); | ||
| 1991 | return c.addNode(.{ | 1986 | return c.addNode(.{ |
| 1992 | .tag = .array_cat, | 1987 | .tag = .builtin_call_two, |
| 1993 | .main_token = try c.addToken(.asterisk_asterisk, "**"), | 1988 | .main_token = as_tok, |
| 1994 | .data = .{ .node_and_node = .{ | 1989 | .data = .{ .opt_node_and_opt_node = .{ |
| 1995 | init, | 1990 | .fromOptional(type_node), .fromOptional(splat_node), |
| 1996 | try c.addNode(.{ | ||
| 1997 | .tag = .number_literal, | ||
| 1998 | .main_token = try c.addTokenFmt(.number_literal, "{d}", .{payload.count}), | ||
| 1999 | .data = undefined, | ||
| 2000 | }), | ||
| 2001 | } }, | 1991 | } }, |
| 2002 | }); | 1992 | }); |
| 2003 | }, | 1993 | }, |
lib/compiler_rt/atomics.zig+1-1| ... | @@ -94,7 +94,7 @@ const SpinlockTable = struct { | ... | @@ -94,7 +94,7 @@ const SpinlockTable = struct { |
| 94 | } | 94 | } |
| 95 | }; | 95 | }; |
| 96 | 96 | ||
| 97 | list: [max_spinlocks]Spinlock = [_]Spinlock{.{}} ** max_spinlocks, | 97 | list: [max_spinlocks]Spinlock = @splat(.{}), |
| 98 | 98 | ||
| 99 | // The spinlock table behaves as a really simple hash table, mapping | 99 | // The spinlock table behaves as a really simple hash table, mapping |
| 100 | // addresses to spinlocks. The mapping is not unique but that's only a | 100 | // addresses to spinlocks. The mapping is not unique but that's only a |
lib/compiler_rt/ssp.zig+2-2| ... | @@ -44,10 +44,10 @@ fn __chk_fail() callconv(.c) noreturn { | ... | @@ -44,10 +44,10 @@ fn __chk_fail() callconv(.c) noreturn { |
| 44 | 44 | ||
| 45 | // TODO: Initialize the canary with random data | 45 | // TODO: Initialize the canary with random data |
| 46 | var __stack_chk_guard: usize = blk: { | 46 | var __stack_chk_guard: usize = blk: { |
| 47 | var buf = [1]u8{0} ** @sizeOf(usize); | 47 | var buf: [@sizeOf(usize)]u8 = @splat(0); |
| 48 | buf[@sizeOf(usize) - 1] = 255; | 48 | buf[@sizeOf(usize) - 1] = 255; |
| 49 | buf[@sizeOf(usize) - 2] = '\n'; | 49 | buf[@sizeOf(usize) - 2] = '\n'; |
| 50 | break :blk @as(usize, @bitCast(buf)); | 50 | break :blk @bitCast(buf); |
| 51 | }; | 51 | }; |
| 52 | 52 | ||
| 53 | fn __strcpy_chk(dest: [*:0]u8, src: [*:0]const u8, dest_n: usize) callconv(.c) [*:0]u8 { | 53 | fn __strcpy_chk(dest: [*:0]u8, src: [*:0]const u8, dest_n: usize) callconv(.c) [*:0]u8 { |
lib/std/Io/Threaded.zig+4-4| ... | @@ -6329,7 +6329,7 @@ pub fn GetFinalPathNameByHandle( | ... | @@ -6329,7 +6329,7 @@ pub fn GetFinalPathNameByHandle( |
| 6329 | const MIN_SIZE = @sizeOf(windows.MOUNTMGR_MOUNT_POINT) + windows.MAX_PATH; | 6329 | const MIN_SIZE = @sizeOf(windows.MOUNTMGR_MOUNT_POINT) + windows.MAX_PATH; |
| 6330 | // We initialize the input buffer to all zeros for convenience since | 6330 | // We initialize the input buffer to all zeros for convenience since |
| 6331 | // `DeviceIoControl` with `IOCTL_MOUNTMGR_QUERY_POINTS` expects this. | 6331 | // `DeviceIoControl` with `IOCTL_MOUNTMGR_QUERY_POINTS` expects this. |
| 6332 | var input_buf: [MIN_SIZE]u8 align(@alignOf(windows.MOUNTMGR_MOUNT_POINT)) = [_]u8{0} ** MIN_SIZE; | 6332 | var input_buf: [MIN_SIZE]u8 align(@alignOf(windows.MOUNTMGR_MOUNT_POINT)) = @splat(0); |
| 6333 | var output_buf: [MIN_SIZE * 4]u8 align(@alignOf(windows.MOUNTMGR_MOUNT_POINTS)) = undefined; | 6333 | var output_buf: [MIN_SIZE * 4]u8 align(@alignOf(windows.MOUNTMGR_MOUNT_POINTS)) = undefined; |
| 6334 | 6334 | ||
| 6335 | // This surprising path is a filesystem path to the mount manager on Windows. | 6335 | // This surprising path is a filesystem path to the mount manager on Windows. |
| ... | @@ -6409,7 +6409,7 @@ pub fn GetFinalPathNameByHandle( | ... | @@ -6409,7 +6409,7 @@ pub fn GetFinalPathNameByHandle( |
| 6409 | 6409 | ||
| 6410 | // 49 is the maximum length accepted by mountmgrIsVolumeName | 6410 | // 49 is the maximum length accepted by mountmgrIsVolumeName |
| 6411 | const vol_input_size = @sizeOf(windows.MOUNTMGR_TARGET_NAME) + (49 * 2); | 6411 | const vol_input_size = @sizeOf(windows.MOUNTMGR_TARGET_NAME) + (49 * 2); |
| 6412 | var vol_input_buf: [vol_input_size]u8 align(@alignOf(windows.MOUNTMGR_TARGET_NAME)) = [_]u8{0} ** vol_input_size; | 6412 | var vol_input_buf: [vol_input_size]u8 align(@alignOf(windows.MOUNTMGR_TARGET_NAME)) = @splat(0); |
| 6413 | // Note: If the path exceeds MAX_PATH, the Disk Management GUI doesn't accept the full path, | 6413 | // Note: If the path exceeds MAX_PATH, the Disk Management GUI doesn't accept the full path, |
| 6414 | // and instead if must be specified using a shortened form (e.g. C:\FOO~1\BAR~1\<...>). | 6414 | // and instead if must be specified using a shortened form (e.g. C:\FOO~1\BAR~1\<...>). |
| 6415 | // However, just to be sure we can handle any path length, we use PATH_MAX_WIDE here. | 6415 | // However, just to be sure we can handle any path length, we use PATH_MAX_WIDE here. |
| ... | @@ -8914,7 +8914,7 @@ fn isCygwinPty(file: File) Io.Cancelable!bool { | ... | @@ -8914,7 +8914,7 @@ fn isCygwinPty(file: File) Io.Cancelable!bool { |
| 8914 | // we can use this smaller buffer and just return false on any error from | 8914 | // we can use this smaller buffer and just return false on any error from |
| 8915 | // NtQueryInformationFile. | 8915 | // NtQueryInformationFile. |
| 8916 | const num_name_bytes = windows.MAX_PATH * 2; | 8916 | const num_name_bytes = windows.MAX_PATH * 2; |
| 8917 | var name_info_bytes align(@alignOf(windows.FILE.NAME_INFORMATION)) = [_]u8{0} ** (name_bytes_offset + num_name_bytes); | 8917 | var name_info_bytes: [name_bytes_offset + num_name_bytes]u8 align(@alignOf(windows.FILE.NAME_INFORMATION)) = @splat(0); |
| 8918 | 8918 | ||
| 8919 | var io_status_block: windows.IO_STATUS_BLOCK = undefined; | 8919 | var io_status_block: windows.IO_STATUS_BLOCK = undefined; |
| 8920 | const syscall: Syscall = try .start(); | 8920 | const syscall: Syscall = try .start(); |
| ... | @@ -16191,7 +16191,7 @@ fn windowsCreateProcessPathExt( | ... | @@ -16191,7 +16191,7 @@ fn windowsCreateProcessPathExt( |
| 16191 | var io_status: windows.IO_STATUS_BLOCK = undefined; | 16191 | var io_status: windows.IO_STATUS_BLOCK = undefined; |
| 16192 | 16192 | ||
| 16193 | const num_supported_pathext = @typeInfo(process.WindowsExtension).@"enum".fields.len; | 16193 | const num_supported_pathext = @typeInfo(process.WindowsExtension).@"enum".fields.len; |
| 16194 | var pathext_seen = [_]bool{false} ** num_supported_pathext; | 16194 | var pathext_seen: [num_supported_pathext]bool = @splat(false); |
| 16195 | var any_pathext_seen = false; | 16195 | var any_pathext_seen = false; |
| 16196 | var unappended_exists = false; | 16196 | var unappended_exists = false; |
| 16197 | 16197 |
lib/std/Io/Writer.zig+1-1| ... | @@ -781,7 +781,7 @@ test splatByteAll { | ... | @@ -781,7 +781,7 @@ test splatByteAll { |
| 781 | defer aw.deinit(); | 781 | defer aw.deinit(); |
| 782 | 782 | ||
| 783 | try aw.writer.splatByteAll('7', 45); | 783 | try aw.writer.splatByteAll('7', 45); |
| 784 | try testing.expectEqualStrings("7" ** 45, aw.writer.buffered()); | 784 | try testing.expectEqualStrings(&@as([45]u8, @splat('7')), aw.writer.buffered()); |
| 785 | } | 785 | } |
| 786 | 786 | ||
| 787 | pub fn splatBytePreserve(w: *Writer, preserve: usize, byte: u8, n: usize) Error!void { | 787 | pub fn splatBytePreserve(w: *Writer, preserve: usize, byte: u8, n: usize) Error!void { |
lib/std/Io/net/HostName.zig+11-6| ... | @@ -76,9 +76,14 @@ test validate { | ... | @@ -76,9 +76,14 @@ test validate { |
| 76 | try validate("a-b.com"); | 76 | try validate("a-b.com"); |
| 77 | try validate("a.b.c.d.e.f.g"); | 77 | try validate("a.b.c.d.e.f.g"); |
| 78 | try validate("127.0.0.1"); // Also a valid hostname | 78 | try validate("127.0.0.1"); // Also a valid hostname |
| 79 | try validate("a" ** 63 ++ ".com"); // Label exactly 63 chars (valid) | 79 | |
| 80 | try validate("a." ** 127 ++ "a"); // Total length 255 (valid) | 80 | const many_a: [63]u8 = @splat('a'); |
| 81 | try validate("a." ** 127 ++ "a."); // Total length 255 + trailing dot (valid) | 81 | try validate(&many_a ++ ".com"); // Label exactly 63 chars (valid) |
| 82 | |||
| 83 | const many_a_dot_buf: [127][2]u8 = @splat(.{ 'a', '.' }); | ||
| 84 | const many_a_dot: []const u8 = @ptrCast(&many_a_dot_buf); | ||
| 85 | try validate(many_a_dot ++ "a"); // Total length 255 (valid) | ||
| 86 | try validate(many_a_dot ++ "a."); // Total length 255 + trailing dot (valid) | ||
| 82 | 87 | ||
| 83 | // Invalid hostnames | 88 | // Invalid hostnames |
| 84 | try std.testing.expectError(error.InvalidHostName, validate("")); | 89 | try std.testing.expectError(error.InvalidHostName, validate("")); |
| ... | @@ -92,9 +97,9 @@ test validate { | ... | @@ -92,9 +97,9 @@ test validate { |
| 92 | try std.testing.expectError(error.InvalidHostName, validate("host_name.com")); | 97 | try std.testing.expectError(error.InvalidHostName, validate("host_name.com")); |
| 93 | try std.testing.expectError(error.InvalidHostName, validate(".")); | 98 | try std.testing.expectError(error.InvalidHostName, validate(".")); |
| 94 | try std.testing.expectError(error.InvalidHostName, validate("..")); | 99 | try std.testing.expectError(error.InvalidHostName, validate("..")); |
| 95 | try std.testing.expectError(error.InvalidHostName, validate("a" ** 64 ++ ".com")); // Label length 64 (too long) | 100 | try std.testing.expectError(error.InvalidHostName, validate(&many_a ++ "a.com")); // Label length 64 (too long) |
| 96 | try std.testing.expectError(error.NameTooLong, validate("a." ** 127 ++ "ab")); // Total length 256 (too long) | 101 | try std.testing.expectError(error.NameTooLong, validate(many_a_dot ++ "ab")); // Total length 256 (too long) |
| 97 | try std.testing.expectError(error.NameTooLong, validate("a." ** 127 ++ "ab.")); // Total length 256 + trailing dot (too long) | 102 | try std.testing.expectError(error.NameTooLong, validate(many_a_dot ++ "ab.")); // Total length 256 + trailing dot (too long) |
| 98 | } | 103 | } |
| 99 | 104 | ||
| 100 | pub fn init(bytes: []const u8) ValidateError!HostName { | 105 | pub fn init(bytes: []const u8) ValidateError!HostName { |
lib/std/Random/ChaCha.zig+2-2| ... | @@ -14,7 +14,7 @@ const State = [8 * Cipher.block_length]u8; | ... | @@ -14,7 +14,7 @@ const State = [8 * Cipher.block_length]u8; |
| 14 | state: State, | 14 | state: State, |
| 15 | offset: usize, | 15 | offset: usize, |
| 16 | 16 | ||
| 17 | const nonce = [_]u8{0} ** Cipher.nonce_length; | 17 | const nonce: [Cipher.nonce_length]u8 = @splat(0); |
| 18 | 18 | ||
| 19 | pub const secret_seed_length = Cipher.key_length; | 19 | pub const secret_seed_length = Cipher.key_length; |
| 20 | 20 | ||
| ... | @@ -38,7 +38,7 @@ pub fn addEntropy(self: *Self, bytes: []const u8) void { | ... | @@ -38,7 +38,7 @@ pub fn addEntropy(self: *Self, bytes: []const u8) void { |
| 38 | ); | 38 | ); |
| 39 | } | 39 | } |
| 40 | if (i < bytes.len) { | 40 | if (i < bytes.len) { |
| 41 | var k = [_]u8{0} ** Cipher.key_length; | 41 | var k: [Cipher.key_length]u8 = @splat(0); |
| 42 | const src = bytes[i..]; | 42 | const src = bytes[i..]; |
| 43 | @memcpy(k[0..src.len], src); | 43 | @memcpy(k[0..src.len], src); |
| 44 | Cipher.xor( | 44 | Cipher.xor( |
lib/std/Random/benchmark.zig+2-2| ... | @@ -55,12 +55,12 @@ const csprngs = [_]Rng{ | ... | @@ -55,12 +55,12 @@ const csprngs = [_]Rng{ |
| 55 | Rng{ | 55 | Rng{ |
| 56 | .ty = Random.Ascon, | 56 | .ty = Random.Ascon, |
| 57 | .name = "ascon", | 57 | .name = "ascon", |
| 58 | .init_u8s = &[_]u8{0} ** 32, | 58 | .init_u8s = &@as([32]u8, @splat(0)), |
| 59 | }, | 59 | }, |
| 60 | Rng{ | 60 | Rng{ |
| 61 | .ty = Random.ChaCha, | 61 | .ty = Random.ChaCha, |
| 62 | .name = "chacha", | 62 | .name = "chacha", |
| 63 | .init_u8s = &[_]u8{0} ** 32, | 63 | .init_u8s = &@as([32]u8, @splat(0)), |
| 64 | }, | 64 | }, |
| 65 | }; | 65 | }; |
| 66 | 66 |
lib/std/Random/test.zig+4-4| ... | @@ -383,8 +383,8 @@ test "Random shuffle" { | ... | @@ -383,8 +383,8 @@ test "Random shuffle" { |
| 383 | var prng = DefaultPrng.init(0); | 383 | var prng = DefaultPrng.init(0); |
| 384 | const random = prng.random(); | 384 | const random = prng.random(); |
| 385 | 385 | ||
| 386 | var seq = [_]u8{ 0, 1, 2, 3, 4 }; | 386 | var seq: [5]u8 = .{ 0, 1, 2, 3, 4 }; |
| 387 | var seen = [_]bool{false} ** 5; | 387 | var seen: [5]bool = @splat(false); |
| 388 | 388 | ||
| 389 | var i: usize = 0; | 389 | var i: usize = 0; |
| 390 | while (i < 1000) : (i += 1) { | 390 | while (i < 1000) : (i += 1) { |
| ... | @@ -421,8 +421,8 @@ fn testRange(r: Random, start: i8, end: i8) !void { | ... | @@ -421,8 +421,8 @@ fn testRange(r: Random, start: i8, end: i8) !void { |
| 421 | try testRangeBias(r, start, end, false); | 421 | try testRangeBias(r, start, end, false); |
| 422 | } | 422 | } |
| 423 | fn testRangeBias(r: Random, start: i8, end: i8, biased: bool) !void { | 423 | fn testRangeBias(r: Random, start: i8, end: i8, biased: bool) !void { |
| 424 | const count = @as(usize, @intCast(@as(i32, end) - @as(i32, start))); | 424 | const count: usize = @intCast(@as(i32, end) - @as(i32, start)); |
| 425 | var values_buffer = [_]bool{false} ** 0x100; | 425 | var values_buffer: [0x100]bool = @splat(false); |
| 426 | const values = values_buffer[0..count]; | 426 | const values = values_buffer[0..count]; |
| 427 | var i: usize = 0; | 427 | var i: usize = 0; |
| 428 | while (i < count) { | 428 | while (i < count) { |
lib/std/Thread.zig+2-2| ... | @@ -1574,9 +1574,9 @@ const LinuxThreadImpl = struct { | ... | @@ -1574,9 +1574,9 @@ const LinuxThreadImpl = struct { |
| 1574 | }; | 1574 | }; |
| 1575 | 1575 | ||
| 1576 | fn testThreadName(io: Io, thread: *Thread) !void { | 1576 | fn testThreadName(io: Io, thread: *Thread) !void { |
| 1577 | const testCases = &[_][]const u8{ | 1577 | const testCases: []const []const u8 = &.{ |
| 1578 | "mythread", | 1578 | "mythread", |
| 1579 | "b" ** max_name_len, | 1579 | &@as([max_name_len]u8, @splat('b')), |
| 1580 | }; | 1580 | }; |
| 1581 | 1581 | ||
| 1582 | inline for (testCases) |tc| { | 1582 | inline for (testCases) |tc| { |
lib/std/base64.zig+5-5| ... | @@ -86,7 +86,7 @@ pub const Base64Encoder = struct { | ... | @@ -86,7 +86,7 @@ pub const Base64Encoder = struct { |
| 86 | /// A bunch of assertions, then simply pass the data right through. | 86 | /// A bunch of assertions, then simply pass the data right through. |
| 87 | pub fn init(alphabet_chars: [64]u8, pad_char: ?u8) Base64Encoder { | 87 | pub fn init(alphabet_chars: [64]u8, pad_char: ?u8) Base64Encoder { |
| 88 | assert(alphabet_chars.len == 64); | 88 | assert(alphabet_chars.len == 64); |
| 89 | var char_in_alphabet = [_]bool{false} ** 256; | 89 | var char_in_alphabet: [256]bool = @splat(false); |
| 90 | for (alphabet_chars) |c| { | 90 | for (alphabet_chars) |c| { |
| 91 | assert(!char_in_alphabet[c]); | 91 | assert(!char_in_alphabet[c]); |
| 92 | assert(pad_char == null or c != pad_char.?); | 92 | assert(pad_char == null or c != pad_char.?); |
| ... | @@ -176,12 +176,12 @@ pub const Base64Decoder = struct { | ... | @@ -176,12 +176,12 @@ pub const Base64Decoder = struct { |
| 176 | 176 | ||
| 177 | pub fn init(alphabet_chars: [64]u8, pad_char: ?u8) Base64Decoder { | 177 | pub fn init(alphabet_chars: [64]u8, pad_char: ?u8) Base64Decoder { |
| 178 | var result = Base64Decoder{ | 178 | var result = Base64Decoder{ |
| 179 | .char_to_index = [_]u8{invalid_char} ** 256, | 179 | .char_to_index = @splat(invalid_char), |
| 180 | .fast_char_to_index = .{[_]u32{invalid_char_tst} ** 256} ** 4, | 180 | .fast_char_to_index = @splat(@splat(invalid_char_tst)), |
| 181 | .pad_char = pad_char, | 181 | .pad_char = pad_char, |
| 182 | }; | 182 | }; |
| 183 | 183 | ||
| 184 | var char_in_alphabet = [_]bool{false} ** 256; | 184 | var char_in_alphabet: [256]bool = @splat(false); |
| 185 | for (alphabet_chars, 0..) |c, i| { | 185 | for (alphabet_chars, 0..) |c, i| { |
| 186 | assert(!char_in_alphabet[c]); | 186 | assert(!char_in_alphabet[c]); |
| 187 | assert(pad_char == null or c != pad_char.?); | 187 | assert(pad_char == null or c != pad_char.?); |
| ... | @@ -302,7 +302,7 @@ pub const Base64DecoderWithIgnore = struct { | ... | @@ -302,7 +302,7 @@ pub const Base64DecoderWithIgnore = struct { |
| 302 | pub fn init(alphabet_chars: [64]u8, pad_char: ?u8, ignore_chars: []const u8) Base64DecoderWithIgnore { | 302 | pub fn init(alphabet_chars: [64]u8, pad_char: ?u8, ignore_chars: []const u8) Base64DecoderWithIgnore { |
| 303 | var result = Base64DecoderWithIgnore{ | 303 | var result = Base64DecoderWithIgnore{ |
| 304 | .decoder = Base64Decoder.init(alphabet_chars, pad_char), | 304 | .decoder = Base64Decoder.init(alphabet_chars, pad_char), |
| 305 | .char_is_ignored = [_]bool{false} ** 256, | 305 | .char_is_ignored = @splat(false), |
| 306 | }; | 306 | }; |
| 307 | for (ignore_chars) |c| { | 307 | for (ignore_chars) |c| { |
| 308 | assert(result.decoder.char_to_index[c] == Base64Decoder.invalid_char); | 308 | assert(result.decoder.char_to_index[c] == Base64Decoder.invalid_char); |
lib/std/bit_set.zig+7-7| ... | @@ -406,24 +406,24 @@ pub fn Array(comptime MaskIntType: type, comptime size: usize) type { | ... | @@ -406,24 +406,24 @@ pub fn Array(comptime MaskIntType: type, comptime size: usize) type { |
| 406 | /// Deprecated: use `.empty`. | 406 | /// Deprecated: use `.empty`. |
| 407 | /// Creates a bit set with no elements present. | 407 | /// Creates a bit set with no elements present. |
| 408 | pub fn initEmpty() Self { | 408 | pub fn initEmpty() Self { |
| 409 | return .{ .masks = [_]MaskInt{0} ** num_masks }; | 409 | return .empty; |
| 410 | } | 410 | } |
| 411 | 411 | ||
| 412 | /// Deprecated: use `.full`. | 412 | /// Deprecated: use `.full`. |
| 413 | /// Creates a bit set with all elements present. | 413 | /// Creates a bit set with all elements present. |
| 414 | pub fn initFull() Self { | 414 | pub fn initFull() Self { |
| 415 | if (num_masks == 0) { | 415 | return .full; |
| 416 | return .{ .masks = .{} }; | ||
| 417 | } else { | ||
| 418 | return .{ .masks = [_]MaskInt{~@as(MaskInt, 0)} ** (num_masks - 1) ++ [_]MaskInt{last_item_mask} }; | ||
| 419 | } | ||
| 420 | } | 416 | } |
| 421 | 417 | ||
| 422 | /// A bit set with no elements present. | 418 | /// A bit set with no elements present. |
| 423 | pub const empty: Self = .{ .masks = @splat(0) }; | 419 | pub const empty: Self = .{ .masks = @splat(0) }; |
| 424 | 420 | ||
| 425 | /// A bit set with all elements present. | 421 | /// A bit set with all elements present. |
| 426 | pub const full: Self = .{ .masks = if (num_masks == 0) .{} else ([_]MaskInt{~@as(MaskInt, 0)} ** (num_masks - 1) ++ [_]MaskInt{last_item_mask}) }; | 422 | pub const full: Self = full: { |
| 423 | var masks: [num_masks]MaskInt = @splat(~@as(MaskInt, 0)); | ||
| 424 | if (num_masks > 0) masks[num_masks - 1] = last_item_mask; | ||
| 425 | break :full .{ .masks = masks }; | ||
| 426 | }; | ||
| 427 | 427 | ||
| 428 | /// Returns the number of bits in this bit set | 428 | /// Returns the number of bits in this bit set |
| 429 | pub inline fn capacity(self: Self) usize { | 429 | pub inline fn capacity(self: Self) usize { |
lib/std/c.zig+17-17| ... | @@ -7914,7 +7914,7 @@ pub const pthread_spinlock_t = switch (native_os) { | ... | @@ -7914,7 +7914,7 @@ pub const pthread_spinlock_t = switch (native_os) { |
| 7914 | 7914 | ||
| 7915 | pub const pthread_mutex_t = switch (native_os) { | 7915 | pub const pthread_mutex_t = switch (native_os) { |
| 7916 | .linux => extern struct { | 7916 | .linux => extern struct { |
| 7917 | data: [data_len]u8 align(@alignOf(usize)) = [_]u8{0} ** data_len, | 7917 | data: [data_len]u8 align(@alignOf(usize)) = @splat(0), |
| 7918 | 7918 | ||
| 7919 | const data_len = switch (native_abi) { | 7919 | const data_len = switch (native_abi) { |
| 7920 | .musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24, | 7920 | .musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24, |
| ... | @@ -7930,7 +7930,7 @@ pub const pthread_mutex_t = switch (native_os) { | ... | @@ -7930,7 +7930,7 @@ pub const pthread_mutex_t = switch (native_os) { |
| 7930 | }, | 7930 | }, |
| 7931 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { | 7931 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { |
| 7932 | sig: c_long = 0x32AAABA7, | 7932 | sig: c_long = 0x32AAABA7, |
| 7933 | data: [data_len]u8 = [_]u8{0} ** data_len, | 7933 | data: [data_len]u8 = @splat(0), |
| 7934 | 7934 | ||
| 7935 | const data_len = if (@sizeOf(usize) == 8) 56 else 40; | 7935 | const data_len = if (@sizeOf(usize) == 8) 56 else 40; |
| 7936 | }, | 7936 | }, |
| ... | @@ -7966,10 +7966,10 @@ pub const pthread_mutex_t = switch (native_os) { | ... | @@ -7966,10 +7966,10 @@ pub const pthread_mutex_t = switch (native_os) { |
| 7966 | data: u64 = 0, | 7966 | data: u64 = 0, |
| 7967 | }, | 7967 | }, |
| 7968 | .fuchsia => extern struct { | 7968 | .fuchsia => extern struct { |
| 7969 | data: [40]u8 align(@alignOf(usize)) = [_]u8{0} ** 40, | 7969 | data: [40]u8 align(@alignOf(usize)) = @splat(0), |
| 7970 | }, | 7970 | }, |
| 7971 | .emscripten => extern struct { | 7971 | .emscripten => extern struct { |
| 7972 | data: [24]u8 align(4) = [_]u8{0} ** 24, | 7972 | data: [24]u8 align(4) = @splat(0), |
| 7973 | }, | 7973 | }, |
| 7974 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L68-L73 | 7974 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L68-L73 |
| 7975 | .serenity => extern struct { | 7975 | .serenity => extern struct { |
| ... | @@ -7983,11 +7983,11 @@ pub const pthread_mutex_t = switch (native_os) { | ... | @@ -7983,11 +7983,11 @@ pub const pthread_mutex_t = switch (native_os) { |
| 7983 | 7983 | ||
| 7984 | pub const pthread_cond_t = switch (native_os) { | 7984 | pub const pthread_cond_t = switch (native_os) { |
| 7985 | .linux => extern struct { | 7985 | .linux => extern struct { |
| 7986 | data: [48]u8 align(@alignOf(usize)) = [_]u8{0} ** 48, | 7986 | data: [48]u8 align(@alignOf(usize)) = @splat(0), |
| 7987 | }, | 7987 | }, |
| 7988 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { | 7988 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { |
| 7989 | sig: c_long = 0x3CB0B1BB, | 7989 | sig: c_long = 0x3CB0B1BB, |
| 7990 | data: [data_len]u8 = [_]u8{0} ** data_len, | 7990 | data: [data_len]u8 = @splat(0), |
| 7991 | const data_len = if (@sizeOf(usize) == 8) 40 else 24; | 7991 | const data_len = if (@sizeOf(usize) == 8) 40 else 24; |
| 7992 | }, | 7992 | }, |
| 7993 | .freebsd, .dragonfly, .openbsd => extern struct { | 7993 | .freebsd, .dragonfly, .openbsd => extern struct { |
| ... | @@ -8012,13 +8012,13 @@ pub const pthread_cond_t = switch (native_os) { | ... | @@ -8012,13 +8012,13 @@ pub const pthread_cond_t = switch (native_os) { |
| 8012 | lock: i32 = 0, | 8012 | lock: i32 = 0, |
| 8013 | }, | 8013 | }, |
| 8014 | .illumos => extern struct { | 8014 | .illumos => extern struct { |
| 8015 | flag: [4]u8 = [_]u8{0} ** 4, | 8015 | flag: [4]u8 = @splat(0), |
| 8016 | type: u16 = 0, | 8016 | type: u16 = 0, |
| 8017 | magic: u16 = 0x4356, | 8017 | magic: u16 = 0x4356, |
| 8018 | data: u64 = 0, | 8018 | data: u64 = 0, |
| 8019 | }, | 8019 | }, |
| 8020 | .fuchsia, .emscripten => extern struct { | 8020 | .fuchsia, .emscripten => extern struct { |
| 8021 | data: [48]u8 align(@alignOf(usize)) = [_]u8{0} ** 48, | 8021 | data: [48]u8 align(@alignOf(usize)) = @splat(0), |
| 8022 | }, | 8022 | }, |
| 8023 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L80-L84 | 8023 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L80-L84 |
| 8024 | .serenity => extern struct { | 8024 | .serenity => extern struct { |
| ... | @@ -8033,20 +8033,20 @@ pub const pthread_rwlock_t = switch (native_os) { | ... | @@ -8033,20 +8033,20 @@ pub const pthread_rwlock_t = switch (native_os) { |
| 8033 | .linux => switch (native_abi) { | 8033 | .linux => switch (native_abi) { |
| 8034 | .android, .androideabi => switch (@sizeOf(usize)) { | 8034 | .android, .androideabi => switch (@sizeOf(usize)) { |
| 8035 | 4 => extern struct { | 8035 | 4 => extern struct { |
| 8036 | data: [40]u8 align(@alignOf(usize)) = [_]u8{0} ** 40, | 8036 | data: [40]u8 align(@alignOf(usize)) = @splat(0), |
| 8037 | }, | 8037 | }, |
| 8038 | 8 => extern struct { | 8038 | 8 => extern struct { |
| 8039 | data: [56]u8 align(@alignOf(usize)) = [_]u8{0} ** 56, | 8039 | data: [56]u8 align(@alignOf(usize)) = @splat(0), |
| 8040 | }, | 8040 | }, |
| 8041 | else => @compileError("impossible pointer size"), | 8041 | else => @compileError("impossible pointer size"), |
| 8042 | }, | 8042 | }, |
| 8043 | else => extern struct { | 8043 | else => extern struct { |
| 8044 | data: [56]u8 align(@alignOf(usize)) = [_]u8{0} ** 56, | 8044 | data: [56]u8 align(@alignOf(usize)) = @splat(0), |
| 8045 | }, | 8045 | }, |
| 8046 | }, | 8046 | }, |
| 8047 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { | 8047 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { |
| 8048 | sig: c_long = 0x2DA8B3B4, | 8048 | sig: c_long = 0x2DA8B3B4, |
| 8049 | data: [192]u8 = [_]u8{0} ** 192, | 8049 | data: [192]u8 = @splat(0), |
| 8050 | }, | 8050 | }, |
| 8051 | .freebsd, .dragonfly, .openbsd => extern struct { | 8051 | .freebsd, .dragonfly, .openbsd => extern struct { |
| 8052 | ptr: ?*anyopaque = null, | 8052 | ptr: ?*anyopaque = null, |
| ... | @@ -8079,10 +8079,10 @@ pub const pthread_rwlock_t = switch (native_os) { | ... | @@ -8079,10 +8079,10 @@ pub const pthread_rwlock_t = switch (native_os) { |
| 8079 | writercv: pthread_cond_t = .{}, | 8079 | writercv: pthread_cond_t = .{}, |
| 8080 | }, | 8080 | }, |
| 8081 | .fuchsia => extern struct { | 8081 | .fuchsia => extern struct { |
| 8082 | size: [56]u8 align(@alignOf(usize)) = [_]u8{0} ** 56, | 8082 | size: [56]u8 align(@alignOf(usize)) = @splat(0), |
| 8083 | }, | 8083 | }, |
| 8084 | .emscripten => extern struct { | 8084 | .emscripten => extern struct { |
| 8085 | size: [32]u8 align(4) = [_]u8{0} ** 32, | 8085 | size: [32]u8 align(4) = @splat(0), |
| 8086 | }, | 8086 | }, |
| 8087 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L86 | 8087 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L86 |
| 8088 | .serenity => extern struct { | 8088 | .serenity => extern struct { |
| ... | @@ -8170,8 +8170,8 @@ pub const sem_t = switch (native_os) { | ... | @@ -8170,8 +8170,8 @@ pub const sem_t = switch (native_os) { |
| 8170 | count: u32 = 0, | 8170 | count: u32 = 0, |
| 8171 | type: u16 = 0, | 8171 | type: u16 = 0, |
| 8172 | magic: u16 = 0x534d, | 8172 | magic: u16 = 0x534d, |
| 8173 | __pad1: [3]u64 = [_]u64{0} ** 3, | 8173 | __pad1: [3]u64 = @splat(0), |
| 8174 | __pad2: [2]u64 = [_]u64{0} ** 2, | 8174 | __pad2: [2]u64 = @splat(0), |
| 8175 | }, | 8175 | }, |
| 8176 | .openbsd, .netbsd, .dragonfly => ?*opaque {}, | 8176 | .openbsd, .netbsd, .dragonfly => ?*opaque {}, |
| 8177 | .haiku => extern struct { | 8177 | .haiku => extern struct { |
| ... | @@ -8235,7 +8235,7 @@ pub const Kevent = switch (native_os) { | ... | @@ -8235,7 +8235,7 @@ pub const Kevent = switch (native_os) { |
| 8235 | /// Opaque user data identifier. | 8235 | /// Opaque user data identifier. |
| 8236 | udata: usize, | 8236 | udata: usize, |
| 8237 | /// Future extensions. | 8237 | /// Future extensions. |
| 8238 | _ext: [4]u64 = [_]u64{0} ** 4, | 8238 | _ext: [4]u64 = @splat(0), |
| 8239 | }, | 8239 | }, |
| 8240 | .dragonfly => extern struct { | 8240 | .dragonfly => extern struct { |
| 8241 | ident: usize, | 8241 | ident: usize, |
lib/std/compress/flate/Decompress.zig+1-1| ... | @@ -723,7 +723,7 @@ fn HuffmanDecoder( | ... | @@ -723,7 +723,7 @@ fn HuffmanDecoder( |
| 723 | if (alphabet_size == 286) | 723 | if (alphabet_size == 286) |
| 724 | if (lens[256] == 0) return error.MissingEndOfBlockCode; | 724 | if (lens[256] == 0) return error.MissingEndOfBlockCode; |
| 725 | 725 | ||
| 726 | var count = [_]u16{0} ** (@as(usize, max_code_bits) + 1); | 726 | var count: [@as(usize, max_code_bits) + 1]u16 = @splat(0); |
| 727 | var max: usize = 0; | 727 | var max: usize = 0; |
| 728 | for (lens) |n| { | 728 | for (lens) |n| { |
| 729 | if (n == 0) continue; | 729 | if (n == 0) continue; |
lib/std/crypto.zig+3-3| ... | @@ -394,7 +394,7 @@ test "issue #4532: no index out of bounds" { | ... | @@ -394,7 +394,7 @@ test "issue #4532: no index out of bounds" { |
| 394 | }; | 394 | }; |
| 395 | 395 | ||
| 396 | inline for (types) |Hasher| { | 396 | inline for (types) |Hasher| { |
| 397 | var block = [_]u8{'#'} ** Hasher.block_length; | 397 | var block: [Hasher.block_length]u8 = @splat('#'); |
| 398 | var out1: [Hasher.digest_length]u8 = undefined; | 398 | var out1: [Hasher.digest_length]u8 = undefined; |
| 399 | var out2: [Hasher.digest_length]u8 = undefined; | 399 | var out2: [Hasher.digest_length]u8 = undefined; |
| 400 | const h0 = Hasher.init(.{}); | 400 | const h0 = Hasher.init(.{}); |
| ... | @@ -417,8 +417,8 @@ pub fn secureZero(comptime T: type, s: []volatile T) void { | ... | @@ -417,8 +417,8 @@ pub fn secureZero(comptime T: type, s: []volatile T) void { |
| 417 | } | 417 | } |
| 418 | 418 | ||
| 419 | test secureZero { | 419 | test secureZero { |
| 420 | var a = [_]u8{0xfe} ** 8; | 420 | var a: [8]u8 = @splat(0xFE); |
| 421 | var b = [_]u8{0xfe} ** 8; | 421 | var b: [8]u8 = @splat(0xFE); |
| 422 | 422 | ||
| 423 | @memset(&a, 0); | 423 | @memset(&a, 0); |
| 424 | secureZero(u8, &b); | 424 | secureZero(u8, &b); |
lib/std/crypto/25519/curve25519.zig+2-2| ... | @@ -41,7 +41,7 @@ pub const Curve25519 = struct { | ... | @@ -41,7 +41,7 @@ pub const Curve25519 = struct { |
| 41 | 41 | ||
| 42 | /// Multiply a point by the cofactor, returning WeakPublicKey if the element is in a small-order group. | 42 | /// Multiply a point by the cofactor, returning WeakPublicKey if the element is in a small-order group. |
| 43 | pub fn clearCofactor(p: Curve25519) WeakPublicKeyError!Curve25519 { | 43 | pub fn clearCofactor(p: Curve25519) WeakPublicKeyError!Curve25519 { |
| 44 | const cofactor = [_]u8{8} ++ [_]u8{0} ** 31; | 44 | const cofactor = [_]u8{8} ++ @as([31]u8, @splat(0)); |
| 45 | return ladder(p, cofactor, 4) catch return error.WeakPublicKey; | 45 | return ladder(p, cofactor, 4) catch return error.WeakPublicKey; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| ... | @@ -168,7 +168,7 @@ test "elligator2" { | ... | @@ -168,7 +168,7 @@ test "elligator2" { |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | test "small order check" { | 170 | test "small order check" { |
| 171 | var s: [32]u8 = [_]u8{1} ++ [_]u8{0} ** 31; | 171 | var s: [32]u8 = [_]u8{1} ++ @as([31]u8, @splat(0)); |
| 172 | const small_order_ss: [7][32]u8 = .{ | 172 | const small_order_ss: [7][32]u8 = .{ |
| 173 | .{ | 173 | .{ |
| 174 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0 (order 4) | 174 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0 (order 4) |
lib/std/crypto/25519/edwards25519.zig+3-3| ... | @@ -470,7 +470,7 @@ pub const Edwards25519 = struct { | ... | @@ -470,7 +470,7 @@ pub const Edwards25519 = struct { |
| 470 | st.final(&hctx); | 470 | st.final(&hctx); |
| 471 | xctx = hctx[0..]; | 471 | xctx = hctx[0..]; |
| 472 | } | 472 | } |
| 473 | const empty_block = [_]u8{0} ** H.block_length; | 473 | const empty_block: [H.block_length]u8 = @splat(0); |
| 474 | var t = [3]u8{ 0, n * h_l, 0 }; | 474 | var t = [3]u8{ 0, n * h_l, 0 }; |
| 475 | var xctx_len_u8 = [1]u8{@as(u8, @intCast(xctx.len))}; | 475 | var xctx_len_u8 = [1]u8{@as(u8, @intCast(xctx.len))}; |
| 476 | var st = H.init(.{}); | 476 | var st = H.init(.{}); |
| ... | @@ -539,7 +539,7 @@ pub const Edwards25519 = struct { | ... | @@ -539,7 +539,7 @@ pub const Edwards25519 = struct { |
| 539 | const htest = @import("../test.zig"); | 539 | const htest = @import("../test.zig"); |
| 540 | 540 | ||
| 541 | test "packing/unpacking" { | 541 | test "packing/unpacking" { |
| 542 | const s = [_]u8{170} ++ [_]u8{0} ** 31; | 542 | const s = [1]u8{170} ++ @as([31]u8, @splat(0)); |
| 543 | var b = Edwards25519.basePoint; | 543 | var b = Edwards25519.basePoint; |
| 544 | const pk = try b.mul(s); | 544 | const pk = try b.mul(s); |
| 545 | var buf: [128]u8 = undefined; | 545 | var buf: [128]u8 = undefined; |
| ... | @@ -609,7 +609,7 @@ test "hash-to-curve operation" { | ... | @@ -609,7 +609,7 @@ test "hash-to-curve operation" { |
| 609 | } | 609 | } |
| 610 | 610 | ||
| 611 | test "implicit reduction of invalid scalars" { | 611 | test "implicit reduction of invalid scalars" { |
| 612 | const s = [_]u8{0} ** 31 ++ [_]u8{255}; | 612 | const s = @as([31]u8, @splat(0)) ++ [1]u8{255}; |
| 613 | const p1 = try Edwards25519.basePoint.mulPublic(s); | 613 | const p1 = try Edwards25519.basePoint.mulPublic(s); |
| 614 | const p2 = try Edwards25519.basePoint.mul(s); | 614 | const p2 = try Edwards25519.basePoint.mul(s); |
| 615 | const p3 = try p1.mulPublic(s); | 615 | const p3 = try p1.mulPublic(s); |
lib/std/crypto/25519/ristretto255.zig+2-2| ... | @@ -183,13 +183,13 @@ test "ristretto255" { | ... | @@ -183,13 +183,13 @@ test "ristretto255" { |
| 183 | q = q.dbl().add(p); | 183 | q = q.dbl().add(p); |
| 184 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&q.toBytes()}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E"); | 184 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&q.toBytes()}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E"); |
| 185 | 185 | ||
| 186 | const s = [_]u8{15} ++ [_]u8{0} ** 31; | 186 | const s = [_]u8{15} ++ @as([31]u8, @splat(0)); |
| 187 | const w = try p.mul(s); | 187 | const w = try p.mul(s); |
| 188 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&w.toBytes()}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E"); | 188 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&w.toBytes()}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E"); |
| 189 | 189 | ||
| 190 | try std.testing.expect(p.dbl().dbl().dbl().dbl().equivalent(w.add(p))); | 190 | try std.testing.expect(p.dbl().dbl().dbl().dbl().equivalent(w.add(p))); |
| 191 | 191 | ||
| 192 | const h = [_]u8{69} ** 32 ++ [_]u8{42} ** 32; | 192 | const h = @as([32]u8, @splat(69)) ++ @as([32]u8, @splat(42)); |
| 193 | const ph = Ristretto255.fromUniform(h); | 193 | const ph = Ristretto255.fromUniform(h); |
| 194 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&ph.toBytes()}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19"); | 194 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&ph.toBytes()}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19"); |
| 195 | } | 195 | } |
lib/std/crypto/25519/scalar.zig+6-6| ... | @@ -11,7 +11,7 @@ pub const field_order: u256 = 72370055773322622139731865630429942408571163593799 | ... | @@ -11,7 +11,7 @@ pub const field_order: u256 = 72370055773322622139731865630429942408571163593799 |
| 11 | pub const CompressedScalar = [32]u8; | 11 | pub const CompressedScalar = [32]u8; |
| 12 | 12 | ||
| 13 | /// Zero | 13 | /// Zero |
| 14 | pub const zero = [_]u8{0} ** 32; | 14 | pub const zero: [32]u8 = @splat(0); |
| 15 | 15 | ||
| 16 | const field_order_s = s: { | 16 | const field_order_s = s: { |
| 17 | var s: [32]u8 = undefined; | 17 | var s: [32]u8 = undefined; |
| ... | @@ -81,7 +81,7 @@ pub fn add(a: CompressedScalar, b: CompressedScalar) CompressedScalar { | ... | @@ -81,7 +81,7 @@ pub fn add(a: CompressedScalar, b: CompressedScalar) CompressedScalar { |
| 81 | 81 | ||
| 82 | /// Return -s (mod L) | 82 | /// Return -s (mod L) |
| 83 | pub fn neg(s: CompressedScalar) CompressedScalar { | 83 | pub fn neg(s: CompressedScalar) CompressedScalar { |
| 84 | const fs: [64]u8 = field_order_s ++ [_]u8{0} ** 32; | 84 | const fs: [64]u8 = field_order_s ++ @as([32]u8, @splat(0)); |
| 85 | var sx: [64]u8 = undefined; | 85 | var sx: [64]u8 = undefined; |
| 86 | sx[0..32].* = s; | 86 | sx[0..32].* = s; |
| 87 | @memset(sx[32..], 0); | 87 | @memset(sx[32..], 0); |
| ... | @@ -862,9 +862,9 @@ test "non-canonical scalar25519" { | ... | @@ -862,9 +862,9 @@ test "non-canonical scalar25519" { |
| 862 | } | 862 | } |
| 863 | 863 | ||
| 864 | test "mulAdd overflow check" { | 864 | test "mulAdd overflow check" { |
| 865 | const a: [32]u8 = [_]u8{0xff} ** 32; | 865 | const a: [32]u8 = @splat(0xff); |
| 866 | const b: [32]u8 = [_]u8{0xff} ** 32; | 866 | const b: [32]u8 = @splat(0xff); |
| 867 | const c: [32]u8 = [_]u8{0xff} ** 32; | 867 | const c: [32]u8 = @splat(0xff); |
| 868 | const x = mulAdd(a, b, c); | 868 | const x = mulAdd(a, b, c); |
| 869 | var buf: [128]u8 = undefined; | 869 | var buf: [128]u8 = undefined; |
| 870 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&x}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903"); | 870 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&x}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903"); |
| ... | @@ -886,7 +886,7 @@ test "random scalar" { | ... | @@ -886,7 +886,7 @@ test "random scalar" { |
| 886 | } | 886 | } |
| 887 | 887 | ||
| 888 | test "64-bit reduction" { | 888 | test "64-bit reduction" { |
| 889 | const bytes = field_order_s ++ [_]u8{0} ** 32; | 889 | const bytes = field_order_s ++ @as([32]u8, @splat(0)); |
| 890 | const x = Scalar.fromBytes64(bytes); | 890 | const x = Scalar.fromBytes64(bytes); |
| 891 | try std.testing.expect(x.isZero()); | 891 | try std.testing.expect(x.isZero()); |
| 892 | } | 892 | } |
lib/std/crypto/25519/x25519.zig+1-1| ... | @@ -181,7 +181,7 @@ test "rfc7748 1,000,000 iterations" { | ... | @@ -181,7 +181,7 @@ test "rfc7748 1,000,000 iterations" { |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | test "edwards25519 -> curve25519 map" { | 183 | test "edwards25519 -> curve25519 map" { |
| 184 | const ed_kp = try crypto.sign.Ed25519.KeyPair.generateDeterministic([_]u8{0x42} ** 32); | 184 | const ed_kp = try crypto.sign.Ed25519.KeyPair.generateDeterministic(@splat(0x42)); |
| 185 | const mont_kp = try X25519.KeyPair.fromEd25519(ed_kp); | 185 | const mont_kp = try X25519.KeyPair.fromEd25519(ed_kp); |
| 186 | try htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key); | 186 | try htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key); |
| 187 | try htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key); | 187 | try htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key); |
lib/std/crypto/Certificate.zig+1-1| ... | @@ -1092,7 +1092,7 @@ pub const rsa = struct { | ... | @@ -1092,7 +1092,7 @@ pub const rsa = struct { |
| 1092 | } | 1092 | } |
| 1093 | var m_p_buf: [8 + Hash.digest_length + Hash.digest_length]u8 = undefined; | 1093 | var m_p_buf: [8 + Hash.digest_length + Hash.digest_length]u8 = undefined; |
| 1094 | var m_p = m_p_buf[0 .. 8 + Hash.digest_length + sLen]; | 1094 | var m_p = m_p_buf[0 .. 8 + Hash.digest_length + sLen]; |
| 1095 | std.mem.copyForwards(u8, m_p, &([_]u8{0} ** 8)); | 1095 | std.mem.copyForwards(u8, m_p, @as(*const [8]u8, @splat(0))); |
| 1096 | std.mem.copyForwards(u8, m_p[8..], &mHash); | 1096 | std.mem.copyForwards(u8, m_p[8..], &mHash); |
| 1097 | std.mem.copyForwards(u8, m_p[(8 + Hash.digest_length)..], salt); | 1097 | std.mem.copyForwards(u8, m_p[(8 + Hash.digest_length)..], salt); |
| 1098 | 1098 |
lib/std/crypto/Sha1.zig+1-1| ... | @@ -297,7 +297,7 @@ test "sha1 streaming" { | ... | @@ -297,7 +297,7 @@ test "sha1 streaming" { |
| 297 | } | 297 | } |
| 298 | 298 | ||
| 299 | test "sha1 aligned final" { | 299 | test "sha1 aligned final" { |
| 300 | var block = [_]u8{0} ** Sha1.block_length; | 300 | var block: [Sha1.block_length]u8 = @splat(0); |
| 301 | var out: [Sha1.digest_length]u8 = undefined; | 301 | var out: [Sha1.digest_length]u8 = undefined; |
| 302 | 302 | ||
| 303 | var h = Sha1.init(.{}); | 303 | var h = Sha1.init(.{}); |
lib/std/crypto/aegis.zig+45-39| ... | @@ -55,6 +55,14 @@ pub const Aegis256X2_256 = Aegis256XGeneric(2, 256); | ... | @@ -55,6 +55,14 @@ pub const Aegis256X2_256 = Aegis256XGeneric(2, 256); |
| 55 | /// AEGIS-256 with a 256 bit tag | 55 | /// AEGIS-256 with a 256 bit tag |
| 56 | pub const Aegis256_256 = Aegis256XGeneric(1, 256); | 56 | pub const Aegis256_256 = Aegis256XGeneric(1, 256); |
| 57 | 57 | ||
| 58 | /// `inline` to avoid needless binary bloat from generic instantiations since the arguments are | ||
| 59 | /// usually comptime-known and the function is a trivial leaf function. | ||
| 60 | inline fn repeat16u8(comptime count: usize, part: [16]u8) [16 * count]u8 { | ||
| 61 | const buf: [count][part.len]u8 = @splat(part); | ||
| 62 | const ptr: *const [16 * count]u8 = @ptrCast(&buf); | ||
| 63 | return ptr.*; | ||
| 64 | } | ||
| 65 | |||
| 58 | fn State128X(comptime degree: u7) type { | 66 | fn State128X(comptime degree: u7) type { |
| 59 | return struct { | 67 | return struct { |
| 60 | const AesBlockVec = crypto.core.aes.BlockVec(degree); | 68 | const AesBlockVec = crypto.core.aes.BlockVec(degree); |
| ... | @@ -67,10 +75,10 @@ fn State128X(comptime degree: u7) type { | ... | @@ -67,10 +75,10 @@ fn State128X(comptime degree: u7) type { |
| 67 | const alignment = AesBlockVec.native_word_size; | 75 | const alignment = AesBlockVec.native_word_size; |
| 68 | 76 | ||
| 69 | fn init(key: [16]u8, nonce: [16]u8) State { | 77 | fn init(key: [16]u8, nonce: [16]u8) State { |
| 70 | const c1 = AesBlockVec.fromBytes(&[16]u8{ 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1, 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd } ** degree); | 78 | const c1 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1, 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd })); |
| 71 | const c2 = AesBlockVec.fromBytes(&[16]u8{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 } ** degree); | 79 | const c2 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 })); |
| 72 | const key_block = AesBlockVec.fromBytes(&(key ** degree)); | 80 | const key_block = AesBlockVec.fromBytes(&repeat16u8(degree, key)); |
| 73 | const nonce_block = AesBlockVec.fromBytes(&(nonce ** degree)); | 81 | const nonce_block = AesBlockVec.fromBytes(&repeat16u8(degree, nonce)); |
| 74 | const blocks = [8]AesBlockVec{ | 82 | const blocks = [8]AesBlockVec{ |
| 75 | key_block.xorBlocks(nonce_block), | 83 | key_block.xorBlocks(nonce_block), |
| 76 | c1, | 84 | c1, |
| ... | @@ -84,7 +92,7 @@ fn State128X(comptime degree: u7) type { | ... | @@ -84,7 +92,7 @@ fn State128X(comptime degree: u7) type { |
| 84 | var state = State{ .blocks = blocks }; | 92 | var state = State{ .blocks = blocks }; |
| 85 | if (degree > 1) { | 93 | if (degree > 1) { |
| 86 | const context_block = ctx: { | 94 | const context_block = ctx: { |
| 87 | var contexts_bytes = [_]u8{0} ** aes_block_length; | 95 | var contexts_bytes: [aes_block_length]u8 = @splat(0); |
| 88 | for (0..degree) |i| { | 96 | for (0..degree) |i| { |
| 89 | contexts_bytes[i * 16] = @intCast(i); | 97 | contexts_bytes[i * 16] = @intCast(i); |
| 90 | contexts_bytes[i * 16 + 1] = @intCast(degree - 1); | 98 | contexts_bytes[i * 16 + 1] = @intCast(degree - 1); |
| ... | @@ -150,7 +158,7 @@ fn State128X(comptime degree: u7) type { | ... | @@ -150,7 +158,7 @@ fn State128X(comptime degree: u7) type { |
| 150 | const blocks = &state.blocks; | 158 | const blocks = &state.blocks; |
| 151 | const z0 = blocks[6].xorBlocks(blocks[1]).xorBlocks(blocks[2].andBlocks(blocks[3])); | 159 | const z0 = blocks[6].xorBlocks(blocks[1]).xorBlocks(blocks[2].andBlocks(blocks[3])); |
| 152 | const z1 = blocks[2].xorBlocks(blocks[5]).xorBlocks(blocks[6].andBlocks(blocks[7])); | 160 | const z1 = blocks[2].xorBlocks(blocks[5]).xorBlocks(blocks[6].andBlocks(blocks[7])); |
| 153 | var pad = [_]u8{0} ** rate; | 161 | var pad: [rate]u8 = @splat(0); |
| 154 | pad[0..aes_block_length].* = z0.toBytes(); | 162 | pad[0..aes_block_length].* = z0.toBytes(); |
| 155 | pad[aes_block_length..].* = z1.toBytes(); | 163 | pad[aes_block_length..].* = z1.toBytes(); |
| 156 | for (pad[0..src.len], src) |*p, x| p.* ^= x; | 164 | for (pad[0..src.len], src) |*p, x| p.* ^= x; |
| ... | @@ -214,7 +222,7 @@ fn State128X(comptime degree: u7) type { | ... | @@ -214,7 +222,7 @@ fn State128X(comptime degree: u7) type { |
| 214 | state.update(t, t); | 222 | state.update(t, t); |
| 215 | } | 223 | } |
| 216 | if (degree > 1) { | 224 | if (degree > 1) { |
| 217 | var v = [_]u8{0} ** rate; | 225 | var v: [rate]u8 = @splat(0); |
| 218 | switch (tag_bits) { | 226 | switch (tag_bits) { |
| 219 | 128 => { | 227 | 128 => { |
| 220 | const tags = blocks[0].xorBlocks(blocks[1]).xorBlocks(blocks[2]).xorBlocks(blocks[3]).xorBlocks(blocks[4]).xorBlocks(blocks[5]).xorBlocks(blocks[6]).toBytes(); | 228 | const tags = blocks[0].xorBlocks(blocks[1]).xorBlocks(blocks[2]).xorBlocks(blocks[3]).xorBlocks(blocks[4]).xorBlocks(blocks[5]).xorBlocks(blocks[6]).toBytes(); |
| ... | @@ -362,12 +370,12 @@ fn State256X(comptime degree: u7) type { | ... | @@ -362,12 +370,12 @@ fn State256X(comptime degree: u7) type { |
| 362 | const alignment = AesBlockVec.native_word_size; | 370 | const alignment = AesBlockVec.native_word_size; |
| 363 | 371 | ||
| 364 | fn init(key: [32]u8, nonce: [32]u8) State { | 372 | fn init(key: [32]u8, nonce: [32]u8) State { |
| 365 | const c1 = AesBlockVec.fromBytes(&[16]u8{ 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1, 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd } ** degree); | 373 | const c1 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1, 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd })); |
| 366 | const c2 = AesBlockVec.fromBytes(&[16]u8{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 } ** degree); | 374 | const c2 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 })); |
| 367 | const key_block1 = AesBlockVec.fromBytes(key[0..16] ** degree); | 375 | const key_block1 = AesBlockVec.fromBytes(&repeat16u8(degree, key[0..16].*)); |
| 368 | const key_block2 = AesBlockVec.fromBytes(key[16..32] ** degree); | 376 | const key_block2 = AesBlockVec.fromBytes(&repeat16u8(degree, key[16..32].*)); |
| 369 | const nonce_block1 = AesBlockVec.fromBytes(nonce[0..16] ** degree); | 377 | const nonce_block1 = AesBlockVec.fromBytes(&repeat16u8(degree, nonce[0..16].*)); |
| 370 | const nonce_block2 = AesBlockVec.fromBytes(nonce[16..32] ** degree); | 378 | const nonce_block2 = AesBlockVec.fromBytes(&repeat16u8(degree, nonce[16..32].*)); |
| 371 | const kxn1 = key_block1.xorBlocks(nonce_block1); | 379 | const kxn1 = key_block1.xorBlocks(nonce_block1); |
| 372 | const kxn2 = key_block2.xorBlocks(nonce_block2); | 380 | const kxn2 = key_block2.xorBlocks(nonce_block2); |
| 373 | const blocks = [6]AesBlockVec{ | 381 | const blocks = [6]AesBlockVec{ |
| ... | @@ -381,7 +389,7 @@ fn State256X(comptime degree: u7) type { | ... | @@ -381,7 +389,7 @@ fn State256X(comptime degree: u7) type { |
| 381 | var state = State{ .blocks = blocks }; | 389 | var state = State{ .blocks = blocks }; |
| 382 | if (degree > 1) { | 390 | if (degree > 1) { |
| 383 | const context_block = ctx: { | 391 | const context_block = ctx: { |
| 384 | var contexts_bytes = [_]u8{0} ** aes_block_length; | 392 | var contexts_bytes: [aes_block_length]u8 = @splat(0); |
| 385 | for (0..degree) |i| { | 393 | for (0..degree) |i| { |
| 386 | contexts_bytes[i * 16] = @intCast(i); | 394 | contexts_bytes[i * 16] = @intCast(i); |
| 387 | contexts_bytes[i * 16 + 1] = @intCast(degree - 1); | 395 | contexts_bytes[i * 16 + 1] = @intCast(degree - 1); |
| ... | @@ -509,7 +517,7 @@ fn State256X(comptime degree: u7) type { | ... | @@ -509,7 +517,7 @@ fn State256X(comptime degree: u7) type { |
| 509 | state.update(t); | 517 | state.update(t); |
| 510 | } | 518 | } |
| 511 | if (degree > 1) { | 519 | if (degree > 1) { |
| 512 | var v = [_]u8{0} ** rate; | 520 | var v: [rate]u8 = @splat(0); |
| 513 | switch (tag_bits) { | 521 | switch (tag_bits) { |
| 514 | 128 => { | 522 | 128 => { |
| 515 | const tags = blocks[0].xorBlocks(blocks[1]).xorBlocks(blocks[2]).xorBlocks(blocks[3]).xorBlocks(blocks[4]).xorBlocks(blocks[5]).toBytes(); | 523 | const tags = blocks[0].xorBlocks(blocks[1]).xorBlocks(blocks[2]).xorBlocks(blocks[3]).xorBlocks(blocks[4]).xorBlocks(blocks[5]).toBytes(); |
| ... | @@ -746,9 +754,7 @@ fn AegisMac(comptime T: type) type { | ... | @@ -746,9 +754,7 @@ fn AegisMac(comptime T: type) type { |
| 746 | 754 | ||
| 747 | /// Initialize a state for the MAC function, with a default nonce | 755 | /// Initialize a state for the MAC function, with a default nonce |
| 748 | pub fn init(key: *const [key_length]u8) Mac { | 756 | pub fn init(key: *const [key_length]u8) Mac { |
| 749 | return Mac{ | 757 | return .{ .state = .init(key.*, @splat(0)) }; |
| 750 | .state = T.State.init(key.*, [_]u8{0} ** nonce_length), | ||
| 751 | }; | ||
| 752 | } | 758 | } |
| 753 | 759 | ||
| 754 | /// Add data to the state | 760 | /// Add data to the state |
| ... | @@ -781,7 +787,7 @@ fn AegisMac(comptime T: type) type { | ... | @@ -781,7 +787,7 @@ fn AegisMac(comptime T: type) type { |
| 781 | /// Return an authentication tag for the current state | 787 | /// Return an authentication tag for the current state |
| 782 | pub fn final(self: *Mac, out: *[mac_length]u8) void { | 788 | pub fn final(self: *Mac, out: *[mac_length]u8) void { |
| 783 | if (self.off > 0) { | 789 | if (self.off > 0) { |
| 784 | var pad = [_]u8{0} ** block_length; | 790 | var pad: [block_length]u8 = @splat(0); |
| 785 | @memcpy(pad[0..self.off], self.buf[0..self.off]); | 791 | @memcpy(pad[0..self.off], self.buf[0..self.off]); |
| 786 | self.state.absorb(&pad); | 792 | self.state.absorb(&pad); |
| 787 | } | 793 | } |
| ... | @@ -808,8 +814,8 @@ const htest = @import("test.zig"); | ... | @@ -808,8 +814,8 @@ const htest = @import("test.zig"); |
| 808 | const testing = std.testing; | 814 | const testing = std.testing; |
| 809 | 815 | ||
| 810 | test "Aegis128L test vector 1" { | 816 | test "Aegis128L test vector 1" { |
| 811 | const key: [Aegis128L.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** 14; | 817 | const key: [Aegis128L.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ @as([14]u8, @splat(0x00)); |
| 812 | const nonce: [Aegis128L.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** 13; | 818 | const nonce: [Aegis128L.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([13]u8, @splat(0x00)); |
| 813 | const ad = [8]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; | 819 | const ad = [8]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; |
| 814 | const m = [32]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; | 820 | const m = [32]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; |
| 815 | var c: [m.len]u8 = undefined; | 821 | var c: [m.len]u8 = undefined; |
| ... | @@ -831,10 +837,10 @@ test "Aegis128L test vector 1" { | ... | @@ -831,10 +837,10 @@ test "Aegis128L test vector 1" { |
| 831 | } | 837 | } |
| 832 | 838 | ||
| 833 | test "Aegis128L test vector 2" { | 839 | test "Aegis128L test vector 2" { |
| 834 | const key: [Aegis128L.key_length]u8 = [_]u8{0x00} ** 16; | 840 | const key: [Aegis128L.key_length]u8 = @splat(0x00); |
| 835 | const nonce: [Aegis128L.nonce_length]u8 = [_]u8{0x00} ** 16; | 841 | const nonce: [Aegis128L.nonce_length]u8 = @splat(0x00); |
| 836 | const ad = [_]u8{}; | 842 | const ad: [0]u8 = .{}; |
| 837 | const m = [_]u8{0x00} ** 16; | 843 | const m: [16]u8 = @splat(0x00); |
| 838 | var c: [m.len]u8 = undefined; | 844 | var c: [m.len]u8 = undefined; |
| 839 | var m2: [m.len]u8 = undefined; | 845 | var m2: [m.len]u8 = undefined; |
| 840 | var tag: [Aegis128L.tag_length]u8 = undefined; | 846 | var tag: [Aegis128L.tag_length]u8 = undefined; |
| ... | @@ -848,8 +854,8 @@ test "Aegis128L test vector 2" { | ... | @@ -848,8 +854,8 @@ test "Aegis128L test vector 2" { |
| 848 | } | 854 | } |
| 849 | 855 | ||
| 850 | test "Aegis128L test vector 3" { | 856 | test "Aegis128L test vector 3" { |
| 851 | const key: [Aegis128L.key_length]u8 = [_]u8{0x00} ** 16; | 857 | const key: [Aegis128L.key_length]u8 = @splat(0x00); |
| 852 | const nonce: [Aegis128L.nonce_length]u8 = [_]u8{0x00} ** 16; | 858 | const nonce: [Aegis128L.nonce_length]u8 = @splat(0x00); |
| 853 | const ad = [_]u8{}; | 859 | const ad = [_]u8{}; |
| 854 | const m = [_]u8{}; | 860 | const m = [_]u8{}; |
| 855 | var c: [m.len]u8 = undefined; | 861 | var c: [m.len]u8 = undefined; |
| ... | @@ -881,8 +887,8 @@ test "Aegis128X2 test vector 1" { | ... | @@ -881,8 +887,8 @@ test "Aegis128X2 test vector 1" { |
| 881 | } | 887 | } |
| 882 | 888 | ||
| 883 | test "Aegis256 test vector 1" { | 889 | test "Aegis256 test vector 1" { |
| 884 | const key: [Aegis256.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** 30; | 890 | const key: [Aegis256.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ @as([30]u8, @splat(0x00)); |
| 885 | const nonce: [Aegis256.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** 29; | 891 | const nonce: [Aegis256.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([29]u8, @splat(0x00)); |
| 886 | const ad = [8]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; | 892 | const ad = [8]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; |
| 887 | const m = [32]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; | 893 | const m = [32]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; |
| 888 | var c: [m.len]u8 = undefined; | 894 | var c: [m.len]u8 = undefined; |
| ... | @@ -904,10 +910,10 @@ test "Aegis256 test vector 1" { | ... | @@ -904,10 +910,10 @@ test "Aegis256 test vector 1" { |
| 904 | } | 910 | } |
| 905 | 911 | ||
| 906 | test "Aegis256 test vector 2" { | 912 | test "Aegis256 test vector 2" { |
| 907 | const key: [Aegis256.key_length]u8 = [_]u8{0x00} ** 32; | 913 | const key: [Aegis256.key_length]u8 = @splat(0x00); |
| 908 | const nonce: [Aegis256.nonce_length]u8 = [_]u8{0x00} ** 32; | 914 | const nonce: [Aegis256.nonce_length]u8 = @splat(0x00); |
| 909 | const ad = [_]u8{}; | 915 | const ad = [_]u8{}; |
| 910 | const m = [_]u8{0x00} ** 16; | 916 | const m: [16]u8 = @splat(0x00); |
| 911 | var c: [m.len]u8 = undefined; | 917 | var c: [m.len]u8 = undefined; |
| 912 | var m2: [m.len]u8 = undefined; | 918 | var m2: [m.len]u8 = undefined; |
| 913 | var tag: [Aegis256.tag_length]u8 = undefined; | 919 | var tag: [Aegis256.tag_length]u8 = undefined; |
| ... | @@ -921,8 +927,8 @@ test "Aegis256 test vector 2" { | ... | @@ -921,8 +927,8 @@ test "Aegis256 test vector 2" { |
| 921 | } | 927 | } |
| 922 | 928 | ||
| 923 | test "Aegis256 test vector 3" { | 929 | test "Aegis256 test vector 3" { |
| 924 | const key: [Aegis256.key_length]u8 = [_]u8{0x00} ** 32; | 930 | const key: [Aegis256.key_length]u8 = @splat(0x00); |
| 925 | const nonce: [Aegis256.nonce_length]u8 = [_]u8{0x00} ** 32; | 931 | const nonce: [Aegis256.nonce_length]u8 = @splat(0x00); |
| 926 | const ad = [_]u8{}; | 932 | const ad = [_]u8{}; |
| 927 | const m = [_]u8{}; | 933 | const m = [_]u8{}; |
| 928 | var c: [m.len]u8 = undefined; | 934 | var c: [m.len]u8 = undefined; |
| ... | @@ -954,7 +960,7 @@ test "Aegis256X4 test vector 1" { | ... | @@ -954,7 +960,7 @@ test "Aegis256X4 test vector 1" { |
| 954 | } | 960 | } |
| 955 | 961 | ||
| 956 | test "Aegis MAC" { | 962 | test "Aegis MAC" { |
| 957 | const key = [_]u8{0x00} ** Aegis128LMac.key_length; | 963 | const key: [Aegis128LMac.key_length]u8 = @splat(0x00); |
| 958 | var msg: [64]u8 = undefined; | 964 | var msg: [64]u8 = undefined; |
| 959 | for (&msg, 0..) |*m, i| { | 965 | for (&msg, 0..) |*m, i| { |
| 960 | m.* = @as(u8, @truncate(i)); | 966 | m.* = @as(u8, @truncate(i)); |
| ... | @@ -989,8 +995,8 @@ test "Aegis MAC" { | ... | @@ -989,8 +995,8 @@ test "Aegis MAC" { |
| 989 | } | 995 | } |
| 990 | 996 | ||
| 991 | test "AEGISMAC-128* test vectors" { | 997 | test "AEGISMAC-128* test vectors" { |
| 992 | const key = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** (16 - 2); | 998 | const key = [_]u8{ 0x10, 0x01 } ++ @as([16 - 2]u8, @splat(0x00)); |
| 993 | const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** (16 - 3); | 999 | const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([16 - 3]u8, @splat(0x00)); |
| 994 | var msg: [35]u8 = undefined; | 1000 | var msg: [35]u8 = undefined; |
| 995 | for (&msg, 0..) |*byte, i| byte.* = @truncate(i); | 1001 | for (&msg, 0..) |*byte, i| byte.* = @truncate(i); |
| 996 | var mac128: [16]u8 = undefined; | 1002 | var mac128: [16]u8 = undefined; |
| ... | @@ -1013,8 +1019,8 @@ test "AEGISMAC-128* test vectors" { | ... | @@ -1013,8 +1019,8 @@ test "AEGISMAC-128* test vectors" { |
| 1013 | } | 1019 | } |
| 1014 | 1020 | ||
| 1015 | test "AEGISMAC-256* test vectors" { | 1021 | test "AEGISMAC-256* test vectors" { |
| 1016 | const key = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** (32 - 2); | 1022 | const key = [_]u8{ 0x10, 0x01 } ++ @as([32 - 2]u8, @splat(0x00)); |
| 1017 | const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** (32 - 3); | 1023 | const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([32 - 3]u8, @splat(0x00)); |
| 1018 | var msg: [35]u8 = undefined; | 1024 | var msg: [35]u8 = undefined; |
| 1019 | for (&msg, 0..) |*byte, i| byte.* = @truncate(i); | 1025 | for (&msg, 0..) |*byte, i| byte.* = @truncate(i); |
| 1020 | var mac128: [16]u8 = undefined; | 1026 | var mac128: [16]u8 = undefined; |
lib/std/crypto/aes_ccm.zig+20-20| ... | @@ -201,7 +201,7 @@ fn AesCcm(comptime BlockCipher: type, comptime tag_len: usize, comptime nonce_le | ... | @@ -201,7 +201,7 @@ fn AesCcm(comptime BlockCipher: type, comptime tag_len: usize, comptime nonce_le |
| 201 | const total_ad_size = ad_len_size + ad.len; | 201 | const total_ad_size = ad_len_size + ad.len; |
| 202 | const remainder = total_ad_size % block_length; | 202 | const remainder = total_ad_size % block_length; |
| 203 | if (remainder > 0) { | 203 | if (remainder > 0) { |
| 204 | const padding = [_]u8{0} ** block_length; | 204 | const padding: [block_length]u8 = @splat(0); |
| 205 | ctx.update(padding[0 .. block_length - remainder]); | 205 | ctx.update(padding[0 .. block_length - remainder]); |
| 206 | } | 206 | } |
| 207 | } | 207 | } |
| ... | @@ -264,8 +264,8 @@ const fmt = std.fmt; | ... | @@ -264,8 +264,8 @@ const fmt = std.fmt; |
| 264 | const hexToBytes = fmt.hexToBytes; | 264 | const hexToBytes = fmt.hexToBytes; |
| 265 | 265 | ||
| 266 | test "Aes256Ccm8 - Encrypt decrypt round-trip" { | 266 | test "Aes256Ccm8 - Encrypt decrypt round-trip" { |
| 267 | const key: [32]u8 = [_]u8{0x42} ** 32; | 267 | const key: [32]u8 = @splat(0x42); |
| 268 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 268 | const nonce: [13]u8 = @splat(0x11); |
| 269 | const m = "Hello, World! This is a test message."; | 269 | const m = "Hello, World! This is a test message."; |
| 270 | var c: [m.len]u8 = undefined; | 270 | var c: [m.len]u8 = undefined; |
| 271 | var m2: [m.len]u8 = undefined; | 271 | var m2: [m.len]u8 = undefined; |
| ... | @@ -279,8 +279,8 @@ test "Aes256Ccm8 - Encrypt decrypt round-trip" { | ... | @@ -279,8 +279,8 @@ test "Aes256Ccm8 - Encrypt decrypt round-trip" { |
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | test "Aes256Ccm8 - Associated data" { | 281 | test "Aes256Ccm8 - Associated data" { |
| 282 | const key: [32]u8 = [_]u8{0x42} ** 32; | 282 | const key: [32]u8 = @splat(0x42); |
| 283 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 283 | const nonce: [13]u8 = @splat(0x11); |
| 284 | const m = "secret message"; | 284 | const m = "secret message"; |
| 285 | const ad = "additional authenticated data"; | 285 | const ad = "additional authenticated data"; |
| 286 | var c: [m.len]u8 = undefined; | 286 | var c: [m.len]u8 = undefined; |
| ... | @@ -299,9 +299,9 @@ test "Aes256Ccm8 - Associated data" { | ... | @@ -299,9 +299,9 @@ test "Aes256Ccm8 - Associated data" { |
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | test "Aes256Ccm8 - Wrong key" { | 301 | test "Aes256Ccm8 - Wrong key" { |
| 302 | const key: [32]u8 = [_]u8{0x42} ** 32; | 302 | const key: [32]u8 = @splat(0x42); |
| 303 | const wrong_key: [32]u8 = [_]u8{0x43} ** 32; | 303 | const wrong_key: [32]u8 = @splat(0x43); |
| 304 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 304 | const nonce: [13]u8 = @splat(0x11); |
| 305 | const m = "secret"; | 305 | const m = "secret"; |
| 306 | var c: [m.len]u8 = undefined; | 306 | var c: [m.len]u8 = undefined; |
| 307 | var m2: [m.len]u8 = undefined; | 307 | var m2: [m.len]u8 = undefined; |
| ... | @@ -314,8 +314,8 @@ test "Aes256Ccm8 - Wrong key" { | ... | @@ -314,8 +314,8 @@ test "Aes256Ccm8 - Wrong key" { |
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | test "Aes256Ccm8 - Corrupted ciphertext" { | 316 | test "Aes256Ccm8 - Corrupted ciphertext" { |
| 317 | const key: [32]u8 = [_]u8{0x42} ** 32; | 317 | const key: [32]u8 = @splat(0x42); |
| 318 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 318 | const nonce: [13]u8 = @splat(0x11); |
| 319 | const m = "secret message"; | 319 | const m = "secret message"; |
| 320 | var c: [m.len]u8 = undefined; | 320 | var c: [m.len]u8 = undefined; |
| 321 | var m2: [m.len]u8 = undefined; | 321 | var m2: [m.len]u8 = undefined; |
| ... | @@ -330,8 +330,8 @@ test "Aes256Ccm8 - Corrupted ciphertext" { | ... | @@ -330,8 +330,8 @@ test "Aes256Ccm8 - Corrupted ciphertext" { |
| 330 | } | 330 | } |
| 331 | 331 | ||
| 332 | test "Aes256Ccm8 - Empty plaintext" { | 332 | test "Aes256Ccm8 - Empty plaintext" { |
| 333 | const key: [32]u8 = [_]u8{0x42} ** 32; | 333 | const key: [32]u8 = @splat(0x42); |
| 334 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 334 | const nonce: [13]u8 = @splat(0x11); |
| 335 | const m = ""; | 335 | const m = ""; |
| 336 | var c: [m.len]u8 = undefined; | 336 | var c: [m.len]u8 = undefined; |
| 337 | var m2: [m.len]u8 = undefined; | 337 | var m2: [m.len]u8 = undefined; |
| ... | @@ -345,8 +345,8 @@ test "Aes256Ccm8 - Empty plaintext" { | ... | @@ -345,8 +345,8 @@ test "Aes256Ccm8 - Empty plaintext" { |
| 345 | } | 345 | } |
| 346 | 346 | ||
| 347 | test "Aes128Ccm8 - Basic functionality" { | 347 | test "Aes128Ccm8 - Basic functionality" { |
| 348 | const key: [16]u8 = [_]u8{0x42} ** 16; | 348 | const key: [16]u8 = @splat(0x42); |
| 349 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 349 | const nonce: [13]u8 = @splat(0x11); |
| 350 | const m = "Test AES-128-CCM"; | 350 | const m = "Test AES-128-CCM"; |
| 351 | var c: [m.len]u8 = undefined; | 351 | var c: [m.len]u8 = undefined; |
| 352 | var m2: [m.len]u8 = undefined; | 352 | var m2: [m.len]u8 = undefined; |
| ... | @@ -360,8 +360,8 @@ test "Aes128Ccm8 - Basic functionality" { | ... | @@ -360,8 +360,8 @@ test "Aes128Ccm8 - Basic functionality" { |
| 360 | } | 360 | } |
| 361 | 361 | ||
| 362 | test "Aes256Ccm16 - 16-byte tag" { | 362 | test "Aes256Ccm16 - 16-byte tag" { |
| 363 | const key: [32]u8 = [_]u8{0x42} ** 32; | 363 | const key: [32]u8 = @splat(0x42); |
| 364 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 364 | const nonce: [13]u8 = @splat(0x11); |
| 365 | const m = "Test 16-byte tag"; | 365 | const m = "Test 16-byte tag"; |
| 366 | var c: [m.len]u8 = undefined; | 366 | var c: [m.len]u8 = undefined; |
| 367 | var m2: [m.len]u8 = undefined; | 367 | var m2: [m.len]u8 = undefined; |
| ... | @@ -845,8 +845,8 @@ test "Aes128Ccm0 - IEEE 802.15.4 Data Frame (Encryption-only)" { | ... | @@ -845,8 +845,8 @@ test "Aes128Ccm0 - IEEE 802.15.4 Data Frame (Encryption-only)" { |
| 845 | } | 845 | } |
| 846 | 846 | ||
| 847 | test "Aes128Ccm0 - Zero-length plaintext with encryption-only" { | 847 | test "Aes128Ccm0 - Zero-length plaintext with encryption-only" { |
| 848 | const key: [16]u8 = [_]u8{0x42} ** 16; | 848 | const key: [16]u8 = @splat(0x42); |
| 849 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 849 | const nonce: [13]u8 = @splat(0x11); |
| 850 | const m = ""; | 850 | const m = ""; |
| 851 | const ad = "some associated data"; | 851 | const ad = "some associated data"; |
| 852 | var c: [m.len]u8 = undefined; | 852 | var c: [m.len]u8 = undefined; |
| ... | @@ -861,8 +861,8 @@ test "Aes128Ccm0 - Zero-length plaintext with encryption-only" { | ... | @@ -861,8 +861,8 @@ test "Aes128Ccm0 - Zero-length plaintext with encryption-only" { |
| 861 | } | 861 | } |
| 862 | 862 | ||
| 863 | test "Aes256Ccm0 - Basic encryption-only round-trip" { | 863 | test "Aes256Ccm0 - Basic encryption-only round-trip" { |
| 864 | const key: [32]u8 = [_]u8{0x42} ** 32; | 864 | const key: [32]u8 = @splat(0x42); |
| 865 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 865 | const nonce: [13]u8 = @splat(0x11); |
| 866 | const m = "Hello, CCM* encryption-only mode!"; | 866 | const m = "Hello, CCM* encryption-only mode!"; |
| 867 | var c: [m.len]u8 = undefined; | 867 | var c: [m.len]u8 = undefined; |
| 868 | var m2: [m.len]u8 = undefined; | 868 | var m2: [m.len]u8 = undefined; |
lib/std/crypto/aes_gcm.zig+10-12| ... | @@ -19,8 +19,6 @@ fn AesGcm(comptime Aes: anytype) type { | ... | @@ -19,8 +19,6 @@ fn AesGcm(comptime Aes: anytype) type { |
| 19 | pub const nonce_length = 12; | 19 | pub const nonce_length = 12; |
| 20 | pub const key_length = Aes.key_bits / 8; | 20 | pub const key_length = Aes.key_bits / 8; |
| 21 | 21 | ||
| 22 | const zeros = [_]u8{0} ** 16; | ||
| 23 | |||
| 24 | /// `c`: The ciphertext buffer to write the encrypted data to. | 22 | /// `c`: The ciphertext buffer to write the encrypted data to. |
| 25 | /// `tag`: The authentication tag buffer to write the computed tag to. | 23 | /// `tag`: The authentication tag buffer to write the computed tag to. |
| 26 | /// `m`: The plaintext message to encrypt. | 24 | /// `m`: The plaintext message to encrypt. |
| ... | @@ -33,7 +31,7 @@ fn AesGcm(comptime Aes: anytype) type { | ... | @@ -33,7 +31,7 @@ fn AesGcm(comptime Aes: anytype) type { |
| 33 | 31 | ||
| 34 | const aes = Aes.initEnc(key); | 32 | const aes = Aes.initEnc(key); |
| 35 | var h: [16]u8 = undefined; | 33 | var h: [16]u8 = undefined; |
| 36 | aes.encrypt(&h, &zeros); | 34 | aes.encrypt(&h, &@splat(0)); |
| 37 | 35 | ||
| 38 | var t: [16]u8 = undefined; | 36 | var t: [16]u8 = undefined; |
| 39 | var j: [16]u8 = undefined; | 37 | var j: [16]u8 = undefined; |
| ... | @@ -75,7 +73,7 @@ fn AesGcm(comptime Aes: anytype) type { | ... | @@ -75,7 +73,7 @@ fn AesGcm(comptime Aes: anytype) type { |
| 75 | 73 | ||
| 76 | const aes = Aes.initEnc(key); | 74 | const aes = Aes.initEnc(key); |
| 77 | var h: [16]u8 = undefined; | 75 | var h: [16]u8 = undefined; |
| 78 | aes.encrypt(&h, &zeros); | 76 | aes.encrypt(&h, &@splat(0)); |
| 79 | 77 | ||
| 80 | var t: [16]u8 = undefined; | 78 | var t: [16]u8 = undefined; |
| 81 | var j: [16]u8 = undefined; | 79 | var j: [16]u8 = undefined; |
| ... | @@ -118,8 +116,8 @@ const htest = @import("test.zig"); | ... | @@ -118,8 +116,8 @@ const htest = @import("test.zig"); |
| 118 | const testing = std.testing; | 116 | const testing = std.testing; |
| 119 | 117 | ||
| 120 | test "Aes256Gcm - Empty message and no associated data" { | 118 | test "Aes256Gcm - Empty message and no associated data" { |
| 121 | const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length; | 119 | const key: [Aes256Gcm.key_length]u8 = @splat(0x69); |
| 122 | const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length; | 120 | const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42); |
| 123 | const ad = ""; | 121 | const ad = ""; |
| 124 | const m = ""; | 122 | const m = ""; |
| 125 | var c: [m.len]u8 = undefined; | 123 | var c: [m.len]u8 = undefined; |
| ... | @@ -130,8 +128,8 @@ test "Aes256Gcm - Empty message and no associated data" { | ... | @@ -130,8 +128,8 @@ test "Aes256Gcm - Empty message and no associated data" { |
| 130 | } | 128 | } |
| 131 | 129 | ||
| 132 | test "Aes256Gcm - Associated data only" { | 130 | test "Aes256Gcm - Associated data only" { |
| 133 | const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length; | 131 | const key: [Aes256Gcm.key_length]u8 = @splat(0x69); |
| 134 | const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length; | 132 | const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42); |
| 135 | const m = ""; | 133 | const m = ""; |
| 136 | const ad = "Test with associated data"; | 134 | const ad = "Test with associated data"; |
| 137 | var c: [m.len]u8 = undefined; | 135 | var c: [m.len]u8 = undefined; |
| ... | @@ -142,8 +140,8 @@ test "Aes256Gcm - Associated data only" { | ... | @@ -142,8 +140,8 @@ test "Aes256Gcm - Associated data only" { |
| 142 | } | 140 | } |
| 143 | 141 | ||
| 144 | test "Aes256Gcm - Message only" { | 142 | test "Aes256Gcm - Message only" { |
| 145 | const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length; | 143 | const key: [Aes256Gcm.key_length]u8 = @splat(0x69); |
| 146 | const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length; | 144 | const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42); |
| 147 | const m = "Test with message only"; | 145 | const m = "Test with message only"; |
| 148 | const ad = ""; | 146 | const ad = ""; |
| 149 | var c: [m.len]u8 = undefined; | 147 | var c: [m.len]u8 = undefined; |
| ... | @@ -159,8 +157,8 @@ test "Aes256Gcm - Message only" { | ... | @@ -159,8 +157,8 @@ test "Aes256Gcm - Message only" { |
| 159 | } | 157 | } |
| 160 | 158 | ||
| 161 | test "Aes256Gcm - Message and associated data" { | 159 | test "Aes256Gcm - Message and associated data" { |
| 162 | const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length; | 160 | const key: [Aes256Gcm.key_length]u8 = @splat(0x69); |
| 163 | const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length; | 161 | const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42); |
| 164 | const m = "Test with message"; | 162 | const m = "Test with message"; |
| 165 | const ad = "Test with associated data"; | 163 | const ad = "Test with associated data"; |
| 166 | var c: [m.len]u8 = undefined; | 164 | var c: [m.len]u8 = undefined; |
lib/std/crypto/aes_ocb.zig+9-9| ... | @@ -48,7 +48,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -48,7 +48,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | fn init(aes_enc_ctx: EncryptCtx) Lx { | 50 | fn init(aes_enc_ctx: EncryptCtx) Lx { |
| 51 | const zeros = [_]u8{0} ** 16; | 51 | const zeros: [16]u8 = @splat(0); |
| 52 | var star: Block = undefined; | 52 | var star: Block = undefined; |
| 53 | aes_enc_ctx.encrypt(&star, &zeros); | 53 | aes_enc_ctx.encrypt(&star, &zeros); |
| 54 | const dol = double(star); | 54 | const dol = double(star); |
| ... | @@ -62,8 +62,8 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -62,8 +62,8 @@ fn AesOcb(comptime Aes: anytype) type { |
| 62 | const full_blocks: usize = a.len / 16; | 62 | const full_blocks: usize = a.len / 16; |
| 63 | const x_max = if (full_blocks > 0) math.log2_int(usize, full_blocks) else 0; | 63 | const x_max = if (full_blocks > 0) math.log2_int(usize, full_blocks) else 0; |
| 64 | const lt = lx.precomp(x_max); | 64 | const lt = lx.precomp(x_max); |
| 65 | var sum = [_]u8{0} ** 16; | 65 | var sum: [16]u8 = @splat(0); |
| 66 | var offset = [_]u8{0} ** 16; | 66 | var offset: [16]u8 = @splat(0); |
| 67 | var i: usize = 0; | 67 | var i: usize = 0; |
| 68 | while (i < full_blocks) : (i += 1) { | 68 | while (i < full_blocks) : (i += 1) { |
| 69 | xorWith(&offset, lt[@ctz(i + 1)]); | 69 | xorWith(&offset, lt[@ctz(i + 1)]); |
| ... | @@ -74,7 +74,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -74,7 +74,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 74 | const leftover = a.len % 16; | 74 | const leftover = a.len % 16; |
| 75 | if (leftover > 0) { | 75 | if (leftover > 0) { |
| 76 | xorWith(&offset, lx.star); | 76 | xorWith(&offset, lx.star); |
| 77 | var padded = [_]u8{0} ** 16; | 77 | var padded: [16]u8 = @splat(0); |
| 78 | @memcpy(padded[0..leftover], a[i * 16 ..][0..leftover]); | 78 | @memcpy(padded[0..leftover], a[i * 16 ..][0..leftover]); |
| 79 | padded[leftover] = 0x80; | 79 | padded[leftover] = 0x80; |
| 80 | var e = xorBlocks(offset, padded); | 80 | var e = xorBlocks(offset, padded); |
| ... | @@ -85,7 +85,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -85,7 +85,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | fn getOffset(aes_enc_ctx: EncryptCtx, npub: [nonce_length]u8) Block { | 87 | fn getOffset(aes_enc_ctx: EncryptCtx, npub: [nonce_length]u8) Block { |
| 88 | var nx = [_]u8{0} ** 16; | 88 | var nx: [16]u8 = @splat(0); |
| 89 | nx[0] = @as(u8, @intCast(@as(u7, @truncate(tag_length * 8)) << 1)); | 89 | nx[0] = @as(u8, @intCast(@as(u7, @truncate(tag_length * 8)) << 1)); |
| 90 | nx[16 - nonce_length - 1] = 1; | 90 | nx[16 - nonce_length - 1] = 1; |
| 91 | nx[nx.len - nonce_length ..].* = npub; | 91 | nx[nx.len - nonce_length ..].* = npub; |
| ... | @@ -121,7 +121,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -121,7 +121,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 121 | const lt = lx.precomp(x_max); | 121 | const lt = lx.precomp(x_max); |
| 122 | 122 | ||
| 123 | var offset = getOffset(aes_enc_ctx, npub); | 123 | var offset = getOffset(aes_enc_ctx, npub); |
| 124 | var sum = [_]u8{0} ** 16; | 124 | var sum: [16]u8 = @splat(0); |
| 125 | var i: usize = 0; | 125 | var i: usize = 0; |
| 126 | 126 | ||
| 127 | while (wb > 0 and i + wb <= full_blocks) : (i += wb) { | 127 | while (wb > 0 and i + wb <= full_blocks) : (i += wb) { |
| ... | @@ -155,7 +155,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -155,7 +155,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 155 | xorWith(&offset, lx.star); | 155 | xorWith(&offset, lx.star); |
| 156 | var pad = offset; | 156 | var pad = offset; |
| 157 | aes_enc_ctx.encrypt(&pad, &pad); | 157 | aes_enc_ctx.encrypt(&pad, &pad); |
| 158 | var e = [_]u8{0} ** 16; | 158 | var e: [16]u8 = @splat(0); |
| 159 | @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]); | 159 | @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]); |
| 160 | e[leftover] = 0x80; | 160 | e[leftover] = 0x80; |
| 161 | for (m[i * 16 ..], 0..) |x, j| { | 161 | for (m[i * 16 ..], 0..) |x, j| { |
| ... | @@ -188,7 +188,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -188,7 +188,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 188 | const lt = lx.precomp(x_max); | 188 | const lt = lx.precomp(x_max); |
| 189 | 189 | ||
| 190 | var offset = getOffset(aes_enc_ctx, npub); | 190 | var offset = getOffset(aes_enc_ctx, npub); |
| 191 | var sum = [_]u8{0} ** 16; | 191 | var sum: [16]u8 = @splat(0); |
| 192 | var i: usize = 0; | 192 | var i: usize = 0; |
| 193 | 193 | ||
| 194 | while (wb > 0 and i + wb <= full_blocks) : (i += wb) { | 194 | while (wb > 0 and i + wb <= full_blocks) : (i += wb) { |
| ... | @@ -226,7 +226,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -226,7 +226,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 226 | for (c[i * 16 ..], 0..) |x, j| { | 226 | for (c[i * 16 ..], 0..) |x, j| { |
| 227 | m[i * 16 + j] = pad[j] ^ x; | 227 | m[i * 16 + j] = pad[j] ^ x; |
| 228 | } | 228 | } |
| 229 | var e = [_]u8{0} ** 16; | 229 | var e: [16]u8 = @splat(0); |
| 230 | @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]); | 230 | @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]); |
| 231 | e[leftover] = 0x80; | 231 | e[leftover] = 0x80; |
| 232 | xorWith(&sum, e); | 232 | xorWith(&sum, e); |
lib/std/crypto/argon2.zig+15-15| ... | @@ -281,9 +281,9 @@ fn processSegment( | ... | @@ -281,9 +281,9 @@ fn processSegment( |
| 281 | slice: u32, | 281 | slice: u32, |
| 282 | lane: u24, | 282 | lane: u24, |
| 283 | ) void { | 283 | ) void { |
| 284 | var addresses align(16) = [_]u64{0} ** block_length; | 284 | var addresses: [block_length]u64 align(16) = @splat(0); |
| 285 | var in align(16) = [_]u64{0} ** block_length; | 285 | var in: [block_length]u64 align(16) = @splat(0); |
| 286 | const zero align(16) = [_]u64{0} ** block_length; | 286 | const zero: [block_length]u64 align(16) = @splat(0); |
| 287 | if (mode == .argon2i or (mode == .argon2id and n == 0 and slice < sync_points / 2)) { | 287 | if (mode == .argon2i or (mode == .argon2id and n == 0 and slice < sync_points / 2)) { |
| 288 | in[0] = n; | 288 | in[0] = n; |
| 289 | in[1] = lane; | 289 | in[1] = lane; |
| ... | @@ -629,10 +629,10 @@ pub fn strVerify( | ... | @@ -629,10 +629,10 @@ pub fn strVerify( |
| 629 | test "argon2d" { | 629 | test "argon2d" { |
| 630 | if (true) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/30074 | 630 | if (true) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/30074 |
| 631 | 631 | ||
| 632 | const password = [_]u8{0x01} ** 32; | 632 | const password: [32]u8 = @splat(0x01); |
| 633 | const salt = [_]u8{0x02} ** 16; | 633 | const salt: [16]u8 = @splat(0x02); |
| 634 | const secret = [_]u8{0x03} ** 8; | 634 | const secret: [8]u8 = @splat(0x03); |
| 635 | const ad = [_]u8{0x04} ** 12; | 635 | const ad: [12]u8 = @splat(0x04); |
| 636 | 636 | ||
| 637 | var dk: [32]u8 = undefined; | 637 | var dk: [32]u8 = undefined; |
| 638 | try kdf( | 638 | try kdf( |
| ... | @@ -655,10 +655,10 @@ test "argon2d" { | ... | @@ -655,10 +655,10 @@ test "argon2d" { |
| 655 | } | 655 | } |
| 656 | 656 | ||
| 657 | test "argon2i" { | 657 | test "argon2i" { |
| 658 | const password = [_]u8{0x01} ** 32; | 658 | const password: [32]u8 = @splat(0x01); |
| 659 | const salt = [_]u8{0x02} ** 16; | 659 | const salt: [16]u8 = @splat(0x02); |
| 660 | const secret = [_]u8{0x03} ** 8; | 660 | const secret: [8]u8 = @splat(0x03); |
| 661 | const ad = [_]u8{0x04} ** 12; | 661 | const ad: [12]u8 = @splat(0x04); |
| 662 | 662 | ||
| 663 | var dk: [32]u8 = undefined; | 663 | var dk: [32]u8 = undefined; |
| 664 | try kdf( | 664 | try kdf( |
| ... | @@ -681,10 +681,10 @@ test "argon2i" { | ... | @@ -681,10 +681,10 @@ test "argon2i" { |
| 681 | } | 681 | } |
| 682 | 682 | ||
| 683 | test "argon2id" { | 683 | test "argon2id" { |
| 684 | const password = [_]u8{0x01} ** 32; | 684 | const password: [32]u8 = @splat(0x01); |
| 685 | const salt = [_]u8{0x02} ** 16; | 685 | const salt: [16]u8 = @splat(0x02); |
| 686 | const secret = [_]u8{0x03} ** 8; | 686 | const secret: [8]u8 = @splat(0x03); |
| 687 | const ad = [_]u8{0x04} ** 12; | 687 | const ad: [12]u8 = @splat(0x04); |
| 688 | 688 | ||
| 689 | var dk: [32]u8 = undefined; | 689 | var dk: [32]u8 = undefined; |
| 690 | try kdf( | 690 | try kdf( |
lib/std/crypto/bcrypt.zig+20-10| ... | @@ -868,20 +868,25 @@ test "bcrypt crypt format" { | ... | @@ -868,20 +868,25 @@ test "bcrypt crypt format" { |
| 868 | strVerify(s, "invalid password", verify_options), | 868 | strVerify(s, "invalid password", verify_options), |
| 869 | ); | 869 | ); |
| 870 | 870 | ||
| 871 | const password_100: []const u8 = password: { | ||
| 872 | const arr: [100][8]u8 = @splat("password".*); | ||
| 873 | break :password @ptrCast(&arr); | ||
| 874 | }; | ||
| 875 | |||
| 871 | var long_buf: [hash_length]u8 = undefined; | 876 | var long_buf: [hash_length]u8 = undefined; |
| 872 | var long_s = try strHash("password" ** 100, hash_options, &long_buf, io); | 877 | var long_s = try strHash(password_100, hash_options, &long_buf, io); |
| 873 | 878 | ||
| 874 | try testing.expect(mem.startsWith(u8, long_s, crypt_format.prefix)); | 879 | try testing.expect(mem.startsWith(u8, long_s, crypt_format.prefix)); |
| 875 | try strVerify(long_s, "password" ** 100, verify_options); | 880 | try strVerify(long_s, password_100, verify_options); |
| 876 | try testing.expectError( | 881 | try testing.expectError( |
| 877 | error.PasswordVerificationFailed, | 882 | error.PasswordVerificationFailed, |
| 878 | strVerify(long_s, "password" ** 101, verify_options), | 883 | strVerify(long_s, password_100 ++ "password", verify_options), |
| 879 | ); | 884 | ); |
| 880 | 885 | ||
| 881 | hash_options.params.silently_truncate_password = true; | 886 | hash_options.params.silently_truncate_password = true; |
| 882 | verify_options.silently_truncate_password = true; | 887 | verify_options.silently_truncate_password = true; |
| 883 | long_s = try strHash("password" ** 100, hash_options, &long_buf, io); | 888 | long_s = try strHash(password_100, hash_options, &long_buf, io); |
| 884 | try strVerify(long_s, "password" ** 101, verify_options); | 889 | try strVerify(long_s, password_100 ++ "password", verify_options); |
| 885 | 890 | ||
| 886 | try strVerify( | 891 | try strVerify( |
| 887 | "$2b$08$WUQKyBCaKpziCwUXHiMVvu40dYVjkTxtWJlftl0PpjY2BxWSvFIEe", | 892 | "$2b$08$WUQKyBCaKpziCwUXHiMVvu40dYVjkTxtWJlftl0PpjY2BxWSvFIEe", |
| ... | @@ -909,20 +914,25 @@ test "bcrypt phc format" { | ... | @@ -909,20 +914,25 @@ test "bcrypt phc format" { |
| 909 | strVerify(s, "invalid password", verify_options), | 914 | strVerify(s, "invalid password", verify_options), |
| 910 | ); | 915 | ); |
| 911 | 916 | ||
| 917 | const password_100: []const u8 = password: { | ||
| 918 | const arr: [100][8]u8 = @splat("password".*); | ||
| 919 | break :password @ptrCast(&arr); | ||
| 920 | }; | ||
| 921 | |||
| 912 | var long_buf: [hash_length * 2]u8 = undefined; | 922 | var long_buf: [hash_length * 2]u8 = undefined; |
| 913 | var long_s = try strHash("password" ** 100, hash_options, &long_buf, io); | 923 | var long_s = try strHash(password_100, hash_options, &long_buf, io); |
| 914 | 924 | ||
| 915 | try testing.expect(mem.startsWith(u8, long_s, prefix)); | 925 | try testing.expect(mem.startsWith(u8, long_s, prefix)); |
| 916 | try strVerify(long_s, "password" ** 100, verify_options); | 926 | try strVerify(long_s, password_100, verify_options); |
| 917 | try testing.expectError( | 927 | try testing.expectError( |
| 918 | error.PasswordVerificationFailed, | 928 | error.PasswordVerificationFailed, |
| 919 | strVerify(long_s, "password" ** 101, verify_options), | 929 | strVerify(long_s, password_100 ++ "password", verify_options), |
| 920 | ); | 930 | ); |
| 921 | 931 | ||
| 922 | hash_options.params.silently_truncate_password = true; | 932 | hash_options.params.silently_truncate_password = true; |
| 923 | verify_options.silently_truncate_password = true; | 933 | verify_options.silently_truncate_password = true; |
| 924 | long_s = try strHash("password" ** 100, hash_options, &long_buf, io); | 934 | long_s = try strHash(password_100, hash_options, &long_buf, io); |
| 925 | try strVerify(long_s, "password" ** 101, verify_options); | 935 | try strVerify(long_s, password_100 ++ "password", verify_options); |
| 926 | 936 | ||
| 927 | try strVerify( | 937 | try strVerify( |
| 928 | "$bcrypt$r=5$2NopntlgE2lX3cTwr4qz8A$r3T7iKYQNnY4hAhGjk9RmuyvgrYJZwc", | 938 | "$bcrypt$r=5$2NopntlgE2lX3cTwr4qz8A$r3T7iKYQNnY4hAhGjk9RmuyvgrYJZwc", |
lib/std/crypto/benchmark.zig+7-7| ... | @@ -173,7 +173,7 @@ const signatures = [_]Crypto{ | ... | @@ -173,7 +173,7 @@ const signatures = [_]Crypto{ |
| 173 | }; | 173 | }; |
| 174 | 174 | ||
| 175 | pub fn benchmarkSignature(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 { | 175 | pub fn benchmarkSignature(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 { |
| 176 | const msg = [_]u8{0} ** 64; | 176 | const msg: [64]u8 = @splat(0); |
| 177 | const key_pair = Signature.KeyPair.generate(io); | 177 | const key_pair = Signature.KeyPair.generate(io); |
| 178 | 178 | ||
| 179 | const start = benchTime(io); | 179 | const start = benchTime(io); |
| ... | @@ -200,7 +200,7 @@ const signature_verifications = [_]Crypto{ | ... | @@ -200,7 +200,7 @@ const signature_verifications = [_]Crypto{ |
| 200 | }; | 200 | }; |
| 201 | 201 | ||
| 202 | pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 { | 202 | pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 { |
| 203 | const msg = [_]u8{0} ** 64; | 203 | const msg: [64]u8 = @splat(0); |
| 204 | const key_pair = Signature.KeyPair.generate(io); | 204 | const key_pair = Signature.KeyPair.generate(io); |
| 205 | const sig = try key_pair.sign(&msg, null); | 205 | const sig = try key_pair.sign(&msg, null); |
| 206 | 206 | ||
| ... | @@ -223,7 +223,7 @@ pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime sign | ... | @@ -223,7 +223,7 @@ pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime sign |
| 223 | const batch_signature_verifications = [_]Crypto{Crypto{ .ty = crypto.sign.Ed25519, .name = "ed25519" }}; | 223 | const batch_signature_verifications = [_]Crypto{Crypto{ .ty = crypto.sign.Ed25519, .name = "ed25519" }}; |
| 224 | 224 | ||
| 225 | pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 { | 225 | pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 { |
| 226 | const msg = [_]u8{0} ** 64; | 226 | const msg: [64]u8 = @splat(0); |
| 227 | const key_pair = Signature.KeyPair.generate(io); | 227 | const key_pair = Signature.KeyPair.generate(io); |
| 228 | const sig = try key_pair.sign(&msg, null); | 228 | const sig = try key_pair.sign(&msg, null); |
| 229 | 229 | ||
| ... | @@ -367,7 +367,7 @@ pub fn benchmarkAes(comptime Aes: anytype, comptime count: comptime_int, io: Io) | ... | @@ -367,7 +367,7 @@ pub fn benchmarkAes(comptime Aes: anytype, comptime count: comptime_int, io: Io) |
| 367 | random.bytes(key[0..]); | 367 | random.bytes(key[0..]); |
| 368 | const ctx = Aes.initEnc(key); | 368 | const ctx = Aes.initEnc(key); |
| 369 | 369 | ||
| 370 | var in = [_]u8{0} ** 16; | 370 | var in: [16]u8 = @splat(0); |
| 371 | 371 | ||
| 372 | const start = benchTime(io); | 372 | const start = benchTime(io); |
| 373 | { | 373 | { |
| ... | @@ -395,7 +395,7 @@ pub fn benchmarkAes8(comptime Aes: anytype, comptime count: comptime_int, io: Io | ... | @@ -395,7 +395,7 @@ pub fn benchmarkAes8(comptime Aes: anytype, comptime count: comptime_int, io: Io |
| 395 | random.bytes(key[0..]); | 395 | random.bytes(key[0..]); |
| 396 | const ctx = Aes.initEnc(key); | 396 | const ctx = Aes.initEnc(key); |
| 397 | 397 | ||
| 398 | var in = [_]u8{0} ** (8 * 16); | 398 | var in: [8 * 16]u8 = @splat(0); |
| 399 | 399 | ||
| 400 | const start = benchTime(io); | 400 | const start = benchTime(io); |
| 401 | { | 401 | { |
| ... | @@ -444,7 +444,7 @@ fn benchmarkPwhash( | ... | @@ -444,7 +444,7 @@ fn benchmarkPwhash( |
| 444 | comptime count: comptime_int, | 444 | comptime count: comptime_int, |
| 445 | io: std.Io, | 445 | io: std.Io, |
| 446 | ) !f64 { | 446 | ) !f64 { |
| 447 | const password = "testpass" ** 2; | 447 | const password = "testpasstestpass"; |
| 448 | const opts = ty.HashOptions{ | 448 | const opts = ty.HashOptions{ |
| 449 | .allocator = allocator, | 449 | .allocator = allocator, |
| 450 | .params = @as(*const ty.Params, @ptrCast(@alignCast(params))).*, | 450 | .params = @as(*const ty.Params, @ptrCast(@alignCast(params))).*, |
| ... | @@ -456,7 +456,7 @@ fn benchmarkPwhash( | ... | @@ -456,7 +456,7 @@ fn benchmarkPwhash( |
| 456 | const strHashFnInfo = @typeInfo(@TypeOf(strHash)).@"fn"; | 456 | const strHashFnInfo = @typeInfo(@TypeOf(strHash)).@"fn"; |
| 457 | const needs_io = strHashFnInfo.params.len == 4 and strHashFnInfo.params[3].type == std.Io; | 457 | const needs_io = strHashFnInfo.params.len == 4 and strHashFnInfo.params[3].type == std.Io; |
| 458 | const needs_salt = strHashFnInfo.params.len == 4 and strHashFnInfo.params[3].type != std.Io; | 458 | const needs_salt = strHashFnInfo.params.len == 4 and strHashFnInfo.params[3].type != std.Io; |
| 459 | const salt: [16]u8 = .{0} ** 16; | 459 | const salt: [16]u8 = @splat(0); |
| 460 | 460 | ||
| 461 | const start = benchTime(io); | 461 | const start = benchTime(io); |
| 462 | { | 462 | { |
lib/std/crypto/blake2.zig+100-64| ... | @@ -199,7 +199,9 @@ test "blake2s160 single" { | ... | @@ -199,7 +199,9 @@ test "blake2s160 single" { |
| 199 | try htest.assertEqualHash(Blake2s160, h3, "The quick brown fox jumps over the lazy dog"); | 199 | try htest.assertEqualHash(Blake2s160, h3, "The quick brown fox jumps over the lazy dog"); |
| 200 | 200 | ||
| 201 | const h4 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0"; | 201 | const h4 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0"; |
| 202 | try htest.assertEqualHash(Blake2s160, h4, "a" ** 32 ++ "b" ** 32); | 202 | const repeat_a_32: [32]u8 = @splat('a'); |
| 203 | const repeat_b_32: [32]u8 = @splat('b'); | ||
| 204 | try htest.assertEqualHash(Blake2s160, h4, &repeat_a_32 ++ &repeat_b_32); | ||
| 203 | } | 205 | } |
| 204 | 206 | ||
| 205 | test "blake2s160 streaming" { | 207 | test "blake2s160 streaming" { |
| ... | @@ -227,27 +229,30 @@ test "blake2s160 streaming" { | ... | @@ -227,27 +229,30 @@ test "blake2s160 streaming" { |
| 227 | 229 | ||
| 228 | const h3 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0"; | 230 | const h3 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0"; |
| 229 | 231 | ||
| 232 | const repeat_a_32: [32]u8 = @splat('a'); | ||
| 233 | const repeat_b_32: [32]u8 = @splat('b'); | ||
| 234 | |||
| 230 | h = Blake2s160.init(.{}); | 235 | h = Blake2s160.init(.{}); |
| 231 | h.update("a" ** 32); | 236 | h.update(&repeat_a_32); |
| 232 | h.update("b" ** 32); | 237 | h.update(&repeat_b_32); |
| 233 | h.final(out[0..]); | 238 | h.final(out[0..]); |
| 234 | try htest.assertEqual(h3, out[0..]); | 239 | try htest.assertEqual(h3, out[0..]); |
| 235 | 240 | ||
| 236 | h = Blake2s160.init(.{}); | 241 | h = Blake2s160.init(.{}); |
| 237 | h.update("a" ** 32 ++ "b" ** 32); | 242 | h.update(&repeat_a_32 ++ &repeat_b_32); |
| 238 | h.final(out[0..]); | 243 | h.final(out[0..]); |
| 239 | try htest.assertEqual(h3, out[0..]); | 244 | try htest.assertEqual(h3, out[0..]); |
| 240 | 245 | ||
| 241 | const h4 = "4667fd60791a7fe41f939bca646b4529e296bd68"; | 246 | const h4 = "4667fd60791a7fe41f939bca646b4529e296bd68"; |
| 242 | 247 | ||
| 243 | h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 }); | 248 | h = Blake2s160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 244 | h.update("a" ** 32); | 249 | h.update(&repeat_a_32); |
| 245 | h.update("b" ** 32); | 250 | h.update(&repeat_b_32); |
| 246 | h.final(out[0..]); | 251 | h.final(out[0..]); |
| 247 | try htest.assertEqual(h4, out[0..]); | 252 | try htest.assertEqual(h4, out[0..]); |
| 248 | 253 | ||
| 249 | h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 }); | 254 | h = Blake2s160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 250 | h.update("a" ** 32 ++ "b" ** 32); | 255 | h.update(&repeat_a_32 ++ &repeat_b_32); |
| 251 | h.final(out[0..]); | 256 | h.final(out[0..]); |
| 252 | try htest.assertEqual(h4, out[0..]); | 257 | try htest.assertEqual(h4, out[0..]); |
| 253 | } | 258 | } |
| ... | @@ -256,7 +261,7 @@ test "comptime blake2s160" { | ... | @@ -256,7 +261,7 @@ test "comptime blake2s160" { |
| 256 | //comptime | 261 | //comptime |
| 257 | { | 262 | { |
| 258 | @setEvalBranchQuota(10000); | 263 | @setEvalBranchQuota(10000); |
| 259 | var block = [_]u8{0} ** Blake2s160.block_length; | 264 | var block: [Blake2s160.block_length]u8 = @splat(0); |
| 260 | var out: [Blake2s160.digest_length]u8 = undefined; | 265 | var out: [Blake2s160.digest_length]u8 = undefined; |
| 261 | 266 | ||
| 262 | const h1 = "2c56ad9d0b2c8b474aafa93ab307db2f0940105f"; | 267 | const h1 = "2c56ad9d0b2c8b474aafa93ab307db2f0940105f"; |
| ... | @@ -282,7 +287,9 @@ test "blake2s224 single" { | ... | @@ -282,7 +287,9 @@ test "blake2s224 single" { |
| 282 | try htest.assertEqualHash(Blake2s224, h3, "The quick brown fox jumps over the lazy dog"); | 287 | try htest.assertEqualHash(Blake2s224, h3, "The quick brown fox jumps over the lazy dog"); |
| 283 | 288 | ||
| 284 | const h4 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01"; | 289 | const h4 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01"; |
| 285 | try htest.assertEqualHash(Blake2s224, h4, "a" ** 32 ++ "b" ** 32); | 290 | const repeat_a_32: [32]u8 = @splat('a'); |
| 291 | const repeat_b_32: [32]u8 = @splat('b'); | ||
| 292 | try htest.assertEqualHash(Blake2s224, h4, &repeat_a_32 ++ &repeat_b_32); | ||
| 286 | } | 293 | } |
| 287 | 294 | ||
| 288 | test "blake2s224 streaming" { | 295 | test "blake2s224 streaming" { |
| ... | @@ -308,29 +315,32 @@ test "blake2s224 streaming" { | ... | @@ -308,29 +315,32 @@ test "blake2s224 streaming" { |
| 308 | h.final(out[0..]); | 315 | h.final(out[0..]); |
| 309 | try htest.assertEqual(h2, out[0..]); | 316 | try htest.assertEqual(h2, out[0..]); |
| 310 | 317 | ||
| 318 | const repeat_a_32: [32]u8 = @splat('a'); | ||
| 319 | const repeat_b_32: [32]u8 = @splat('b'); | ||
| 320 | |||
| 311 | const h3 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01"; | 321 | const h3 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01"; |
| 312 | 322 | ||
| 313 | h = Blake2s224.init(.{}); | 323 | h = Blake2s224.init(.{}); |
| 314 | h.update("a" ** 32); | 324 | h.update(&repeat_a_32); |
| 315 | h.update("b" ** 32); | 325 | h.update(&repeat_b_32); |
| 316 | h.final(out[0..]); | 326 | h.final(out[0..]); |
| 317 | try htest.assertEqual(h3, out[0..]); | 327 | try htest.assertEqual(h3, out[0..]); |
| 318 | 328 | ||
| 319 | h = Blake2s224.init(.{}); | 329 | h = Blake2s224.init(.{}); |
| 320 | h.update("a" ** 32 ++ "b" ** 32); | 330 | h.update(&repeat_a_32 ++ &repeat_b_32); |
| 321 | h.final(out[0..]); | 331 | h.final(out[0..]); |
| 322 | try htest.assertEqual(h3, out[0..]); | 332 | try htest.assertEqual(h3, out[0..]); |
| 323 | 333 | ||
| 324 | const h4 = "a4d6a9d253441b80e5dfd60a04db169ffab77aec56a2855c402828c3"; | 334 | const h4 = "a4d6a9d253441b80e5dfd60a04db169ffab77aec56a2855c402828c3"; |
| 325 | 335 | ||
| 326 | h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 }); | 336 | h = Blake2s224.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 327 | h.update("a" ** 32); | 337 | h.update(&repeat_a_32); |
| 328 | h.update("b" ** 32); | 338 | h.update(&repeat_b_32); |
| 329 | h.final(out[0..]); | 339 | h.final(out[0..]); |
| 330 | try htest.assertEqual(h4, out[0..]); | 340 | try htest.assertEqual(h4, out[0..]); |
| 331 | 341 | ||
| 332 | h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 }); | 342 | h = Blake2s224.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 333 | h.update("a" ** 32 ++ "b" ** 32); | 343 | h.update(&repeat_a_32 ++ &repeat_b_32); |
| 334 | h.final(out[0..]); | 344 | h.final(out[0..]); |
| 335 | try htest.assertEqual(h4, out[0..]); | 345 | try htest.assertEqual(h4, out[0..]); |
| 336 | } | 346 | } |
| ... | @@ -338,7 +348,7 @@ test "blake2s224 streaming" { | ... | @@ -338,7 +348,7 @@ test "blake2s224 streaming" { |
| 338 | test "comptime blake2s224" { | 348 | test "comptime blake2s224" { |
| 339 | comptime { | 349 | comptime { |
| 340 | @setEvalBranchQuota(10000); | 350 | @setEvalBranchQuota(10000); |
| 341 | var block = [_]u8{0} ** Blake2s224.block_length; | 351 | var block: [Blake2s224.block_length]u8 = @splat(0); |
| 342 | var out: [Blake2s224.digest_length]u8 = undefined; | 352 | var out: [Blake2s224.digest_length]u8 = undefined; |
| 343 | 353 | ||
| 344 | const h1 = "86b7611563293f8c73627df7a6d6ba25ca0548c2a6481f7d116ee576"; | 354 | const h1 = "86b7611563293f8c73627df7a6d6ba25ca0548c2a6481f7d116ee576"; |
| ... | @@ -364,7 +374,9 @@ test "blake2s256 single" { | ... | @@ -364,7 +374,9 @@ test "blake2s256 single" { |
| 364 | try htest.assertEqualHash(Blake2s256, h3, "The quick brown fox jumps over the lazy dog"); | 374 | try htest.assertEqualHash(Blake2s256, h3, "The quick brown fox jumps over the lazy dog"); |
| 365 | 375 | ||
| 366 | const h4 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977"; | 376 | const h4 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977"; |
| 367 | try htest.assertEqualHash(Blake2s256, h4, "a" ** 32 ++ "b" ** 32); | 377 | const repeat_a_32: [32]u8 = @splat('a'); |
| 378 | const repeat_b_32: [32]u8 = @splat('b'); | ||
| 379 | try htest.assertEqualHash(Blake2s256, h4, &repeat_a_32 ++ &repeat_b_32); | ||
| 368 | } | 380 | } |
| 369 | 381 | ||
| 370 | test "blake2s256 streaming" { | 382 | test "blake2s256 streaming" { |
| ... | @@ -390,16 +402,19 @@ test "blake2s256 streaming" { | ... | @@ -390,16 +402,19 @@ test "blake2s256 streaming" { |
| 390 | h.final(out[0..]); | 402 | h.final(out[0..]); |
| 391 | try htest.assertEqual(h2, out[0..]); | 403 | try htest.assertEqual(h2, out[0..]); |
| 392 | 404 | ||
| 405 | const repeat_a_32: [32]u8 = @splat('a'); | ||
| 406 | const repeat_b_32: [32]u8 = @splat('b'); | ||
| 407 | |||
| 393 | const h3 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977"; | 408 | const h3 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977"; |
| 394 | 409 | ||
| 395 | h = Blake2s256.init(.{}); | 410 | h = Blake2s256.init(.{}); |
| 396 | h.update("a" ** 32); | 411 | h.update(&repeat_a_32); |
| 397 | h.update("b" ** 32); | 412 | h.update(&repeat_b_32); |
| 398 | h.final(out[0..]); | 413 | h.final(out[0..]); |
| 399 | try htest.assertEqual(h3, out[0..]); | 414 | try htest.assertEqual(h3, out[0..]); |
| 400 | 415 | ||
| 401 | h = Blake2s256.init(.{}); | 416 | h = Blake2s256.init(.{}); |
| 402 | h.update("a" ** 32 ++ "b" ** 32); | 417 | h.update(&repeat_a_32 ++ &repeat_b_32); |
| 403 | h.final(out[0..]); | 418 | h.final(out[0..]); |
| 404 | try htest.assertEqual(h3, out[0..]); | 419 | try htest.assertEqual(h3, out[0..]); |
| 405 | } | 420 | } |
| ... | @@ -410,18 +425,21 @@ test "blake2s256 keyed" { | ... | @@ -410,18 +425,21 @@ test "blake2s256 keyed" { |
| 410 | const h1 = "10f918da4d74fab3302e48a5d67d03804b1ec95372a62a0f33b7c9fa28ba1ae6"; | 425 | const h1 = "10f918da4d74fab3302e48a5d67d03804b1ec95372a62a0f33b7c9fa28ba1ae6"; |
| 411 | const key = "secret_key"; | 426 | const key = "secret_key"; |
| 412 | 427 | ||
| 413 | Blake2s256.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key }); | 428 | const repeat_a_64: [64]u8 = @splat('a'); |
| 429 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 430 | |||
| 431 | Blake2s256.hash(&repeat_a_64 ++ &repeat_b_64, &out, .{ .key = key }); | ||
| 414 | try htest.assertEqual(h1, out[0..]); | 432 | try htest.assertEqual(h1, out[0..]); |
| 415 | 433 | ||
| 416 | var h = Blake2s256.init(.{ .key = key }); | 434 | var h = Blake2s256.init(.{ .key = key }); |
| 417 | h.update("a" ** 64 ++ "b" ** 64); | 435 | h.update(&repeat_a_64 ++ &repeat_b_64); |
| 418 | h.final(out[0..]); | 436 | h.final(out[0..]); |
| 419 | 437 | ||
| 420 | try htest.assertEqual(h1, out[0..]); | 438 | try htest.assertEqual(h1, out[0..]); |
| 421 | 439 | ||
| 422 | h = Blake2s256.init(.{ .key = key }); | 440 | h = Blake2s256.init(.{ .key = key }); |
| 423 | h.update("a" ** 64); | 441 | h.update(&repeat_a_64); |
| 424 | h.update("b" ** 64); | 442 | h.update(&repeat_b_64); |
| 425 | h.final(out[0..]); | 443 | h.final(out[0..]); |
| 426 | 444 | ||
| 427 | try htest.assertEqual(h1, out[0..]); | 445 | try htest.assertEqual(h1, out[0..]); |
| ... | @@ -430,7 +448,7 @@ test "blake2s256 keyed" { | ... | @@ -430,7 +448,7 @@ test "blake2s256 keyed" { |
| 430 | test "comptime blake2s256" { | 448 | test "comptime blake2s256" { |
| 431 | comptime { | 449 | comptime { |
| 432 | @setEvalBranchQuota(10000); | 450 | @setEvalBranchQuota(10000); |
| 433 | var block = [_]u8{0} ** Blake2s256.block_length; | 451 | var block: [Blake2s256.block_length]u8 = @splat(0); |
| 434 | var out: [Blake2s256.digest_length]u8 = undefined; | 452 | var out: [Blake2s256.digest_length]u8 = undefined; |
| 435 | 453 | ||
| 436 | const h1 = "ae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3"; | 454 | const h1 = "ae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3"; |
| ... | @@ -623,7 +641,9 @@ test "blake2b160 single" { | ... | @@ -623,7 +641,9 @@ test "blake2b160 single" { |
| 623 | try htest.assertEqualHash(Blake2b160, h3, "The quick brown fox jumps over the lazy dog"); | 641 | try htest.assertEqualHash(Blake2b160, h3, "The quick brown fox jumps over the lazy dog"); |
| 624 | 642 | ||
| 625 | const h4 = "43758f5de1740f651f1ae39de92260fe8bd5a11f"; | 643 | const h4 = "43758f5de1740f651f1ae39de92260fe8bd5a11f"; |
| 626 | try htest.assertEqualHash(Blake2b160, h4, "a" ** 64 ++ "b" ** 64); | 644 | const repeat_a_64: [64]u8 = @splat('a'); |
| 645 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 646 | try htest.assertEqualHash(Blake2b160, h4, &repeat_a_64 ++ &repeat_b_64); | ||
| 627 | } | 647 | } |
| 628 | 648 | ||
| 629 | test "blake2b160 streaming" { | 649 | test "blake2b160 streaming" { |
| ... | @@ -649,36 +669,39 @@ test "blake2b160 streaming" { | ... | @@ -649,36 +669,39 @@ test "blake2b160 streaming" { |
| 649 | h.final(out[0..]); | 669 | h.final(out[0..]); |
| 650 | try htest.assertEqual(h2, out[0..]); | 670 | try htest.assertEqual(h2, out[0..]); |
| 651 | 671 | ||
| 672 | const repeat_a_64: [64]u8 = @splat('a'); | ||
| 673 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 674 | |||
| 652 | const h3 = "43758f5de1740f651f1ae39de92260fe8bd5a11f"; | 675 | const h3 = "43758f5de1740f651f1ae39de92260fe8bd5a11f"; |
| 653 | 676 | ||
| 654 | h = Blake2b160.init(.{}); | 677 | h = Blake2b160.init(.{}); |
| 655 | h.update("a" ** 64 ++ "b" ** 64); | 678 | h.update(&repeat_a_64 ++ &repeat_b_64); |
| 656 | h.final(out[0..]); | 679 | h.final(out[0..]); |
| 657 | try htest.assertEqual(h3, out[0..]); | 680 | try htest.assertEqual(h3, out[0..]); |
| 658 | 681 | ||
| 659 | h = Blake2b160.init(.{}); | 682 | h = Blake2b160.init(.{}); |
| 660 | h.update("a" ** 64); | 683 | h.update(&repeat_a_64); |
| 661 | h.update("b" ** 64); | 684 | h.update(&repeat_b_64); |
| 662 | h.final(out[0..]); | 685 | h.final(out[0..]); |
| 663 | try htest.assertEqual(h3, out[0..]); | 686 | try htest.assertEqual(h3, out[0..]); |
| 664 | 687 | ||
| 665 | h = Blake2b160.init(.{}); | 688 | h = Blake2b160.init(.{}); |
| 666 | h.update("a" ** 64); | 689 | h.update(&repeat_a_64); |
| 667 | h.update("b" ** 64); | 690 | h.update(&repeat_b_64); |
| 668 | h.final(out[0..]); | 691 | h.final(out[0..]); |
| 669 | try htest.assertEqual(h3, out[0..]); | 692 | try htest.assertEqual(h3, out[0..]); |
| 670 | 693 | ||
| 671 | const h4 = "72328f8a8200663752fc302d372b5dd9b49dd8dc"; | 694 | const h4 = "72328f8a8200663752fc302d372b5dd9b49dd8dc"; |
| 672 | 695 | ||
| 673 | h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 }); | 696 | h = Blake2b160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 674 | h.update("a" ** 64); | 697 | h.update(&repeat_a_64); |
| 675 | h.update("b" ** 64); | 698 | h.update(&repeat_b_64); |
| 676 | h.final(out[0..]); | 699 | h.final(out[0..]); |
| 677 | try htest.assertEqual(h4, out[0..]); | 700 | try htest.assertEqual(h4, out[0..]); |
| 678 | 701 | ||
| 679 | h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 }); | 702 | h = Blake2b160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 680 | h.update("a" ** 64); | 703 | h.update(&repeat_a_64); |
| 681 | h.update("b" ** 64); | 704 | h.update(&repeat_b_64); |
| 682 | h.final(out[0..]); | 705 | h.final(out[0..]); |
| 683 | try htest.assertEqual(h4, out[0..]); | 706 | try htest.assertEqual(h4, out[0..]); |
| 684 | } | 707 | } |
| ... | @@ -686,7 +709,7 @@ test "blake2b160 streaming" { | ... | @@ -686,7 +709,7 @@ test "blake2b160 streaming" { |
| 686 | test "comptime blake2b160" { | 709 | test "comptime blake2b160" { |
| 687 | comptime { | 710 | comptime { |
| 688 | @setEvalBranchQuota(10000); | 711 | @setEvalBranchQuota(10000); |
| 689 | var block = [_]u8{0} ** Blake2b160.block_length; | 712 | var block: [Blake2b160.block_length]u8 = @splat(0); |
| 690 | var out: [Blake2b160.digest_length]u8 = undefined; | 713 | var out: [Blake2b160.digest_length]u8 = undefined; |
| 691 | 714 | ||
| 692 | const h1 = "8d26f158f564e3293b42f5e3d34263cb173aa9c9"; | 715 | const h1 = "8d26f158f564e3293b42f5e3d34263cb173aa9c9"; |
| ... | @@ -712,7 +735,9 @@ test "blake2b384 single" { | ... | @@ -712,7 +735,9 @@ test "blake2b384 single" { |
| 712 | try htest.assertEqualHash(Blake2b384, h3, "The quick brown fox jumps over the lazy dog"); | 735 | try htest.assertEqualHash(Blake2b384, h3, "The quick brown fox jumps over the lazy dog"); |
| 713 | 736 | ||
| 714 | const h4 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c"; | 737 | const h4 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c"; |
| 715 | try htest.assertEqualHash(Blake2b384, h4, "a" ** 64 ++ "b" ** 64); | 738 | const repeat_a_64: [64]u8 = @splat('a'); |
| 739 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 740 | try htest.assertEqualHash(Blake2b384, h4, &repeat_a_64 ++ &repeat_b_64); | ||
| 716 | } | 741 | } |
| 717 | 742 | ||
| 718 | test "blake2b384 streaming" { | 743 | test "blake2b384 streaming" { |
| ... | @@ -738,36 +763,39 @@ test "blake2b384 streaming" { | ... | @@ -738,36 +763,39 @@ test "blake2b384 streaming" { |
| 738 | h.final(out[0..]); | 763 | h.final(out[0..]); |
| 739 | try htest.assertEqual(h2, out[0..]); | 764 | try htest.assertEqual(h2, out[0..]); |
| 740 | 765 | ||
| 766 | const repeat_a_64: [64]u8 = @splat('a'); | ||
| 767 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 768 | |||
| 741 | const h3 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c"; | 769 | const h3 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c"; |
| 742 | 770 | ||
| 743 | h = Blake2b384.init(.{}); | 771 | h = Blake2b384.init(.{}); |
| 744 | h.update("a" ** 64 ++ "b" ** 64); | 772 | h.update(&repeat_a_64 ++ &repeat_b_64); |
| 745 | h.final(out[0..]); | 773 | h.final(out[0..]); |
| 746 | try htest.assertEqual(h3, out[0..]); | 774 | try htest.assertEqual(h3, out[0..]); |
| 747 | 775 | ||
| 748 | h = Blake2b384.init(.{}); | 776 | h = Blake2b384.init(.{}); |
| 749 | h.update("a" ** 64); | 777 | h.update(&repeat_a_64); |
| 750 | h.update("b" ** 64); | 778 | h.update(&repeat_b_64); |
| 751 | h.final(out[0..]); | 779 | h.final(out[0..]); |
| 752 | try htest.assertEqual(h3, out[0..]); | 780 | try htest.assertEqual(h3, out[0..]); |
| 753 | 781 | ||
| 754 | h = Blake2b384.init(.{}); | 782 | h = Blake2b384.init(.{}); |
| 755 | h.update("a" ** 64); | 783 | h.update(&repeat_a_64); |
| 756 | h.update("b" ** 64); | 784 | h.update(&repeat_b_64); |
| 757 | h.final(out[0..]); | 785 | h.final(out[0..]); |
| 758 | try htest.assertEqual(h3, out[0..]); | 786 | try htest.assertEqual(h3, out[0..]); |
| 759 | 787 | ||
| 760 | const h4 = "934c48fcb197031c71f583d92f98703510805e72142e0b46f5752d1e971bc86c355d556035613ff7a4154b4de09dac5c"; | 788 | const h4 = "934c48fcb197031c71f583d92f98703510805e72142e0b46f5752d1e971bc86c355d556035613ff7a4154b4de09dac5c"; |
| 761 | 789 | ||
| 762 | h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 }); | 790 | h = Blake2b384.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 763 | h.update("a" ** 64); | 791 | h.update(&repeat_a_64); |
| 764 | h.update("b" ** 64); | 792 | h.update(&repeat_b_64); |
| 765 | h.final(out[0..]); | 793 | h.final(out[0..]); |
| 766 | try htest.assertEqual(h4, out[0..]); | 794 | try htest.assertEqual(h4, out[0..]); |
| 767 | 795 | ||
| 768 | h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 }); | 796 | h = Blake2b384.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 769 | h.update("a" ** 64); | 797 | h.update(&repeat_a_64); |
| 770 | h.update("b" ** 64); | 798 | h.update(&repeat_b_64); |
| 771 | h.final(out[0..]); | 799 | h.final(out[0..]); |
| 772 | try htest.assertEqual(h4, out[0..]); | 800 | try htest.assertEqual(h4, out[0..]); |
| 773 | } | 801 | } |
| ... | @@ -775,7 +803,7 @@ test "blake2b384 streaming" { | ... | @@ -775,7 +803,7 @@ test "blake2b384 streaming" { |
| 775 | test "comptime blake2b384" { | 803 | test "comptime blake2b384" { |
| 776 | comptime { | 804 | comptime { |
| 777 | @setEvalBranchQuota(20000); | 805 | @setEvalBranchQuota(20000); |
| 778 | var block = [_]u8{0} ** Blake2b384.block_length; | 806 | var block: [Blake2b384.block_length]u8 = @splat(0); |
| 779 | var out: [Blake2b384.digest_length]u8 = undefined; | 807 | var out: [Blake2b384.digest_length]u8 = undefined; |
| 780 | 808 | ||
| 781 | const h1 = "e8aa1931ea0422e4446fecdd25c16cf35c240b10cb4659dd5c776eddcaa4d922397a589404b46eb2e53d78132d05fd7d"; | 809 | const h1 = "e8aa1931ea0422e4446fecdd25c16cf35c240b10cb4659dd5c776eddcaa4d922397a589404b46eb2e53d78132d05fd7d"; |
| ... | @@ -801,7 +829,9 @@ test "blake2b512 single" { | ... | @@ -801,7 +829,9 @@ test "blake2b512 single" { |
| 801 | try htest.assertEqualHash(Blake2b512, h3, "The quick brown fox jumps over the lazy dog"); | 829 | try htest.assertEqualHash(Blake2b512, h3, "The quick brown fox jumps over the lazy dog"); |
| 802 | 830 | ||
| 803 | const h4 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920"; | 831 | const h4 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920"; |
| 804 | try htest.assertEqualHash(Blake2b512, h4, "a" ** 64 ++ "b" ** 64); | 832 | const repeat_a_64: [64]u8 = @splat('a'); |
| 833 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 834 | try htest.assertEqualHash(Blake2b512, h4, &repeat_a_64 ++ &repeat_b_64); | ||
| 805 | } | 835 | } |
| 806 | 836 | ||
| 807 | test "blake2b512 streaming" { | 837 | test "blake2b512 streaming" { |
| ... | @@ -827,16 +857,19 @@ test "blake2b512 streaming" { | ... | @@ -827,16 +857,19 @@ test "blake2b512 streaming" { |
| 827 | h.final(out[0..]); | 857 | h.final(out[0..]); |
| 828 | try htest.assertEqual(h2, out[0..]); | 858 | try htest.assertEqual(h2, out[0..]); |
| 829 | 859 | ||
| 860 | const repeat_a_64: [64]u8 = @splat('a'); | ||
| 861 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 862 | |||
| 830 | const h3 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920"; | 863 | const h3 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920"; |
| 831 | 864 | ||
| 832 | h = Blake2b512.init(.{}); | 865 | h = Blake2b512.init(.{}); |
| 833 | h.update("a" ** 64 ++ "b" ** 64); | 866 | h.update(&repeat_a_64 ++ &repeat_b_64); |
| 834 | h.final(out[0..]); | 867 | h.final(out[0..]); |
| 835 | try htest.assertEqual(h3, out[0..]); | 868 | try htest.assertEqual(h3, out[0..]); |
| 836 | 869 | ||
| 837 | h = Blake2b512.init(.{}); | 870 | h = Blake2b512.init(.{}); |
| 838 | h.update("a" ** 64); | 871 | h.update(&repeat_a_64); |
| 839 | h.update("b" ** 64); | 872 | h.update(&repeat_b_64); |
| 840 | h.final(out[0..]); | 873 | h.final(out[0..]); |
| 841 | try htest.assertEqual(h3, out[0..]); | 874 | try htest.assertEqual(h3, out[0..]); |
| 842 | } | 875 | } |
| ... | @@ -847,18 +880,21 @@ test "blake2b512 keyed" { | ... | @@ -847,18 +880,21 @@ test "blake2b512 keyed" { |
| 847 | const h1 = "8a978060ccaf582f388f37454363071ac9a67e3a704585fd879fb8a419a447e389c7c6de790faa20a7a7dccf197de736bc5b40b98a930b36df5bee7555750c4d"; | 880 | const h1 = "8a978060ccaf582f388f37454363071ac9a67e3a704585fd879fb8a419a447e389c7c6de790faa20a7a7dccf197de736bc5b40b98a930b36df5bee7555750c4d"; |
| 848 | const key = "secret_key"; | 881 | const key = "secret_key"; |
| 849 | 882 | ||
| 850 | Blake2b512.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key }); | 883 | const repeat_a_64: [64]u8 = @splat('a'); |
| 884 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 885 | |||
| 886 | Blake2b512.hash(&repeat_a_64 ++ &repeat_b_64, &out, .{ .key = key }); | ||
| 851 | try htest.assertEqual(h1, out[0..]); | 887 | try htest.assertEqual(h1, out[0..]); |
| 852 | 888 | ||
| 853 | var h = Blake2b512.init(.{ .key = key }); | 889 | var h = Blake2b512.init(.{ .key = key }); |
| 854 | h.update("a" ** 64 ++ "b" ** 64); | 890 | h.update(&repeat_a_64 ++ &repeat_b_64); |
| 855 | h.final(out[0..]); | 891 | h.final(out[0..]); |
| 856 | 892 | ||
| 857 | try htest.assertEqual(h1, out[0..]); | 893 | try htest.assertEqual(h1, out[0..]); |
| 858 | 894 | ||
| 859 | h = Blake2b512.init(.{ .key = key }); | 895 | h = Blake2b512.init(.{ .key = key }); |
| 860 | h.update("a" ** 64); | 896 | h.update(&repeat_a_64); |
| 861 | h.update("b" ** 64); | 897 | h.update(&repeat_b_64); |
| 862 | h.final(out[0..]); | 898 | h.final(out[0..]); |
| 863 | 899 | ||
| 864 | try htest.assertEqual(h1, out[0..]); | 900 | try htest.assertEqual(h1, out[0..]); |
| ... | @@ -867,7 +903,7 @@ test "blake2b512 keyed" { | ... | @@ -867,7 +903,7 @@ test "blake2b512 keyed" { |
| 867 | test "comptime blake2b512" { | 903 | test "comptime blake2b512" { |
| 868 | comptime { | 904 | comptime { |
| 869 | @setEvalBranchQuota(12000); | 905 | @setEvalBranchQuota(12000); |
| 870 | var block = [_]u8{0} ** Blake2b512.block_length; | 906 | var block: [Blake2b512.block_length]u8 = @splat(0); |
| 871 | var out: [Blake2b512.digest_length]u8 = undefined; | 907 | var out: [Blake2b512.digest_length]u8 = undefined; |
| 872 | 908 | ||
| 873 | const h1 = "865939e120e6805438478841afb739ae4250cf372653078a065cdcfffca4caf798e6d462b65d658fc165782640eded70963449ae1500fb0f24981d7727e22c41"; | 909 | const h1 = "865939e120e6805438478841afb739ae4250cf372653078a065cdcfffca4caf798e6d462b65d658fc165782640eded70963449ae1500fb0f24981d7727e22c41"; |
lib/std/crypto/cbc_mac.zig+1-1| ... | @@ -21,7 +21,7 @@ pub fn CbcMac(comptime BlockCipher: type) type { | ... | @@ -21,7 +21,7 @@ pub fn CbcMac(comptime BlockCipher: type) type { |
| 21 | pub const mac_length = block_length; | 21 | pub const mac_length = block_length; |
| 22 | 22 | ||
| 23 | cipher_ctx: BlockCipherCtx, | 23 | cipher_ctx: BlockCipherCtx, |
| 24 | buf: Block = [_]u8{0} ** block_length, | 24 | buf: Block = @splat(0), |
| 25 | pos: usize = 0, | 25 | pos: usize = 0, |
| 26 | 26 | ||
| 27 | pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void { | 27 | pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void { |
lib/std/crypto/chacha20.zig+10-10| ... | @@ -648,7 +648,7 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { | ... | @@ -648,7 +648,7 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { |
| 648 | assert(c.len == m.len); | 648 | assert(c.len == m.len); |
| 649 | assert(m.len <= 64 * (@as(u39, 1 << 32) - 1)); | 649 | assert(m.len <= 64 * (@as(u39, 1 << 32) - 1)); |
| 650 | 650 | ||
| 651 | var polyKey = [_]u8{0} ** 32; | 651 | var polyKey: [32]u8 = @splat(0); |
| 652 | ChaChaIETF(rounds_nb).xor(polyKey[0..], polyKey[0..], 0, k, npub); | 652 | ChaChaIETF(rounds_nb).xor(polyKey[0..], polyKey[0..], 0, k, npub); |
| 653 | 653 | ||
| 654 | ChaChaIETF(rounds_nb).xor(c[0..m.len], m, 1, k, npub); | 654 | ChaChaIETF(rounds_nb).xor(c[0..m.len], m, 1, k, npub); |
| ... | @@ -656,13 +656,13 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { | ... | @@ -656,13 +656,13 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { |
| 656 | var mac = Poly1305.init(polyKey[0..]); | 656 | var mac = Poly1305.init(polyKey[0..]); |
| 657 | mac.update(ad); | 657 | mac.update(ad); |
| 658 | if (ad.len % 16 != 0) { | 658 | if (ad.len % 16 != 0) { |
| 659 | const zeros = [_]u8{0} ** 16; | 659 | const zeros: [16]u8 = @splat(0); |
| 660 | const padding = 16 - (ad.len % 16); | 660 | const padding = 16 - (ad.len % 16); |
| 661 | mac.update(zeros[0..padding]); | 661 | mac.update(zeros[0..padding]); |
| 662 | } | 662 | } |
| 663 | mac.update(c[0..m.len]); | 663 | mac.update(c[0..m.len]); |
| 664 | if (m.len % 16 != 0) { | 664 | if (m.len % 16 != 0) { |
| 665 | const zeros = [_]u8{0} ** 16; | 665 | const zeros: [16]u8 = @splat(0); |
| 666 | const padding = 16 - (m.len % 16); | 666 | const padding = 16 - (m.len % 16); |
| 667 | mac.update(zeros[0..padding]); | 667 | mac.update(zeros[0..padding]); |
| 668 | } | 668 | } |
| ... | @@ -685,20 +685,20 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { | ... | @@ -685,20 +685,20 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { |
| 685 | pub fn decrypt(m: []u8, c: []const u8, tag: [tag_length]u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) AuthenticationError!void { | 685 | pub fn decrypt(m: []u8, c: []const u8, tag: [tag_length]u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) AuthenticationError!void { |
| 686 | assert(c.len == m.len); | 686 | assert(c.len == m.len); |
| 687 | 687 | ||
| 688 | var polyKey = [_]u8{0} ** 32; | 688 | var polyKey: [32]u8 = @splat(0); |
| 689 | ChaChaIETF(rounds_nb).xor(polyKey[0..], polyKey[0..], 0, k, npub); | 689 | ChaChaIETF(rounds_nb).xor(polyKey[0..], polyKey[0..], 0, k, npub); |
| 690 | 690 | ||
| 691 | var mac = Poly1305.init(polyKey[0..]); | 691 | var mac = Poly1305.init(polyKey[0..]); |
| 692 | 692 | ||
| 693 | mac.update(ad); | 693 | mac.update(ad); |
| 694 | if (ad.len % 16 != 0) { | 694 | if (ad.len % 16 != 0) { |
| 695 | const zeros = [_]u8{0} ** 16; | 695 | const zeros: [16]u8 = @splat(0); |
| 696 | const padding = 16 - (ad.len % 16); | 696 | const padding = 16 - (ad.len % 16); |
| 697 | mac.update(zeros[0..padding]); | 697 | mac.update(zeros[0..padding]); |
| 698 | } | 698 | } |
| 699 | mac.update(c); | 699 | mac.update(c); |
| 700 | if (c.len % 16 != 0) { | 700 | if (c.len % 16 != 0) { |
| 701 | const zeros = [_]u8{0} ** 16; | 701 | const zeros: [16]u8 = @splat(0); |
| 702 | const padding = 16 - (c.len % 16); | 702 | const padding = 16 - (c.len % 16); |
| 703 | mac.update(zeros[0..padding]); | 703 | mac.update(zeros[0..padding]); |
| 704 | } | 704 | } |
| ... | @@ -759,8 +759,8 @@ test "AEAD API" { | ... | @@ -759,8 +759,8 @@ test "AEAD API" { |
| 759 | const ad = "Additional data"; | 759 | const ad = "Additional data"; |
| 760 | 760 | ||
| 761 | inline for (aeads) |aead| { | 761 | inline for (aeads) |aead| { |
| 762 | const key = [_]u8{69} ** aead.key_length; | 762 | const key: [aead.key_length]u8 = @splat(69); |
| 763 | const nonce = [_]u8{42} ** aead.nonce_length; | 763 | const nonce: [aead.nonce_length]u8 = @splat(42); |
| 764 | var c: [m.len]u8 = undefined; | 764 | var c: [m.len]u8 = undefined; |
| 765 | var tag: [aead.tag_length]u8 = undefined; | 765 | var tag: [aead.tag_length]u8 = undefined; |
| 766 | var out: [m.len]u8 = undefined; | 766 | var out: [m.len]u8 = undefined; |
| ... | @@ -1138,8 +1138,8 @@ test "open" { | ... | @@ -1138,8 +1138,8 @@ test "open" { |
| 1138 | } | 1138 | } |
| 1139 | 1139 | ||
| 1140 | test "xchacha20" { | 1140 | test "xchacha20" { |
| 1141 | const key = [_]u8{69} ** 32; | 1141 | const key: [32]u8 = @splat(69); |
| 1142 | const nonce = [_]u8{42} ** 24; | 1142 | const nonce: [24]u8 = @splat(42); |
| 1143 | const m = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it."; | 1143 | const m = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it."; |
| 1144 | { | 1144 | { |
| 1145 | var c: [m.len]u8 = undefined; | 1145 | var c: [m.len]u8 = undefined; |
lib/std/crypto/cmac.zig+2-2| ... | @@ -20,7 +20,7 @@ pub fn Cmac(comptime BlockCipher: type) type { | ... | @@ -20,7 +20,7 @@ pub fn Cmac(comptime BlockCipher: type) type { |
| 20 | cipher_ctx: BlockCipherCtx, | 20 | cipher_ctx: BlockCipherCtx, |
| 21 | k1: Block, | 21 | k1: Block, |
| 22 | k2: Block, | 22 | k2: Block, |
| 23 | buf: Block = [_]u8{0} ** block_length, | 23 | buf: Block = @splat(0), |
| 24 | pos: usize = 0, | 24 | pos: usize = 0, |
| 25 | 25 | ||
| 26 | pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void { | 26 | pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void { |
| ... | @@ -31,7 +31,7 @@ pub fn Cmac(comptime BlockCipher: type) type { | ... | @@ -31,7 +31,7 @@ pub fn Cmac(comptime BlockCipher: type) type { |
| 31 | 31 | ||
| 32 | pub fn init(key: *const [key_length]u8) Self { | 32 | pub fn init(key: *const [key_length]u8) Self { |
| 33 | const cipher_ctx = BlockCipher.initEnc(key.*); | 33 | const cipher_ctx = BlockCipher.initEnc(key.*); |
| 34 | const zeros = [_]u8{0} ** block_length; | 34 | const zeros: [block_length]u8 = @splat(0); |
| 35 | var k1: Block = undefined; | 35 | var k1: Block = undefined; |
| 36 | cipher_ctx.encrypt(&k1, &zeros); | 36 | cipher_ctx.encrypt(&k1, &zeros); |
| 37 | k1 = double(k1); | 37 | k1 = double(k1); |
lib/std/crypto/codecs/asn1.zig+1-1| ... | @@ -233,7 +233,7 @@ test Element { | ... | @@ -233,7 +233,7 @@ test Element { |
| 233 | .slice = Element.Slice{ .start = 2, .end = short_form.len }, | 233 | .slice = Element.Slice{ .start = 2, .end = short_form.len }, |
| 234 | }, Element.decode(&short_form, 0)); | 234 | }, Element.decode(&short_form, 0)); |
| 235 | 235 | ||
| 236 | const long_form = [_]u8{ 0x30, 129, 129 } ++ [_]u8{0} ** 129; | 236 | const long_form = [_]u8{ 0x30, 129, 129 } ++ @as([129]u8, @splat(0)); |
| 237 | try std.testing.expectEqual(Element{ | 237 | try std.testing.expectEqual(Element{ |
| 238 | .tag = Tag.universal(.sequence, true), | 238 | .tag = Tag.universal(.sequence, true), |
| 239 | .slice = Element.Slice{ .start = 3, .end = long_form.len }, | 239 | .slice = Element.Slice{ .start = 3, .end = long_form.len }, |
lib/std/crypto/ecdsa.zig+9-9| ... | @@ -212,7 +212,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -212,7 +212,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 212 | fn finalizePrehashed(self: *Signer, msg_hash: [Hash.digest_length]u8) (IdentityElementError || NonCanonicalError)!Signature { | 212 | fn finalizePrehashed(self: *Signer, msg_hash: [Hash.digest_length]u8) (IdentityElementError || NonCanonicalError)!Signature { |
| 213 | const scalar_encoded_length = Curve.scalar.encoded_length; | 213 | const scalar_encoded_length = Curve.scalar.encoded_length; |
| 214 | const h_len = @max(Hash.digest_length, scalar_encoded_length); | 214 | const h_len = @max(Hash.digest_length, scalar_encoded_length); |
| 215 | var h: [h_len]u8 = [_]u8{0} ** (h_len - Hash.digest_length) ++ msg_hash; | 215 | var h: [h_len]u8 = @as([h_len - Hash.digest_length]u8, @splat(0)) ++ msg_hash; |
| 216 | 216 | ||
| 217 | std.debug.assert(h.len >= scalar_encoded_length); | 217 | std.debug.assert(h.len >= scalar_encoded_length); |
| 218 | const z = reduceToScalar(scalar_encoded_length, h[0..scalar_encoded_length].*); | 218 | const z = reduceToScalar(scalar_encoded_length, h[0..scalar_encoded_length].*); |
| ... | @@ -275,7 +275,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -275,7 +275,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 275 | fn verifyPrehashed(self: *Verifier, msg_hash: [Hash.digest_length]u8) VerifyError!void { | 275 | fn verifyPrehashed(self: *Verifier, msg_hash: [Hash.digest_length]u8) VerifyError!void { |
| 276 | const ht = Curve.scalar.encoded_length; | 276 | const ht = Curve.scalar.encoded_length; |
| 277 | const h_len = @max(Hash.digest_length, ht); | 277 | const h_len = @max(Hash.digest_length, ht); |
| 278 | var h: [h_len]u8 = [_]u8{0} ** (h_len - Hash.digest_length) ++ msg_hash; | 278 | var h: [h_len]u8 = @as([h_len - Hash.digest_length]u8, @splat(0)) ++ msg_hash; |
| 279 | 279 | ||
| 280 | const z = reduceToScalar(ht, h[0..ht].*); | 280 | const z = reduceToScalar(ht, h[0..ht].*); |
| 281 | if (z.isZero()) { | 281 | if (z.isZero()) { |
| ... | @@ -316,8 +316,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -316,8 +316,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 316 | /// | 316 | /// |
| 317 | /// Except in tests, applications should generally call `generate()` instead of this function. | 317 | /// Except in tests, applications should generally call `generate()` instead of this function. |
| 318 | pub fn generateDeterministic(seed: [seed_length]u8) IdentityElementError!KeyPair { | 318 | pub fn generateDeterministic(seed: [seed_length]u8) IdentityElementError!KeyPair { |
| 319 | const h = [_]u8{0x00} ** Hash.digest_length; | 319 | const h: [Hash.digest_length]u8 = @splat(0x00); |
| 320 | const k0 = [_]u8{0x01} ** SecretKey.encoded_length; | 320 | const k0: [SecretKey.encoded_length]u8 = @splat(0x01); |
| 321 | const secret_key = deterministicScalar(h, k0, seed).toBytes(.big); | 321 | const secret_key = deterministicScalar(h, k0, seed).toBytes(.big); |
| 322 | return fromSecretKey(SecretKey{ .bytes = secret_key }); | 322 | return fromSecretKey(SecretKey{ .bytes = secret_key }); |
| 323 | } | 323 | } |
| ... | @@ -367,11 +367,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -367,11 +367,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 367 | // Reduce the coordinate of a field element to the scalar field. | 367 | // Reduce the coordinate of a field element to the scalar field. |
| 368 | fn reduceToScalar(comptime unreduced_len: usize, s: [unreduced_len]u8) Curve.scalar.Scalar { | 368 | fn reduceToScalar(comptime unreduced_len: usize, s: [unreduced_len]u8) Curve.scalar.Scalar { |
| 369 | if (unreduced_len >= 48) { | 369 | if (unreduced_len >= 48) { |
| 370 | var xs = [_]u8{0} ** 64; | 370 | var xs: [64]u8 = @splat(0); |
| 371 | @memcpy(xs[xs.len - s.len ..], s[0..]); | 371 | @memcpy(xs[xs.len - s.len ..], s[0..]); |
| 372 | return Curve.scalar.Scalar.fromBytes64(xs, .big); | 372 | return Curve.scalar.Scalar.fromBytes64(xs, .big); |
| 373 | } | 373 | } |
| 374 | var xs = [_]u8{0} ** 48; | 374 | var xs: [48]u8 = @splat(0); |
| 375 | @memcpy(xs[xs.len - s.len ..], s[0..]); | 375 | @memcpy(xs[xs.len - s.len ..], s[0..]); |
| 376 | return Curve.scalar.Scalar.fromBytes48(xs, .big); | 376 | return Curve.scalar.Scalar.fromBytes48(xs, .big); |
| 377 | } | 377 | } |
| ... | @@ -379,9 +379,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -379,9 +379,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 379 | // Create a deterministic scalar according to a secret key and optional noise. | 379 | // Create a deterministic scalar according to a secret key and optional noise. |
| 380 | // This uses the overly conservative scheme from the "Deterministic ECDSA and EdDSA Signatures with Additional Randomness" draft. | 380 | // This uses the overly conservative scheme from the "Deterministic ECDSA and EdDSA Signatures with Additional Randomness" draft. |
| 381 | fn deterministicScalar(h: [Hash.digest_length]u8, secret_key: Curve.scalar.CompressedScalar, noise: ?[noise_length]u8) Curve.scalar.Scalar { | 381 | fn deterministicScalar(h: [Hash.digest_length]u8, secret_key: Curve.scalar.CompressedScalar, noise: ?[noise_length]u8) Curve.scalar.Scalar { |
| 382 | var k = [_]u8{0x00} ** h.len; | 382 | var k: [h.len]u8 = @splat(0); |
| 383 | var m = [_]u8{0x00} ** (h.len + 1 + noise_length + secret_key.len + h.len); | 383 | var m: [h.len + 1 + noise_length + secret_key.len + h.len]u8 = @splat(0); |
| 384 | var t = [_]u8{0x00} ** Curve.scalar.encoded_length; | 384 | var t: [Curve.scalar.encoded_length]u8 = @splat(0); |
| 385 | const m_v = m[0..h.len]; | 385 | const m_v = m[0..h.len]; |
| 386 | const m_i = &m[m_v.len]; | 386 | const m_i = &m[m_v.len]; |
| 387 | const m_z = m[m_v.len + 1 ..][0..noise_length]; | 387 | const m_z = m[m_v.len + 1 ..][0..noise_length]; |
lib/std/crypto/ff.zig+2-2| ... | @@ -96,7 +96,7 @@ pub fn Uint(comptime max_bits: comptime_int) type { | ... | @@ -96,7 +96,7 @@ pub fn Uint(comptime max_bits: comptime_int) type { |
| 96 | 96 | ||
| 97 | /// The zero integer. | 97 | /// The zero integer. |
| 98 | pub const zero: Self = .{ | 98 | pub const zero: Self = .{ |
| 99 | .limbs_buffer = [1]Limb{0} ** max_limbs_count, | 99 | .limbs_buffer = @splat(0), |
| 100 | .limbs_len = max_limbs_count, | 100 | .limbs_len = max_limbs_count, |
| 101 | }; | 101 | }; |
| 102 | 102 | ||
| ... | @@ -738,7 +738,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type { | ... | @@ -738,7 +738,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type { |
| 738 | } | 738 | } |
| 739 | } else { | 739 | } else { |
| 740 | // Use a precomputation table for large exponents | 740 | // Use a precomputation table for large exponents |
| 741 | var pc = [1]Fe{x} ++ [_]Fe{self.zero} ** 14; | 741 | var pc: [15]Fe = [1]Fe{x} ++ @as([14]Fe, @splat(self.zero)); |
| 742 | if (!x.montgomery) { | 742 | if (!x.montgomery) { |
| 743 | self.toMontgomery(&pc[0]) catch unreachable; | 743 | self.toMontgomery(&pc[0]) catch unreachable; |
| 744 | } | 744 | } |
lib/std/crypto/ghash_polyval.zig+4-4| ... | @@ -417,8 +417,8 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { | ... | @@ -417,8 +417,8 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { |
| 417 | const htest = @import("test.zig"); | 417 | const htest = @import("test.zig"); |
| 418 | 418 | ||
| 419 | test "ghash" { | 419 | test "ghash" { |
| 420 | const key = [_]u8{0x42} ** 16; | 420 | const key: [16]u8 = @splat(0x42); |
| 421 | const m = [_]u8{0x69} ** 256; | 421 | const m: [256]u8 = @splat(0x69); |
| 422 | 422 | ||
| 423 | var st = Ghash.init(&key); | 423 | var st = Ghash.init(&key); |
| 424 | st.update(&m); | 424 | st.update(&m); |
| ... | @@ -467,8 +467,8 @@ test "ghash2" { | ... | @@ -467,8 +467,8 @@ test "ghash2" { |
| 467 | } | 467 | } |
| 468 | 468 | ||
| 469 | test "polyval" { | 469 | test "polyval" { |
| 470 | const key = [_]u8{0x42} ** 16; | 470 | const key: [16]u8 = @splat(0x42); |
| 471 | const m = [_]u8{0x69} ** 256; | 471 | const m: [256]u8 = @splat(0x69); |
| 472 | 472 | ||
| 473 | var st = Polyval.init(&key); | 473 | var st = Polyval.init(&key); |
| 474 | st.update(&m); | 474 | st.update(&m); |
lib/std/crypto/hkdf.zig+1-1| ... | @@ -72,7 +72,7 @@ pub fn Hkdf(comptime Hmac: type) type { | ... | @@ -72,7 +72,7 @@ pub fn Hkdf(comptime Hmac: type) type { |
| 72 | const htest = @import("test.zig"); | 72 | const htest = @import("test.zig"); |
| 73 | 73 | ||
| 74 | test "Hkdf" { | 74 | test "Hkdf" { |
| 75 | const ikm = [_]u8{0x0b} ** 22; | 75 | const ikm: [22]u8 = @splat(0x0b); |
| 76 | const salt = [_]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c }; | 76 | const salt = [_]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c }; |
| 77 | const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; | 77 | const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; |
| 78 | const kdf = HkdfSha256; | 78 | const kdf = HkdfSha256; |
lib/std/crypto/isap.zig+3-3| ... | @@ -42,7 +42,7 @@ pub const IsapA128A = struct { | ... | @@ -42,7 +42,7 @@ pub const IsapA128A = struct { |
| 42 | break; | 42 | break; |
| 43 | } | 43 | } |
| 44 | } else { | 44 | } else { |
| 45 | var padded = [_]u8{0} ** 8; | 45 | var padded: [8]u8 = @splat(0); |
| 46 | @memcpy(padded[0..left], m[i..]); | 46 | @memcpy(padded[0..left], m[i..]); |
| 47 | padded[left] = 0x80; | 47 | padded[left] = 0x80; |
| 48 | isap.st.addBytes(&padded); | 48 | isap.st.addBytes(&padded); |
| ... | @@ -169,8 +169,8 @@ pub const IsapA128A = struct { | ... | @@ -169,8 +169,8 @@ pub const IsapA128A = struct { |
| 169 | }; | 169 | }; |
| 170 | 170 | ||
| 171 | test "ISAP" { | 171 | test "ISAP" { |
| 172 | const k = [_]u8{1} ** 16; | 172 | const k: [16]u8 = @splat(1); |
| 173 | const n = [_]u8{2} ** 16; | 173 | const n: [16]u8 = @splat(2); |
| 174 | var tag: [16]u8 = undefined; | 174 | var tag: [16]u8 = undefined; |
| 175 | const ad = "ad"; | 175 | const ad = "ad"; |
| 176 | var msg = "test"; | 176 | var msg = "test"; |
lib/std/crypto/kangarootwelve.zig+1-1| ... | @@ -881,7 +881,7 @@ fn ktMultiThreaded( | ... | @@ -881,7 +881,7 @@ fn ktMultiThreaded( |
| 881 | // Buffer for out-of-order results (select_buf slots get reused) | 881 | // Buffer for out-of-order results (select_buf slots get reused) |
| 882 | const pending_cv_buf = try allocator.alloc([leaves_per_batch * cv_size]u8, max_concurrent); | 882 | const pending_cv_buf = try allocator.alloc([leaves_per_batch * cv_size]u8, max_concurrent); |
| 883 | defer allocator.free(pending_cv_buf); | 883 | defer allocator.free(pending_cv_buf); |
| 884 | var pending_cv_lens: [256]usize = .{0} ** 256; | 884 | var pending_cv_lens: [256]usize = @splat(0); |
| 885 | 885 | ||
| 886 | var select_outstanding: usize = 0; | 886 | var select_outstanding: usize = 0; |
| 887 | var select: Select = .init(io, select_buf); | 887 | var select: Select = .init(io, select_buf); |
lib/std/crypto/keccak_p.zig+7-7| ... | @@ -40,7 +40,7 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -40,7 +40,7 @@ pub fn KeccakF(comptime f: u11) type { |
| 40 | break :rc rc; | 40 | break :rc rc; |
| 41 | }; | 41 | }; |
| 42 | 42 | ||
| 43 | st: Block = [_]T{0} ** 25, | 43 | st: Block = @splat(0), |
| 44 | 44 | ||
| 45 | /// Initialize the state from a slice of bytes. | 45 | /// Initialize the state from a slice of bytes. |
| 46 | pub fn init(bytes: [block_bytes]u8) Self { | 46 | pub fn init(bytes: [block_bytes]u8) Self { |
| ... | @@ -70,7 +70,7 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -70,7 +70,7 @@ pub fn KeccakF(comptime f: u11) type { |
| 70 | self.st[i / @sizeOf(T)] = mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little); | 70 | self.st[i / @sizeOf(T)] = mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little); |
| 71 | } | 71 | } |
| 72 | if (i < bytes.len) { | 72 | if (i < bytes.len) { |
| 73 | var padded = [_]u8{0} ** @sizeOf(T); | 73 | var padded: [@sizeOf(T)]u8 = @splat(0); |
| 74 | @memcpy(padded[0 .. bytes.len - i], bytes[i..]); | 74 | @memcpy(padded[0 .. bytes.len - i], bytes[i..]); |
| 75 | self.st[i / @sizeOf(T)] = mem.readInt(T, padded[0..], .little); | 75 | self.st[i / @sizeOf(T)] = mem.readInt(T, padded[0..], .little); |
| 76 | } | 76 | } |
| ... | @@ -89,7 +89,7 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -89,7 +89,7 @@ pub fn KeccakF(comptime f: u11) type { |
| 89 | self.st[i / @sizeOf(T)] ^= mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little); | 89 | self.st[i / @sizeOf(T)] ^= mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little); |
| 90 | } | 90 | } |
| 91 | if (i < bytes.len) { | 91 | if (i < bytes.len) { |
| 92 | var padded = [_]u8{0} ** @sizeOf(T); | 92 | var padded: [@sizeOf(T)]u8 = @splat(0); |
| 93 | @memcpy(padded[0 .. bytes.len - i], bytes[i..]); | 93 | @memcpy(padded[0 .. bytes.len - i], bytes[i..]); |
| 94 | self.st[i / @sizeOf(T)] ^= mem.readInt(T, padded[0..], .little); | 94 | self.st[i / @sizeOf(T)] ^= mem.readInt(T, padded[0..], .little); |
| 95 | } | 95 | } |
| ... | @@ -102,7 +102,7 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -102,7 +102,7 @@ pub fn KeccakF(comptime f: u11) type { |
| 102 | mem.writeInt(T, out[i..][0..@sizeOf(T)], self.st[i / @sizeOf(T)], .little); | 102 | mem.writeInt(T, out[i..][0..@sizeOf(T)], self.st[i / @sizeOf(T)], .little); |
| 103 | } | 103 | } |
| 104 | if (i < out.len) { | 104 | if (i < out.len) { |
| 105 | var padded = [_]u8{0} ** @sizeOf(T); | 105 | var padded: [@sizeOf(T)]u8 = @splat(0); |
| 106 | mem.writeInt(T, padded[0..], self.st[i / @sizeOf(T)], .little); | 106 | mem.writeInt(T, padded[0..], self.st[i / @sizeOf(T)], .little); |
| 107 | @memcpy(out[i..], padded[0 .. out.len - i]); | 107 | @memcpy(out[i..], padded[0 .. out.len - i]); |
| 108 | } | 108 | } |
| ... | @@ -118,7 +118,7 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -118,7 +118,7 @@ pub fn KeccakF(comptime f: u11) type { |
| 118 | mem.writeInt(T, out[i..][0..@sizeOf(T)], x, native_endian); | 118 | mem.writeInt(T, out[i..][0..@sizeOf(T)], x, native_endian); |
| 119 | } | 119 | } |
| 120 | if (i < in.len) { | 120 | if (i < in.len) { |
| 121 | var padded = [_]u8{0} ** @sizeOf(T); | 121 | var padded: [@sizeOf(T)]u8 = @splat(0); |
| 122 | @memcpy(padded[0 .. in.len - i], in[i..]); | 122 | @memcpy(padded[0 .. in.len - i], in[i..]); |
| 123 | const x = mem.readInt(T, &padded, native_endian) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]); | 123 | const x = mem.readInt(T, &padded, native_endian) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]); |
| 124 | mem.writeInt(T, &padded, x, native_endian); | 124 | mem.writeInt(T, &padded, x, native_endian); |
| ... | @@ -140,7 +140,7 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -140,7 +140,7 @@ pub fn KeccakF(comptime f: u11) type { |
| 140 | const st = &self.st; | 140 | const st = &self.st; |
| 141 | 141 | ||
| 142 | // theta | 142 | // theta |
| 143 | var t = [_]T{0} ** 5; | 143 | var t: [5]T = @splat(0); |
| 144 | inline for (0..5) |i| { | 144 | inline for (0..5) |i| { |
| 145 | inline for (0..5) |j| { | 145 | inline for (0..5) |j| { |
| 146 | t[i] ^= st[j * 5 + i]; | 146 | t[i] ^= st[j * 5 + i]; |
| ... | @@ -382,7 +382,7 @@ test "Keccak-f800" { | ... | @@ -382,7 +382,7 @@ test "Keccak-f800" { |
| 382 | } | 382 | } |
| 383 | 383 | ||
| 384 | test "squeeze" { | 384 | test "squeeze" { |
| 385 | var st = State(800, 256, 22).init([_]u8{0x80} ** 100, 0x01); | 385 | var st: State(800, 256, 22) = .init(@splat(0x80), 0x01); |
| 386 | 386 | ||
| 387 | var out0: [15]u8 = undefined; | 387 | var out0: [15]u8 = undefined; |
| 388 | var out1: [out0.len]u8 = undefined; | 388 | var out1: [out0.len]u8 = undefined; |
lib/std/crypto/md5.zig+1-1| ... | @@ -272,7 +272,7 @@ test "streaming" { | ... | @@ -272,7 +272,7 @@ test "streaming" { |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | test "aligned final" { | 274 | test "aligned final" { |
| 275 | var block = [_]u8{0} ** Md5.block_length; | 275 | const block: [Md5.block_length]u8 = @splat(0); |
| 276 | var out: [Md5.digest_length]u8 = undefined; | 276 | var out: [Md5.digest_length]u8 = undefined; |
| 277 | 277 | ||
| 278 | var h = Md5.init(.{}); | 278 | var h = Md5.init(.{}); |
lib/std/crypto/ml_dsa.zig+33-33| ... | @@ -156,7 +156,7 @@ const Params = struct { | ... | @@ -156,7 +156,7 @@ const Params = struct { |
| 156 | const Poly = struct { | 156 | const Poly = struct { |
| 157 | cs: [N]u32, | 157 | cs: [N]u32, |
| 158 | 158 | ||
| 159 | const zero: Poly = .{ .cs = .{0} ** N }; | 159 | const zero: Poly = .{ .cs = @splat(0) }; |
| 160 | 160 | ||
| 161 | // Add two polynomials (no normalization) | 161 | // Add two polynomials (no normalization) |
| 162 | fn add(a: Poly, b: Poly) Poly { | 162 | fn add(a: Poly, b: Poly) Poly { |
| ... | @@ -302,7 +302,7 @@ fn PolyVec(comptime len: u8) type { | ... | @@ -302,7 +302,7 @@ fn PolyVec(comptime len: u8) type { |
| 302 | ps: [len]Poly, | 302 | ps: [len]Poly, |
| 303 | 303 | ||
| 304 | const Self = @This(); | 304 | const Self = @This(); |
| 305 | const zero: Self = .{ .ps = .{Poly.zero} ** len }; | 305 | const zero: Self = .{ .ps = @splat(.zero) }; |
| 306 | 306 | ||
| 307 | /// Apply a unary operation to each polynomial in the vector | 307 | /// Apply a unary operation to each polynomial in the vector |
| 308 | fn map(v: Self, comptime op: fn (Poly) Poly) Self { | 308 | fn map(v: Self, comptime op: fn (Poly) Poly) Self { |
| ... | @@ -581,7 +581,7 @@ fn PolyVec(comptime len: u8) type { | ... | @@ -581,7 +581,7 @@ fn PolyVec(comptime len: u8) type { |
| 581 | 581 | ||
| 582 | /// Unpack hints from bytes | 582 | /// Unpack hints from bytes |
| 583 | fn unpackHint(comptime omega: u16, buf: []const u8) ?Self { | 583 | fn unpackHint(comptime omega: u16, buf: []const u8) ?Self { |
| 584 | var result: Self = .{ .ps = .{Poly.zero} ** len }; | 584 | var result: Self = .{ .ps = @splat(.zero) }; |
| 585 | var prev_sop: u8 = 0; // previous switch-over-point | 585 | var prev_sop: u8 = 0; // previous switch-over-point |
| 586 | 586 | ||
| 587 | for (0..len) |i| { | 587 | for (0..len) |i| { |
| ... | @@ -1839,7 +1839,7 @@ fn MLDSAImpl(comptime p: Params) type { | ... | @@ -1839,7 +1839,7 @@ fn MLDSAImpl(comptime p: Params) type { |
| 1839 | return Signer{ | 1839 | return Signer{ |
| 1840 | .h = h, | 1840 | .h = h, |
| 1841 | .secret_key = secret_key, | 1841 | .secret_key = secret_key, |
| 1842 | .rnd = noise orelse .{0} ** 32, | 1842 | .rnd = noise orelse @splat(0), |
| 1843 | }; | 1843 | }; |
| 1844 | } | 1844 | } |
| 1845 | 1845 | ||
| ... | @@ -2324,7 +2324,7 @@ test "decompose correctness for ML-DSA-87" { | ... | @@ -2324,7 +2324,7 @@ test "decompose correctness for ML-DSA-87" { |
| 2324 | 2324 | ||
| 2325 | test "polyDeriveUniform deterministic" { | 2325 | test "polyDeriveUniform deterministic" { |
| 2326 | // Test that polyDeriveUniform produces deterministic results | 2326 | // Test that polyDeriveUniform produces deterministic results |
| 2327 | const seed: [32]u8 = .{0x01} ++ .{0x00} ** 31; | 2327 | const seed: [32]u8 = .{0x01} ++ @as([31]u8, @splat(0x00)); |
| 2328 | const nonce: u16 = 0; | 2328 | const nonce: u16 = 0; |
| 2329 | 2329 | ||
| 2330 | const p1 = polyDeriveUniform(&seed, nonce); | 2330 | const p1 = polyDeriveUniform(&seed, nonce); |
| ... | @@ -2343,7 +2343,7 @@ test "polyDeriveUniform deterministic" { | ... | @@ -2343,7 +2343,7 @@ test "polyDeriveUniform deterministic" { |
| 2343 | 2343 | ||
| 2344 | test "polyDeriveUniform different nonces" { | 2344 | test "polyDeriveUniform different nonces" { |
| 2345 | // Test that different nonces produce different polynomials | 2345 | // Test that different nonces produce different polynomials |
| 2346 | const seed: [32]u8 = .{0x01} ++ .{0x00} ** 31; | 2346 | const seed: [32]u8 = .{0x01} ++ @as([31]u8, @splat(0x00)); |
| 2347 | 2347 | ||
| 2348 | const p1 = polyDeriveUniform(&seed, 0); | 2348 | const p1 = polyDeriveUniform(&seed, 0); |
| 2349 | const p2 = polyDeriveUniform(&seed, 1); | 2349 | const p2 = polyDeriveUniform(&seed, 1); |
| ... | @@ -2361,7 +2361,7 @@ test "polyDeriveUniform different nonces" { | ... | @@ -2361,7 +2361,7 @@ test "polyDeriveUniform different nonces" { |
| 2361 | 2361 | ||
| 2362 | test "expandS with eta=2" { | 2362 | test "expandS with eta=2" { |
| 2363 | // Test eta=2 sampling | 2363 | // Test eta=2 sampling |
| 2364 | const seed: [64]u8 = .{0x02} ++ .{0x00} ** 63; | 2364 | const seed: [64]u8 = .{0x02} ++ @as([63]u8, @splat(0x00)); |
| 2365 | const nonce: u16 = 0; | 2365 | const nonce: u16 = 0; |
| 2366 | 2366 | ||
| 2367 | const p = expandS(2, &seed, nonce); | 2367 | const p = expandS(2, &seed, nonce); |
| ... | @@ -2378,7 +2378,7 @@ test "expandS with eta=2" { | ... | @@ -2378,7 +2378,7 @@ test "expandS with eta=2" { |
| 2378 | 2378 | ||
| 2379 | test "expandS with eta=4" { | 2379 | test "expandS with eta=4" { |
| 2380 | // Test eta=4 sampling | 2380 | // Test eta=4 sampling |
| 2381 | const seed: [64]u8 = .{0x03} ++ .{0x00} ** 63; | 2381 | const seed: [64]u8 = .{0x03} ++ @as([63]u8, @splat(0x00)); |
| 2382 | const nonce: u16 = 0; | 2382 | const nonce: u16 = 0; |
| 2383 | 2383 | ||
| 2384 | const p = expandS(4, &seed, nonce); | 2384 | const p = expandS(4, &seed, nonce); |
| ... | @@ -2395,7 +2395,7 @@ test "expandS with eta=4" { | ... | @@ -2395,7 +2395,7 @@ test "expandS with eta=4" { |
| 2395 | test "sampleInBall has correct weight" { | 2395 | test "sampleInBall has correct weight" { |
| 2396 | // Test that ball polynomial has exactly tau non-zero coefficients | 2396 | // Test that ball polynomial has exactly tau non-zero coefficients |
| 2397 | const tau = 39; // From ML-DSA-44 | 2397 | const tau = 39; // From ML-DSA-44 |
| 2398 | const seed: [32]u8 = .{0x04} ++ .{0x00} ** 31; | 2398 | const seed: [32]u8 = .{0x03} ++ @as([31]u8, @splat(0x00)); |
| 2399 | 2399 | ||
| 2400 | const p = sampleInBall(tau, &seed); | 2400 | const p = sampleInBall(tau, &seed); |
| 2401 | 2401 | ||
| ... | @@ -2415,7 +2415,7 @@ test "sampleInBall has correct weight" { | ... | @@ -2415,7 +2415,7 @@ test "sampleInBall has correct weight" { |
| 2415 | test "sampleInBall deterministic" { | 2415 | test "sampleInBall deterministic" { |
| 2416 | // Test that ball sampling is deterministic | 2416 | // Test that ball sampling is deterministic |
| 2417 | const tau = 49; // From ML-DSA-65 | 2417 | const tau = 49; // From ML-DSA-65 |
| 2418 | const seed: [32]u8 = .{0x05} ++ .{0x00} ** 31; | 2418 | const seed: [32]u8 = .{0x05} ++ @as([31]u8, @splat(0x00)); |
| 2419 | 2419 | ||
| 2420 | const p1 = sampleInBall(tau, &seed); | 2420 | const p1 = sampleInBall(tau, &seed); |
| 2421 | const p2 = sampleInBall(tau, &seed); | 2421 | const p2 = sampleInBall(tau, &seed); |
| ... | @@ -2851,13 +2851,13 @@ test "Key generation basic - all variants" { | ... | @@ -2851,13 +2851,13 @@ test "Key generation basic - all variants" { |
| 2851 | .{ .variant = MLDSA65, .seed_byte = 0x65 }, | 2851 | .{ .variant = MLDSA65, .seed_byte = 0x65 }, |
| 2852 | .{ .variant = MLDSA87, .seed_byte = 0x87 }, | 2852 | .{ .variant = MLDSA87, .seed_byte = 0x87 }, |
| 2853 | }) |config| { | 2853 | }) |config| { |
| 2854 | const seed = [_]u8{config.seed_byte} ** 32; | 2854 | const seed: [32]u8 = @splat(config.seed_byte); |
| 2855 | try testKeyGenerationBasic(config.variant, seed); | 2855 | try testKeyGenerationBasic(config.variant, seed); |
| 2856 | } | 2856 | } |
| 2857 | } | 2857 | } |
| 2858 | 2858 | ||
| 2859 | test "Key generation determinism" { | 2859 | test "Key generation determinism" { |
| 2860 | const seed = [_]u8{ 0x12, 0x34, 0x56, 0x78 } ++ [_]u8{0xAB} ** 28; | 2860 | const seed = [_]u8{ 0x12, 0x34, 0x56, 0x78 } ++ @as([28]u8, @splat(0xAB)); |
| 2861 | 2861 | ||
| 2862 | // Generate two key pairs from the same seed | 2862 | // Generate two key pairs from the same seed |
| 2863 | const result1 = MLDSA44.newKeyFromSeed(&seed); | 2863 | const result1 = MLDSA44.newKeyFromSeed(&seed); |
| ... | @@ -2874,7 +2874,7 @@ test "Key generation determinism" { | ... | @@ -2874,7 +2874,7 @@ test "Key generation determinism" { |
| 2874 | } | 2874 | } |
| 2875 | 2875 | ||
| 2876 | test "Private key can compute public key" { | 2876 | test "Private key can compute public key" { |
| 2877 | const seed = [_]u8{0xFF} ** 32; | 2877 | const seed: [32]u8 = @splat(0xFF); |
| 2878 | const result = MLDSA44.newKeyFromSeed(&seed); | 2878 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 2879 | const pk = result.pk; | 2879 | const pk = result.pk; |
| 2880 | const sk = result.sk; | 2880 | const sk = result.sk; |
| ... | @@ -2907,13 +2907,13 @@ test "Sign and verify - all variants" { | ... | @@ -2907,13 +2907,13 @@ test "Sign and verify - all variants" { |
| 2907 | .{ .variant = MLDSA65, .seed_byte = 0x65, .message = "Hello, ML-DSA-65!" }, | 2907 | .{ .variant = MLDSA65, .seed_byte = 0x65, .message = "Hello, ML-DSA-65!" }, |
| 2908 | .{ .variant = MLDSA87, .seed_byte = 0x87, .message = "Hello, ML-DSA-87!" }, | 2908 | .{ .variant = MLDSA87, .seed_byte = 0x87, .message = "Hello, ML-DSA-87!" }, |
| 2909 | }) |config| { | 2909 | }) |config| { |
| 2910 | const seed = [_]u8{config.seed_byte} ** 32; | 2910 | const seed: [32]u8 = @splat(config.seed_byte); |
| 2911 | try testSignAndVerify(config.variant, seed, config.message); | 2911 | try testSignAndVerify(config.variant, seed, config.message); |
| 2912 | } | 2912 | } |
| 2913 | } | 2913 | } |
| 2914 | 2914 | ||
| 2915 | test "Invalid signature rejection" { | 2915 | test "Invalid signature rejection" { |
| 2916 | const seed = [_]u8{0x99} ** 32; | 2916 | const seed: [32]u8 = @splat(0x99); |
| 2917 | const result = MLDSA44.newKeyFromSeed(&seed); | 2917 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 2918 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); | 2918 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); |
| 2919 | 2919 | ||
| ... | @@ -2934,7 +2934,7 @@ test "Invalid signature rejection" { | ... | @@ -2934,7 +2934,7 @@ test "Invalid signature rejection" { |
| 2934 | } | 2934 | } |
| 2935 | 2935 | ||
| 2936 | test "Context string support" { | 2936 | test "Context string support" { |
| 2937 | const seed = [_]u8{0xAA} ** 32; | 2937 | const seed: [32]u8 = @splat(0xAA); |
| 2938 | const result = MLDSA44.newKeyFromSeed(&seed); | 2938 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 2939 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); | 2939 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); |
| 2940 | 2940 | ||
| ... | @@ -2964,17 +2964,17 @@ test "Context string support" { | ... | @@ -2964,17 +2964,17 @@ test "Context string support" { |
| 2964 | try testing.expectError(error.SignatureVerificationFailed, sig2.verifyWithContext(message, kp.public_key, context1)); | 2964 | try testing.expectError(error.SignatureVerificationFailed, sig2.verifyWithContext(message, kp.public_key, context1)); |
| 2965 | 2965 | ||
| 2966 | // Test maximum context length (255 bytes) | 2966 | // Test maximum context length (255 bytes) |
| 2967 | const max_context = [_]u8{0xBB} ** 255; | 2967 | const max_context: [255]u8 = @splat(0xBB); |
| 2968 | const sig3 = try kp.signWithContext(message, null, &max_context); | 2968 | const sig3 = try kp.signWithContext(message, null, &max_context); |
| 2969 | try sig3.verifyWithContext(message, kp.public_key, &max_context); | 2969 | try sig3.verifyWithContext(message, kp.public_key, &max_context); |
| 2970 | 2970 | ||
| 2971 | // Test context too long (256 bytes should fail) | 2971 | // Test context too long (256 bytes should fail) |
| 2972 | const too_long_context = [_]u8{0xCC} ** 256; | 2972 | const too_long_context: [256]u8 = @splat(0xCC); |
| 2973 | try testing.expectError(error.ContextTooLong, kp.signWithContext(message, null, &too_long_context)); | 2973 | try testing.expectError(error.ContextTooLong, kp.signWithContext(message, null, &too_long_context)); |
| 2974 | } | 2974 | } |
| 2975 | 2975 | ||
| 2976 | test "Context string with streaming API" { | 2976 | test "Context string with streaming API" { |
| 2977 | const seed = [_]u8{0xDD} ** 32; | 2977 | const seed: [32]u8 = @splat(0xDD); |
| 2978 | const result = MLDSA44.newKeyFromSeed(&seed); | 2978 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 2979 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); | 2979 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); |
| 2980 | 2980 | ||
| ... | @@ -3002,12 +3002,12 @@ test "Context string with streaming API" { | ... | @@ -3002,12 +3002,12 @@ test "Context string with streaming API" { |
| 3002 | } | 3002 | } |
| 3003 | 3003 | ||
| 3004 | test "Signature determinism (same rnd)" { | 3004 | test "Signature determinism (same rnd)" { |
| 3005 | const seed = [_]u8{0x11} ** 32; | 3005 | const seed: [32]u8 = @splat(0x11); |
| 3006 | const result = MLDSA44.newKeyFromSeed(&seed); | 3006 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 3007 | const sk = result.sk; | 3007 | const sk = result.sk; |
| 3008 | 3008 | ||
| 3009 | const message = "Deterministic test"; | 3009 | const message = "Deterministic test"; |
| 3010 | const rnd = [_]u8{0x22} ** 32; | 3010 | const rnd: [32]u8 = @splat(0x22); |
| 3011 | 3011 | ||
| 3012 | // Sign twice with same randomness using streaming API | 3012 | // Sign twice with same randomness using streaming API |
| 3013 | var st1 = try sk.signer(rnd); | 3013 | var st1 = try sk.signer(rnd); |
| ... | @@ -3023,7 +3023,7 @@ test "Signature determinism (same rnd)" { | ... | @@ -3023,7 +3023,7 @@ test "Signature determinism (same rnd)" { |
| 3023 | } | 3023 | } |
| 3024 | 3024 | ||
| 3025 | test "Signature toBytes/fromBytes roundtrip" { | 3025 | test "Signature toBytes/fromBytes roundtrip" { |
| 3026 | const seed = [_]u8{0x33} ** 32; | 3026 | const seed: [32]u8 = @splat(0x33); |
| 3027 | const result = MLDSA44.newKeyFromSeed(&seed); | 3027 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 3028 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); | 3028 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); |
| 3029 | 3029 | ||
| ... | @@ -3043,7 +3043,7 @@ test "Signature toBytes/fromBytes roundtrip" { | ... | @@ -3043,7 +3043,7 @@ test "Signature toBytes/fromBytes roundtrip" { |
| 3043 | } | 3043 | } |
| 3044 | 3044 | ||
| 3045 | test "Empty message signing" { | 3045 | test "Empty message signing" { |
| 3046 | const seed = [_]u8{0x44} ** 32; | 3046 | const seed: [32]u8 = @splat(0x44); |
| 3047 | const result = MLDSA44.newKeyFromSeed(&seed); | 3047 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 3048 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); | 3048 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); |
| 3049 | 3049 | ||
| ... | @@ -3057,12 +3057,12 @@ test "Empty message signing" { | ... | @@ -3057,12 +3057,12 @@ test "Empty message signing" { |
| 3057 | } | 3057 | } |
| 3058 | 3058 | ||
| 3059 | test "Long message signing" { | 3059 | test "Long message signing" { |
| 3060 | const seed = [_]u8{0x55} ** 32; | 3060 | const seed: [32]u8 = @splat(0x55); |
| 3061 | const result = MLDSA44.newKeyFromSeed(&seed); | 3061 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 3062 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); | 3062 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); |
| 3063 | 3063 | ||
| 3064 | // Create a long message (1KB) | 3064 | // Create a long message (1KB) |
| 3065 | const long_message = [_]u8{0xAB} ** 1024; | 3065 | const long_message: [1024]u8 = @splat(0xAB); |
| 3066 | 3066 | ||
| 3067 | // Sign long message | 3067 | // Sign long message |
| 3068 | const sig = try kp.sign(&long_message, null); | 3068 | const sig = try kp.sign(&long_message, null); |
| ... | @@ -3209,7 +3209,7 @@ test "KeyPair API - generate and sign" { | ... | @@ -3209,7 +3209,7 @@ test "KeyPair API - generate and sign" { |
| 3209 | 3209 | ||
| 3210 | test "KeyPair API - generateDeterministic" { | 3210 | test "KeyPair API - generateDeterministic" { |
| 3211 | // Test deterministic key generation | 3211 | // Test deterministic key generation |
| 3212 | const seed = [_]u8{42} ** 32; | 3212 | const seed: [32]u8 = @splat(42); |
| 3213 | const kp1 = try MLDSA44.KeyPair.generateDeterministic(seed); | 3213 | const kp1 = try MLDSA44.KeyPair.generateDeterministic(seed); |
| 3214 | const kp2 = try MLDSA44.KeyPair.generateDeterministic(seed); | 3214 | const kp2 = try MLDSA44.KeyPair.generateDeterministic(seed); |
| 3215 | 3215 | ||
| ... | @@ -3240,7 +3240,7 @@ test "Signature verification with noise" { | ... | @@ -3240,7 +3240,7 @@ test "Signature verification with noise" { |
| 3240 | const msg = "Message to be signed with randomness"; | 3240 | const msg = "Message to be signed with randomness"; |
| 3241 | 3241 | ||
| 3242 | // Create some noise | 3242 | // Create some noise |
| 3243 | const noise = [_]u8{ 1, 2, 3, 4, 5 } ++ [_]u8{0} ** 27; | 3243 | const noise = [_]u8{ 1, 2, 3, 4, 5 } ++ @as([27]u8, @splat(0)); |
| 3244 | 3244 | ||
| 3245 | // Sign with noise | 3245 | // Sign with noise |
| 3246 | const sig = try kp.sign(msg, noise); | 3246 | const sig = try kp.sign(msg, noise); |
| ... | @@ -3262,7 +3262,7 @@ test "Signature verification failure" { | ... | @@ -3262,7 +3262,7 @@ test "Signature verification failure" { |
| 3262 | } | 3262 | } |
| 3263 | 3263 | ||
| 3264 | test "Streaming API - sign and verify" { | 3264 | test "Streaming API - sign and verify" { |
| 3265 | const seed = [_]u8{0x55} ** 32; | 3265 | const seed: [32]u8 = @splat(0x55); |
| 3266 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); | 3266 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); |
| 3267 | 3267 | ||
| 3268 | const msg = "Test message for streaming API"; | 3268 | const msg = "Test message for streaming API"; |
| ... | @@ -3279,7 +3279,7 @@ test "Streaming API - sign and verify" { | ... | @@ -3279,7 +3279,7 @@ test "Streaming API - sign and verify" { |
| 3279 | } | 3279 | } |
| 3280 | 3280 | ||
| 3281 | test "Streaming API - chunked message" { | 3281 | test "Streaming API - chunked message" { |
| 3282 | const seed = [_]u8{0x66} ** 32; | 3282 | const seed: [32]u8 = @splat(0x66); |
| 3283 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); | 3283 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); |
| 3284 | 3284 | ||
| 3285 | // Create a message in chunks | 3285 | // Create a message in chunks |
| ... | @@ -3313,7 +3313,7 @@ test "Streaming API - chunked message" { | ... | @@ -3313,7 +3313,7 @@ test "Streaming API - chunked message" { |
| 3313 | } | 3313 | } |
| 3314 | 3314 | ||
| 3315 | test "Streaming API - large message" { | 3315 | test "Streaming API - large message" { |
| 3316 | const seed = [_]u8{0x77} ** 32; | 3316 | const seed: [32]u8 = @splat(0x77); |
| 3317 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); | 3317 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); |
| 3318 | 3318 | ||
| 3319 | // Create a large message (1MB) | 3319 | // Create a large message (1MB) |
| ... | @@ -3344,7 +3344,7 @@ test "Streaming API - all parameter sets" { | ... | @@ -3344,7 +3344,7 @@ test "Streaming API - all parameter sets" { |
| 3344 | 3344 | ||
| 3345 | // ML-DSA-44 | 3345 | // ML-DSA-44 |
| 3346 | { | 3346 | { |
| 3347 | const seed = [_]u8{0x44} ** 32; | 3347 | const seed: [32]u8 = @splat(0x44); |
| 3348 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); | 3348 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); |
| 3349 | var signer = try kp.signer(null); | 3349 | var signer = try kp.signer(null); |
| 3350 | signer.update(test_msg); | 3350 | signer.update(test_msg); |
| ... | @@ -3356,7 +3356,7 @@ test "Streaming API - all parameter sets" { | ... | @@ -3356,7 +3356,7 @@ test "Streaming API - all parameter sets" { |
| 3356 | 3356 | ||
| 3357 | // ML-DSA-65 | 3357 | // ML-DSA-65 |
| 3358 | { | 3358 | { |
| 3359 | const seed = [_]u8{0x65} ** 32; | 3359 | const seed: [32]u8 = @splat(0x65); |
| 3360 | const kp = try MLDSA65.KeyPair.generateDeterministic(seed); | 3360 | const kp = try MLDSA65.KeyPair.generateDeterministic(seed); |
| 3361 | var signer = try kp.signer(null); | 3361 | var signer = try kp.signer(null); |
| 3362 | signer.update(test_msg); | 3362 | signer.update(test_msg); |
| ... | @@ -3368,7 +3368,7 @@ test "Streaming API - all parameter sets" { | ... | @@ -3368,7 +3368,7 @@ test "Streaming API - all parameter sets" { |
| 3368 | 3368 | ||
| 3369 | // ML-DSA-87 | 3369 | // ML-DSA-87 |
| 3370 | { | 3370 | { |
| 3371 | const seed = [_]u8{0x87} ** 32; | 3371 | const seed: [32]u8 = @splat(0x87); |
| 3372 | const kp = try MLDSA87.KeyPair.generateDeterministic(seed); | 3372 | const kp = try MLDSA87.KeyPair.generateDeterministic(seed); |
| 3373 | var signer = try kp.signer(null); | 3373 | var signer = try kp.signer(null); |
| 3374 | signer.update(test_msg); | 3374 | signer.update(test_msg); |
lib/std/crypto/ml_kem.zig+4-4| ... | @@ -615,7 +615,7 @@ const inv_ntt_reductions = [_]i16{ | ... | @@ -615,7 +615,7 @@ const inv_ntt_reductions = [_]i16{ |
| 615 | test "invNTTReductions bounds" { | 615 | test "invNTTReductions bounds" { |
| 616 | // Checks whether the reductions proposed by invNTTReductions | 616 | // Checks whether the reductions proposed by invNTTReductions |
| 617 | // don't overflow during invNTT(). | 617 | // don't overflow during invNTT(). |
| 618 | var xs = [_]i32{1} ** 256; // start at |x| ≤ q | 618 | var xs: [256]i32 = @splat(1); // start at |x| ≤ q |
| 619 | 619 | ||
| 620 | var r: usize = 0; | 620 | var r: usize = 0; |
| 621 | var layer: math.Log2Int(usize) = 1; | 621 | var layer: math.Log2Int(usize) = 1; |
| ... | @@ -797,7 +797,7 @@ const Poly = struct { | ... | @@ -797,7 +797,7 @@ const Poly = struct { |
| 797 | cs: [N]i16, | 797 | cs: [N]i16, |
| 798 | 798 | ||
| 799 | const encoded_length = N / 2 * 3; | 799 | const encoded_length = N / 2 * 3; |
| 800 | const zero: Poly = .{ .cs = .{0} ** N }; | 800 | const zero: Poly = .{ .cs = @splat(0) }; |
| 801 | 801 | ||
| 802 | // Add two polynomials (coefficients not normalized) | 802 | // Add two polynomials (coefficients not normalized) |
| 803 | fn add(a: Poly, b: Poly) Poly { | 803 | fn add(a: Poly, b: Poly) Poly { |
| ... | @@ -1011,7 +1011,7 @@ const Poly = struct { | ... | @@ -1011,7 +1011,7 @@ const Poly = struct { |
| 1011 | 1011 | ||
| 1012 | const out_length: usize = comptime @divTrunc(N * d, 8); | 1012 | const out_length: usize = comptime @divTrunc(N * d, 8); |
| 1013 | comptime assert(out_length * 8 == d * N); | 1013 | comptime assert(out_length * 8 == d * N); |
| 1014 | var out = [_]u8{0} ** out_length; | 1014 | var out: [out_length]u8 = @splat(0); |
| 1015 | 1015 | ||
| 1016 | while (in_off < N) { | 1016 | while (in_off < N) { |
| 1017 | // First we compress into in. | 1017 | // First we compress into in. |
| ... | @@ -1754,7 +1754,7 @@ const NistDRBG = struct { | ... | @@ -1754,7 +1754,7 @@ const NistDRBG = struct { |
| 1754 | } | 1754 | } |
| 1755 | 1755 | ||
| 1756 | fn init(seed: [48]u8) NistDRBG { | 1756 | fn init(seed: [48]u8) NistDRBG { |
| 1757 | var ret: NistDRBG = .{ .key = .{0} ** 32, .v = .{0} ** 16 }; | 1757 | var ret: NistDRBG = .{ .key = @splat(0), .v = @splat(0) }; |
| 1758 | ret.update(seed); | 1758 | ret.update(seed); |
| 1759 | return ret; | 1759 | return ret; |
| 1760 | } | 1760 | } |
lib/std/crypto/modes.zig+1-1| ... | @@ -183,7 +183,7 @@ test "ctr mode" { | ... | @@ -183,7 +183,7 @@ test "ctr mode" { |
| 183 | // Test 9: Large input (> 2*block_length, 100 bytes) | 183 | // Test 9: Large input (> 2*block_length, 100 bytes) |
| 184 | { | 184 | { |
| 185 | // Create a 100-byte input by extending with zeros | 185 | // Create a 100-byte input by extending with zeros |
| 186 | var in: [100]u8 = [_]u8{0} ** 100; | 186 | var in: [100]u8 = @splat(0); |
| 187 | @memcpy(in[0..64], &[_]u8{ | 187 | @memcpy(in[0..64], &[_]u8{ |
| 188 | 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, | 188 | 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, |
| 189 | 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, | 189 | 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, |
lib/std/crypto/pbkdf2.zig+1-1| ... | @@ -206,7 +206,7 @@ test "RFC 6070 16,777,216 iterations" { | ... | @@ -206,7 +206,7 @@ test "RFC 6070 16,777,216 iterations" { |
| 206 | const c = 16777216; | 206 | const c = 16777216; |
| 207 | const dk_len = 20; | 207 | const dk_len = 20; |
| 208 | 208 | ||
| 209 | var dk = [_]u8{0} ** dk_len; | 209 | var dk: [dk_len]u8 = @splat(0); |
| 210 | 210 | ||
| 211 | try pbkdf2(&dk, p, s, c, HmacSha1); | 211 | try pbkdf2(&dk, p, s, c, HmacSha1); |
| 212 | 212 |
lib/std/crypto/pcurves/p256/scalar.zig+3-3| ... | @@ -196,19 +196,19 @@ const ScalarDouble = struct { | ... | @@ -196,19 +196,19 @@ const ScalarDouble = struct { |
| 196 | } | 196 | } |
| 197 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; | 197 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; |
| 198 | { | 198 | { |
| 199 | var b = [_]u8{0} ** encoded_length; | 199 | var b: [encoded_length]u8 = @splat(0); |
| 200 | const len = @min(s.len, 24); | 200 | const len = @min(s.len, 24); |
| 201 | b[0..len].* = s[0..len].*; | 201 | b[0..len].* = s[0..len].*; |
| 202 | t.x1 = Fe.fromBytes(b, .little) catch unreachable; | 202 | t.x1 = Fe.fromBytes(b, .little) catch unreachable; |
| 203 | } | 203 | } |
| 204 | if (s_.len >= 24) { | 204 | if (s_.len >= 24) { |
| 205 | var b = [_]u8{0} ** encoded_length; | 205 | var b: [encoded_length]u8 = @splat(0); |
| 206 | const len = @min(s.len - 24, 24); | 206 | const len = @min(s.len - 24, 24); |
| 207 | b[0..len].* = s[24..][0..len].*; | 207 | b[0..len].* = s[24..][0..len].*; |
| 208 | t.x2 = Fe.fromBytes(b, .little) catch unreachable; | 208 | t.x2 = Fe.fromBytes(b, .little) catch unreachable; |
| 209 | } | 209 | } |
| 210 | if (s_.len >= 48) { | 210 | if (s_.len >= 48) { |
| 211 | var b = [_]u8{0} ** encoded_length; | 211 | var b: [encoded_length]u8 = @splat(0); |
| 212 | const len = s.len - 48; | 212 | const len = s.len - 48; |
| 213 | b[0..len].* = s[48..][0..len].*; | 213 | b[0..len].* = s[48..][0..len].*; |
| 214 | t.x3 = Fe.fromBytes(b, .little) catch unreachable; | 214 | t.x3 = Fe.fromBytes(b, .little) catch unreachable; |
lib/std/crypto/pcurves/p384/scalar.zig+2-2| ... | @@ -184,13 +184,13 @@ const ScalarDouble = struct { | ... | @@ -184,13 +184,13 @@ const ScalarDouble = struct { |
| 184 | } | 184 | } |
| 185 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero }; | 185 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero }; |
| 186 | { | 186 | { |
| 187 | var b = [_]u8{0} ** encoded_length; | 187 | var b: [encoded_length]u8 = @splat(0); |
| 188 | const len = @min(s.len, 32); | 188 | const len = @min(s.len, 32); |
| 189 | b[0..len].* = s[0..len].*; | 189 | b[0..len].* = s[0..len].*; |
| 190 | t.x1 = Fe.fromBytes(b, .little) catch unreachable; | 190 | t.x1 = Fe.fromBytes(b, .little) catch unreachable; |
| 191 | } | 191 | } |
| 192 | if (s_.len >= 32) { | 192 | if (s_.len >= 32) { |
| 193 | var b = [_]u8{0} ** encoded_length; | 193 | var b: [encoded_length]u8 = @splat(0); |
| 194 | const len = @min(s.len - 32, 32); | 194 | const len = @min(s.len - 32, 32); |
| 195 | b[0..len].* = s[32..][0..len].*; | 195 | b[0..len].* = s[32..][0..len].*; |
| 196 | t.x2 = Fe.fromBytes(b, .little) catch unreachable; | 196 | t.x2 = Fe.fromBytes(b, .little) catch unreachable; |
lib/std/crypto/pcurves/secp256k1/scalar.zig+3-3| ... | @@ -196,19 +196,19 @@ const ScalarDouble = struct { | ... | @@ -196,19 +196,19 @@ const ScalarDouble = struct { |
| 196 | } | 196 | } |
| 197 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; | 197 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; |
| 198 | { | 198 | { |
| 199 | var b = [_]u8{0} ** encoded_length; | 199 | var b: [encoded_length]u8 = @splat(0); |
| 200 | const len = @min(s.len, 24); | 200 | const len = @min(s.len, 24); |
| 201 | b[0..len].* = s[0..len].*; | 201 | b[0..len].* = s[0..len].*; |
| 202 | t.x1 = Fe.fromBytes(b, .little) catch unreachable; | 202 | t.x1 = Fe.fromBytes(b, .little) catch unreachable; |
| 203 | } | 203 | } |
| 204 | if (s_.len >= 24) { | 204 | if (s_.len >= 24) { |
| 205 | var b = [_]u8{0} ** encoded_length; | 205 | var b: [encoded_length]u8 = @splat(0); |
| 206 | const len = @min(s.len - 24, 24); | 206 | const len = @min(s.len - 24, 24); |
| 207 | b[0..len].* = s[24..][0..len].*; | 207 | b[0..len].* = s[24..][0..len].*; |
| 208 | t.x2 = Fe.fromBytes(b, .little) catch unreachable; | 208 | t.x2 = Fe.fromBytes(b, .little) catch unreachable; |
| 209 | } | 209 | } |
| 210 | if (s_.len >= 48) { | 210 | if (s_.len >= 48) { |
| 211 | var b = [_]u8{0} ** encoded_length; | 211 | var b: [encoded_length]u8 = @splat(0); |
| 212 | const len = s.len - 48; | 212 | const len = s.len - 48; |
| 213 | b[0..len].* = s[48..][0..len].*; | 213 | b[0..len].* = s[48..][0..len].*; |
| 214 | t.x3 = Fe.fromBytes(b, .little) catch unreachable; | 214 | t.x3 = Fe.fromBytes(b, .little) catch unreachable; |
lib/std/crypto/pcurves/tests/p256.zig+5-5| ... | @@ -97,7 +97,7 @@ test "p256 public key is the neutral element (public verification)" { | ... | @@ -97,7 +97,7 @@ test "p256 public key is the neutral element (public verification)" { |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | test "p256 field element non-canonical encoding" { | 99 | test "p256 field element non-canonical encoding" { |
| 100 | const s = [_]u8{0xff} ** 32; | 100 | const s: [32]u8 = @splat(0xff); |
| 101 | try testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .little)); | 101 | try testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .little)); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| ... | @@ -110,8 +110,8 @@ test "p256 neutral element decoding" { | ... | @@ -110,8 +110,8 @@ test "p256 neutral element decoding" { |
| 110 | test "p256 double base multiplication" { | 110 | test "p256 double base multiplication" { |
| 111 | const p1 = P256.basePoint; | 111 | const p1 = P256.basePoint; |
| 112 | const p2 = P256.basePoint.dbl(); | 112 | const p2 = P256.basePoint.dbl(); |
| 113 | const s1 = [_]u8{0x01} ** 32; | 113 | const s1: [32]u8 = @splat(0x01); |
| 114 | const s2 = [_]u8{0x02} ** 32; | 114 | const s2: [32]u8 = @splat(0x02); |
| 115 | const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little); | 115 | const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little); |
| 116 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); | 116 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); |
| 117 | try testing.expect(pr1.equivalent(pr2)); | 117 | try testing.expect(pr1.equivalent(pr2)); |
| ... | @@ -120,8 +120,8 @@ test "p256 double base multiplication" { | ... | @@ -120,8 +120,8 @@ test "p256 double base multiplication" { |
| 120 | test "p256 double base multiplication with large scalars" { | 120 | test "p256 double base multiplication with large scalars" { |
| 121 | const p1 = P256.basePoint; | 121 | const p1 = P256.basePoint; |
| 122 | const p2 = P256.basePoint.dbl(); | 122 | const p2 = P256.basePoint.dbl(); |
| 123 | const s1 = [_]u8{0xee} ** 32; | 123 | const s1: [32]u8 = @splat(0xee); |
| 124 | const s2 = [_]u8{0xdd} ** 32; | 124 | const s2: [32]u8 = @splat(0xdd); |
| 125 | const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little); | 125 | const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little); |
| 126 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); | 126 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); |
| 127 | try testing.expect(pr1.equivalent(pr2)); | 127 | try testing.expect(pr1.equivalent(pr2)); |
lib/std/crypto/pcurves/tests/p384.zig+5-5| ... | @@ -100,7 +100,7 @@ test "p384 public key is the neutral element (public verification)" { | ... | @@ -100,7 +100,7 @@ test "p384 public key is the neutral element (public verification)" { |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | test "p384 field element non-canonical encoding" { | 102 | test "p384 field element non-canonical encoding" { |
| 103 | const s = [_]u8{0xff} ** 48; | 103 | const s: [48]u8 = @splat(0xff); |
| 104 | try testing.expectError(error.NonCanonical, P384.Fe.fromBytes(s, .little)); | 104 | try testing.expectError(error.NonCanonical, P384.Fe.fromBytes(s, .little)); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| ... | @@ -113,8 +113,8 @@ test "p384 neutral element decoding" { | ... | @@ -113,8 +113,8 @@ test "p384 neutral element decoding" { |
| 113 | test "p384 double base multiplication" { | 113 | test "p384 double base multiplication" { |
| 114 | const p1 = P384.basePoint; | 114 | const p1 = P384.basePoint; |
| 115 | const p2 = P384.basePoint.dbl(); | 115 | const p2 = P384.basePoint.dbl(); |
| 116 | const s1 = [_]u8{0x01} ** 48; | 116 | const s1: [48]u8 = @splat(0x01); |
| 117 | const s2 = [_]u8{0x02} ** 48; | 117 | const s2: [48]u8 = @splat(0x02); |
| 118 | const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .little); | 118 | const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .little); |
| 119 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); | 119 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); |
| 120 | try testing.expect(pr1.equivalent(pr2)); | 120 | try testing.expect(pr1.equivalent(pr2)); |
| ... | @@ -123,8 +123,8 @@ test "p384 double base multiplication" { | ... | @@ -123,8 +123,8 @@ test "p384 double base multiplication" { |
| 123 | test "p384 double base multiplication with large scalars" { | 123 | test "p384 double base multiplication with large scalars" { |
| 124 | const p1 = P384.basePoint; | 124 | const p1 = P384.basePoint; |
| 125 | const p2 = P384.basePoint.dbl(); | 125 | const p2 = P384.basePoint.dbl(); |
| 126 | const s1 = [_]u8{0xee} ** 48; | 126 | const s1: [48]u8 = @splat(0xee); |
| 127 | const s2 = [_]u8{0xdd} ** 48; | 127 | const s2: [48]u8 = @splat(0xdd); |
| 128 | const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .little); | 128 | const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .little); |
| 129 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); | 129 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); |
| 130 | try testing.expect(pr1.equivalent(pr2)); | 130 | try testing.expect(pr1.equivalent(pr2)); |
lib/std/crypto/pcurves/tests/secp256k1.zig+3-3| ... | @@ -109,7 +109,7 @@ test "secp256k1 public key is the neutral element (public verification)" { | ... | @@ -109,7 +109,7 @@ test "secp256k1 public key is the neutral element (public verification)" { |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | test "secp256k1 field element non-canonical encoding" { | 111 | test "secp256k1 field element non-canonical encoding" { |
| 112 | const s = [_]u8{0xff} ** 32; | 112 | const s: [32]u8 = @splat(0xff); |
| 113 | try testing.expectError(error.NonCanonical, Secp256k1.Fe.fromBytes(s, .little)); | 113 | try testing.expectError(error.NonCanonical, Secp256k1.Fe.fromBytes(s, .little)); |
| 114 | } | 114 | } |
| 115 | 115 | ||
| ... | @@ -122,8 +122,8 @@ test "secp256k1 neutral element decoding" { | ... | @@ -122,8 +122,8 @@ test "secp256k1 neutral element decoding" { |
| 122 | test "secp256k1 double base multiplication" { | 122 | test "secp256k1 double base multiplication" { |
| 123 | const p1 = Secp256k1.basePoint; | 123 | const p1 = Secp256k1.basePoint; |
| 124 | const p2 = Secp256k1.basePoint.dbl(); | 124 | const p2 = Secp256k1.basePoint.dbl(); |
| 125 | const s1 = [_]u8{0x01} ** 32; | 125 | const s1: [32]u8 = @splat(0x01); |
| 126 | const s2 = [_]u8{0x02} ** 32; | 126 | const s2: [32]u8 = @splat(0x02); |
| 127 | const pr1 = try Secp256k1.mulDoubleBasePublic(p1, s1, p2, s2, .little); | 127 | const pr1 = try Secp256k1.mulDoubleBasePublic(p1, s1, p2, s2, .little); |
| 128 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); | 128 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); |
| 129 | try testing.expect(pr1.equivalent(pr2)); | 129 | try testing.expect(pr1.equivalent(pr2)); |
lib/std/crypto/salsa20.zig+8-8| ... | @@ -384,7 +384,7 @@ pub const XSalsa20Poly1305 = struct { | ... | @@ -384,7 +384,7 @@ pub const XSalsa20Poly1305 = struct { |
| 384 | pub fn encrypt(c: []u8, tag: *[tag_length]u8, m: []const u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) void { | 384 | pub fn encrypt(c: []u8, tag: *[tag_length]u8, m: []const u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) void { |
| 385 | debug.assert(c.len == m.len); | 385 | debug.assert(c.len == m.len); |
| 386 | const extended = extend(rounds, k, npub); | 386 | const extended = extend(rounds, k, npub); |
| 387 | var block0 = [_]u8{0} ** 64; | 387 | var block0: [64]u8 = @splat(0); |
| 388 | const mlen0 = @min(32, m.len); | 388 | const mlen0 = @min(32, m.len); |
| 389 | @memcpy(block0[32..][0..mlen0], m[0..mlen0]); | 389 | @memcpy(block0[32..][0..mlen0], m[0..mlen0]); |
| 390 | Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce); | 390 | Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce); |
| ... | @@ -408,7 +408,7 @@ pub const XSalsa20Poly1305 = struct { | ... | @@ -408,7 +408,7 @@ pub const XSalsa20Poly1305 = struct { |
| 408 | pub fn decrypt(m: []u8, c: []const u8, tag: [tag_length]u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) AuthenticationError!void { | 408 | pub fn decrypt(m: []u8, c: []const u8, tag: [tag_length]u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) AuthenticationError!void { |
| 409 | debug.assert(c.len == m.len); | 409 | debug.assert(c.len == m.len); |
| 410 | const extended = extend(rounds, k, npub); | 410 | const extended = extend(rounds, k, npub); |
| 411 | var block0 = [_]u8{0} ** 64; | 411 | var block0: [64]u8 = @splat(0); |
| 412 | const mlen0 = @min(32, c.len); | 412 | const mlen0 = @min(32, c.len); |
| 413 | @memcpy(block0[32..][0..mlen0], c[0..mlen0]); | 413 | @memcpy(block0[32..][0..mlen0], c[0..mlen0]); |
| 414 | Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce); | 414 | Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce); |
| ... | @@ -489,7 +489,7 @@ pub const Box = struct { | ... | @@ -489,7 +489,7 @@ pub const Box = struct { |
| 489 | /// Compute a secret suitable for `secretbox` given a recipient's public key and a sender's secret key. | 489 | /// Compute a secret suitable for `secretbox` given a recipient's public key and a sender's secret key. |
| 490 | pub fn createSharedSecret(public_key: [public_length]u8, secret_key: [secret_length]u8) (IdentityElementError || WeakPublicKeyError)![shared_length]u8 { | 490 | pub fn createSharedSecret(public_key: [public_length]u8, secret_key: [secret_length]u8) (IdentityElementError || WeakPublicKeyError)![shared_length]u8 { |
| 491 | const p = try X25519.scalarmult(secret_key, public_key); | 491 | const p = try X25519.scalarmult(secret_key, public_key); |
| 492 | const zero = [_]u8{0} ** 16; | 492 | const zero: [16]u8 = @splat(0); |
| 493 | return SalsaImpl(20).hsalsa(zero, p); | 493 | return SalsaImpl(20).hsalsa(zero, p); |
| 494 | } | 494 | } |
| 495 | 495 | ||
| ... | @@ -559,15 +559,15 @@ const htest = @import("test.zig"); | ... | @@ -559,15 +559,15 @@ const htest = @import("test.zig"); |
| 559 | test "(x)salsa20" { | 559 | test "(x)salsa20" { |
| 560 | if (builtin.cpu.has(.riscv, .v) and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/24299 | 560 | if (builtin.cpu.has(.riscv, .v) and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/24299 |
| 561 | 561 | ||
| 562 | const key = [_]u8{0x69} ** 32; | 562 | const key: [32]u8 = @splat(0x69); |
| 563 | const nonce = [_]u8{0x42} ** 8; | 563 | const nonce: [8]u8 = @splat(0x42); |
| 564 | const msg = [_]u8{0} ** 20; | 564 | const msg: [20]u8 = @splat(0); |
| 565 | var c: [msg.len]u8 = undefined; | 565 | var c: [msg.len]u8 = undefined; |
| 566 | 566 | ||
| 567 | Salsa20.xor(&c, msg[0..], 0, key, nonce); | 567 | Salsa20.xor(&c, msg[0..], 0, key, nonce); |
| 568 | try htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]); | 568 | try htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]); |
| 569 | 569 | ||
| 570 | const extended_nonce = [_]u8{0x42} ** 24; | 570 | const extended_nonce: [24]u8 = @splat(0x42); |
| 571 | XSalsa20.xor(&c, msg[0..], 0, key, extended_nonce); | 571 | XSalsa20.xor(&c, msg[0..], 0, key, extended_nonce); |
| 572 | try htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]); | 572 | try htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]); |
| 573 | } | 573 | } |
| ... | @@ -637,7 +637,7 @@ test "xsalsa20poly1305 sealedbox" { | ... | @@ -637,7 +637,7 @@ test "xsalsa20poly1305 sealedbox" { |
| 637 | test "secretbox twoblocks" { | 637 | test "secretbox twoblocks" { |
| 638 | const key = [_]u8{ 0xc9, 0xc9, 0x4d, 0xcf, 0x68, 0xbe, 0x00, 0xe4, 0x7f, 0xe6, 0x13, 0x26, 0xfc, 0xc4, 0x2f, 0xd0, 0xdb, 0x93, 0x91, 0x1c, 0x09, 0x94, 0x89, 0xe1, 0x1b, 0x88, 0x63, 0x18, 0x86, 0x64, 0x8b, 0x7b }; | 638 | const key = [_]u8{ 0xc9, 0xc9, 0x4d, 0xcf, 0x68, 0xbe, 0x00, 0xe4, 0x7f, 0xe6, 0x13, 0x26, 0xfc, 0xc4, 0x2f, 0xd0, 0xdb, 0x93, 0x91, 0x1c, 0x09, 0x94, 0x89, 0xe1, 0x1b, 0x88, 0x63, 0x18, 0x86, 0x64, 0x8b, 0x7b }; |
| 639 | const nonce = [_]u8{ 0xa4, 0x33, 0xe9, 0x0a, 0x07, 0x68, 0x6e, 0x9a, 0x2b, 0x6d, 0xd4, 0x59, 0x04, 0x72, 0x3e, 0xd3, 0x8a, 0x67, 0x55, 0xc7, 0x9e, 0x3e, 0x77, 0xdc }; | 639 | const nonce = [_]u8{ 0xa4, 0x33, 0xe9, 0x0a, 0x07, 0x68, 0x6e, 0x9a, 0x2b, 0x6d, 0xd4, 0x59, 0x04, 0x72, 0x3e, 0xd3, 0x8a, 0x67, 0x55, 0xc7, 0x9e, 0x3e, 0x77, 0xdc }; |
| 640 | const msg = [_]u8{'a'} ** 97; | 640 | const msg: [97]u8 = @splat('a'); |
| 641 | var ciphertext: [msg.len + SecretBox.tag_length]u8 = undefined; | 641 | var ciphertext: [msg.len + SecretBox.tag_length]u8 = undefined; |
| 642 | SecretBox.seal(&ciphertext, &msg, nonce, key); | 642 | SecretBox.seal(&ciphertext, &msg, nonce, key); |
| 643 | try htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext); | 643 | try htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext); |
lib/std/crypto/sha2.zig+2-2| ... | @@ -461,7 +461,7 @@ test "sha256 streaming" { | ... | @@ -461,7 +461,7 @@ test "sha256 streaming" { |
| 461 | } | 461 | } |
| 462 | 462 | ||
| 463 | test "sha256 aligned final" { | 463 | test "sha256 aligned final" { |
| 464 | var block = [_]u8{0} ** Sha256.block_length; | 464 | var block: [Sha256.block_length]u8 = @splat(0); |
| 465 | var out: [Sha256.digest_length]u8 = undefined; | 465 | var out: [Sha256.digest_length]u8 = undefined; |
| 466 | 466 | ||
| 467 | var h = Sha256.init(.{}); | 467 | var h = Sha256.init(.{}); |
| ... | @@ -833,7 +833,7 @@ test "sha512 streaming" { | ... | @@ -833,7 +833,7 @@ test "sha512 streaming" { |
| 833 | } | 833 | } |
| 834 | 834 | ||
| 835 | test "sha512 aligned final" { | 835 | test "sha512 aligned final" { |
| 836 | var block = [_]u8{0} ** Sha512.block_length; | 836 | var block: [Sha512.block_length]u8 = @splat(0); |
| 837 | var out: [Sha512.digest_length]u8 = undefined; | 837 | var out: [Sha512.digest_length]u8 = undefined; |
| 838 | 838 | ||
| 839 | var h = Sha512.init(.{}); | 839 | var h = Sha512.init(.{}); |
lib/std/crypto/sha3.zig+2-2| ... | @@ -543,7 +543,7 @@ test "sha3-256 streaming" { | ... | @@ -543,7 +543,7 @@ test "sha3-256 streaming" { |
| 543 | } | 543 | } |
| 544 | 544 | ||
| 545 | test "sha3-256 aligned final" { | 545 | test "sha3-256 aligned final" { |
| 546 | var block = [_]u8{0} ** Sha3_256.block_length; | 546 | var block: [Sha3_256.block_length]u8 = @splat(0); |
| 547 | var out: [Sha3_256.digest_length]u8 = undefined; | 547 | var out: [Sha3_256.digest_length]u8 = undefined; |
| 548 | 548 | ||
| 549 | var h = Sha3_256.init(.{}); | 549 | var h = Sha3_256.init(.{}); |
| ... | @@ -616,7 +616,7 @@ test "sha3-512 streaming" { | ... | @@ -616,7 +616,7 @@ test "sha3-512 streaming" { |
| 616 | } | 616 | } |
| 617 | 617 | ||
| 618 | test "sha3-512 aligned final" { | 618 | test "sha3-512 aligned final" { |
| 619 | var block = [_]u8{0} ** Sha3_512.block_length; | 619 | var block: [Sha3_512.block_length]u8 = @splat(0); |
| 620 | var out: [Sha3_512.digest_length]u8 = undefined; | 620 | var out: [Sha3_512.digest_length]u8 = undefined; |
| 621 | 621 | ||
| 622 | var h = Sha3_512.init(.{}); | 622 | var h = Sha3_512.init(.{}); |
lib/std/crypto/siphash.zig+1-1| ... | @@ -91,7 +91,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round | ... | @@ -91,7 +91,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round |
| 91 | 91 | ||
| 92 | self.msg_len +%= @as(u8, @truncate(b.len)); | 92 | self.msg_len +%= @as(u8, @truncate(b.len)); |
| 93 | 93 | ||
| 94 | var buf = [_]u8{0} ** 8; | 94 | var buf: [8]u8 = @splat(0); |
| 95 | @memcpy(buf[0..b.len], b); | 95 | @memcpy(buf[0..b.len], b); |
| 96 | buf[7] = self.msg_len; | 96 | buf[7] = self.msg_len; |
| 97 | self.round(buf); | 97 | self.round(buf); |
lib/std/crypto/timing_safe.zig+5-4| ... | @@ -207,8 +207,8 @@ test "eql (vectors)" { | ... | @@ -207,8 +207,8 @@ test "eql (vectors)" { |
| 207 | 207 | ||
| 208 | test compare { | 208 | test compare { |
| 209 | const expectEqual = std.testing.expectEqual; | 209 | const expectEqual = std.testing.expectEqual; |
| 210 | var a = [_]u8{10} ** 32; | 210 | var a: [32]u8 = @splat(10); |
| 211 | var b = [_]u8{10} ** 32; | 211 | var b: [32]u8 = @splat(10); |
| 212 | try expectEqual(compare(u8, &a, &b, .big), .eq); | 212 | try expectEqual(compare(u8, &a, &b, .big), .eq); |
| 213 | try expectEqual(compare(u8, &a, &b, .little), .eq); | 213 | try expectEqual(compare(u8, &a, &b, .little), .eq); |
| 214 | a[31] = 1; | 214 | a[31] = 1; |
| ... | @@ -228,7 +228,7 @@ test "add and sub" { | ... | @@ -228,7 +228,7 @@ test "add and sub" { |
| 228 | var a: [len]u8 = undefined; | 228 | var a: [len]u8 = undefined; |
| 229 | var b: [len]u8 = undefined; | 229 | var b: [len]u8 = undefined; |
| 230 | var c: [len]u8 = undefined; | 230 | var c: [len]u8 = undefined; |
| 231 | const zero = [_]u8{0} ** len; | 231 | const zero: [len]u8 = @splat(0); |
| 232 | var iterations: usize = 100; | 232 | var iterations: usize = 100; |
| 233 | while (iterations != 0) : (iterations -= 1) { | 233 | while (iterations != 0) : (iterations -= 1) { |
| 234 | io.random(&a); | 234 | io.random(&a); |
| ... | @@ -262,7 +262,8 @@ test classify { | ... | @@ -262,7 +262,8 @@ test classify { |
| 262 | declassify(&out); | 262 | declassify(&out); |
| 263 | 263 | ||
| 264 | // Comparing public data in non-constant time is acceptable. | 264 | // Comparing public data in non-constant time is acceptable. |
| 265 | try expect(!std.mem.eql(u8, &out, &[_]u8{0} ** out.len)); | 265 | const zeroes: [out.len]u8 = @splat(0); |
| 266 | try expect(!std.mem.eql(u8, &out, &zeroes)); | ||
| 266 | 267 | ||
| 267 | // Comparing secret data must be done in constant time. The result | 268 | // Comparing secret data must be done in constant time. The result |
| 268 | // is going to be considered as secret as well. | 269 | // is going to be considered as secret as well. |
lib/std/crypto/tls/Client.zig+10-9| ... | @@ -375,7 +375,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client | ... | @@ -375,7 +375,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client |
| 375 | const auth_tag = record_decoder.array(P.AEAD.tag_length).*; | 375 | const auth_tag = record_decoder.array(P.AEAD.tag_length).*; |
| 376 | const nonce = nonce: { | 376 | const nonce = nonce: { |
| 377 | const V = @Vector(P.AEAD.nonce_length, u8); | 377 | const V = @Vector(P.AEAD.nonce_length, u8); |
| 378 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 378 | const pad: [P.AEAD.nonce_length - 8]u8 = @splat(0); |
| 379 | const operand: V = pad ++ @as([8]u8, @bitCast(big(read_seq))); | 379 | const operand: V = pad ++ @as([8]u8, @bitCast(big(read_seq))); |
| 380 | break :nonce @as(V, pv.server_handshake_iv) ^ operand; | 380 | break :nonce @as(V, pv.server_handshake_iv) ^ operand; |
| 381 | }; | 381 | }; |
| ... | @@ -415,7 +415,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client | ... | @@ -415,7 +415,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client |
| 415 | comptime std.math.shl(u64, std.math.maxInt(u64), 8 * P.record_iv_length); | 415 | comptime std.math.shl(u64, std.math.maxInt(u64), 8 * P.record_iv_length); |
| 416 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { | 416 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { |
| 417 | const V = @Vector(P.AEAD.nonce_length, u8); | 417 | const V = @Vector(P.AEAD.nonce_length, u8); |
| 418 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 418 | const pad: [P.AEAD.nonce_length - 8]u8 = @splat(0); |
| 419 | const operand: V = pad ++ @as([8]u8, @bitCast(big(masked_read_seq))); | 419 | const operand: V = pad ++ @as([8]u8, @bitCast(big(masked_read_seq))); |
| 420 | break :nonce @as(V, pv.app_cipher.server_write_IV ++ record_iv) ^ operand; | 420 | break :nonce @as(V, pv.app_cipher.server_write_IV ++ record_iv) ^ operand; |
| 421 | }; | 421 | }; |
| ... | @@ -539,7 +539,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client | ... | @@ -539,7 +539,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client |
| 539 | const p = &@field(handshake_cipher, @tagName(tag.with())); | 539 | const p = &@field(handshake_cipher, @tagName(tag.with())); |
| 540 | const P = @TypeOf(p.*).A; | 540 | const P = @TypeOf(p.*).A; |
| 541 | const hello_hash = p.transcript_hash.peek(); | 541 | const hello_hash = p.transcript_hash.peek(); |
| 542 | const zeroes = [1]u8{0} ** P.Hash.digest_length; | 542 | const zeroes: [P.Hash.digest_length]u8 = @splat(0); |
| 543 | const early_secret = P.Hkdf.extract(&[1]u8{0}, &zeroes); | 543 | const early_secret = P.Hkdf.extract(&[1]u8{0}, &zeroes); |
| 544 | const empty_hash = tls.emptyHash(P.Hash); | 544 | const empty_hash = tls.emptyHash(P.Hash); |
| 545 | p.version = .{ .tls_1_3 = undefined }; | 545 | p.version = .{ .tls_1_3 = undefined }; |
| ... | @@ -791,7 +791,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client | ... | @@ -791,7 +791,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client |
| 791 | const pv = &p.version.tls_1_2; | 791 | const pv = &p.version.tls_1_2; |
| 792 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { | 792 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { |
| 793 | const V = @Vector(P.AEAD.nonce_length, u8); | 793 | const V = @Vector(P.AEAD.nonce_length, u8); |
| 794 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 794 | const pad: [P.AEAD.nonce_length - 8]u8 = @splat(0); |
| 795 | const operand: V = pad ++ @as([8]u8, @bitCast(big(write_seq))); | 795 | const operand: V = pad ++ @as([8]u8, @bitCast(big(write_seq))); |
| 796 | break :nonce @as(V, pv.app_cipher.client_write_IV ++ pv.app_cipher.client_salt) ^ operand; | 796 | break :nonce @as(V, pv.app_cipher.client_write_IV ++ pv.app_cipher.client_salt) ^ operand; |
| 797 | }; | 797 | }; |
| ... | @@ -832,8 +832,9 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client | ... | @@ -832,8 +832,9 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client |
| 832 | } | 832 | } |
| 833 | switch (handshake_cipher) { | 833 | switch (handshake_cipher) { |
| 834 | inline else => |*p| { | 834 | inline else => |*p| { |
| 835 | const pad: [64]u8 = @splat(' '); | ||
| 835 | try main_cert_pub_key.verifySignature(&hsd, &.{ | 836 | try main_cert_pub_key.verifySignature(&hsd, &.{ |
| 836 | " " ** 64 ++ "TLS 1.3, server CertificateVerify\x00", | 837 | pad ++ "TLS 1.3, server CertificateVerify\x00", |
| 837 | &p.transcript_hash.peek(), | 838 | &p.transcript_hash.peek(), |
| 838 | }); | 839 | }); |
| 839 | p.transcript_hash.update(wrapped_handshake); | 840 | p.transcript_hash.update(wrapped_handshake); |
| ... | @@ -1066,7 +1067,7 @@ fn prepareCiphertextRecord( | ... | @@ -1066,7 +1067,7 @@ fn prepareCiphertextRecord( |
| 1066 | ciphertext_end += auth_tag.len; | 1067 | ciphertext_end += auth_tag.len; |
| 1067 | const nonce = nonce: { | 1068 | const nonce = nonce: { |
| 1068 | const V = @Vector(P.AEAD.nonce_length, u8); | 1069 | const V = @Vector(P.AEAD.nonce_length, u8); |
| 1069 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 1070 | const pad: [P.AEAD.nonce_length - 8]u8 = @splat(0); |
| 1070 | const operand: V = pad ++ mem.toBytes(big(c.write_seq)); | 1071 | const operand: V = pad ++ mem.toBytes(big(c.write_seq)); |
| 1071 | break :nonce @as(V, pv.client_iv) ^ operand; | 1072 | break :nonce @as(V, pv.client_iv) ^ operand; |
| 1072 | }; | 1073 | }; |
| ... | @@ -1103,7 +1104,7 @@ fn prepareCiphertextRecord( | ... | @@ -1103,7 +1104,7 @@ fn prepareCiphertextRecord( |
| 1103 | ciphertext_end += P.record_iv_length; | 1104 | ciphertext_end += P.record_iv_length; |
| 1104 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { | 1105 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { |
| 1105 | const V = @Vector(P.AEAD.nonce_length, u8); | 1106 | const V = @Vector(P.AEAD.nonce_length, u8); |
| 1106 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 1107 | const pad: [P.AEAD.nonce_length - 8]u8 = @splat(0); |
| 1107 | const operand: V = pad ++ @as([8]u8, @bitCast(big(c.write_seq))); | 1108 | const operand: V = pad ++ @as([8]u8, @bitCast(big(c.write_seq))); |
| 1108 | break :nonce @as(V, pv.client_write_IV ++ pv.client_salt) ^ operand; | 1109 | break :nonce @as(V, pv.client_write_IV ++ pv.client_salt) ^ operand; |
| 1109 | }; | 1110 | }; |
| ... | @@ -1185,7 +1186,7 @@ fn readIndirect(c: *Client) Reader.Error!usize { | ... | @@ -1185,7 +1186,7 @@ fn readIndirect(c: *Client) Reader.Error!usize { |
| 1185 | const auth_tag = (input.takeArray(P.AEAD.tag_length) catch unreachable).*; // already peeked | 1186 | const auth_tag = (input.takeArray(P.AEAD.tag_length) catch unreachable).*; // already peeked |
| 1186 | const nonce = nonce: { | 1187 | const nonce = nonce: { |
| 1187 | const V = @Vector(P.AEAD.nonce_length, u8); | 1188 | const V = @Vector(P.AEAD.nonce_length, u8); |
| 1188 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 1189 | const pad: [P.AEAD.nonce_length - 8]u8 = @splat(0); |
| 1189 | const operand: V = pad ++ mem.toBytes(big(c.read_seq)); | 1190 | const operand: V = pad ++ mem.toBytes(big(c.read_seq)); |
| 1190 | break :nonce @as(V, pv.server_iv) ^ operand; | 1191 | break :nonce @as(V, pv.server_iv) ^ operand; |
| 1191 | }; | 1192 | }; |
| ... | @@ -1211,7 +1212,7 @@ fn readIndirect(c: *Client) Reader.Error!usize { | ... | @@ -1211,7 +1212,7 @@ fn readIndirect(c: *Client) Reader.Error!usize { |
| 1211 | comptime std.math.shl(u64, std.math.maxInt(u64), 8 * P.record_iv_length); | 1212 | comptime std.math.shl(u64, std.math.maxInt(u64), 8 * P.record_iv_length); |
| 1212 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { | 1213 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { |
| 1213 | const V = @Vector(P.AEAD.nonce_length, u8); | 1214 | const V = @Vector(P.AEAD.nonce_length, u8); |
| 1214 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 1215 | const pad: [P.AEAD.nonce_length - 8]u8 = @splat(0); |
| 1215 | const operand: V = pad ++ @as([8]u8, @bitCast(big(masked_read_seq))); | 1216 | const operand: V = pad ++ @as([8]u8, @bitCast(big(masked_read_seq))); |
| 1216 | break :nonce @as(V, pv.server_write_IV ++ record_iv) ^ operand; | 1217 | break :nonce @as(V, pv.server_write_IV ++ record_iv) ^ operand; |
| 1217 | }; | 1218 | }; |
lib/std/debug.zig+6-4| ... | @@ -1381,7 +1381,7 @@ test printLineFromFile { | ... | @@ -1381,7 +1381,7 @@ test printLineFromFile { |
| 1381 | try writer.flush(); | 1381 | try writer.flush(); |
| 1382 | 1382 | ||
| 1383 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }); | 1383 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }); |
| 1384 | try expectEqualStrings(("a" ** overlap) ++ "\n", aw.written()); | 1384 | try expectEqualStrings(&@as([overlap]u8, @splat('a')) ++ "\n", aw.written()); |
| 1385 | aw.clearRetainingCapacity(); | 1385 | aw.clearRetainingCapacity(); |
| 1386 | } | 1386 | } |
| 1387 | { | 1387 | { |
| ... | @@ -1395,7 +1395,7 @@ test printLineFromFile { | ... | @@ -1395,7 +1395,7 @@ test printLineFromFile { |
| 1395 | try writer.splatByteAll('a', std.heap.page_size_max); | 1395 | try writer.splatByteAll('a', std.heap.page_size_max); |
| 1396 | 1396 | ||
| 1397 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 }); | 1397 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 }); |
| 1398 | try expectEqualStrings(("a" ** std.heap.page_size_max) ++ "\n", aw.written()); | 1398 | try expectEqualStrings(&@as([std.heap.page_size_max]u8, @splat('a')) ++ "\n", aw.written()); |
| 1399 | aw.clearRetainingCapacity(); | 1399 | aw.clearRetainingCapacity(); |
| 1400 | } | 1400 | } |
| 1401 | { | 1401 | { |
| ... | @@ -1410,14 +1410,16 @@ test printLineFromFile { | ... | @@ -1410,14 +1410,16 @@ test printLineFromFile { |
| 1410 | 1410 | ||
| 1411 | try expectError(error.EndOfStream, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 })); | 1411 | try expectError(error.EndOfStream, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 })); |
| 1412 | 1412 | ||
| 1413 | const many_a: [3 * std.heap.page_size_max]u8 = @splat('a'); | ||
| 1414 | |||
| 1413 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 }); | 1415 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 }); |
| 1414 | try expectEqualStrings(("a" ** (3 * std.heap.page_size_max)) ++ "\n", aw.written()); | 1416 | try expectEqualStrings(&many_a ++ "\n", aw.written()); |
| 1415 | aw.clearRetainingCapacity(); | 1417 | aw.clearRetainingCapacity(); |
| 1416 | 1418 | ||
| 1417 | try writer.writeAll("a\na"); | 1419 | try writer.writeAll("a\na"); |
| 1418 | 1420 | ||
| 1419 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 }); | 1421 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 }); |
| 1420 | try expectEqualStrings(("a" ** (3 * std.heap.page_size_max)) ++ "a\n", aw.written()); | 1422 | try expectEqualStrings(&many_a ++ "a\n", aw.written()); |
| 1421 | aw.clearRetainingCapacity(); | 1423 | aw.clearRetainingCapacity(); |
| 1422 | 1424 | ||
| 1423 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }); | 1425 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }); |
lib/std/debug/Dwarf.zig+1-1| ... | @@ -1346,7 +1346,7 @@ const FileEntry = struct { | ... | @@ -1346,7 +1346,7 @@ const FileEntry = struct { |
| 1346 | dir_index: u32 = 0, | 1346 | dir_index: u32 = 0, |
| 1347 | mtime: u64 = 0, | 1347 | mtime: u64 = 0, |
| 1348 | size: u64 = 0, | 1348 | size: u64 = 0, |
| 1349 | md5: [16]u8 = [1]u8{0} ** 16, | 1349 | md5: [16]u8 = @splat(0), |
| 1350 | }; | 1350 | }; |
| 1351 | 1351 | ||
| 1352 | const LineNumberProgram = struct { | 1352 | const LineNumberProgram = struct { |
lib/std/elf.zig+1-1| ... | @@ -3054,7 +3054,7 @@ pub const ar_hdr = extern struct { | ... | @@ -3054,7 +3054,7 @@ pub const ar_hdr = extern struct { |
| 3054 | fn genSpecialMemberName(comptime name: []const u8) *const [16]u8 { | 3054 | fn genSpecialMemberName(comptime name: []const u8) *const [16]u8 { |
| 3055 | assert(name.len <= 16); | 3055 | assert(name.len <= 16); |
| 3056 | const padding = 16 - name.len; | 3056 | const padding = 16 - name.len; |
| 3057 | return name ++ &[_]u8{0x20} ** padding; | 3057 | return name ++ @as([padding]u8, @splat(0x20)); |
| 3058 | } | 3058 | } |
| 3059 | 3059 | ||
| 3060 | // Archive files start with the ARMAG identifying string. Then follows a | 3060 | // Archive files start with the ARMAG identifying string. Then follows a |
lib/std/enums.zig+1-1| ... | @@ -166,7 +166,7 @@ pub fn directEnumArrayDefault( | ... | @@ -166,7 +166,7 @@ pub fn directEnumArrayDefault( |
| 166 | init_values: EnumFieldStruct(E, Data, default), | 166 | init_values: EnumFieldStruct(E, Data, default), |
| 167 | ) [directEnumArrayLen(E, max_unused_slots)]Data { | 167 | ) [directEnumArrayLen(E, max_unused_slots)]Data { |
| 168 | const len = comptime directEnumArrayLen(E, max_unused_slots); | 168 | const len = comptime directEnumArrayLen(E, max_unused_slots); |
| 169 | var result: [len]Data = if (default) |d| [_]Data{d} ** len else undefined; | 169 | var result: [len]Data = @splat(default orelse undefined); |
| 170 | inline for (@typeInfo(@TypeOf(init_values)).@"struct".fields) |f| { | 170 | inline for (@typeInfo(@TypeOf(init_values)).@"struct".fields) |f| { |
| 171 | const enum_value = @field(E, f.name); | 171 | const enum_value = @field(E, f.name); |
| 172 | const index = @as(usize, @intCast(@intFromEnum(enum_value))); | 172 | const index = @as(usize, @intCast(@intFromEnum(enum_value))); |
lib/std/fmt.zig+5-1| ... | @@ -1194,8 +1194,12 @@ test bytesToHex { | ... | @@ -1194,8 +1194,12 @@ test bytesToHex { |
| 1194 | } | 1194 | } |
| 1195 | 1195 | ||
| 1196 | test hexToBytes { | 1196 | test hexToBytes { |
| 1197 | const repeated: []const u8 = repeated: { | ||
| 1198 | const buf: [32][2]u8 = @splat("90".*); | ||
| 1199 | break :repeated @ptrCast(&buf); | ||
| 1200 | }; | ||
| 1197 | var buf: [32]u8 = undefined; | 1201 | var buf: [32]u8 = undefined; |
| 1198 | try expectFmt("90" ** 32, "{X}", .{try hexToBytes(&buf, "90" ** 32)}); | 1202 | try expectFmt(repeated, "{X}", .{try hexToBytes(&buf, repeated)}); |
| 1199 | try expectFmt("ABCD", "{X}", .{try hexToBytes(&buf, "ABCD")}); | 1203 | try expectFmt("ABCD", "{X}", .{try hexToBytes(&buf, "ABCD")}); |
| 1200 | try expectFmt("", "{X}", .{try hexToBytes(&buf, "")}); | 1204 | try expectFmt("", "{X}", .{try hexToBytes(&buf, "")}); |
| 1201 | try std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z")); | 1205 | try std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z")); |
lib/std/fmt/parse_float/decimal.zig+1-1| ... | @@ -80,7 +80,7 @@ pub fn Decimal(comptime T: type) type { | ... | @@ -80,7 +80,7 @@ pub fn Decimal(comptime T: type) type { |
| 80 | .num_digits = 0, | 80 | .num_digits = 0, |
| 81 | .decimal_point = 0, | 81 | .decimal_point = 0, |
| 82 | .truncated = false, | 82 | .truncated = false, |
| 83 | .digits = [_]u8{0} ** max_digits, | 83 | .digits = @splat(0), |
| 84 | }; | 84 | }; |
| 85 | } | 85 | } |
| 86 | 86 |
lib/std/fs/test.zig+7-3| ... | @@ -1449,11 +1449,15 @@ test "max file name component lengths" { | ... | @@ -1449,11 +1449,15 @@ test "max file name component lengths" { |
| 1449 | if (native_os == .windows) { | 1449 | if (native_os == .windows) { |
| 1450 | // U+FFFF is the character with the largest code point that is encoded as a single | 1450 | // U+FFFF is the character with the largest code point that is encoded as a single |
| 1451 | // WTF-16 code unit, so Windows allows for NAME_MAX of them. | 1451 | // WTF-16 code unit, so Windows allows for NAME_MAX of them. |
| 1452 | const maxed_windows_filename1 = ("\u{FFFF}".*) ** windows.NAME_MAX; | 1452 | const codepoint1 = "\u{FFFF}".*; |
| 1453 | const buf1: [windows.NAME_MAX][codepoint1.len]u8 = @splat(codepoint1); | ||
| 1454 | const maxed_windows_filename1: []const u8 = @ptrCast(&buf1); | ||
| 1453 | // This is also a code point that is encoded as one WTF-16 code unit, but | 1455 | // This is also a code point that is encoded as one WTF-16 code unit, but |
| 1454 | // three WTF-8 bytes, so it exercises the limits of both WTF-16 and WTF-8 encodings. | 1456 | // three WTF-8 bytes, so it exercises the limits of both WTF-16 and WTF-8 encodings. |
| 1455 | const maxed_windows_filename2 = ("€".*) ** windows.NAME_MAX; | 1457 | const codepoint2 = "€".*; |
| 1456 | try testFilenameLimits(io, tmp.dir, &maxed_windows_filename1, &maxed_windows_filename2); | 1458 | const buf2: [windows.NAME_MAX][codepoint2.len]u8 = @splat(codepoint2); |
| 1459 | const maxed_windows_filename2: []const u8 = @ptrCast(&buf2); | ||
| 1460 | try testFilenameLimits(io, tmp.dir, maxed_windows_filename1, maxed_windows_filename2); | ||
| 1457 | } else if (native_os == .wasi) { | 1461 | } else if (native_os == .wasi) { |
| 1458 | // On WASI, the maxed filename depends on the host OS, so in order for this test to | 1462 | // On WASI, the maxed filename depends on the host OS, so in order for this test to |
| 1459 | // work on any host, we need to use a length that will work for all platforms | 1463 | // work on any host, we need to use a length that will work for all platforms |
lib/std/hash/Adler32.zig+3-3| ... | @@ -88,15 +88,15 @@ test "sanity" { | ... | @@ -88,15 +88,15 @@ test "sanity" { |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | test "long" { | 90 | test "long" { |
| 91 | const long1 = [_]u8{1} ** 1024; | 91 | const long1: [1024]u8 = @splat(1); |
| 92 | try testing.expectEqual(@as(u32, 0x06780401), hash(long1[0..])); | 92 | try testing.expectEqual(@as(u32, 0x06780401), hash(long1[0..])); |
| 93 | 93 | ||
| 94 | const long2 = [_]u8{1} ** 1025; | 94 | const long2: [1025]u8 = @splat(1); |
| 95 | try testing.expectEqual(@as(u32, 0x0a7a0402), hash(long2[0..])); | 95 | try testing.expectEqual(@as(u32, 0x0a7a0402), hash(long2[0..])); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | test "very long" { | 98 | test "very long" { |
| 99 | const long = [_]u8{1} ** 5553; | 99 | const long: [5553]u8 = @splat(1); |
| 100 | try testing.expectEqual(@as(u32, 0x707f15b2), hash(long[0..])); | 100 | try testing.expectEqual(@as(u32, 0x707f15b2), hash(long[0..])); |
| 101 | } | 101 | } |
| 102 | 102 |
lib/std/hash/benchmark.zig+2-2| ... | @@ -93,13 +93,13 @@ const hashes = [_]Hash{ | ... | @@ -93,13 +93,13 @@ const hashes = [_]Hash{ |
| 93 | .ty = hash.SipHash64(1, 3), | 93 | .ty = hash.SipHash64(1, 3), |
| 94 | .name = "siphash64", | 94 | .name = "siphash64", |
| 95 | .has_crypto_api = true, | 95 | .has_crypto_api = true, |
| 96 | .init_u8s = &[_]u8{0} ** 16, | 96 | .init_u8s = &@as([16]u8, @splat(0)), |
| 97 | }, | 97 | }, |
| 98 | Hash{ | 98 | Hash{ |
| 99 | .ty = hash.SipHash128(1, 3), | 99 | .ty = hash.SipHash128(1, 3), |
| 100 | .name = "siphash128", | 100 | .name = "siphash128", |
| 101 | .has_crypto_api = true, | 101 | .has_crypto_api = true, |
| 102 | .init_u8s = &[_]u8{0} ** 16, | 102 | .init_u8s = &@as([16]u8, @splat(0)), |
| 103 | }, | 103 | }, |
| 104 | }; | 104 | }; |
| 105 | 105 |
lib/std/hash/wyhash.zig+1-1| ... | @@ -253,7 +253,7 @@ test "iterative api" { | ... | @@ -253,7 +253,7 @@ test "iterative api" { |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | test "iterative maintains last sixteen" { | 255 | test "iterative maintains last sixteen" { |
| 256 | const input = "Z" ** 48 ++ "01234567890abcdefg"; | 256 | const input = &@as([48]u8, @splat('Z')) ++ "01234567890abcdefg"; |
| 257 | const seed = 0; | 257 | const seed = 0; |
| 258 | 258 | ||
| 259 | for (0..17) |i| { | 259 | for (0..17) |i| { |
lib/std/heap/debug_allocator.zig+1-1| ... | @@ -164,7 +164,7 @@ pub fn DebugAllocator(comptime config: Config) type { | ... | @@ -164,7 +164,7 @@ pub fn DebugAllocator(comptime config: Config) type { |
| 164 | return struct { | 164 | return struct { |
| 165 | backing_allocator: Allocator = std.heap.page_allocator, | 165 | backing_allocator: Allocator = std.heap.page_allocator, |
| 166 | /// Tracks the active bucket, which is the one that has free slots in it. | 166 | /// Tracks the active bucket, which is the one that has free slots in it. |
| 167 | buckets: [small_bucket_count]?*BucketHeader = [1]?*BucketHeader{null} ** small_bucket_count, | 167 | buckets: [small_bucket_count]?*BucketHeader = @splat(null), |
| 168 | large_allocations: LargeAllocTable = .empty, | 168 | large_allocations: LargeAllocTable = .empty, |
| 169 | total_requested_bytes: @TypeOf(total_requested_bytes_init) = total_requested_bytes_init, | 169 | total_requested_bytes: @TypeOf(total_requested_bytes_init) = total_requested_bytes_init, |
| 170 | requested_memory_limit: @TypeOf(requested_memory_limit_init) = requested_memory_limit_init, | 170 | requested_memory_limit: @TypeOf(requested_memory_limit_init) = requested_memory_limit_init, |
lib/std/http.zig+1-1| ... | @@ -749,7 +749,7 @@ pub const BodyWriter = struct { | ... | @@ -749,7 +749,7 @@ pub const BodyWriter = struct { |
| 749 | /// How many zeroes to reserve for hex-encoded chunk length. | 749 | /// How many zeroes to reserve for hex-encoded chunk length. |
| 750 | const chunk_len_digits = 8; | 750 | const chunk_len_digits = 8; |
| 751 | const max_chunk_len: usize = std.math.pow(u64, 16, chunk_len_digits) - 1; | 751 | const max_chunk_len: usize = std.math.pow(u64, 16, chunk_len_digits) - 1; |
| 752 | const chunk_header_template = ("0" ** chunk_len_digits) ++ "\r\n"; | 752 | const chunk_header_template = @as([chunk_len_digits]u8, @splat('0')) ++ "\r\n"; |
| 753 | 753 | ||
| 754 | comptime { | 754 | comptime { |
| 755 | assert(max_chunk_len == std.math.maxInt(u32)); | 755 | assert(max_chunk_len == std.math.maxInt(u32)); |
lib/std/json/JSONTestSuite_test.zig+10-5| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | // This file was generated by _generate_JSONTestSuite.zig | 1 | //! This file was generated by _generate_JSONTestSuite.zig |
| 2 | // These test cases are sourced from: https://github.com/nst/JSONTestSuite | 2 | //! These test cases are sourced from: https://github.com/nst/JSONTestSuite |
| 3 | const ok = @import("./test.zig").ok; | 3 | const ok = @import("./test.zig").ok; |
| 4 | const err = @import("./test.zig").err; | 4 | const err = @import("./test.zig").err; |
| 5 | const any = @import("./test.zig").any; | 5 | const any = @import("./test.zig").any; |
| ... | @@ -104,7 +104,7 @@ test "i_string_utf16LE_no_BOM.json" { | ... | @@ -104,7 +104,7 @@ test "i_string_utf16LE_no_BOM.json" { |
| 104 | try any("[\x00\"\x00\xe9\x00\"\x00]\x00"); | 104 | try any("[\x00\"\x00\xe9\x00\"\x00]\x00"); |
| 105 | } | 105 | } |
| 106 | test "i_structure_500_nested_arrays.json" { | 106 | test "i_structure_500_nested_arrays.json" { |
| 107 | try any("[" ** 500 ++ "]" ** 500); | 107 | try any(&@as([500]u8, @splat('[')) ++ &@as([500]u8, @splat(']'))); |
| 108 | } | 108 | } |
| 109 | test "i_structure_UTF-8_BOM_empty_object.json" { | 109 | test "i_structure_UTF-8_BOM_empty_object.json" { |
| 110 | try any("\xef\xbb\xbf{}"); | 110 | try any("\xef\xbb\xbf{}"); |
| ... | @@ -527,7 +527,7 @@ test "n_string_with_trailing_garbage.json" { | ... | @@ -527,7 +527,7 @@ test "n_string_with_trailing_garbage.json" { |
| 527 | try err("\"\"x"); | 527 | try err("\"\"x"); |
| 528 | } | 528 | } |
| 529 | test "n_structure_100000_opening_arrays.json" { | 529 | test "n_structure_100000_opening_arrays.json" { |
| 530 | try err("[" ** 100000); | 530 | try err(&@as([100000]u8, @splat('['))); |
| 531 | } | 531 | } |
| 532 | test "n_structure_U+2060_word_joined.json" { | 532 | test "n_structure_U+2060_word_joined.json" { |
| 533 | try err("[\xe2\x81\xa0]"); | 533 | try err("[\xe2\x81\xa0]"); |
| ... | @@ -605,7 +605,12 @@ test "n_structure_open_array_comma.json" { | ... | @@ -605,7 +605,12 @@ test "n_structure_open_array_comma.json" { |
| 605 | try err("[,"); | 605 | try err("[,"); |
| 606 | } | 606 | } |
| 607 | test "n_structure_open_array_object.json" { | 607 | test "n_structure_open_array_object.json" { |
| 608 | try err("[{\"\":" ** 50000 ++ "\n"); | 608 | try err(str: { |
| 609 | const part = "[{\"\":"; | ||
| 610 | const buf: [50000][part.len]u8 = @splat(part.*); | ||
| 611 | const s: []const u8 = @ptrCast(&buf); | ||
| 612 | break :str s ++ "\n"; | ||
| 613 | }); | ||
| 609 | } | 614 | } |
| 610 | test "n_structure_open_array_open_object.json" { | 615 | test "n_structure_open_array_open_object.json" { |
| 611 | try err("[{"); | 616 | try err("[{"); |
lib/std/json/scanner_test.zig+28-17| ... | @@ -261,19 +261,28 @@ test "strings" { | ... | @@ -261,19 +261,28 @@ test "strings" { |
| 261 | } | 261 | } |
| 262 | } | 262 | } |
| 263 | 263 | ||
| 264 | const nesting_test_cases = .{ | 264 | const nesting_test_cases = cases: { |
| 265 | .{ null, "[]" }, | 265 | const open_arrays: *const [1000]u8 = &@splat('['); |
| 266 | .{ null, "{}" }, | 266 | const close_arrays: *const [1000]u8 = &@splat(']'); |
| 267 | .{ error.SyntaxError, "[}" }, | 267 | |
| 268 | .{ error.SyntaxError, "{]" }, | 268 | const open_objects_buf: [1000][4]u8 = @splat("{\"\":".*); |
| 269 | .{ null, "[" ** 1000 ++ "]" ** 1000 }, | 269 | const open_objects: []const u8 = @ptrCast(&open_objects_buf); |
| 270 | .{ null, "{\"\":" ** 1000 ++ "0" ++ "}" ** 1000 }, | 270 | const close_objects: *const [1000]u8 = &@splat('}'); |
| 271 | .{ error.SyntaxError, "[" ** 1000 ++ "]" ** 999 ++ "}" }, | 271 | |
| 272 | .{ error.SyntaxError, "{\"\":" ** 1000 ++ "0" ++ "}" ** 999 ++ "]" }, | 272 | break :cases .{ |
| 273 | .{ error.SyntaxError, "[" ** 1000 ++ "]" ** 1001 }, | 273 | .{ null, "[]" }, |
| 274 | .{ error.SyntaxError, "{\"\":" ** 1000 ++ "0" ++ "}" ** 1001 }, | 274 | .{ null, "{}" }, |
| 275 | .{ error.UnexpectedEndOfInput, "[" ** 1000 ++ "]" ** 999 }, | 275 | .{ error.SyntaxError, "[}" }, |
| 276 | .{ error.UnexpectedEndOfInput, "{\"\":" ** 1000 ++ "0" ++ "}" ** 999 }, | 276 | .{ error.SyntaxError, "{]" }, |
| 277 | .{ null, open_arrays ++ close_arrays }, | ||
| 278 | .{ null, open_objects ++ "0" ++ close_objects }, | ||
| 279 | .{ error.SyntaxError, open_arrays ++ close_arrays[0..999] ++ "}" }, | ||
| 280 | .{ error.SyntaxError, open_objects ++ "0" ++ close_objects[0..999] ++ "]" }, | ||
| 281 | .{ error.SyntaxError, open_arrays ++ close_arrays ++ "]" }, | ||
| 282 | .{ error.SyntaxError, open_objects ++ "0" ++ close_objects ++ "}" }, | ||
| 283 | .{ error.UnexpectedEndOfInput, open_arrays ++ close_arrays[0..999] }, | ||
| 284 | .{ error.UnexpectedEndOfInput, open_objects ++ "0" ++ close_objects[0..999] }, | ||
| 285 | }; | ||
| 277 | }; | 286 | }; |
| 278 | 287 | ||
| 279 | test "nesting" { | 288 | test "nesting" { |
| ... | @@ -421,11 +430,12 @@ test "skipValue" { | ... | @@ -421,11 +430,12 @@ test "skipValue" { |
| 421 | try testSkipValue("{\"foo\": \"bar\\nbaz\"}"); | 430 | try testSkipValue("{\"foo\": \"bar\\nbaz\"}"); |
| 422 | 431 | ||
| 423 | // An absurd number of nestings | 432 | // An absurd number of nestings |
| 424 | const nestings = 1000; | 433 | const open_all: [1000]u8 = @splat('['); |
| 425 | try testSkipValue("[" ** nestings ++ "]" ** nestings); | 434 | const close_all: [1000]u8 = @splat(']'); |
| 435 | try testSkipValue(&(open_all ++ close_all)); | ||
| 426 | 436 | ||
| 427 | // Would a number token cause problems in a deeply-nested array? | 437 | // Would a number token cause problems in a deeply-nested array? |
| 428 | try testSkipValue("[" ** nestings ++ "0.118, 999, 881.99, 911.9, 725, 3" ++ "]" ** nestings); | 438 | try testSkipValue(&open_all ++ "0.118, 999, 881.99, 911.9, 725, 3" ++ &close_all); |
| 429 | 439 | ||
| 430 | // Mismatched brace/square bracket | 440 | // Mismatched brace/square bracket |
| 431 | try std.testing.expectError(error.SyntaxError, testSkipValue("[102, 111, 111}")); | 441 | try std.testing.expectError(error.SyntaxError, testSkipValue("[102, 111, 111}")); |
| ... | @@ -474,7 +484,8 @@ test "enableDiagnostics" { | ... | @@ -474,7 +484,8 @@ test "enableDiagnostics" { |
| 474 | 484 | ||
| 475 | inline for ([_]comptime_int{ 5, 6, 7, 99 }) |reps| { | 485 | inline for ([_]comptime_int{ 5, 6, 7, 99 }) |reps| { |
| 476 | // The error happens 1 byte before the end. | 486 | // The error happens 1 byte before the end. |
| 477 | const s = "[" ** reps ++ "}"; | 487 | const open_all: [reps]u8 = @splat('['); |
| 488 | const s = &open_all ++ "}"; | ||
| 478 | try testDiagnostics(error.SyntaxError, 1, s.len, s.len - 1, s); | 489 | try testDiagnostics(error.SyntaxError, 1, s.len, s.len - 1, s); |
| 479 | } | 490 | } |
| 480 | } | 491 | } |
lib/std/json/static.zig+2-2| ... | @@ -334,7 +334,7 @@ pub fn innerParse( | ... | @@ -334,7 +334,7 @@ pub fn innerParse( |
| 334 | if (.object_begin != try source.next()) return error.UnexpectedToken; | 334 | if (.object_begin != try source.next()) return error.UnexpectedToken; |
| 335 | 335 | ||
| 336 | var r: T = undefined; | 336 | var r: T = undefined; |
| 337 | var fields_seen = [_]bool{false} ** structInfo.fields.len; | 337 | var fields_seen: [structInfo.fields.len]bool = @splat(false); |
| 338 | 338 | ||
| 339 | while (true) { | 339 | while (true) { |
| 340 | var name_token: ?Token = try source.nextAllocMax(allocator, .alloc_if_needed, options.max_value_len.?); | 340 | var name_token: ?Token = try source.nextAllocMax(allocator, .alloc_if_needed, options.max_value_len.?); |
| ... | @@ -649,7 +649,7 @@ pub fn innerParseFromValue( | ... | @@ -649,7 +649,7 @@ pub fn innerParseFromValue( |
| 649 | if (source != .object) return error.UnexpectedToken; | 649 | if (source != .object) return error.UnexpectedToken; |
| 650 | 650 | ||
| 651 | var r: T = undefined; | 651 | var r: T = undefined; |
| 652 | var fields_seen = [_]bool{false} ** structInfo.fields.len; | 652 | var fields_seen: [structInfo.fields.len]bool = @splat(false); |
| 653 | 653 | ||
| 654 | var it = source.object.iterator(); | 654 | var it = source.object.iterator(); |
| 655 | while (it.next()) |kv| { | 655 | while (it.next()) |kv| { |
lib/std/math/big/int.zig+3-3| ... | @@ -29,8 +29,8 @@ const Constants = struct { | ... | @@ -29,8 +29,8 @@ const Constants = struct { |
| 29 | }; | 29 | }; |
| 30 | const constants: Constants = blk: { | 30 | const constants: Constants = blk: { |
| 31 | @setEvalBranchQuota(2000); | 31 | @setEvalBranchQuota(2000); |
| 32 | var digits_per_limb = [_]u8{0} ** 37; | 32 | var digits_per_limb: [37]u8 = @splat(0); |
| 33 | var bases = [_]Limb{0} ** 37; | 33 | var bases: [37]Limb = @splat(0); |
| 34 | for (2..37) |base| { | 34 | for (2..37) |base| { |
| 35 | digits_per_limb[base] = @intCast(math.log(Limb, base, math.maxInt(Limb))); | 35 | digits_per_limb[base] = @intCast(math.log(Limb, base, math.maxInt(Limb))); |
| 36 | bases[base] = std.math.pow(Limb, base, digits_per_limb[base]); | 36 | bases[base] = std.math.pow(Limb, base, digits_per_limb[base]); |
| ... | @@ -2391,7 +2391,7 @@ pub const Const = struct { | ... | @@ -2391,7 +2391,7 @@ pub const Const = struct { |
| 2391 | var limbs: [calcToStringLimbsBufferLen(available_len, 10)]Limb = undefined; | 2391 | var limbs: [calcToStringLimbsBufferLen(available_len, 10)]Limb = undefined; |
| 2392 | 2392 | ||
| 2393 | const biggest: Const = .{ | 2393 | const biggest: Const = .{ |
| 2394 | .limbs = &([1]Limb{comptime math.maxInt(Limb)} ** available_len), | 2394 | .limbs = &@as([available_len]Limb, @splat(comptime math.maxInt(Limb))), |
| 2395 | .positive = false, | 2395 | .positive = false, |
| 2396 | }; | 2396 | }; |
| 2397 | var buf: [biggest.sizeInBaseUpperBound(2)]u8 = undefined; | 2397 | var buf: [biggest.sizeInBaseUpperBound(2)]u8 = undefined; |
lib/std/math/big/int_test.zig+13-13| ... | @@ -3351,7 +3351,7 @@ test "big int popcount" { | ... | @@ -3351,7 +3351,7 @@ test "big int popcount" { |
| 3351 | try popCountTest(&a, limb_bits * 2 + 1, limb_bits * 2 + 1); | 3351 | try popCountTest(&a, limb_bits * 2 + 1, limb_bits * 2 + 1); |
| 3352 | 3352 | ||
| 3353 | // Check very large numbers. | 3353 | // Check very large numbers. |
| 3354 | try a.setString(16, "ff00000100000100" ++ ("0000000000000000" ** 62)); | 3354 | try a.setString(16, "ff00000100000100" ++ &@as([16 * 62]u8, @splat('0'))); |
| 3355 | try popCountTest(&a, 4032, 10); | 3355 | try popCountTest(&a, 4032, 10); |
| 3356 | try popCountTest(&a, 6000, 10); | 3356 | try popCountTest(&a, 6000, 10); |
| 3357 | a.negate(); | 3357 | a.negate(); |
| ... | @@ -3459,13 +3459,13 @@ test "big int write twos complement +/- zero" { | ... | @@ -3459,13 +3459,13 @@ test "big int write twos complement +/- zero" { |
| 3459 | // Test zero | 3459 | // Test zero |
| 3460 | 3460 | ||
| 3461 | m.toConst().writeTwosComplement(buffer1[0..13], .little); | 3461 | m.toConst().writeTwosComplement(buffer1[0..13], .little); |
| 3462 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)), buffer1); | 3462 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xAA, 0xAA, 0xAA }, buffer1); |
| 3463 | m.toConst().writeTwosComplement(buffer1[0..13], .big); | 3463 | m.toConst().writeTwosComplement(buffer1[0..13], .big); |
| 3464 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)), buffer1); | 3464 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xAA, 0xAA, 0xAA }, buffer1); |
| 3465 | m.toConst().writeTwosComplement(buffer1[0..16], .little); | 3465 | m.toConst().writeTwosComplement(buffer1[0..16], .little); |
| 3466 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 16)), buffer1); | 3466 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, buffer1); |
| 3467 | m.toConst().writeTwosComplement(buffer1[0..16], .big); | 3467 | m.toConst().writeTwosComplement(buffer1[0..16], .big); |
| 3468 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 16)), buffer1); | 3468 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, buffer1); |
| 3469 | 3469 | ||
| 3470 | @memset(buffer1, 0xaa); | 3470 | @memset(buffer1, 0xaa); |
| 3471 | m.positive = false; | 3471 | m.positive = false; |
| ... | @@ -3473,13 +3473,13 @@ test "big int write twos complement +/- zero" { | ... | @@ -3473,13 +3473,13 @@ test "big int write twos complement +/- zero" { |
| 3473 | // Test negative zero | 3473 | // Test negative zero |
| 3474 | 3474 | ||
| 3475 | m.toConst().writeTwosComplement(buffer1[0..13], .little); | 3475 | m.toConst().writeTwosComplement(buffer1[0..13], .little); |
| 3476 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)), buffer1); | 3476 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xAA, 0xAA, 0xAA }, buffer1); |
| 3477 | m.toConst().writeTwosComplement(buffer1[0..13], .big); | 3477 | m.toConst().writeTwosComplement(buffer1[0..13], .big); |
| 3478 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)), buffer1); | 3478 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xAA, 0xAA, 0xAA }, buffer1); |
| 3479 | m.toConst().writeTwosComplement(buffer1[0..16], .little); | 3479 | m.toConst().writeTwosComplement(buffer1[0..16], .little); |
| 3480 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 16)), buffer1); | 3480 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, buffer1); |
| 3481 | m.toConst().writeTwosComplement(buffer1[0..16], .big); | 3481 | m.toConst().writeTwosComplement(buffer1[0..16], .big); |
| 3482 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 16)), buffer1); | 3482 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, buffer1); |
| 3483 | } | 3483 | } |
| 3484 | 3484 | ||
| 3485 | test "big int conversion write twos complement with padding" { | 3485 | test "big int conversion write twos complement with padding" { |
| ... | @@ -3556,7 +3556,7 @@ test "big int conversion write twos complement with padding" { | ... | @@ -3556,7 +3556,7 @@ test "big int conversion write twos complement with padding" { |
| 3556 | 3556 | ||
| 3557 | // Test 0 | 3557 | // Test 0 |
| 3558 | 3558 | ||
| 3559 | buffer = &([_]u8{0} ** 16); | 3559 | buffer = &@as([16]u8, @splat(0)); |
| 3560 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); | 3560 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); |
| 3561 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); | 3561 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); |
| 3562 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); | 3562 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); |
| ... | @@ -3567,7 +3567,7 @@ test "big int conversion write twos complement with padding" { | ... | @@ -3567,7 +3567,7 @@ test "big int conversion write twos complement with padding" { |
| 3567 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); | 3567 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); |
| 3568 | 3568 | ||
| 3569 | bit_count = 0; | 3569 | bit_count = 0; |
| 3570 | buffer = &([_]u8{0xaa} ** 16); | 3570 | buffer = &@as([16]u8, @splat(0xaa)); |
| 3571 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); | 3571 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); |
| 3572 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); | 3572 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); |
| 3573 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); | 3573 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); |
| ... | @@ -3592,13 +3592,13 @@ test "big int conversion write twos complement zero" { | ... | @@ -3592,13 +3592,13 @@ test "big int conversion write twos complement zero" { |
| 3592 | const bit_count: usize = 12 * 8 + 1; | 3592 | const bit_count: usize = 12 * 8 + 1; |
| 3593 | var buffer: []const u8 = undefined; | 3593 | var buffer: []const u8 = undefined; |
| 3594 | 3594 | ||
| 3595 | buffer = &([_]u8{0} ** 13); | 3595 | buffer = &@as([13]u8, @splat(0)); |
| 3596 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); | 3596 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); |
| 3597 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); | 3597 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); |
| 3598 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); | 3598 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); |
| 3599 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); | 3599 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); |
| 3600 | 3600 | ||
| 3601 | buffer = &([_]u8{0} ** 16); | 3601 | buffer = &@as([16]u8, @splat(0)); |
| 3602 | m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned); | 3602 | m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned); |
| 3603 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); | 3603 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); |
| 3604 | m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned); | 3604 | m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned); |
lib/std/mem.zig+9-6| ... | @@ -359,7 +359,10 @@ test zeroes { | ... | @@ -359,7 +359,10 @@ test zeroes { |
| 359 | var a = zeroes(C_struct); | 359 | var a = zeroes(C_struct); |
| 360 | 360 | ||
| 361 | // Extern structs should have padding zeroed out. | 361 | // Extern structs should have padding zeroed out. |
| 362 | try testing.expectEqualSlices(u8, &[_]u8{0} ** @sizeOf(@TypeOf(a)), asBytes(&a)); | 362 | { |
| 363 | const num_bytes = @sizeOf(@TypeOf(a)); | ||
| 364 | try testing.expectEqualSlices(u8, &@as([num_bytes]u8, @splat(0)), @ptrCast(&a)); | ||
| 365 | } | ||
| 363 | 366 | ||
| 364 | a.y += 10; | 367 | a.y += 10; |
| 365 | 368 | ||
| ... | @@ -1587,7 +1590,7 @@ test find { | ... | @@ -1587,7 +1590,7 @@ test find { |
| 1587 | test "find multibyte" { | 1590 | test "find multibyte" { |
| 1588 | { | 1591 | { |
| 1589 | // make haystack and needle long enough to trigger Boyer-Moore-Horspool algorithm | 1592 | // make haystack and needle long enough to trigger Boyer-Moore-Horspool algorithm |
| 1590 | const haystack = [1]u16{0} ** 100 ++ [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff }; | 1593 | const haystack = @as([100]u16, @splat(0)) ++ [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff }; |
| 1591 | const needle = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee }; | 1594 | const needle = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee }; |
| 1592 | try testing.expectEqual(findPos(u16, &haystack, 0, &needle), 100); | 1595 | try testing.expectEqual(findPos(u16, &haystack, 0, &needle), 100); |
| 1593 | 1596 | ||
| ... | @@ -1600,7 +1603,7 @@ test "find multibyte" { | ... | @@ -1600,7 +1603,7 @@ test "find multibyte" { |
| 1600 | 1603 | ||
| 1601 | { | 1604 | { |
| 1602 | // make haystack and needle long enough to trigger Boyer-Moore-Horspool algorithm | 1605 | // make haystack and needle long enough to trigger Boyer-Moore-Horspool algorithm |
| 1603 | const haystack = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff } ++ [1]u16{0} ** 100; | 1606 | const haystack = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff } ++ @as([100]u16, @splat(0)); |
| 1604 | const needle = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee }; | 1607 | const needle = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee }; |
| 1605 | try testing.expectEqual(lastIndexOf(u16, &haystack, &needle), 0); | 1608 | try testing.expectEqual(lastIndexOf(u16, &haystack, &needle), 0); |
| 1606 | 1609 | ||
| ... | @@ -4645,7 +4648,7 @@ test "sliceAsBytes with sentinel slice" { | ... | @@ -4645,7 +4648,7 @@ test "sliceAsBytes with sentinel slice" { |
| 4645 | } | 4648 | } |
| 4646 | 4649 | ||
| 4647 | test "sliceAsBytes with zero-bit element type" { | 4650 | test "sliceAsBytes with zero-bit element type" { |
| 4648 | const lots_of_nothing = [1]void{{}} ** 10_000; | 4651 | const lots_of_nothing: [10_000]void = @splat({}); |
| 4649 | const bytes = sliceAsBytes(&lots_of_nothing); | 4652 | const bytes = sliceAsBytes(&lots_of_nothing); |
| 4650 | try testing.expect(bytes.len == 0); | 4653 | try testing.expect(bytes.len == 0); |
| 4651 | } | 4654 | } |
| ... | @@ -4863,8 +4866,8 @@ test doNotOptimizeAway { | ... | @@ -4863,8 +4866,8 @@ test doNotOptimizeAway { |
| 4863 | doNotOptimizeAway(@as(u200, 0)); | 4866 | doNotOptimizeAway(@as(u200, 0)); |
| 4864 | doNotOptimizeAway(@as(f32, 0.0)); | 4867 | doNotOptimizeAway(@as(f32, 0.0)); |
| 4865 | doNotOptimizeAway(@as(f64, 0.0)); | 4868 | doNotOptimizeAway(@as(f64, 0.0)); |
| 4866 | doNotOptimizeAway([_]u8{0} ** 4); | 4869 | doNotOptimizeAway(@as([4]u8, @splat(0))); |
| 4867 | doNotOptimizeAway([_]u8{0} ** 100); | 4870 | doNotOptimizeAway(@as([100]u8, @splat(0))); |
| 4868 | doNotOptimizeAway(@as(std.builtin.Endian, .little)); | 4871 | doNotOptimizeAway(@as(std.builtin.Endian, .little)); |
| 4869 | } | 4872 | } |
| 4870 | 4873 |
lib/std/os/emscripten.zig+2-2| ... | @@ -373,7 +373,7 @@ pub const rusage = extern struct { | ... | @@ -373,7 +373,7 @@ pub const rusage = extern struct { |
| 373 | nsignals: isize, | 373 | nsignals: isize, |
| 374 | nvcsw: isize, | 374 | nvcsw: isize, |
| 375 | nivcsw: isize, | 375 | nivcsw: isize, |
| 376 | __reserved: [16]isize = [1]isize{0} ** 16, | 376 | __reserved: [16]isize = @splat(0), |
| 377 | 377 | ||
| 378 | pub const SELF = 0; | 378 | pub const SELF = 0; |
| 379 | pub const CHILDREN = -1; | 379 | pub const CHILDREN = -1; |
| ... | @@ -481,7 +481,7 @@ pub const Sigaction = extern struct { | ... | @@ -481,7 +481,7 @@ pub const Sigaction = extern struct { |
| 481 | 481 | ||
| 482 | pub const sigset_t = [1024 / 32]u32; | 482 | pub const sigset_t = [1024 / 32]u32; |
| 483 | pub fn sigemptyset() sigset_t { | 483 | pub fn sigemptyset() sigset_t { |
| 484 | return [_]u32{0} ** @typeInfo(sigset_t).array.len; | 484 | return @splat(0); |
| 485 | } | 485 | } |
| 486 | pub const siginfo_t = extern struct { | 486 | pub const siginfo_t = extern struct { |
| 487 | signo: i32, | 487 | signo: i32, |
lib/std/os/linux.zig+4-4| ... | @@ -2262,12 +2262,12 @@ pub fn sigrtmax() u8 { | ... | @@ -2262,12 +2262,12 @@ pub fn sigrtmax() u8 { |
| 2262 | 2262 | ||
| 2263 | /// Zig's version of sigemptyset. Returns initialized sigset_t. | 2263 | /// Zig's version of sigemptyset. Returns initialized sigset_t. |
| 2264 | pub fn sigemptyset() sigset_t { | 2264 | pub fn sigemptyset() sigset_t { |
| 2265 | return [_]SigsetElement{0} ** sigset_len; | 2265 | return @splat(0); |
| 2266 | } | 2266 | } |
| 2267 | 2267 | ||
| 2268 | /// Zig's version of sigfillset. Returns initalized sigset_t. | 2268 | /// Zig's version of sigfillset. Returns initalized sigset_t. |
| 2269 | pub fn sigfillset() sigset_t { | 2269 | pub fn sigfillset() sigset_t { |
| 2270 | return [_]SigsetElement{~@as(SigsetElement, 0)} ** sigset_len; | 2270 | return @splat(~@as(SigsetElement, 0)); |
| 2271 | } | 2271 | } |
| 2272 | 2272 | ||
| 2273 | fn sigset_bit_index(sig: SIG) struct { word: usize, mask: SigsetElement } { | 2273 | fn sigset_bit_index(sig: SIG) struct { word: usize, mask: SigsetElement } { |
| ... | @@ -6129,7 +6129,7 @@ pub const sockaddr = extern struct { | ... | @@ -6129,7 +6129,7 @@ pub const sockaddr = extern struct { |
| 6129 | flags: u8, | 6129 | flags: u8, |
| 6130 | 6130 | ||
| 6131 | /// The total size of this structure should be exactly the same as that of struct sockaddr. | 6131 | /// The total size of this structure should be exactly the same as that of struct sockaddr. |
| 6132 | zero: [3]u8 = [_]u8{0} ** 3, | 6132 | zero: [3]u8 = @splat(0), |
| 6133 | comptime { | 6133 | comptime { |
| 6134 | std.debug.assert(@sizeOf(vm) == @sizeOf(sockaddr)); | 6134 | std.debug.assert(@sizeOf(vm) == @sizeOf(sockaddr)); |
| 6135 | } | 6135 | } |
| ... | @@ -7475,7 +7475,7 @@ pub const rusage = extern struct { | ... | @@ -7475,7 +7475,7 @@ pub const rusage = extern struct { |
| 7475 | nsignals: isize, | 7475 | nsignals: isize, |
| 7476 | nvcsw: isize, | 7476 | nvcsw: isize, |
| 7477 | nivcsw: isize, | 7477 | nivcsw: isize, |
| 7478 | __reserved: [16]isize = [1]isize{0} ** 16, | 7478 | __reserved: [16]isize = @splat(0), |
| 7479 | 7479 | ||
| 7480 | pub const SELF = 0; | 7480 | pub const SELF = 0; |
| 7481 | pub const CHILDREN = -1; | 7481 | pub const CHILDREN = -1; |
lib/std/os/linux/IoUring/test.zig+34-30| ... | @@ -115,12 +115,12 @@ test "readv" { | ... | @@ -115,12 +115,12 @@ test "readv" { |
| 115 | // https://github.com/torvalds/linux/blob/v5.4/fs/io_uring.c#L3119-L3124 vs | 115 | // https://github.com/torvalds/linux/blob/v5.4/fs/io_uring.c#L3119-L3124 vs |
| 116 | // https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L6687-L6691 | 116 | // https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L6687-L6691 |
| 117 | // We therefore avoid stressing sparse fd sets here: | 117 | // We therefore avoid stressing sparse fd sets here: |
| 118 | var registered_fds = [_]linux.fd_t{0} ** 1; | 118 | var registered_fds: [1]linux.fd_t = .{0}; |
| 119 | const fd_index = 0; | 119 | const fd_index = 0; |
| 120 | registered_fds[fd_index] = file.handle; | 120 | registered_fds[fd_index] = file.handle; |
| 121 | try ring.register_files(registered_fds[0..]); | 121 | try ring.register_files(registered_fds[0..]); |
| 122 | 122 | ||
| 123 | var buffer = [_]u8{42} ** 128; | 123 | var buffer: [128]u8 = @splat(42); |
| 124 | var iovecs = [_]iovec{iovec{ .base = &buffer, .len = buffer.len }}; | 124 | var iovecs = [_]iovec{iovec{ .base = &buffer, .len = buffer.len }}; |
| 125 | const sqe = try ring.read(0xcccccccc, fd_index, .{ .iovecs = iovecs[0..] }, 0); | 125 | const sqe = try ring.read(0xcccccccc, fd_index, .{ .iovecs = iovecs[0..] }, 0); |
| 126 | try testing.expectEqual(linux.IORING_OP.READV, sqe.opcode); | 126 | try testing.expectEqual(linux.IORING_OP.READV, sqe.opcode); |
| ... | @@ -133,7 +133,7 @@ test "readv" { | ... | @@ -133,7 +133,7 @@ test "readv" { |
| 133 | .res = buffer.len, | 133 | .res = buffer.len, |
| 134 | .flags = 0, | 134 | .flags = 0, |
| 135 | }, try ring.copy_cqe()); | 135 | }, try ring.copy_cqe()); |
| 136 | try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer.len), buffer[0..]); | 136 | try testing.expectEqualSlices(u8, &@as([buffer.len]u8, @splat(0)), buffer[0..]); |
| 137 | 137 | ||
| 138 | try ring.unregister_files(); | 138 | try ring.unregister_files(); |
| 139 | } | 139 | } |
| ... | @@ -156,11 +156,11 @@ test "writev/fsync/readv" { | ... | @@ -156,11 +156,11 @@ test "writev/fsync/readv" { |
| 156 | defer file.close(io); | 156 | defer file.close(io); |
| 157 | const fd = file.handle; | 157 | const fd = file.handle; |
| 158 | 158 | ||
| 159 | const buffer_write = [_]u8{42} ** 128; | 159 | const buffer_write: [128]u8 = @splat(42); |
| 160 | const iovecs_write = [_]iovec_const{ | 160 | const iovecs_write = [_]iovec_const{ |
| 161 | iovec_const{ .base = &buffer_write, .len = buffer_write.len }, | 161 | iovec_const{ .base = &buffer_write, .len = buffer_write.len }, |
| 162 | }; | 162 | }; |
| 163 | var buffer_read = [_]u8{0} ** 128; | 163 | var buffer_read: [128]u8 = @splat(0); |
| 164 | var iovecs_read = [_]iovec{ | 164 | var iovecs_read = [_]iovec{ |
| 165 | iovec{ .base = &buffer_read, .len = buffer_read.len }, | 165 | iovec{ .base = &buffer_read, .len = buffer_read.len }, |
| 166 | }; | 166 | }; |
| ... | @@ -225,8 +225,8 @@ test "write/read" { | ... | @@ -225,8 +225,8 @@ test "write/read" { |
| 225 | defer file.close(io); | 225 | defer file.close(io); |
| 226 | const fd = file.handle; | 226 | const fd = file.handle; |
| 227 | 227 | ||
| 228 | const buffer_write = [_]u8{97} ** 20; | 228 | const buffer_write: [20]u8 = @splat(97); |
| 229 | var buffer_read = [_]u8{98} ** 20; | 229 | var buffer_read: [20]u8 = @splat(98); |
| 230 | const sqe_write = try ring.write(0x11111111, fd, buffer_write[0..], 10); | 230 | const sqe_write = try ring.write(0x11111111, fd, buffer_write[0..], 10); |
| 231 | try testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode); | 231 | try testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode); |
| 232 | try testing.expectEqual(@as(u64, 10), sqe_write.off); | 232 | try testing.expectEqual(@as(u64, 10), sqe_write.off); |
| ... | @@ -276,8 +276,8 @@ test "splice/read" { | ... | @@ -276,8 +276,8 @@ test "splice/read" { |
| 276 | defer file_dst.close(io); | 276 | defer file_dst.close(io); |
| 277 | const fd_dst = file_dst.handle; | 277 | const fd_dst = file_dst.handle; |
| 278 | 278 | ||
| 279 | const buffer_write = [_]u8{97} ** 20; | 279 | const buffer_write: [20]u8 = @splat(97); |
| 280 | var buffer_read = [_]u8{98} ** 20; | 280 | var buffer_read: [20]u8 = @splat(98); |
| 281 | try file_src.writeStreamingAll(io, &buffer_write); | 281 | try file_src.writeStreamingAll(io, &buffer_write); |
| 282 | 282 | ||
| 283 | const fds = try std.Io.Threaded.pipe2(.{}); | 283 | const fds = try std.Io.Threaded.pipe2(.{}); |
| ... | @@ -542,7 +542,7 @@ test "sendmsg/recvmsg" { | ... | @@ -542,7 +542,7 @@ test "sendmsg/recvmsg" { |
| 542 | const client = try socket(address_server.family, posix.SOCK.DGRAM, 0); | 542 | const client = try socket(address_server.family, posix.SOCK.DGRAM, 0); |
| 543 | defer _ = linux.close(client); | 543 | defer _ = linux.close(client); |
| 544 | 544 | ||
| 545 | const buffer_send = [_]u8{42} ** 128; | 545 | const buffer_send: [128]u8 = @splat(42); |
| 546 | const iovecs_send = [_]iovec_const{ | 546 | const iovecs_send = [_]iovec_const{ |
| 547 | iovec_const{ .base = &buffer_send, .len = buffer_send.len }, | 547 | iovec_const{ .base = &buffer_send, .len = buffer_send.len }, |
| 548 | }; | 548 | }; |
| ... | @@ -560,7 +560,7 @@ test "sendmsg/recvmsg" { | ... | @@ -560,7 +560,7 @@ test "sendmsg/recvmsg" { |
| 560 | try testing.expectEqual(linux.IORING_OP.SENDMSG, sqe_sendmsg.opcode); | 560 | try testing.expectEqual(linux.IORING_OP.SENDMSG, sqe_sendmsg.opcode); |
| 561 | try testing.expectEqual(client, sqe_sendmsg.fd); | 561 | try testing.expectEqual(client, sqe_sendmsg.fd); |
| 562 | 562 | ||
| 563 | var buffer_recv = [_]u8{0} ** 128; | 563 | var buffer_recv: [128]u8 = @splat(0); |
| 564 | var iovecs_recv = [_]iovec{ | 564 | var iovecs_recv = [_]iovec{ |
| 565 | iovec{ .base = &buffer_recv, .len = buffer_recv.len }, | 565 | iovec{ .base = &buffer_recv, .len = buffer_recv.len }, |
| 566 | }; | 566 | }; |
| ... | @@ -944,7 +944,7 @@ test "register_files_update" { | ... | @@ -944,7 +944,7 @@ test "register_files_update" { |
| 944 | const file = try Io.Dir.openFileAbsolute(io, "/dev/zero", .{}); | 944 | const file = try Io.Dir.openFileAbsolute(io, "/dev/zero", .{}); |
| 945 | defer file.close(io); | 945 | defer file.close(io); |
| 946 | 946 | ||
| 947 | var registered_fds = [_]linux.fd_t{0} ** 2; | 947 | var registered_fds: [2]linux.fd_t = @splat(0); |
| 948 | const fd_index = 0; | 948 | const fd_index = 0; |
| 949 | const fd_index2 = 1; | 949 | const fd_index2 = 1; |
| 950 | registered_fds[fd_index] = file.handle; | 950 | registered_fds[fd_index] = file.handle; |
| ... | @@ -966,7 +966,7 @@ test "register_files_update" { | ... | @@ -966,7 +966,7 @@ test "register_files_update" { |
| 966 | registered_fds[fd_index2] = -1; | 966 | registered_fds[fd_index2] = -1; |
| 967 | try ring.register_files_update(0, registered_fds[0..]); | 967 | try ring.register_files_update(0, registered_fds[0..]); |
| 968 | 968 | ||
| 969 | var buffer = [_]u8{42} ** 128; | 969 | var buffer: [128]u8 = @splat(42); |
| 970 | { | 970 | { |
| 971 | const sqe = try ring.read(0xcccccccc, fd_index, .{ .buffer = &buffer }, 0); | 971 | const sqe = try ring.read(0xcccccccc, fd_index, .{ .buffer = &buffer }, 0); |
| 972 | try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode); | 972 | try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode); |
| ... | @@ -978,7 +978,7 @@ test "register_files_update" { | ... | @@ -978,7 +978,7 @@ test "register_files_update" { |
| 978 | .res = buffer.len, | 978 | .res = buffer.len, |
| 979 | .flags = 0, | 979 | .flags = 0, |
| 980 | }, try ring.copy_cqe()); | 980 | }, try ring.copy_cqe()); |
| 981 | try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer.len), buffer[0..]); | 981 | try testing.expectEqualSlices(u8, &@as([buffer.len]u8, @splat(0)), buffer[0..]); |
| 982 | } | 982 | } |
| 983 | 983 | ||
| 984 | // Test with a non-zero offset | 984 | // Test with a non-zero offset |
| ... | @@ -999,7 +999,7 @@ test "register_files_update" { | ... | @@ -999,7 +999,7 @@ test "register_files_update" { |
| 999 | .res = buffer.len, | 999 | .res = buffer.len, |
| 1000 | .flags = 0, | 1000 | .flags = 0, |
| 1001 | }, try ring.copy_cqe()); | 1001 | }, try ring.copy_cqe()); |
| 1002 | try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer.len), buffer[0..]); | 1002 | try testing.expectEqualSlices(u8, &@as([buffer.len]u8, @splat(0)), buffer[0..]); |
| 1003 | } | 1003 | } |
| 1004 | 1004 | ||
| 1005 | try ring.register_files_update(0, registered_fds[0..]); | 1005 | try ring.register_files_update(0, registered_fds[0..]); |
| ... | @@ -1404,7 +1404,7 @@ test "provide_buffers: read" { | ... | @@ -1404,7 +1404,7 @@ test "provide_buffers: read" { |
| 1404 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); | 1404 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); |
| 1405 | 1405 | ||
| 1406 | try testing.expectEqual(@as(u64, 0xdededede), cqe.user_data); | 1406 | try testing.expectEqual(@as(u64, 0xdededede), cqe.user_data); |
| 1407 | try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]); | 1407 | try testing.expectEqualSlices(u8, &@as([buffer_len]u8, @splat(0)), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]); |
| 1408 | } | 1408 | } |
| 1409 | 1409 | ||
| 1410 | // This read should fail | 1410 | // This read should fail |
| ... | @@ -1468,7 +1468,7 @@ test "provide_buffers: read" { | ... | @@ -1468,7 +1468,7 @@ test "provide_buffers: read" { |
| 1468 | try testing.expectEqual(used_buffer_id, reprovided_buffer_id); | 1468 | try testing.expectEqual(used_buffer_id, reprovided_buffer_id); |
| 1469 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); | 1469 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); |
| 1470 | try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data); | 1470 | try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data); |
| 1471 | try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]); | 1471 | try testing.expectEqualSlices(u8, &@as([buffer_len]u8, @splat(0)), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]); |
| 1472 | } | 1472 | } |
| 1473 | } | 1473 | } |
| 1474 | 1474 | ||
| ... | @@ -1542,7 +1542,7 @@ test "remove_buffers" { | ... | @@ -1542,7 +1542,7 @@ test "remove_buffers" { |
| 1542 | try testing.expect(used_buffer_id >= 0 and used_buffer_id < 4); | 1542 | try testing.expect(used_buffer_id >= 0 and used_buffer_id < 4); |
| 1543 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); | 1543 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); |
| 1544 | try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data); | 1544 | try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data); |
| 1545 | try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]); | 1545 | try testing.expectEqualSlices(u8, &@as([buffer_len]u8, @splat(0)), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]); |
| 1546 | } | 1546 | } |
| 1547 | 1547 | ||
| 1548 | // Final read should _not_ work | 1548 | // Final read should _not_ work |
| ... | @@ -1608,7 +1608,7 @@ test "provide_buffers: accept/connect/send/recv" { | ... | @@ -1608,7 +1608,7 @@ test "provide_buffers: accept/connect/send/recv" { |
| 1608 | { | 1608 | { |
| 1609 | var i: usize = 0; | 1609 | var i: usize = 0; |
| 1610 | while (i < buffers.len) : (i += 1) { | 1610 | while (i < buffers.len) : (i += 1) { |
| 1611 | _ = try ring.send(0xdeaddead, socket_test_harness.server, &([_]u8{'z'} ** buffer_len), 0); | 1611 | _ = try ring.send(0xdeaddead, socket_test_harness.server, &@as([buffer_len]u8, @splat('z')), 0); |
| 1612 | try testing.expectEqual(@as(u32, 1), try ring.submit()); | 1612 | try testing.expectEqual(@as(u32, 1), try ring.submit()); |
| 1613 | } | 1613 | } |
| 1614 | 1614 | ||
| ... | @@ -1646,7 +1646,7 @@ test "provide_buffers: accept/connect/send/recv" { | ... | @@ -1646,7 +1646,7 @@ test "provide_buffers: accept/connect/send/recv" { |
| 1646 | 1646 | ||
| 1647 | try testing.expectEqual(@as(u64, 0xdededede), cqe.user_data); | 1647 | try testing.expectEqual(@as(u64, 0xdededede), cqe.user_data); |
| 1648 | const buffer = buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]; | 1648 | const buffer = buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]; |
| 1649 | try testing.expectEqualSlices(u8, &([_]u8{'z'} ** buffer_len), buffer); | 1649 | try testing.expectEqualSlices(u8, &@as([buffer_len]u8, @splat('z')), buffer); |
| 1650 | } | 1650 | } |
| 1651 | 1651 | ||
| 1652 | // This recv should fail | 1652 | // This recv should fail |
| ... | @@ -1690,7 +1690,7 @@ test "provide_buffers: accept/connect/send/recv" { | ... | @@ -1690,7 +1690,7 @@ test "provide_buffers: accept/connect/send/recv" { |
| 1690 | // Redo 1 send on the server socket | 1690 | // Redo 1 send on the server socket |
| 1691 | 1691 | ||
| 1692 | { | 1692 | { |
| 1693 | _ = try ring.send(0xdeaddead, socket_test_harness.server, &([_]u8{'w'} ** buffer_len), 0); | 1693 | _ = try ring.send(0xdeaddead, socket_test_harness.server, &@as([buffer_len]u8, @splat('w')), 0); |
| 1694 | try testing.expectEqual(@as(u32, 1), try ring.submit()); | 1694 | try testing.expectEqual(@as(u32, 1), try ring.submit()); |
| 1695 | 1695 | ||
| 1696 | _ = try ring.copy_cqe(); | 1696 | _ = try ring.copy_cqe(); |
| ... | @@ -1724,7 +1724,7 @@ test "provide_buffers: accept/connect/send/recv" { | ... | @@ -1724,7 +1724,7 @@ test "provide_buffers: accept/connect/send/recv" { |
| 1724 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); | 1724 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); |
| 1725 | try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data); | 1725 | try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data); |
| 1726 | const buffer = buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]; | 1726 | const buffer = buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]; |
| 1727 | try testing.expectEqualSlices(u8, &([_]u8{'w'} ** buffer_len), buffer); | 1727 | try testing.expectEqualSlices(u8, &@as([buffer_len]u8, @splat('w')), buffer); |
| 1728 | } | 1728 | } |
| 1729 | } | 1729 | } |
| 1730 | 1730 | ||
| ... | @@ -1784,8 +1784,8 @@ test "accept/connect/send_zc/recv" { | ... | @@ -1784,8 +1784,8 @@ test "accept/connect/send_zc/recv" { |
| 1784 | const socket_test_harness = try createSocketTestHarness(&ring); | 1784 | const socket_test_harness = try createSocketTestHarness(&ring); |
| 1785 | defer socket_test_harness.close(); | 1785 | defer socket_test_harness.close(); |
| 1786 | 1786 | ||
| 1787 | const buffer_send = [_]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe }; | 1787 | const buffer_send: [15]u8 = .{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe }; |
| 1788 | var buffer_recv = [_]u8{0} ** 10; | 1788 | var buffer_recv: [10]u8 = @splat(0); |
| 1789 | 1789 | ||
| 1790 | // zero-copy send | 1790 | // zero-copy send |
| 1791 | const sqe_send = try ring.send_zc(0xeeeeeeee, socket_test_harness.client, buffer_send[0..], 0, 0); | 1791 | const sqe_send = try ring.send_zc(0xeeeeeeee, socket_test_harness.client, buffer_send[0..], 0, 0); |
| ... | @@ -1844,7 +1844,7 @@ test "accept_direct" { | ... | @@ -1844,7 +1844,7 @@ test "accept_direct" { |
| 1844 | }; | 1844 | }; |
| 1845 | 1845 | ||
| 1846 | // register direct file descriptors | 1846 | // register direct file descriptors |
| 1847 | var registered_fds = [_]linux.fd_t{-1} ** 2; | 1847 | var registered_fds: [2]linux.fd_t = @splat(-1); |
| 1848 | try ring.register_files(registered_fds[0..]); | 1848 | try ring.register_files(registered_fds[0..]); |
| 1849 | 1849 | ||
| 1850 | const listener_socket = try createListenerSocket(&address); | 1850 | const listener_socket = try createListenerSocket(&address); |
| ... | @@ -1856,7 +1856,7 @@ test "accept_direct" { | ... | @@ -1856,7 +1856,7 @@ test "accept_direct" { |
| 1856 | 1856 | ||
| 1857 | for (0..2) |_| { | 1857 | for (0..2) |_| { |
| 1858 | for (registered_fds, 0..) |_, i| { | 1858 | for (registered_fds, 0..) |_, i| { |
| 1859 | var buffer_recv = [_]u8{0} ** 16; | 1859 | var buffer_recv: [16]u8 = @splat(0); |
| 1860 | const buffer_send: []const u8 = data[0 .. data.len - i]; // make it different at each loop | 1860 | const buffer_send: []const u8 = data[0 .. data.len - i]; // make it different at each loop |
| 1861 | 1861 | ||
| 1862 | // submit accept, will chose registered fd and return index in cqe | 1862 | // submit accept, will chose registered fd and return index in cqe |
| ... | @@ -1932,7 +1932,7 @@ test "accept_multishot_direct" { | ... | @@ -1932,7 +1932,7 @@ test "accept_multishot_direct" { |
| 1932 | .addr = @bitCast([4]u8{ 127, 0, 0, 1 }), | 1932 | .addr = @bitCast([4]u8{ 127, 0, 0, 1 }), |
| 1933 | }; | 1933 | }; |
| 1934 | 1934 | ||
| 1935 | var registered_fds = [_]linux.fd_t{-1} ** 2; | 1935 | var registered_fds: [2]linux.fd_t = @splat(-1); |
| 1936 | try ring.register_files(registered_fds[0..]); | 1936 | try ring.register_files(registered_fds[0..]); |
| 1937 | 1937 | ||
| 1938 | const listener_socket = try createListenerSocket(&address); | 1938 | const listener_socket = try createListenerSocket(&address); |
| ... | @@ -2011,7 +2011,7 @@ test "socket_direct/socket_direct_alloc/close_direct" { | ... | @@ -2011,7 +2011,7 @@ test "socket_direct/socket_direct_alloc/close_direct" { |
| 2011 | }; | 2011 | }; |
| 2012 | defer ring.deinit(); | 2012 | defer ring.deinit(); |
| 2013 | 2013 | ||
| 2014 | var registered_fds = [_]linux.fd_t{-1} ** 3; | 2014 | var registered_fds: [3]linux.fd_t = @splat(-1); |
| 2015 | try ring.register_files(registered_fds[0..]); | 2015 | try ring.register_files(registered_fds[0..]); |
| 2016 | 2016 | ||
| 2017 | // create socket in registered file descriptor at index 0 (last param) | 2017 | // create socket in registered file descriptor at index 0 (last param) |
| ... | @@ -2092,7 +2092,7 @@ test "openat_direct/close_direct" { | ... | @@ -2092,7 +2092,7 @@ test "openat_direct/close_direct" { |
| 2092 | }; | 2092 | }; |
| 2093 | defer ring.deinit(); | 2093 | defer ring.deinit(); |
| 2094 | 2094 | ||
| 2095 | var registered_fds = [_]linux.fd_t{-1} ** 3; | 2095 | var registered_fds: [3]linux.fd_t = @splat(-1); |
| 2096 | try ring.register_files(registered_fds[0..]); | 2096 | try ring.register_files(registered_fds[0..]); |
| 2097 | 2097 | ||
| 2098 | var tmp = std.testing.tmpDir(.{}); | 2098 | var tmp = std.testing.tmpDir(.{}); |
| ... | @@ -2562,7 +2562,11 @@ fn expect_buf_grp_cqe( | ... | @@ -2562,7 +2562,11 @@ fn expect_buf_grp_cqe( |
| 2562 | } | 2562 | } |
| 2563 | 2563 | ||
| 2564 | fn testSendRecv(ring: *IoUring, send_fd: posix.socket_t, recv_fd: posix.socket_t) !void { | 2564 | fn testSendRecv(ring: *IoUring, send_fd: posix.socket_t, recv_fd: posix.socket_t) !void { |
| 2565 | const buffer_send = "0123456789abcdf" ** 10; | 2565 | const buffer_send: []const u8 = comptime buf: { |
| 2566 | const part = "0123456789abcdf"; | ||
| 2567 | const repeated: [10][part.len]u8 = @splat(part.*); | ||
| 2568 | break :buf @ptrCast(&repeated); | ||
| 2569 | }; | ||
| 2566 | var buffer_recv: [buffer_send.len * 2]u8 = undefined; | 2570 | var buffer_recv: [buffer_send.len * 2]u8 = undefined; |
| 2567 | 2571 | ||
| 2568 | // 2 sends | 2572 | // 2 sends |
lib/std/os/linux/test.zig+1-1| ... | @@ -70,7 +70,7 @@ test "timer" { | ... | @@ -70,7 +70,7 @@ test "timer" { |
| 70 | try expect(err == .SUCCESS); | 70 | try expect(err == .SUCCESS); |
| 71 | 71 | ||
| 72 | const events_one: linux.epoll_event = undefined; | 72 | const events_one: linux.epoll_event = undefined; |
| 73 | var events = [_]linux.epoll_event{events_one} ** 8; | 73 | var events: [8]linux.epoll_event = @splat(events_one); |
| 74 | 74 | ||
| 75 | err = linux.errno(linux.epoll_wait(@as(i32, @intCast(epoll_fd)), &events, 8, -1)); | 75 | err = linux.errno(linux.epoll_wait(@as(i32, @intCast(epoll_fd)), &events, 8, -1)); |
| 76 | try expect(err == .SUCCESS); | 76 | try expect(err == .SUCCESS); |
lib/std/os/uefi/hii.zig+1-1| ... | @@ -66,7 +66,7 @@ pub const WideGlyph = extern struct { | ... | @@ -66,7 +66,7 @@ pub const WideGlyph = extern struct { |
| 66 | attributes: WideGlyphAttributes, | 66 | attributes: WideGlyphAttributes, |
| 67 | glyph_col_1: [19]u8, | 67 | glyph_col_1: [19]u8, |
| 68 | glyph_col_2: [19]u8, | 68 | glyph_col_2: [19]u8, |
| 69 | _pad: [3]u8 = [_]u8{0} ** 3, | 69 | _pad: [3]u8 = @splat(0), |
| 70 | }; | 70 | }; |
| 71 | 71 | ||
| 72 | pub const StringPackage = extern struct { | 72 | pub const StringPackage = extern struct { |
lib/std/posix/test.zig+2-2| ... | @@ -187,11 +187,11 @@ test "mmap" { | ... | @@ -187,11 +187,11 @@ test "mmap" { |
| 187 | try expectEqual(@as(usize, 1234), data.len); | 187 | try expectEqual(@as(usize, 1234), data.len); |
| 188 | 188 | ||
| 189 | // By definition the data returned by mmap is zero-filled | 189 | // By definition the data returned by mmap is zero-filled |
| 190 | try expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234)); | 190 | try expect(mem.eql(u8, data, &@as([1234]u8, @splat(0x00)))); |
| 191 | 191 | ||
| 192 | // Make sure the memory is writeable as requested | 192 | // Make sure the memory is writeable as requested |
| 193 | @memset(data, 0x55); | 193 | @memset(data, 0x55); |
| 194 | try expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234)); | 194 | try expect(mem.eql(u8, data, &@as([1234]u8, @splat(0x55)))); |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | const test_out_file = "os_tmp_test"; | 197 | const test_out_file = "os_tmp_test"; |
lib/std/tar.zig+8-4| ... | @@ -734,6 +734,10 @@ test PaxIterator { | ... | @@ -734,6 +734,10 @@ test PaxIterator { |
| 734 | value: []const u8 = undefined, | 734 | value: []const u8 = undefined, |
| 735 | err: ?anyerror = null, | 735 | err: ?anyerror = null, |
| 736 | }; | 736 | }; |
| 737 | const long_path: *const [1000]u8 = comptime path: { | ||
| 738 | const buf: [100][10]u8 = @splat("0123456789".*); | ||
| 739 | break :path @ptrCast(&buf); | ||
| 740 | }; | ||
| 737 | const cases = [_]struct { | 741 | const cases = [_]struct { |
| 738 | data: []const u8, | 742 | data: []const u8, |
| 739 | attrs: []const Attr, | 743 | attrs: []const Attr, |
| ... | @@ -816,9 +820,9 @@ test PaxIterator { | ... | @@ -816,9 +820,9 @@ test PaxIterator { |
| 816 | }, | 820 | }, |
| 817 | }, | 821 | }, |
| 818 | .{ // 1000 characters path | 822 | .{ // 1000 characters path |
| 819 | .data = "1011 path=" ++ "0123456789" ** 100 ++ "\n", | 823 | .data = "1011 path=" ++ long_path ++ "\n", |
| 820 | .attrs = &[_]Attr{ | 824 | .attrs = &[_]Attr{ |
| 821 | .{ .kind = .path, .value = "0123456789" ** 100 }, | 825 | .{ .kind = .path, .value = long_path }, |
| 822 | }, | 826 | }, |
| 823 | }, | 827 | }, |
| 824 | }; | 828 | }; |
| ... | @@ -879,7 +883,7 @@ test "header parse size" { | ... | @@ -879,7 +883,7 @@ test "header parse size" { |
| 879 | }; | 883 | }; |
| 880 | 884 | ||
| 881 | for (cases) |case| { | 885 | for (cases) |case| { |
| 882 | var bytes = [_]u8{0} ** Header.SIZE; | 886 | var bytes: [Header.SIZE]u8 = @splat(0); |
| 883 | @memcpy(bytes[124 .. 124 + case.in.len], case.in); | 887 | @memcpy(bytes[124 .. 124 + case.in.len], case.in); |
| 884 | var header = Header{ .bytes = &bytes }; | 888 | var header = Header{ .bytes = &bytes }; |
| 885 | if (case.err) |err| { | 889 | if (case.err) |err| { |
| ... | @@ -904,7 +908,7 @@ test "header parse mode" { | ... | @@ -904,7 +908,7 @@ test "header parse mode" { |
| 904 | .{ .in = "777777777777", .want = 0o77777777 }, | 908 | .{ .in = "777777777777", .want = 0o77777777 }, |
| 905 | }; | 909 | }; |
| 906 | for (cases) |case| { | 910 | for (cases) |case| { |
| 907 | var bytes = [_]u8{0} ** Header.SIZE; | 911 | var bytes: [Header.SIZE]u8 = @splat(0); |
| 908 | @memcpy(bytes[100 .. 100 + case.in.len], case.in); | 912 | @memcpy(bytes[100 .. 100 + case.in.len], case.in); |
| 909 | var header = Header{ .bytes = &bytes }; | 913 | var header = Header{ .bytes = &bytes }; |
| 910 | if (case.err) |err| { | 914 | if (case.err) |err| { |
lib/std/tar/Writer.zig+39-33| ... | @@ -193,23 +193,23 @@ pub const Header = extern struct { | ... | @@ -193,23 +193,23 @@ pub const Header = extern struct { |
| 193 | // numeric field of width w contains w minus 1 digits, and a null. | 193 | // numeric field of width w contains w minus 1 digits, and a null. |
| 194 | // Reference: https://www.gnu.org/software/tar/manual/html_node/Standard.html | 194 | // Reference: https://www.gnu.org/software/tar/manual/html_node/Standard.html |
| 195 | // POSIX header: byte offset | 195 | // POSIX header: byte offset |
| 196 | name: [100]u8 = [_]u8{0} ** 100, // 0 | 196 | name: [100]u8 = @splat(0), // 0 |
| 197 | mode: [7:0]u8 = default_mode.file, // 100 | 197 | mode: [7:0]u8 = default_mode.file, // 100 |
| 198 | uid: [7:0]u8 = [_:0]u8{0} ** 7, // unused 108 | 198 | uid: [7:0]u8 = @splat(0), // unused 108 |
| 199 | gid: [7:0]u8 = [_:0]u8{0} ** 7, // unused 116 | 199 | gid: [7:0]u8 = @splat(0), // unused 116 |
| 200 | size: [11:0]u8 = [_:0]u8{'0'} ** 11, // 124 | 200 | size: [11:0]u8 = @splat('0'), // 124 |
| 201 | mtime: [11:0]u8 = [_:0]u8{'0'} ** 11, // 136 | 201 | mtime: [11:0]u8 = @splat('0'), // 136 |
| 202 | checksum: [7:0]u8 = [_:0]u8{' '} ** 7, // 148 | 202 | checksum: [7:0]u8 = @splat(' '), // 148 |
| 203 | typeflag: FileType = .regular, // 156 | 203 | typeflag: FileType = .regular, // 156 |
| 204 | linkname: [100]u8 = [_]u8{0} ** 100, // 157 | 204 | linkname: [100]u8 = @splat(0), // 157 |
| 205 | magic: [6]u8 = [_]u8{ 'u', 's', 't', 'a', 'r', 0 }, // 257 | 205 | magic: [6]u8 = .{ 'u', 's', 't', 'a', 'r', 0 }, // 257 |
| 206 | version: [2]u8 = [_]u8{ '0', '0' }, // 263 | 206 | version: [2]u8 = .{ '0', '0' }, // 263 |
| 207 | uname: [32]u8 = [_]u8{0} ** 32, // unused 265 | 207 | uname: [32]u8 = @splat(0), // unused 265 |
| 208 | gname: [32]u8 = [_]u8{0} ** 32, // unused 297 | 208 | gname: [32]u8 = @splat(0), // unused 297 |
| 209 | devmajor: [7:0]u8 = [_:0]u8{0} ** 7, // unused 329 | 209 | devmajor: [7:0]u8 = @splat(0), // unused 329 |
| 210 | devminor: [7:0]u8 = [_:0]u8{0} ** 7, // unused 337 | 210 | devminor: [7:0]u8 = @splat(0), // unused 337 |
| 211 | prefix: [155]u8 = [_]u8{0} ** 155, // 345 | 211 | prefix: [155]u8 = @splat(0), // 345 |
| 212 | pad: [12]u8 = [_]u8{0} ** 12, // unused 500 | 212 | pad: [12]u8 = @splat(0), // unused 500 |
| 213 | 213 | ||
| 214 | pub const FileType = enum(u8) { | 214 | pub const FileType = enum(u8) { |
| 215 | regular = '0', | 215 | regular = '0', |
| ... | @@ -342,26 +342,26 @@ pub const Header = extern struct { | ... | @@ -342,26 +342,26 @@ pub const Header = extern struct { |
| 342 | }, | 342 | }, |
| 343 | // no more both fits into name | 343 | // no more both fits into name |
| 344 | .{ | 344 | .{ |
| 345 | .in = &.{ "prefix", "0123456789/" ** 8 ++ "basename" }, | 345 | .in = &.{ "prefix", repeatString(8, "0123456789/") ++ "basename" }, |
| 346 | .out = &.{ "prefix", "0123456789/" ** 8 ++ "basename" }, | 346 | .out = &.{ "prefix", repeatString(8, "0123456789/") ++ "basename" }, |
| 347 | }, | 347 | }, |
| 348 | // put as much as you can into prefix the rest goes into name | 348 | // put as much as you can into prefix the rest goes into name |
| 349 | .{ | 349 | .{ |
| 350 | .in = &.{ "prefix", "0123456789/" ** 10 ++ "basename" }, | 350 | .in = &.{ "prefix", repeatString(10, "0123456789/") ++ "basename" }, |
| 351 | .out = &.{ "prefix/" ++ "0123456789/" ** 9 ++ "0123456789", "basename" }, | 351 | .out = &.{ "prefix/" ++ repeatString(9, "0123456789/") ++ "0123456789", "basename" }, |
| 352 | }, | 352 | }, |
| 353 | 353 | ||
| 354 | .{ | 354 | .{ |
| 355 | .in = &.{ "prefix", "0123456789/" ** 15 ++ "basename" }, | 355 | .in = &.{ "prefix", repeatString(15, "0123456789/") ++ "basename" }, |
| 356 | .out = &.{ "prefix/" ++ "0123456789/" ** 12 ++ "0123456789", "0123456789/0123456789/basename" }, | 356 | .out = &.{ "prefix/" ++ repeatString(12, "0123456789/") ++ "0123456789", "0123456789/0123456789/basename" }, |
| 357 | }, | 357 | }, |
| 358 | .{ | 358 | .{ |
| 359 | .in = &.{ "prefix", "0123456789/" ** 21 ++ "basename" }, | 359 | .in = &.{ "prefix", repeatString(21, "0123456789/") ++ "basename" }, |
| 360 | .out = &.{ "prefix/" ++ "0123456789/" ** 12 ++ "0123456789", "0123456789/" ** 8 ++ "basename" }, | 360 | .out = &.{ "prefix/" ++ repeatString(12, "0123456789/") ++ "0123456789", repeatString(8, "0123456789/") ++ "basename" }, |
| 361 | }, | 361 | }, |
| 362 | .{ | 362 | .{ |
| 363 | .in = &.{ "", "012345678/" ** 10 ++ "foo" }, | 363 | .in = &.{ "", repeatString(10, "012345678/") ++ "foo" }, |
| 364 | .out = &.{ "012345678/" ** 9 ++ "012345678", "foo" }, | 364 | .out = &.{ repeatString(9, "012345678/") ++ "012345678", "foo" }, |
| 365 | }, | 365 | }, |
| 366 | }; | 366 | }; |
| 367 | 367 | ||
| ... | @@ -378,10 +378,10 @@ pub const Header = extern struct { | ... | @@ -378,10 +378,10 @@ pub const Header = extern struct { |
| 378 | // basename can't fit into name (106 characters) | 378 | // basename can't fit into name (106 characters) |
| 379 | .{ .in = &.{ "zig", "test/cases/compile_errors/regression_test_2980_base_type_u32_is_not_type_checked_properly_when_assigning_a_value_within_a_struct.zig" } }, | 379 | .{ .in = &.{ "zig", "test/cases/compile_errors/regression_test_2980_base_type_u32_is_not_type_checked_properly_when_assigning_a_value_within_a_struct.zig" } }, |
| 380 | // cant fit into 255 + sep | 380 | // cant fit into 255 + sep |
| 381 | .{ .in = &.{ "prefix", "0123456789/" ** 22 ++ "basename" } }, | 381 | .{ .in = &.{ "prefix", repeatString(22, "0123456789/") ++ "basename" } }, |
| 382 | // can fit but sub_path can't be split (there is no separator) | 382 | // can fit but sub_path can't be split (there is no separator) |
| 383 | .{ .in = &.{ "prefix", "0123456789" ** 10 ++ "a" } }, | 383 | .{ .in = &.{ "prefix", repeatString(10, "0123456789") ++ "a" } }, |
| 384 | .{ .in = &.{ "prefix", "0123456789" ** 14 ++ "basename" } }, | 384 | .{ .in = &.{ "prefix", repeatString(14, "0123456789") ++ "basename" } }, |
| 385 | }; | 385 | }; |
| 386 | 386 | ||
| 387 | for (error_cases) |case| { | 387 | for (error_cases) |case| { |
| ... | @@ -404,11 +404,11 @@ test "write files" { | ... | @@ -404,11 +404,11 @@ test "write files" { |
| 404 | content: []const u8, | 404 | content: []const u8, |
| 405 | }{ | 405 | }{ |
| 406 | .{ .path = "foo", .content = "bar" }, | 406 | .{ .path = "foo", .content = "bar" }, |
| 407 | .{ .path = "a12345678/" ** 10 ++ "foo", .content = "a" ** 511 }, | 407 | .{ .path = repeatString(10, "a12345678/") ++ "foo", .content = repeatString(511, "a") }, |
| 408 | .{ .path = "b12345678/" ** 24 ++ "foo", .content = "b" ** 512 }, | 408 | .{ .path = repeatString(24, "b12345678/") ++ "foo", .content = repeatString(512, "b") }, |
| 409 | .{ .path = "c12345678/" ** 25 ++ "foo", .content = "c" ** 513 }, | 409 | .{ .path = repeatString(25, "c12345678/") ++ "foo", .content = repeatString(513, "c") }, |
| 410 | .{ .path = "d12345678/" ** 51 ++ "foo", .content = "d" ** 1025 }, | 410 | .{ .path = repeatString(51, "d12345678/") ++ "foo", .content = repeatString(1025, "d") }, |
| 411 | .{ .path = "e123456789" ** 11, .content = "e" }, | 411 | .{ .path = repeatString(11, "e123456789"), .content = "e" }, |
| 412 | }; | 412 | }; |
| 413 | 413 | ||
| 414 | var file_name_buffer: [std.fs.max_path_bytes]u8 = undefined; | 414 | var file_name_buffer: [std.fs.max_path_bytes]u8 = undefined; |
| ... | @@ -482,3 +482,9 @@ test "write files" { | ... | @@ -482,3 +482,9 @@ test "write files" { |
| 482 | try w.finishPedantically(); | 482 | try w.finishPedantically(); |
| 483 | } | 483 | } |
| 484 | } | 484 | } |
| 485 | |||
| 486 | /// Marked `inline` to avoid unnecessary binary float, since arguments are always comptime-known. | ||
| 487 | inline fn repeatString(comptime n: usize, comptime str: []const u8) []const u8 { | ||
| 488 | const buf: [n][str.len]u8 = @splat(str[0..str.len].*); | ||
| 489 | return @ptrCast(&buf); | ||
| 490 | } |
lib/std/tar/test.zig+6-2| ... | @@ -53,7 +53,7 @@ const trailing_slash_case: Case = .{ | ... | @@ -53,7 +53,7 @@ const trailing_slash_case: Case = .{ |
| 53 | .data = @embedFile("testdata/trailing-slash.tar"), | 53 | .data = @embedFile("testdata/trailing-slash.tar"), |
| 54 | .files = &[_]Case.File{ | 54 | .files = &[_]Case.File{ |
| 55 | .{ | 55 | .{ |
| 56 | .name = "123456789/" ** 30, | 56 | .name = @ptrCast(&@as([30][10]u8, @splat("123456789/".*))), |
| 57 | .kind = .directory, | 57 | .kind = .directory, |
| 58 | }, | 58 | }, |
| 59 | }, | 59 | }, |
| ... | @@ -64,7 +64,11 @@ const writer_big_long_case: Case = .{ | ... | @@ -64,7 +64,11 @@ const writer_big_long_case: Case = .{ |
| 64 | .data = @embedFile("testdata/writer-big-long.tar"), | 64 | .data = @embedFile("testdata/writer-big-long.tar"), |
| 65 | .files = &[_]Case.File{ | 65 | .files = &[_]Case.File{ |
| 66 | .{ | 66 | .{ |
| 67 | .name = "longname/" ** 15 ++ "16gig.txt", | 67 | .name = name: { |
| 68 | const buf: [15][9]u8 = @splat("longname/".*); | ||
| 69 | const dir: []const u8 = @ptrCast(&buf); | ||
| 70 | break :name dir ++ "16gig.txt"; | ||
| 71 | }, | ||
| 68 | .size = 16 * 1024 * 1024 * 1024, | 72 | .size = 16 * 1024 * 1024 * 1024, |
| 69 | .mode = 0o644, | 73 | .mode = 0o644, |
| 70 | .truncated = true, | 74 | .truncated = true, |
lib/std/unicode.zig+13-8| ... | @@ -275,11 +275,16 @@ fn utf8ValidateSliceImpl(input: []const u8, comptime surrogates: Surrogates) boo | ... | @@ -275,11 +275,16 @@ fn utf8ValidateSliceImpl(input: []const u8, comptime surrogates: Surrogates) boo |
| 275 | const s7 = 0x44; // accept 4, size 4 | 275 | const s7 = 0x44; // accept 4, size 4 |
| 276 | 276 | ||
| 277 | // Information about the first byte in a UTF-8 sequence. | 277 | // Information about the first byte in a UTF-8 sequence. |
| 278 | const first = comptime ([_]u8{as} ** 128) ++ ([_]u8{xx} ** 64) ++ [_]u8{ | 278 | const first = comptime first: { |
| 279 | xx, xx, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, | 279 | const a: [128]u8 = @splat(as); |
| 280 | s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, | 280 | const b: [64]u8 = @splat(xx); |
| 281 | s2, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s4, s3, s3, | 281 | const c: [64]u8 = .{ |
| 282 | s5, s6, s6, s6, s7, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, | 282 | xx, xx, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, |
| 283 | s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, | ||
| 284 | s2, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s4, s3, s3, | ||
| 285 | s5, s6, s6, s6, s7, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, | ||
| 286 | }; | ||
| 287 | break :first a ++ b ++ c; | ||
| 283 | }; | 288 | }; |
| 284 | 289 | ||
| 285 | const n = remaining.len; | 290 | const n = remaining.len; |
| ... | @@ -647,7 +652,7 @@ test "validate slice" { | ... | @@ -647,7 +652,7 @@ test "validate slice" { |
| 647 | 652 | ||
| 648 | // We skip a variable (based on recommended vector size) chunks of | 653 | // We skip a variable (based on recommended vector size) chunks of |
| 649 | // ASCII characters. Let's make sure we're chunking correctly. | 654 | // ASCII characters. Let's make sure we're chunking correctly. |
| 650 | const str = [_]u8{'a'} ** 550 ++ "\xc0"; | 655 | const str = @as([550]u8, @splat('a')) ++ "\xc0"; |
| 651 | for (0..str.len - 3) |i| { | 656 | for (0..str.len - 3) |i| { |
| 652 | try testing.expect(!utf8ValidateSlice(str[i..])); | 657 | try testing.expect(!utf8ValidateSlice(str[i..])); |
| 653 | } | 658 | } |
| ... | @@ -1394,7 +1399,7 @@ test "ArrayList functions on a re-used list" { | ... | @@ -1394,7 +1399,7 @@ test "ArrayList functions on a re-used list" { |
| 1394 | fn utf8ToUtf16LeStringLiteralImpl(comptime utf8: []const u8, comptime surrogates: Surrogates) *const [calcUtf16LeLenImpl(utf8, surrogates) catch |err| @compileError(err):0]u16 { | 1399 | fn utf8ToUtf16LeStringLiteralImpl(comptime utf8: []const u8, comptime surrogates: Surrogates) *const [calcUtf16LeLenImpl(utf8, surrogates) catch |err| @compileError(err):0]u16 { |
| 1395 | return comptime blk: { | 1400 | return comptime blk: { |
| 1396 | const len: usize = calcUtf16LeLenImpl(utf8, surrogates) catch unreachable; | 1401 | const len: usize = calcUtf16LeLenImpl(utf8, surrogates) catch unreachable; |
| 1397 | var utf16le: [len:0]u16 = [_:0]u16{0} ** len; | 1402 | var utf16le: [len:0]u16 = @splat(0); |
| 1398 | const utf16le_len = utf8ToUtf16LeImpl(&utf16le, utf8[0..], surrogates) catch |err| @compileError(err); | 1403 | const utf16le_len = utf8ToUtf16LeImpl(&utf16le, utf8[0..], surrogates) catch |err| @compileError(err); |
| 1399 | assert(len == utf16le_len); | 1404 | assert(len == utf16le_len); |
| 1400 | const final = utf16le; | 1405 | const final = utf16le; |
| ... | @@ -1640,7 +1645,7 @@ test "validate WTF-8 slice" { | ... | @@ -1640,7 +1645,7 @@ test "validate WTF-8 slice" { |
| 1640 | 1645 | ||
| 1641 | // We skip a variable (based on recommended vector size) chunks of | 1646 | // We skip a variable (based on recommended vector size) chunks of |
| 1642 | // ASCII characters. Let's make sure we're chunking correctly. | 1647 | // ASCII characters. Let's make sure we're chunking correctly. |
| 1643 | const str = [_]u8{'a'} ** 550 ++ "\xc0"; | 1648 | const str = @as([550]u8, @splat('a')) ++ "\xc0"; |
| 1644 | for (0..str.len - 3) |i| { | 1649 | for (0..str.len - 3) |i| { |
| 1645 | try testing.expect(!wtf8ValidateSlice(str[i..])); | 1650 | try testing.expect(!wtf8ValidateSlice(str[i..])); |
| 1646 | } | 1651 | } |
lib/std/unicode/throughput_test.zig+9-3| ... | @@ -63,21 +63,27 @@ pub fn main(init: std.process.Init) !void { | ... | @@ -63,21 +63,27 @@ pub fn main(init: std.process.Init) !void { |
| 63 | try stdout.print("pure ASCII strings\n", .{}); | 63 | try stdout.print("pure ASCII strings\n", .{}); |
| 64 | try stdout.flush(); | 64 | try stdout.flush(); |
| 65 | { | 65 | { |
| 66 | const result = try benchmarkCodepointCount("hello" ** 16, io); | 66 | const part = "hello"; |
| 67 | const buf: [16][part.len]u8 = @splat(part.*); | ||
| 68 | const result = try benchmarkCodepointCount(@ptrCast(&buf), io); | ||
| 67 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); | 69 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); |
| 68 | } | 70 | } |
| 69 | 71 | ||
| 70 | try stdout.print("pure Unicode strings\n", .{}); | 72 | try stdout.print("pure Unicode strings\n", .{}); |
| 71 | try stdout.flush(); | 73 | try stdout.flush(); |
| 72 | { | 74 | { |
| 73 | const result = try benchmarkCodepointCount("こんにちは" ** 16, io); | 75 | const part = "こんにちは"; |
| 76 | const buf: [16][part.len]u8 = @splat(part.*); | ||
| 77 | const result = try benchmarkCodepointCount(@ptrCast(&buf), io); | ||
| 74 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); | 78 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); |
| 75 | } | 79 | } |
| 76 | 80 | ||
| 77 | try stdout.print("mixed ASCII/Unicode strings\n", .{}); | 81 | try stdout.print("mixed ASCII/Unicode strings\n", .{}); |
| 78 | try stdout.flush(); | 82 | try stdout.flush(); |
| 79 | { | 83 | { |
| 80 | const result = try benchmarkCodepointCount("Hyvää huomenta" ** 16, io); | 84 | const part = "Hyvää huomenta"; |
| 85 | const buf: [16][part.len]u8 = @splat(part.*); | ||
| 86 | const result = try benchmarkCodepointCount(@ptrCast(&buf), io); | ||
| 81 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); | 87 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); |
| 82 | } | 88 | } |
| 83 | try stdout.flush(); | 89 | try stdout.flush(); |
lib/std/zig/AstGen.zig+1-1| ... | @@ -4795,7 +4795,7 @@ fn testDecl( | ... | @@ -4795,7 +4795,7 @@ fn testDecl( |
| 4795 | .noalias_bits = 0, | 4795 | .noalias_bits = 0, |
| 4796 | 4796 | ||
| 4797 | // Tests don't have a prototype that needs hashing | 4797 | // Tests don't have a prototype that needs hashing |
| 4798 | .proto_hash = .{0} ** 16, | 4798 | .proto_hash = @splat(0), |
| 4799 | }); | 4799 | }); |
| 4800 | 4800 | ||
| 4801 | _ = try decl_block.addBreak(.break_inline, decl_inst, func_inst); | 4801 | _ = try decl_block.addBreak(.break_inline, decl_inst, func_inst); |
lib/std/zig/LibCInstallation.zig+1-1| ... | @@ -46,7 +46,7 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const | ... | @@ -46,7 +46,7 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const |
| 46 | found: bool, | 46 | found: bool, |
| 47 | allocated: ?[:0]u8, | 47 | allocated: ?[:0]u8, |
| 48 | }; | 48 | }; |
| 49 | var found_keys = [1]FoundKey{FoundKey{ .found = false, .allocated = null }} ** fields.len; | 49 | var found_keys: [fields.len]FoundKey = @splat(.{ .found = false, .allocated = null }); |
| 50 | errdefer { | 50 | errdefer { |
| 51 | self = .{}; | 51 | self = .{}; |
| 52 | for (found_keys) |found_key| { | 52 | for (found_keys) |found_key| { |
lib/std/zig/WindowsSdk.zig+1-1| ... | @@ -120,7 +120,7 @@ fn iterateAndFilterByVersion( | ... | @@ -120,7 +120,7 @@ fn iterateAndFilterByVersion( |
| 120 | if (!std.mem.startsWith(u8, entry.name, prefix)) continue; | 120 | if (!std.mem.startsWith(u8, entry.name, prefix)) continue; |
| 121 | 121 | ||
| 122 | var version: Version = .{ | 122 | var version: Version = .{ |
| 123 | .nums = .{0} ** 4, | 123 | .nums = @splat(0), |
| 124 | .build = "", | 124 | .build = "", |
| 125 | }; | 125 | }; |
| 126 | const suffix = entry.name[prefix.len..]; | 126 | const suffix = entry.name[prefix.len..]; |
lib/std/zig/llvm/Builder.zig+3-7| ... | @@ -7628,9 +7628,7 @@ pub const Constant = enum(u32) { | ... | @@ -7628,9 +7628,7 @@ pub const Constant = enum(u32) { |
| 7628 | const expected_limbs = @divExact(512, @bitSizeOf(std.math.big.Limb)); | 7628 | const expected_limbs = @divExact(512, @bitSizeOf(std.math.big.Limb)); |
| 7629 | string: [ | 7629 | string: [ |
| 7630 | (std.math.big.int.Const{ | 7630 | (std.math.big.int.Const{ |
| 7631 | .limbs = &([1]std.math.big.Limb{ | 7631 | .limbs = &@splat(maxInt(std.math.big.Limb)), |
| 7632 | maxInt(std.math.big.Limb), | ||
| 7633 | } ** expected_limbs), | ||
| 7634 | .positive = false, | 7632 | .positive = false, |
| 7635 | }).sizeInBaseUpperBound(10) | 7633 | }).sizeInBaseUpperBound(10) |
| 7636 | ]u8, | 7634 | ]u8, |
| ... | @@ -9347,7 +9345,7 @@ pub fn nanConst(self: *Builder, ty: Type) Allocator.Error!Constant { | ... | @@ -9347,7 +9345,7 @@ pub fn nanConst(self: *Builder, ty: Type) Allocator.Error!Constant { |
| 9347 | .double => try self.doubleConst(std.math.nan(f64)), | 9345 | .double => try self.doubleConst(std.math.nan(f64)), |
| 9348 | .fp128 => try self.fp128Const(std.math.nan(f128)), | 9346 | .fp128 => try self.fp128Const(std.math.nan(f128)), |
| 9349 | .x86_fp80 => try self.x86_fp80Const(std.math.nan(f80)), | 9347 | .x86_fp80 => try self.x86_fp80Const(std.math.nan(f80)), |
| 9350 | .ppc_fp128 => try self.ppc_fp128Const(.{std.math.nan(f64)} ** 2), | 9348 | .ppc_fp128 => try self.ppc_fp128Const(@splat(.{std.math.nan(f64)})), |
| 9351 | else => unreachable, | 9349 | else => unreachable, |
| 9352 | }; | 9350 | }; |
| 9353 | } | 9351 | } |
| ... | @@ -10597,9 +10595,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void | ... | @@ -10597,9 +10595,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 10597 | const expected_limbs = @divExact(512, @bitSizeOf(std.math.big.Limb)); | 10595 | const expected_limbs = @divExact(512, @bitSizeOf(std.math.big.Limb)); |
| 10598 | string: [ | 10596 | string: [ |
| 10599 | (std.math.big.int.Const{ | 10597 | (std.math.big.int.Const{ |
| 10600 | .limbs = &([1]std.math.big.Limb{ | 10598 | .limbs = &@splat(maxInt(std.math.big.Limb)), |
| 10601 | maxInt(std.math.big.Limb), | ||
| 10602 | } ** expected_limbs), | ||
| 10603 | .positive = false, | 10599 | .positive = false, |
| 10604 | }).sizeInBaseUpperBound(10) | 10600 | }).sizeInBaseUpperBound(10) |
| 10605 | ]u8, | 10601 | ]u8, |
src/Air/Liveness.zig+4-4| ... | @@ -611,7 +611,7 @@ fn analyzeInst( | ... | @@ -611,7 +611,7 @@ fn analyzeInst( |
| 611 | const call = a.air.unwrapCall(inst); | 611 | const call = a.air.unwrapCall(inst); |
| 612 | const args = call.args; | 612 | const args = call.args; |
| 613 | if (args.len + 1 <= bpi - 1) { | 613 | if (args.len + 1 <= bpi - 1) { |
| 614 | var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1); | 614 | var buf: [bpi - 1]Air.Inst.Ref = @splat(.none); |
| 615 | buf[0] = call.callee; | 615 | buf[0] = call.callee; |
| 616 | @memcpy(buf[1..][0..args.len], args); | 616 | @memcpy(buf[1..][0..args.len], args); |
| 617 | return analyzeOperands(a, pass, data, inst, buf); | 617 | return analyzeOperands(a, pass, data, inst, buf); |
| ... | @@ -655,7 +655,7 @@ fn analyzeInst( | ... | @@ -655,7 +655,7 @@ fn analyzeInst( |
| 655 | const elements = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra.items[ty_pl.payload..][0..len])); | 655 | const elements = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra.items[ty_pl.payload..][0..len])); |
| 656 | 656 | ||
| 657 | if (elements.len <= bpi - 1) { | 657 | if (elements.len <= bpi - 1) { |
| 658 | var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1); | 658 | var buf: [bpi - 1]Air.Inst.Ref = @splat(.none); |
| 659 | @memcpy(buf[0..elements.len], elements); | 659 | @memcpy(buf[0..elements.len], elements); |
| 660 | return analyzeOperands(a, pass, data, inst, buf); | 660 | return analyzeOperands(a, pass, data, inst, buf); |
| 661 | } | 661 | } |
| ... | @@ -711,7 +711,7 @@ fn analyzeInst( | ... | @@ -711,7 +711,7 @@ fn analyzeInst( |
| 711 | const inputs = unwrapped_asm.inputs; | 711 | const inputs = unwrapped_asm.inputs; |
| 712 | 712 | ||
| 713 | const num_operands = simple: { | 713 | const num_operands = simple: { |
| 714 | var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1); | 714 | var buf: [bpi - 1]Air.Inst.Ref = @splat(.none); |
| 715 | var buf_index: usize = 0; | 715 | var buf_index: usize = 0; |
| 716 | for (unwrapped_asm.outputs) |output| { | 716 | for (unwrapped_asm.outputs) |output| { |
| 717 | if (output != .none) { | 717 | if (output != .none) { |
| ... | @@ -1421,7 +1421,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type { | ... | @@ -1421,7 +1421,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type { |
| 1421 | inst: Air.Inst.Index, | 1421 | inst: Air.Inst.Index, |
| 1422 | 1422 | ||
| 1423 | operands_remaining: u32, | 1423 | operands_remaining: u32, |
| 1424 | small: [bpi - 1]Air.Inst.Ref = .{.none} ** (bpi - 1), | 1424 | small: [bpi - 1]Air.Inst.Ref = @splat(.none), |
| 1425 | extra_tombs: []u32, | 1425 | extra_tombs: []u32, |
| 1426 | 1426 | ||
| 1427 | // Only used in `LivenessPass.main_analysis` | 1427 | // Only used in `LivenessPass.main_analysis` |
src/codegen/aarch64/Select.zig+2-2| ... | @@ -4345,7 +4345,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory, | ... | @@ -4345,7 +4345,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory, |
| 4345 | try isel.emit(.ldr(neg_zero_ra.q(), .{ | 4345 | try isel.emit(.ldr(neg_zero_ra.q(), .{ |
| 4346 | .literal = @intCast((isel.instructions.items.len + 1 + isel.literals.items.len) << 2), | 4346 | .literal = @intCast((isel.instructions.items.len + 1 + isel.literals.items.len) << 2), |
| 4347 | })); | 4347 | })); |
| 4348 | try isel.emitLiteral(&(.{0} ** 15 ++ .{0x80})); | 4348 | try isel.emitLiteral(&(@as([15]u8, @splat(0)) ++ .{0x80})); |
| 4349 | try src_mat.finish(isel); | 4349 | try src_mat.finish(isel); |
| 4350 | }, | 4350 | }, |
| 4351 | } | 4351 | } |
| ... | @@ -4425,7 +4425,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory, | ... | @@ -4425,7 +4425,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory, |
| 4425 | try isel.emit(.ldr(neg_zero_ra.q(), .{ | 4425 | try isel.emit(.ldr(neg_zero_ra.q(), .{ |
| 4426 | .literal = @intCast((isel.instructions.items.len + 1 + isel.literals.items.len) << 2), | 4426 | .literal = @intCast((isel.instructions.items.len + 1 + isel.literals.items.len) << 2), |
| 4427 | })); | 4427 | })); |
| 4428 | try isel.emitLiteral(&(.{0} ** 15 ++ .{0x80})); | 4428 | try isel.emitLiteral(&(@as([15]u8, @splat(0)) ++ .{0x80})); |
| 4429 | try src_mat.finish(isel); | 4429 | try src_mat.finish(isel); |
| 4430 | }, | 4430 | }, |
| 4431 | } | 4431 | } |
src/codegen/llvm.zig+6-2| ... | @@ -647,7 +647,11 @@ pub const Object = struct { | ... | @@ -647,7 +647,11 @@ pub const Object = struct { |
| 647 | debug_enums_fwd_ref.toOptional(), | 647 | debug_enums_fwd_ref.toOptional(), |
| 648 | debug_globals_fwd_ref.toOptional(), | 648 | debug_globals_fwd_ref.toOptional(), |
| 649 | }; | 649 | }; |
| 650 | } else .{Builder.Metadata.Optional.none} ** 3; | 650 | } else .{ |
| 651 | Builder.Metadata.Optional.none, | ||
| 652 | Builder.Metadata.Optional.none, | ||
| 653 | Builder.Metadata.Optional.none, | ||
| 654 | }; | ||
| 651 | 655 | ||
| 652 | const obj = try arena.create(Object); | 656 | const obj = try arena.create(Object); |
| 653 | obj.* = .{ | 657 | obj.* = .{ |
| ... | @@ -1439,7 +1443,7 @@ pub const Object = struct { | ... | @@ -1439,7 +1443,7 @@ pub const Object = struct { |
| 1439 | ); | 1443 | ); |
| 1440 | llvm_function.setSubprogram(subprogram, &o.builder); | 1444 | llvm_function.setSubprogram(subprogram, &o.builder); |
| 1441 | break :debug_info .{ file, subprogram }; | 1445 | break :debug_info .{ file, subprogram }; |
| 1442 | } else .{undefined} ** 2; | 1446 | } else .{ undefined, undefined }; |
| 1443 | 1447 | ||
| 1444 | const fuzz: ?FuncGen.Fuzz = f: { | 1448 | const fuzz: ?FuncGen.Fuzz = f: { |
| 1445 | if (!owner_mod.fuzz) break :f null; | 1449 | if (!owner_mod.fuzz) break :f null; |
src/codegen/llvm/FuncGen.zig+1-1| ... | @@ -3981,7 +3981,7 @@ fn buildFloatOp( | ... | @@ -3981,7 +3981,7 @@ fn buildFloatOp( |
| 3981 | const scalar_llvm_ty = try o.lowerType(scalar_ty); | 3981 | const scalar_llvm_ty = try o.lowerType(scalar_ty); |
| 3982 | const libc_fn = try o.getLibcFunction( | 3982 | const libc_fn = try o.getLibcFunction( |
| 3983 | fn_name, | 3983 | fn_name, |
| 3984 | ([1]Builder.Type{scalar_llvm_ty} ** 3)[0..params.len], | 3984 | @as([3]Builder.Type, @splat(scalar_llvm_ty))[0..params.len], |
| 3985 | scalar_llvm_ty, | 3985 | scalar_llvm_ty, |
| 3986 | ); | 3986 | ); |
| 3987 | if (ty.zigTypeTag(zcu) == .vector) { | 3987 | if (ty.zigTypeTag(zcu) == .vector) { |
src/codegen/riscv64/CodeGen.zig+5-5| ... | @@ -6230,7 +6230,7 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void { | ... | @@ -6230,7 +6230,7 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void { |
| 6230 | sym: SymbolOffset, | 6230 | sym: SymbolOffset, |
| 6231 | }; | 6231 | }; |
| 6232 | 6232 | ||
| 6233 | var ops: [4]Operand = .{.none} ** 4; | 6233 | var ops: [4]Operand = @splat(.none); |
| 6234 | var last_op = false; | 6234 | var last_op = false; |
| 6235 | var op_it = mem.splitAny(u8, mnem_it.rest(), ",("); | 6235 | var op_it = mem.splitAny(u8, mnem_it.rest(), ",("); |
| 6236 | next_op: for (&ops) |*op| { | 6236 | next_op: for (&ops) |*op| { |
| ... | @@ -6466,7 +6466,7 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void { | ... | @@ -6466,7 +6466,7 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void { |
| 6466 | } | 6466 | } |
| 6467 | 6467 | ||
| 6468 | simple: { | 6468 | simple: { |
| 6469 | var buf = [1]Air.Inst.Ref{.none} ** (Air.Liveness.bpi - 1); | 6469 | var buf: [Air.Liveness.bpi - 1]Air.Inst.Ref = @splat(.none); |
| 6470 | var buf_index: usize = 0; | 6470 | var buf_index: usize = 0; |
| 6471 | for (outputs) |output| { | 6471 | for (outputs) |output| { |
| 6472 | if (output == .none) continue; | 6472 | if (output == .none) continue; |
| ... | @@ -6581,7 +6581,7 @@ fn genInlineMemcpy( | ... | @@ -6581,7 +6581,7 @@ fn genInlineMemcpy( |
| 6581 | src_ptr: MCValue, | 6581 | src_ptr: MCValue, |
| 6582 | len: MCValue, | 6582 | len: MCValue, |
| 6583 | ) !void { | 6583 | ) !void { |
| 6584 | const regs = try func.register_manager.allocRegs(4, .{null} ** 4, abi.Registers.Integer.temporary); | 6584 | const regs = try func.register_manager.allocRegs(4, @splat(null), abi.Registers.Integer.temporary); |
| 6585 | const locks = func.register_manager.lockRegsAssumeUnused(4, regs); | 6585 | const locks = func.register_manager.lockRegsAssumeUnused(4, regs); |
| 6586 | defer for (locks) |lock| func.register_manager.unlockReg(lock); | 6586 | defer for (locks) |lock| func.register_manager.unlockReg(lock); |
| 6587 | 6587 | ||
| ... | @@ -6691,7 +6691,7 @@ fn genInlineMemset( | ... | @@ -6691,7 +6691,7 @@ fn genInlineMemset( |
| 6691 | src_value: MCValue, | 6691 | src_value: MCValue, |
| 6692 | len: MCValue, | 6692 | len: MCValue, |
| 6693 | ) !void { | 6693 | ) !void { |
| 6694 | const regs = try func.register_manager.allocRegs(3, .{null} ** 3, abi.Registers.Integer.temporary); | 6694 | const regs = try func.register_manager.allocRegs(3, @splat(null), abi.Registers.Integer.temporary); |
| 6695 | const locks = func.register_manager.lockRegsAssumeUnused(3, regs); | 6695 | const locks = func.register_manager.lockRegsAssumeUnused(3, regs); |
| 6696 | defer for (locks) |lock| func.register_manager.unlockReg(lock); | 6696 | defer for (locks) |lock| func.register_manager.unlockReg(lock); |
| 6697 | 6697 | ||
| ... | @@ -8076,7 +8076,7 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void { | ... | @@ -8076,7 +8076,7 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void { |
| 8076 | }; | 8076 | }; |
| 8077 | 8077 | ||
| 8078 | if (elements.len <= Air.Liveness.bpi - 1) { | 8078 | if (elements.len <= Air.Liveness.bpi - 1) { |
| 8079 | var buf = [1]Air.Inst.Ref{.none} ** (Air.Liveness.bpi - 1); | 8079 | var buf: [Air.Liveness.bpi - 1]Air.Inst.Ref = @splat(.none); |
| 8080 | @memcpy(buf[0..elements.len], elements); | 8080 | @memcpy(buf[0..elements.len], elements); |
| 8081 | return func.finishAir(inst, result, buf); | 8081 | return func.finishAir(inst, result, buf); |
| 8082 | } | 8082 | } |
src/codegen/riscv64/abi.zig+1-1| ... | @@ -98,7 +98,7 @@ pub const SystemClass = enum { integer, float, memory, none }; | ... | @@ -98,7 +98,7 @@ pub const SystemClass = enum { integer, float, memory, none }; |
| 98 | /// There are a maximum of 8 possible return slots. Returned values are in | 98 | /// There are a maximum of 8 possible return slots. Returned values are in |
| 99 | /// the beginning of the array; unused slots are filled with .none. | 99 | /// the beginning of the array; unused slots are filled with .none. |
| 100 | pub fn classifySystem(ty: Type, zcu: *Zcu) [8]SystemClass { | 100 | pub fn classifySystem(ty: Type, zcu: *Zcu) [8]SystemClass { |
| 101 | var result = [1]SystemClass{.none} ** 8; | 101 | var result: [8]SystemClass = @splat(.none); |
| 102 | const memory_class = [_]SystemClass{ | 102 | const memory_class = [_]SystemClass{ |
| 103 | .memory, .none, .none, .none, | 103 | .memory, .none, .none, .none, |
| 104 | .none, .none, .none, .none, | 104 | .none, .none, .none, .none, |
src/codegen/sparc64/CodeGen.zig+3-3| ... | @@ -833,7 +833,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -833,7 +833,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { |
| 833 | }; | 833 | }; |
| 834 | 834 | ||
| 835 | if (elements.len <= Air.Liveness.bpi - 1) { | 835 | if (elements.len <= Air.Liveness.bpi - 1) { |
| 836 | var buf = [1]Air.Inst.Ref{.none} ** (Air.Liveness.bpi - 1); | 836 | var buf: [Air.Liveness.bpi - 1]Air.Inst.Ref = @splat(.none); |
| 837 | @memcpy(buf[0..elements.len], elements); | 837 | @memcpy(buf[0..elements.len], elements); |
| 838 | return self.finishAir(inst, result, buf); | 838 | return self.finishAir(inst, result, buf); |
| 839 | } | 839 | } |
| ... | @@ -944,7 +944,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -944,7 +944,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void { |
| 944 | }; | 944 | }; |
| 945 | 945 | ||
| 946 | simple: { | 946 | simple: { |
| 947 | var buf = [1]Air.Inst.Ref{.none} ** (Air.Liveness.bpi - 1); | 947 | var buf: [Air.Liveness.bpi - 1]Air.Inst.Ref = @splat(.none); |
| 948 | var buf_index: usize = 0; | 948 | var buf_index: usize = 0; |
| 949 | for (outputs) |output| { | 949 | for (outputs) |output| { |
| 950 | if (output == .none) continue; | 950 | if (output == .none) continue; |
| ... | @@ -1344,7 +1344,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier | ... | @@ -1344,7 +1344,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 1344 | const result = info.return_value; | 1344 | const result = info.return_value; |
| 1345 | 1345 | ||
| 1346 | if (args.len + 1 <= Air.Liveness.bpi - 1) { | 1346 | if (args.len + 1 <= Air.Liveness.bpi - 1) { |
| 1347 | var buf = [1]Air.Inst.Ref{.none} ** (Air.Liveness.bpi - 1); | 1347 | var buf: [Air.Liveness.bpi - 1]Air.Inst.Ref = @splat(.none); |
| 1348 | buf[0] = call.callee; | 1348 | buf[0] = call.callee; |
| 1349 | @memcpy(buf[1..][0..args.len], args); | 1349 | @memcpy(buf[1..][0..args.len], args); |
| 1350 | return self.finishAir(inst, result, buf); | 1350 | return self.finishAir(inst, result, buf); |
src/codegen/x86_64/CodeGen.zig+6-4| ... | @@ -181601,9 +181601,9 @@ fn splitType(self: *CodeGen, comptime parts_len: usize, ty: Type) ![parts_len]Ty | ... | @@ -181601,9 +181601,9 @@ fn splitType(self: *CodeGen, comptime parts_len: usize, ty: Type) ![parts_len]Ty |
| 181601 | const ip = &zcu.intern_pool; | 181601 | const ip = &zcu.intern_pool; |
| 181602 | var parts: [parts_len]Type = undefined; | 181602 | var parts: [parts_len]Type = undefined; |
| 181603 | switch (ip.indexToKey(ty.toIntern())) { | 181603 | switch (ip.indexToKey(ty.toIntern())) { |
| 181604 | .vector_type => |vector_type| if (std.math.divExact(u32, vector_type.len, parts_len)) |vec_len| return .{ | 181604 | .vector_type => |vector_type| if (std.math.divExact(u32, vector_type.len, parts_len)) |vec_len| { |
| 181605 | try pt.vectorType(.{ .len = vec_len, .child = vector_type.child }), | 181605 | return @splat(try pt.vectorType(.{ .len = vec_len, .child = vector_type.child })); |
| 181606 | } ** parts_len else |err| switch (err) { | 181606 | } else |err| switch (err) { |
| 181607 | error.DivisionByZero => unreachable, | 181607 | error.DivisionByZero => unreachable, |
| 181608 | error.UnexpectedRemainder => {}, | 181608 | error.UnexpectedRemainder => {}, |
| 181609 | }, | 181609 | }, |
| ... | @@ -188774,7 +188774,9 @@ const Select = struct { | ... | @@ -188774,7 +188774,9 @@ const Select = struct { |
| 188774 | try pt.aggregateValue(try pt.vectorType(.{ .len = 4, .child = .u32_type }), &(.{ | 188774 | try pt.aggregateValue(try pt.vectorType(.{ .len = 4, .child = .u32_type }), &(.{ |
| 188775 | (try pt.intValue(.u32, @as(u64, @bitCast(@as(f64, 0x1p52))) >> 32)).toIntern(), | 188775 | (try pt.intValue(.u32, @as(u64, @bitCast(@as(f64, 0x1p52))) >> 32)).toIntern(), |
| 188776 | (try pt.intValue(.u32, @as(u64, @bitCast(@as(f64, 0x1p84))) >> 32)).toIntern(), | 188776 | (try pt.intValue(.u32, @as(u64, @bitCast(@as(f64, 0x1p84))) >> 32)).toIntern(), |
| 188777 | } ++ .{(try pt.intValue(.u32, 0)).toIntern()} ** 2)), | 188777 | (try pt.intValue(.u32, 0)).toIntern(), |
| 188778 | (try pt.intValue(.u32, 0)).toIntern(), | ||
| 188779 | })), | ||
| 188778 | ), true }, | 188780 | ), true }, |
| 188779 | .f32_0_0x1p64_mem => .{ try cg.tempMemFromValue( | 188781 | .f32_0_0x1p64_mem => .{ try cg.tempMemFromValue( |
| 188780 | try pt.aggregateValue(try pt.vectorType(.{ .len = 2, .child = .f32_type }), &.{ | 188782 | try pt.aggregateValue(try pt.vectorType(.{ .len = 2, .child = .f32_type }), &.{ |
src/codegen/x86_64/Encoding.zig+10-2| ... | @@ -1044,9 +1044,17 @@ const mnemonic_to_encodings_map = init: { | ... | @@ -1044,9 +1044,17 @@ const mnemonic_to_encodings_map = init: { |
| 1044 | const index = &mnemonic_index[@intFromEnum(entry[0])]; | 1044 | const index = &mnemonic_index[@intFromEnum(entry[0])]; |
| 1045 | mnemonic_map[@intFromEnum(entry[0])][index.*] = .{ | 1045 | mnemonic_map[@intFromEnum(entry[0])][index.*] = .{ |
| 1046 | .op_en = entry[1], | 1046 | .op_en = entry[1], |
| 1047 | .ops = (entry[2] ++ .{.none} ** (ops_len - entry[2].len)).*, | 1047 | .ops = ops: { |
| 1048 | var ops: [ops_len]Op = @splat(.none); | ||
| 1049 | @memcpy(ops[0..entry[2].len], entry[2]); | ||
| 1050 | break :ops ops; | ||
| 1051 | }, | ||
| 1048 | .opc_len = entry[3].len, | 1052 | .opc_len = entry[3].len, |
| 1049 | .opc = (entry[3] ++ .{undefined} ** (opc_len - entry[3].len)).*, | 1053 | .opc = opc: { |
| 1054 | var opc: [opc_len]u8 = @splat(undefined); | ||
| 1055 | @memcpy(opc[0..entry[3].len], entry[3]); | ||
| 1056 | break :opc opc; | ||
| 1057 | }, | ||
| 1050 | .modrm_ext = entry[4], | 1058 | .modrm_ext = entry[4], |
| 1051 | .mode = entry[5], | 1059 | .mode = entry[5], |
| 1052 | .feature = entry[6], | 1060 | .feature = entry[6], |
src/codegen/x86_64/encoder.zig+2-2| ... | @@ -14,7 +14,7 @@ const Symbol = bits.Symbol; | ... | @@ -14,7 +14,7 @@ const Symbol = bits.Symbol; |
| 14 | pub const Instruction = struct { | 14 | pub const Instruction = struct { |
| 15 | prefix: Prefix = .none, | 15 | prefix: Prefix = .none, |
| 16 | encoding: Encoding, | 16 | encoding: Encoding, |
| 17 | ops: [4]Operand = .{.none} ** 4, | 17 | ops: [4]Operand = @splat(.none), |
| 18 | 18 | ||
| 19 | pub const Mnemonic = Encoding.Mnemonic; | 19 | pub const Mnemonic = Encoding.Mnemonic; |
| 20 | 20 | ||
| ... | @@ -335,7 +335,7 @@ pub const Instruction = struct { | ... | @@ -335,7 +335,7 @@ pub const Instruction = struct { |
| 335 | var inst: Instruction = .{ | 335 | var inst: Instruction = .{ |
| 336 | .prefix = prefix, | 336 | .prefix = prefix, |
| 337 | .encoding = encoding, | 337 | .encoding = encoding, |
| 338 | .ops = [1]Operand{.none} ** 4, | 338 | .ops = @splat(.none), |
| 339 | }; | 339 | }; |
| 340 | @memcpy(inst.ops[0..ops.len], ops); | 340 | @memcpy(inst.ops[0..ops.len], ops); |
| 341 | return inst; | 341 | return inst; |
src/libs/mingw/implib.zig+1-1| ... | @@ -387,7 +387,7 @@ const first_string_table_entry = getNameBytesForStringTableOffset(first_string_t | ... | @@ -387,7 +387,7 @@ const first_string_table_entry = getNameBytesForStringTableOffset(first_string_t |
| 387 | const byte_size_of_relocation = 10; | 387 | const byte_size_of_relocation = 10; |
| 388 | 388 | ||
| 389 | fn getNameBytesForStringTableOffset(offset: u32) [8]u8 { | 389 | fn getNameBytesForStringTableOffset(offset: u32) [8]u8 { |
| 390 | var bytes = [_]u8{0} ** 8; | 390 | var bytes: [8]u8 = @splat(0); |
| 391 | std.mem.writeInt(u32, bytes[4..8], offset, .little); | 391 | std.mem.writeInt(u32, bytes[4..8], offset, .little); |
| 392 | return bytes; | 392 | return bytes; |
| 393 | } | 393 | } |
src/link/Coff.zig+20-4| ... | @@ -81,15 +81,31 @@ pub const msdos_stub: [120]u8 = .{ | ... | @@ -81,15 +81,31 @@ pub const msdos_stub: [120]u8 = .{ |
| 81 | 0x00, 0x00, // Overlay number. Zero means this is the main executable. | 81 | 0x00, 0x00, // Overlay number. Zero means this is the main executable. |
| 82 | } | 82 | } |
| 83 | // Reserved words. | 83 | // Reserved words. |
| 84 | ++ .{ 0x00, 0x00 } ** 4 | 84 | ++ .{ |
| 85 | // OEM-related fields. | 85 | 0x00, 0x00, |
| 86 | 0x00, 0x00, | ||
| 87 | 0x00, 0x00, | ||
| 88 | 0x00, 0x00, | ||
| 89 | } | ||
| 90 | // OEM-related fields. | ||
| 86 | ++ .{ | 91 | ++ .{ |
| 87 | 0x00, 0x00, // OEM identifier. | 92 | 0x00, 0x00, // OEM identifier. |
| 88 | 0x00, 0x00, // OEM information. | 93 | 0x00, 0x00, // OEM information. |
| 89 | } | 94 | } |
| 90 | // Reserved words. | 95 | // Reserved words. |
| 91 | ++ .{ 0x00, 0x00 } ** 10 | 96 | ++ .{ |
| 92 | // Address of the PE header (a long). This matches the size of this entire MS-DOS stub, so that's the address of what's after this MS-DOS stub. | 97 | 0x00, 0x00, |
| 98 | 0x00, 0x00, | ||
| 99 | 0x00, 0x00, | ||
| 100 | 0x00, 0x00, | ||
| 101 | 0x00, 0x00, | ||
| 102 | 0x00, 0x00, | ||
| 103 | 0x00, 0x00, | ||
| 104 | 0x00, 0x00, | ||
| 105 | 0x00, 0x00, | ||
| 106 | 0x00, 0x00, | ||
| 107 | } | ||
| 108 | // Address of the PE header (a long). This matches the size of this entire MS-DOS stub, so that's the address of what's after this MS-DOS stub. | ||
| 93 | ++ .{ 0x78, 0x00, 0x00, 0x00 } | 109 | ++ .{ 0x78, 0x00, 0x00, 0x00 } |
| 94 | // What follows is a 16-bit x86 MS-DOS program of 7 instructions that prints the bytes after these instructions and then exits. | 110 | // What follows is a 16-bit x86 MS-DOS program of 7 instructions that prints the bytes after these instructions and then exits. |
| 95 | ++ .{ | 111 | ++ .{ |
src/link/Dwarf.zig+1-1| ... | @@ -2975,7 +2975,7 @@ fn finishWipNavFuncWriterError( | ... | @@ -2975,7 +2975,7 @@ fn finishWipNavFuncWriterError( |
| 2975 | wip_nav.unit, | 2975 | wip_nav.unit, |
| 2976 | wip_nav.entry, | 2976 | wip_nav.entry, |
| 2977 | dwarf, | 2977 | dwarf, |
| 2978 | ([1]u8{DW.RLE.start_end} ++ [1]u8{0} ** (8 + 8))[0 .. 1 + @intFromEnum(dwarf.address_size) + @intFromEnum(dwarf.address_size)], | 2978 | ([1]u8{DW.RLE.start_end} ++ @as([8 + 8]u8, @splat(0)))[0 .. 1 + @intFromEnum(dwarf.address_size) + @intFromEnum(dwarf.address_size)], |
| 2979 | ); | 2979 | ); |
| 2980 | } | 2980 | } |
| 2981 | 2981 |
src/link/Elf.zig+1-1| ... | @@ -3943,7 +3943,7 @@ fn formatPhdr(ctx: FormatPhdr, writer: *std.Io.Writer) std.Io.Writer.Error!void | ... | @@ -3943,7 +3943,7 @@ fn formatPhdr(ctx: FormatPhdr, writer: *std.Io.Writer) std.Io.Writer.Error!void |
| 3943 | const write = phdr.p_flags & elf.PF_W != 0; | 3943 | const write = phdr.p_flags & elf.PF_W != 0; |
| 3944 | const read = phdr.p_flags & elf.PF_R != 0; | 3944 | const read = phdr.p_flags & elf.PF_R != 0; |
| 3945 | const exec = phdr.p_flags & elf.PF_X != 0; | 3945 | const exec = phdr.p_flags & elf.PF_X != 0; |
| 3946 | var flags: [3]u8 = [_]u8{'_'} ** 3; | 3946 | var flags: [3]u8 = @splat('_'); |
| 3947 | if (exec) flags[0] = 'X'; | 3947 | if (exec) flags[0] = 'X'; |
| 3948 | if (write) flags[1] = 'W'; | 3948 | if (write) flags[1] = 'W'; |
| 3949 | if (read) flags[2] = 'R'; | 3949 | if (read) flags[2] = 'R'; |
src/link/Elf/Symbol.zig+1-1| ... | @@ -363,7 +363,7 @@ const Format = struct { | ... | @@ -363,7 +363,7 @@ const Format = struct { |
| 363 | if (symbol.atom(elf_file)) |atom_ptr| { | 363 | if (symbol.atom(elf_file)) |atom_ptr| { |
| 364 | try writer.print(" : atom({d})", .{atom_ptr.atom_index}); | 364 | try writer.print(" : atom({d})", .{atom_ptr.atom_index}); |
| 365 | } | 365 | } |
| 366 | var buf: [2]u8 = .{'_'} ** 2; | 366 | var buf: [2]u8 = @splat('_'); |
| 367 | if (symbol.flags.@"export") buf[0] = 'E'; | 367 | if (symbol.flags.@"export") buf[0] = 'E'; |
| 368 | if (symbol.flags.import) buf[1] = 'I'; | 368 | if (symbol.flags.import) buf[1] = 'I'; |
| 369 | try writer.print(" : {s}", .{&buf}); | 369 | try writer.print(" : {s}", .{&buf}); |
src/link/MachO.zig+2-2| ... | @@ -38,7 +38,7 @@ symtab_cmd: macho.symtab_command = .{}, | ... | @@ -38,7 +38,7 @@ symtab_cmd: macho.symtab_command = .{}, |
| 38 | dysymtab_cmd: macho.dysymtab_command = .{}, | 38 | dysymtab_cmd: macho.dysymtab_command = .{}, |
| 39 | function_starts_cmd: macho.linkedit_data_command = .{ .cmd = .FUNCTION_STARTS }, | 39 | function_starts_cmd: macho.linkedit_data_command = .{ .cmd = .FUNCTION_STARTS }, |
| 40 | data_in_code_cmd: macho.linkedit_data_command = .{ .cmd = .DATA_IN_CODE }, | 40 | data_in_code_cmd: macho.linkedit_data_command = .{ .cmd = .DATA_IN_CODE }, |
| 41 | uuid_cmd: macho.uuid_command = .{ .uuid = [_]u8{0} ** 16 }, | 41 | uuid_cmd: macho.uuid_command = .{ .uuid = @splat(0) }, |
| 42 | codesig_cmd: macho.linkedit_data_command = .{ .cmd = .CODE_SIGNATURE }, | 42 | codesig_cmd: macho.linkedit_data_command = .{ .cmd = .CODE_SIGNATURE }, |
| 43 | 43 | ||
| 44 | pagezero_seg_index: ?u8 = null, | 44 | pagezero_seg_index: ?u8 = null, |
| ... | @@ -3763,7 +3763,7 @@ pub fn addSection( | ... | @@ -3763,7 +3763,7 @@ pub fn addSection( |
| 3763 | } | 3763 | } |
| 3764 | 3764 | ||
| 3765 | pub fn makeStaticString(bytes: []const u8) [16]u8 { | 3765 | pub fn makeStaticString(bytes: []const u8) [16]u8 { |
| 3766 | var buf = [_]u8{0} ** 16; | 3766 | var buf: [16]u8 = @splat(0); |
| 3767 | @memcpy(buf[0..bytes.len], bytes); | 3767 | @memcpy(buf[0..bytes.len], bytes); |
| 3768 | return buf; | 3768 | return buf; |
| 3769 | } | 3769 | } |
src/link/MachO/CodeSignature.zig+1-1| ... | @@ -95,7 +95,7 @@ const CodeDirectory = struct { | ... | @@ -95,7 +95,7 @@ const CodeDirectory = struct { |
| 95 | }; | 95 | }; |
| 96 | comptime var i = 0; | 96 | comptime var i = 0; |
| 97 | inline while (i < n_special_slots) : (i += 1) { | 97 | inline while (i < n_special_slots) : (i += 1) { |
| 98 | cdir.special_slots[i] = [_]u8{0} ** hash_size; | 98 | cdir.special_slots[i] = @splat(0); |
| 99 | } | 99 | } |
| 100 | return cdir; | 100 | return cdir; |
| 101 | } | 101 | } |
src/link/MachO/DebugSymbols.zig+1-1| ... | @@ -25,7 +25,7 @@ allocator: Allocator, | ... | @@ -25,7 +25,7 @@ allocator: Allocator, |
| 25 | file: ?Io.File, | 25 | file: ?Io.File, |
| 26 | 26 | ||
| 27 | symtab_cmd: macho.symtab_command = .{}, | 27 | symtab_cmd: macho.symtab_command = .{}, |
| 28 | uuid_cmd: macho.uuid_command = .{ .uuid = [_]u8{0} ** 16 }, | 28 | uuid_cmd: macho.uuid_command = .{ .uuid = @splat(0) }, |
| 29 | 29 | ||
| 30 | segments: std.ArrayList(macho.segment_command_64) = .empty, | 30 | segments: std.ArrayList(macho.segment_command_64) = .empty, |
| 31 | sections: std.ArrayList(macho.section_64) = .empty, | 31 | sections: std.ArrayList(macho.section_64) = .empty, |
src/link/MachO/InternalObject.zig+1-1| ... | @@ -11,7 +11,7 @@ symbols_extra: std.ArrayList(u32) = .empty, | ... | @@ -11,7 +11,7 @@ symbols_extra: std.ArrayList(u32) = .empty, |
| 11 | globals: std.ArrayList(MachO.SymbolResolver.Index) = .empty, | 11 | globals: std.ArrayList(MachO.SymbolResolver.Index) = .empty, |
| 12 | 12 | ||
| 13 | objc_methnames: std.ArrayList(u8) = .empty, | 13 | objc_methnames: std.ArrayList(u8) = .empty, |
| 14 | objc_selrefs: [@sizeOf(u64)]u8 = [_]u8{0} ** @sizeOf(u64), | 14 | objc_selrefs: [@sizeOf(u64)]u8 = @splat(0), |
| 15 | 15 | ||
| 16 | force_undefined: std.ArrayList(Symbol.Index) = .empty, | 16 | force_undefined: std.ArrayList(Symbol.Index) = .empty, |
| 17 | entry_index: ?Symbol.Index = null, | 17 | entry_index: ?Symbol.Index = null, |
src/link/MachO/Symbol.zig+1-1| ... | @@ -325,7 +325,7 @@ const Format = struct { | ... | @@ -325,7 +325,7 @@ const Format = struct { |
| 325 | if (symbol.getAtom(f.macho_file)) |atom| { | 325 | if (symbol.getAtom(f.macho_file)) |atom| { |
| 326 | try w.print(" : atom({d})", .{atom.atom_index}); | 326 | try w.print(" : atom({d})", .{atom.atom_index}); |
| 327 | } | 327 | } |
| 328 | var buf: [3]u8 = .{'_'} ** 3; | 328 | var buf: [3]u8 = @splat('_'); |
| 329 | if (symbol.flags.@"export") buf[0] = 'E'; | 329 | if (symbol.flags.@"export") buf[0] = 'E'; |
| 330 | if (symbol.flags.import) buf[1] = 'I'; | 330 | if (symbol.flags.import) buf[1] = 'I'; |
| 331 | switch (symbol.visibility) { | 331 | switch (symbol.visibility) { |
test/behavior/array.zig+4-16| ... | @@ -104,18 +104,6 @@ test "array init with concat" { | ... | @@ -104,18 +104,6 @@ test "array init with concat" { |
| 104 | try expect(std.mem.eql(u8, &i, "abcd")); | 104 | try expect(std.mem.eql(u8, &i, "abcd")); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | test "array init with mult" { | ||
| 108 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | ||
| 109 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 110 | |||
| 111 | const a = 'a'; | ||
| 112 | var i: [8]u8 = [2]u8{ a, 'b' } ** 4; | ||
| 113 | try expect(std.mem.eql(u8, &i, "abababab")); | ||
| 114 | |||
| 115 | var j: [4]u8 = [1]u8{'a'} ** 4; | ||
| 116 | try expect(std.mem.eql(u8, &j, "aaaa")); | ||
| 117 | } | ||
| 118 | |||
| 119 | test "array literal with explicit type" { | 107 | test "array literal with explicit type" { |
| 120 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 108 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 121 | 109 | ||
| ... | @@ -320,7 +308,7 @@ test "set global var array via slice embedded in struct" { | ... | @@ -320,7 +308,7 @@ test "set global var array via slice embedded in struct" { |
| 320 | try expect(s_array[2].b == 3); | 308 | try expect(s_array[2].b == 3); |
| 321 | } | 309 | } |
| 322 | 310 | ||
| 323 | test "read/write through global variable array of struct fields initialized via array mult" { | 311 | test "read/write through global variable array of struct fields initialized via splat" { |
| 324 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 312 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 325 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 313 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 326 | 314 | ||
| ... | @@ -335,7 +323,7 @@ test "read/write through global variable array of struct fields initialized via | ... | @@ -335,7 +323,7 @@ test "read/write through global variable array of struct fields initialized via |
| 335 | term: usize, | 323 | term: usize, |
| 336 | }; | 324 | }; |
| 337 | 325 | ||
| 338 | var storage: [1]MyStruct = [_]MyStruct{MyStruct{ .term = 1 }} ** 1; | 326 | var storage: [1]MyStruct = @splat(.{ .term = 1 }); |
| 339 | }; | 327 | }; |
| 340 | try S.doTheTest(); | 328 | try S.doTheTest(); |
| 341 | } | 329 | } |
| ... | @@ -641,8 +629,8 @@ test "array of array agregate init" { | ... | @@ -641,8 +629,8 @@ test "array of array agregate init" { |
| 641 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 629 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 642 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 630 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 643 | 631 | ||
| 644 | var a = [1]u32{11} ** 10; | 632 | var a: [10]u32 = @splat(11); |
| 645 | var b = [1][10]u32{a} ** 2; | 633 | var b: [2][10]u32 = @splat(a); |
| 646 | _ = .{ &a, &b }; | 634 | _ = .{ &a, &b }; |
| 647 | try std.testing.expect(b[1][1] == 11); | 635 | try std.testing.expect(b[1][1] == 11); |
| 648 | } | 636 | } |
test/behavior/basic.zig+1-8| ... | @@ -294,13 +294,6 @@ test "string concatenation simple" { | ... | @@ -294,13 +294,6 @@ test "string concatenation simple" { |
| 294 | try expect(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED")); | 294 | try expect(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED")); |
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | test "array mult operator" { | ||
| 298 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 299 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | ||
| 300 | |||
| 301 | try expect(mem.eql(u8, "ab" ** 5, "ababababab")); | ||
| 302 | } | ||
| 303 | |||
| 304 | const global_a: i32 = 1234; | 297 | const global_a: i32 = 1234; |
| 305 | const global_b: *const i32 = &global_a; | 298 | const global_b: *const i32 = &global_a; |
| 306 | const global_c: *const f32 = @as(*const f32, @ptrCast(global_b)); | 299 | const global_c: *const f32 = @as(*const f32, @ptrCast(global_b)); |
| ... | @@ -1041,7 +1034,7 @@ test "const alloc with comptime-known initializer is made comptime-known" { | ... | @@ -1041,7 +1034,7 @@ test "const alloc with comptime-known initializer is made comptime-known" { |
| 1041 | positive: bool, | 1034 | positive: bool, |
| 1042 | }; | 1035 | }; |
| 1043 | const biggest: Const = .{ | 1036 | const biggest: Const = .{ |
| 1044 | .limbs = &([1]usize{comptime std.math.maxInt(usize)} ** 128), | 1037 | .limbs = &@as([128]usize, @splat(comptime std.math.maxInt(usize))), |
| 1045 | .positive = false, | 1038 | .positive = false, |
| 1046 | }; | 1039 | }; |
| 1047 | if (biggest.positive) @compileError("bad"); | 1040 | if (biggest.positive) @compileError("bad"); |
test/behavior/bit_shifting.zig+1-1| ... | @@ -15,7 +15,7 @@ fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, compt | ... | @@ -15,7 +15,7 @@ fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, compt |
| 15 | shards: [1 << shard_key_bits]?*Node, | 15 | shards: [1 << shard_key_bits]?*Node, |
| 16 | 16 | ||
| 17 | pub fn create() Self { | 17 | pub fn create() Self { |
| 18 | return Self{ .shards = [_]?*Node{null} ** (1 << shard_key_bits) }; | 18 | return .{ .shards = @splat(null) }; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | fn getShardKey(key: Key) ShardKey { | 21 | fn getShardKey(key: Key) ShardKey { |
test/behavior/cast.zig+1-1| ... | @@ -3036,7 +3036,7 @@ test "bitcast vector" { | ... | @@ -3036,7 +3036,7 @@ test "bitcast vector" { |
| 3036 | const u8x32 = @Vector(32, u8); | 3036 | const u8x32 = @Vector(32, u8); |
| 3037 | const u32x8 = @Vector(8, u32); | 3037 | const u32x8 = @Vector(8, u32); |
| 3038 | 3038 | ||
| 3039 | const zerox32: u8x32 = [_]u8{0} ** 32; | 3039 | const zerox32: u8x32 = @splat(0); |
| 3040 | const bigsum: u32x8 = @bitCast(zerox32); | 3040 | const bigsum: u32x8 = @bitCast(zerox32); |
| 3041 | try std.testing.expectEqual(0, @reduce(.Add, bigsum)); | 3041 | try std.testing.expectEqual(0, @reduce(.Add, bigsum)); |
| 3042 | } | 3042 | } |
test/behavior/eval.zig+1-45| ... | @@ -727,15 +727,6 @@ test "array concatenation of function calls" { | ... | @@ -727,15 +727,6 @@ test "array concatenation of function calls" { |
| 727 | try expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 })); | 727 | try expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 })); |
| 728 | } | 728 | } |
| 729 | 729 | ||
| 730 | test "array multiplication of function calls" { | ||
| 731 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 732 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 733 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | ||
| 734 | |||
| 735 | var a = oneItem(3) ** scalar(2); | ||
| 736 | try expect(std.mem.eql(i32, &a, &[_]i32{ 3, 3 })); | ||
| 737 | } | ||
| 738 | |||
| 739 | fn oneItem(x: i32) [1]i32 { | 730 | fn oneItem(x: i32) [1]i32 { |
| 740 | return [_]i32{x}; | 731 | return [_]i32{x}; |
| 741 | } | 732 | } |
| ... | @@ -814,41 +805,6 @@ test "array concatenation sets the sentinel - pointer" { | ... | @@ -814,41 +805,6 @@ test "array concatenation sets the sentinel - pointer" { |
| 814 | try expect(ptr[5] == 69); | 805 | try expect(ptr[5] == 69); |
| 815 | } | 806 | } |
| 816 | 807 | ||
| 817 | test "array multiplication sets the sentinel - value" { | ||
| 818 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 819 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 820 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; | ||
| 821 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | ||
| 822 | |||
| 823 | var a = [2:7]u3{ 1, 6 }; | ||
| 824 | _ = &a; | ||
| 825 | const b = a ** 2; | ||
| 826 | comptime assert(@TypeOf(b) == [4:7]u3); | ||
| 827 | try expect(b[0] == 1); | ||
| 828 | try expect(b[1] == 6); | ||
| 829 | try expect(b[2] == 1); | ||
| 830 | try expect(b[3] == 6); | ||
| 831 | const ptr: [*]const u3 = &b; | ||
| 832 | try expect(ptr[4] == 7); | ||
| 833 | } | ||
| 834 | |||
| 835 | test "array multiplication sets the sentinel - pointer" { | ||
| 836 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 837 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 838 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; | ||
| 839 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | ||
| 840 | |||
| 841 | var a = [2:7]u3{ 1, 6 }; | ||
| 842 | const b = &a ** 2; | ||
| 843 | comptime assert(@TypeOf(b) == *const [4:7]u3); | ||
| 844 | try expect(b[0] == 1); | ||
| 845 | try expect(b[1] == 6); | ||
| 846 | try expect(b[2] == 1); | ||
| 847 | try expect(b[3] == 6); | ||
| 848 | const ptr: [*]const u3 = b; | ||
| 849 | try expect(ptr[4] == 7); | ||
| 850 | } | ||
| 851 | |||
| 852 | test "comptime assign int to optional int" { | 808 | test "comptime assign int to optional int" { |
| 853 | comptime { | 809 | comptime { |
| 854 | var x: ?i32 = null; | 810 | var x: ?i32 = null; |
| ... | @@ -1094,7 +1050,7 @@ test "storing an array of type in a field" { | ... | @@ -1094,7 +1050,7 @@ test "storing an array of type in a field" { |
| 1094 | 1050 | ||
| 1095 | fn foo() @This() { | 1051 | fn foo() @This() { |
| 1096 | comptime var foobar: Foobar = undefined; | 1052 | comptime var foobar: Foobar = undefined; |
| 1097 | foobar.str = [_]u8{'a'} ** 1024; | 1053 | foobar.str = @splat('a'); |
| 1098 | return foobar; | 1054 | return foobar; |
| 1099 | } | 1055 | } |
| 1100 | }; | 1056 | }; |
test/behavior/extern_struct_zero_size_fields.zig+2-2| ... | @@ -10,9 +10,9 @@ const T = extern struct { | ... | @@ -10,9 +10,9 @@ const T = extern struct { |
| 10 | baz: struct {} = .{}, | 10 | baz: struct {} = .{}, |
| 11 | ayy: E = .the_only_possible_value, | 11 | ayy: E = .the_only_possible_value, |
| 12 | arr: [0]u0 = .{}, | 12 | arr: [0]u0 = .{}, |
| 13 | matey: [128]void = [_]void{{}} ** 128, | 13 | matey: [128]void = @splat({}), |
| 14 | running_out_of_ideas: packed struct {} = .{}, | 14 | running_out_of_ideas: packed struct {} = .{}, |
| 15 | one_more: [256]S = [_]S{.{}} ** 256, | 15 | one_more: [256]S = @splat(.{}), |
| 16 | }; | 16 | }; |
| 17 | 17 | ||
| 18 | test { | 18 | test { |
test/behavior/for.zig+5-1| ... | @@ -69,7 +69,11 @@ test "basic for loop" { | ... | @@ -69,7 +69,11 @@ test "basic for loop" { |
| 69 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 69 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 70 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 70 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 71 | 71 | ||
| 72 | const expected_result = [_]u8{ 9, 8, 7, 6, 0, 1, 2, 3 } ** 3; | 72 | const expected_result: [24]u8 = .{ |
| 73 | 9, 8, 7, 6, 0, 1, 2, 3, | ||
| 74 | 9, 8, 7, 6, 0, 1, 2, 3, | ||
| 75 | 9, 8, 7, 6, 0, 1, 2, 3, | ||
| 76 | }; | ||
| 73 | 77 | ||
| 74 | var buffer: [expected_result.len]u8 = undefined; | 78 | var buffer: [expected_result.len]u8 = undefined; |
| 75 | var buf_index: usize = 0; | 79 | var buf_index: usize = 0; |
test/behavior/memset.zig+2-2| ... | @@ -109,7 +109,7 @@ test "memset with large array element, runtime known" { | ... | @@ -109,7 +109,7 @@ test "memset with large array element, runtime known" { |
| 109 | 109 | ||
| 110 | const A = [128]u64; | 110 | const A = [128]u64; |
| 111 | var buf: [5]A = undefined; | 111 | var buf: [5]A = undefined; |
| 112 | var runtime_known_element = [_]u64{0} ** 128; | 112 | var runtime_known_element: A = @splat(0); |
| 113 | _ = &runtime_known_element; | 113 | _ = &runtime_known_element; |
| 114 | @memset(&buf, runtime_known_element); | 114 | @memset(&buf, runtime_known_element); |
| 115 | for (buf[0]) |elem| try expect(elem == 0); | 115 | for (buf[0]) |elem| try expect(elem == 0); |
| ... | @@ -127,7 +127,7 @@ test "memset with large array element, comptime known" { | ... | @@ -127,7 +127,7 @@ test "memset with large array element, comptime known" { |
| 127 | 127 | ||
| 128 | const A = [128]u64; | 128 | const A = [128]u64; |
| 129 | var buf: [5]A = undefined; | 129 | var buf: [5]A = undefined; |
| 130 | const comptime_known_element = [_]u64{0} ** 128; | 130 | const comptime_known_element: A = @splat(0); |
| 131 | @memset(&buf, comptime_known_element); | 131 | @memset(&buf, comptime_known_element); |
| 132 | for (buf[0]) |elem| try expect(elem == 0); | 132 | for (buf[0]) |elem| try expect(elem == 0); |
| 133 | for (buf[1]) |elem| try expect(elem == 0); | 133 | for (buf[1]) |elem| try expect(elem == 0); |
test/behavior/optional.zig+1-1| ... | @@ -621,7 +621,7 @@ test "copied optional doesn't alias source" { | ... | @@ -621,7 +621,7 @@ test "copied optional doesn't alias source" { |
| 621 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 621 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 622 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; | 622 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; |
| 623 | 623 | ||
| 624 | var opt_x: ?[3]f32 = [_]f32{0.0} ** 3; | 624 | var opt_x: ?[3]f32 = @splat(0.0); |
| 625 | 625 | ||
| 626 | const x = opt_x.?; | 626 | const x = opt_x.?; |
| 627 | opt_x.?[0] = 15.0; | 627 | opt_x.?[0] = 15.0; |
test/behavior/packed-struct.zig+1-1| ... | @@ -883,7 +883,7 @@ test "pointer to container level packed struct field" { | ... | @@ -883,7 +883,7 @@ test "pointer to container level packed struct field" { |
| 883 | enable_5: bool, | 883 | enable_5: bool, |
| 884 | enable_6: bool, | 884 | enable_6: bool, |
| 885 | }, | 885 | }, |
| 886 | var arr = [_]u32{0} ** 2; | 886 | var arr: [2]u32 = @splat(0); |
| 887 | }; | 887 | }; |
| 888 | @as(*S, @ptrCast(&S.arr[0])).other_bits.enable_3 = true; | 888 | @as(*S, @ptrCast(&S.arr[0])).other_bits.enable_3 = true; |
| 889 | try expect(S.arr[0] == 0x10000000); | 889 | try expect(S.arr[0] == 0x10000000); |
test/behavior/pointers.zig+1-1| ... | @@ -627,7 +627,7 @@ test "pointer to array has explicit alignment" { | ... | @@ -627,7 +627,7 @@ test "pointer to array has explicit alignment" { |
| 627 | return @alignCast(@as(*[4]Base2, @ptrCast(ptr))); | 627 | return @alignCast(@as(*[4]Base2, @ptrCast(ptr))); |
| 628 | } | 628 | } |
| 629 | }; | 629 | }; |
| 630 | var bases = [_]S.Base{.{ .a = 2 }} ** 4; | 630 | var bases: [4]S.Base = @splat(.{ .a = 2 }); |
| 631 | const casted = S.func(&bases); | 631 | const casted = S.func(&bases); |
| 632 | try expect(casted[0].a == 2); | 632 | try expect(casted[0].a == 2); |
| 633 | } | 633 | } |
test/behavior/popcount.zig+4-4| ... | @@ -88,16 +88,16 @@ test "@popCount vectors" { | ... | @@ -88,16 +88,16 @@ test "@popCount vectors" { |
| 88 | 88 | ||
| 89 | fn testPopCountVectors() !void { | 89 | fn testPopCountVectors() !void { |
| 90 | { | 90 | { |
| 91 | var x: @Vector(8, u32) = [1]u32{0xffffffff} ** 8; | 91 | var x: @Vector(8, u32) = @splat(0xffffffff); |
| 92 | _ = &x; | 92 | _ = &x; |
| 93 | const expected = [1]u6{32} ** 8; | 93 | const expected: [8]u6 = @splat(32); |
| 94 | const result: [8]u6 = @popCount(x); | 94 | const result: [8]u6 = @popCount(x); |
| 95 | try expect(std.mem.eql(u6, &expected, &result)); | 95 | try expect(std.mem.eql(u6, &expected, &result)); |
| 96 | } | 96 | } |
| 97 | { | 97 | { |
| 98 | var x: @Vector(8, i16) = [1]i16{-1} ** 8; | 98 | var x: @Vector(8, i16) = @splat(-1); |
| 99 | _ = &x; | 99 | _ = &x; |
| 100 | const expected = [1]u5{16} ** 8; | 100 | const expected: [8]u5 = @splat(16); |
| 101 | const result: [8]u5 = @popCount(x); | 101 | const result: [8]u5 = @popCount(x); |
| 102 | try expect(std.mem.eql(u5, &expected, &result)); | 102 | try expect(std.mem.eql(u5, &expected, &result)); |
| 103 | } | 103 | } |
test/behavior/slice.zig+1-11| ... | @@ -314,7 +314,7 @@ test "C pointer slice access" { | ... | @@ -314,7 +314,7 @@ test "C pointer slice access" { |
| 314 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 314 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 315 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 315 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 316 | 316 | ||
| 317 | var buf: [10]u32 = [1]u32{42} ** 10; | 317 | var buf: [10]u32 = @splat(42); |
| 318 | const c_ptr = @as([*c]const u32, @ptrCast(&buf)); | 318 | const c_ptr = @as([*c]const u32, @ptrCast(&buf)); |
| 319 | 319 | ||
| 320 | var runtime_zero: usize = 0; | 320 | var runtime_zero: usize = 0; |
| ... | @@ -768,16 +768,6 @@ test "array concat of slices gives ptr to array" { | ... | @@ -768,16 +768,6 @@ test "array concat of slices gives ptr to array" { |
| 768 | } | 768 | } |
| 769 | } | 769 | } |
| 770 | 770 | ||
| 771 | test "array mult of slice gives ptr to array" { | ||
| 772 | comptime { | ||
| 773 | var a: []const u8 = "aoeu"; | ||
| 774 | _ = &a; | ||
| 775 | const c = a ** 2; | ||
| 776 | try expect(std.mem.eql(u8, c, "aoeuaoeu")); | ||
| 777 | try expect(@TypeOf(c) == *const [8]u8); | ||
| 778 | } | ||
| 779 | } | ||
| 780 | |||
| 781 | test "slice bounds in comptime concatenation" { | 771 | test "slice bounds in comptime concatenation" { |
| 782 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 772 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 783 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 773 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
test/behavior/slice_sentinel_comptime.zig+31-28| ... | @@ -1,16 +1,19 @@ | ... | @@ -1,16 +1,19 @@ |
| 1 | const builtin = @import("builtin"); | 1 | const builtin = @import("builtin"); |
| 2 | 2 | ||
| 3 | const undef_10_u8: [10]u8 = @splat(undefined); | ||
| 4 | const ff_10_u8: [10]u8 = @splat(0xFF); | ||
| 5 | |||
| 3 | test "comptime slice-sentinel in bounds (unterminated)" { | 6 | test "comptime slice-sentinel in bounds (unterminated)" { |
| 4 | // array | 7 | // array |
| 5 | comptime { | 8 | comptime { |
| 6 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 9 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 7 | const slice = target[0..3 :'d']; | 10 | const slice = target[0..3 :'d']; |
| 8 | _ = slice; | 11 | _ = slice; |
| 9 | } | 12 | } |
| 10 | 13 | ||
| 11 | // ptr_array | 14 | // ptr_array |
| 12 | comptime { | 15 | comptime { |
| 13 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 16 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 14 | var target = &buf; | 17 | var target = &buf; |
| 15 | const slice = target[0..3 :'d']; | 18 | const slice = target[0..3 :'d']; |
| 16 | _ = slice; | 19 | _ = slice; |
| ... | @@ -18,7 +21,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { | ... | @@ -18,7 +21,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { |
| 18 | 21 | ||
| 19 | // vector_ConstPtrSpecialBaseArray | 22 | // vector_ConstPtrSpecialBaseArray |
| 20 | comptime { | 23 | comptime { |
| 21 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 24 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 22 | var target: [*]u8 = &buf; | 25 | var target: [*]u8 = &buf; |
| 23 | const slice = target[0..3 :'d']; | 26 | const slice = target[0..3 :'d']; |
| 24 | _ = slice; | 27 | _ = slice; |
| ... | @@ -26,7 +29,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { | ... | @@ -26,7 +29,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { |
| 26 | 29 | ||
| 27 | // vector_ConstPtrSpecialRef | 30 | // vector_ConstPtrSpecialRef |
| 28 | comptime { | 31 | comptime { |
| 29 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 32 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 30 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); | 33 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); |
| 31 | const slice = target[0..3 :'d']; | 34 | const slice = target[0..3 :'d']; |
| 32 | _ = slice; | 35 | _ = slice; |
| ... | @@ -34,7 +37,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { | ... | @@ -34,7 +37,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { |
| 34 | 37 | ||
| 35 | // cvector_ConstPtrSpecialBaseArray | 38 | // cvector_ConstPtrSpecialBaseArray |
| 36 | comptime { | 39 | comptime { |
| 37 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 40 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 38 | var target: [*c]u8 = &buf; | 41 | var target: [*c]u8 = &buf; |
| 39 | const slice = target[0..3 :'d']; | 42 | const slice = target[0..3 :'d']; |
| 40 | _ = slice; | 43 | _ = slice; |
| ... | @@ -42,7 +45,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { | ... | @@ -42,7 +45,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { |
| 42 | 45 | ||
| 43 | // cvector_ConstPtrSpecialRef | 46 | // cvector_ConstPtrSpecialRef |
| 44 | comptime { | 47 | comptime { |
| 45 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 48 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 46 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); | 49 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); |
| 47 | const slice = target[0..3 :'d']; | 50 | const slice = target[0..3 :'d']; |
| 48 | _ = slice; | 51 | _ = slice; |
| ... | @@ -50,7 +53,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { | ... | @@ -50,7 +53,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { |
| 50 | 53 | ||
| 51 | // slice | 54 | // slice |
| 52 | comptime { | 55 | comptime { |
| 53 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 56 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 54 | var target: []u8 = &buf; | 57 | var target: []u8 = &buf; |
| 55 | const slice = target[0..3 :'d']; | 58 | const slice = target[0..3 :'d']; |
| 56 | _ = slice; | 59 | _ = slice; |
| ... | @@ -60,14 +63,14 @@ test "comptime slice-sentinel in bounds (unterminated)" { | ... | @@ -60,14 +63,14 @@ test "comptime slice-sentinel in bounds (unterminated)" { |
| 60 | test "comptime slice-sentinel in bounds (end,unterminated)" { | 63 | test "comptime slice-sentinel in bounds (end,unterminated)" { |
| 61 | // array | 64 | // array |
| 62 | comptime { | 65 | comptime { |
| 63 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; | 66 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8; |
| 64 | const slice = target[0..13 :0xff]; | 67 | const slice = target[0..13 :0xff]; |
| 65 | _ = slice; | 68 | _ = slice; |
| 66 | } | 69 | } |
| 67 | 70 | ||
| 68 | // ptr_array | 71 | // ptr_array |
| 69 | comptime { | 72 | comptime { |
| 70 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; | 73 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8; |
| 71 | var target = &buf; | 74 | var target = &buf; |
| 72 | const slice = target[0..13 :0xff]; | 75 | const slice = target[0..13 :0xff]; |
| 73 | _ = slice; | 76 | _ = slice; |
| ... | @@ -75,7 +78,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { | ... | @@ -75,7 +78,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { |
| 75 | 78 | ||
| 76 | // vector_ConstPtrSpecialBaseArray | 79 | // vector_ConstPtrSpecialBaseArray |
| 77 | comptime { | 80 | comptime { |
| 78 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; | 81 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8; |
| 79 | var target: [*]u8 = &buf; | 82 | var target: [*]u8 = &buf; |
| 80 | const slice = target[0..13 :0xff]; | 83 | const slice = target[0..13 :0xff]; |
| 81 | _ = slice; | 84 | _ = slice; |
| ... | @@ -83,7 +86,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { | ... | @@ -83,7 +86,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { |
| 83 | 86 | ||
| 84 | // vector_ConstPtrSpecialRef | 87 | // vector_ConstPtrSpecialRef |
| 85 | comptime { | 88 | comptime { |
| 86 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; | 89 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8; |
| 87 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); | 90 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); |
| 88 | const slice = target[0..13 :0xff]; | 91 | const slice = target[0..13 :0xff]; |
| 89 | _ = slice; | 92 | _ = slice; |
| ... | @@ -91,7 +94,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { | ... | @@ -91,7 +94,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { |
| 91 | 94 | ||
| 92 | // cvector_ConstPtrSpecialBaseArray | 95 | // cvector_ConstPtrSpecialBaseArray |
| 93 | comptime { | 96 | comptime { |
| 94 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; | 97 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8; |
| 95 | var target: [*c]u8 = &buf; | 98 | var target: [*c]u8 = &buf; |
| 96 | const slice = target[0..13 :0xff]; | 99 | const slice = target[0..13 :0xff]; |
| 97 | _ = slice; | 100 | _ = slice; |
| ... | @@ -99,7 +102,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { | ... | @@ -99,7 +102,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { |
| 99 | 102 | ||
| 100 | // cvector_ConstPtrSpecialRef | 103 | // cvector_ConstPtrSpecialRef |
| 101 | comptime { | 104 | comptime { |
| 102 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; | 105 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8; |
| 103 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); | 106 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); |
| 104 | const slice = target[0..13 :0xff]; | 107 | const slice = target[0..13 :0xff]; |
| 105 | _ = slice; | 108 | _ = slice; |
| ... | @@ -107,7 +110,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { | ... | @@ -107,7 +110,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { |
| 107 | 110 | ||
| 108 | // slice | 111 | // slice |
| 109 | comptime { | 112 | comptime { |
| 110 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; | 113 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8; |
| 111 | var target: []u8 = &buf; | 114 | var target: []u8 = &buf; |
| 112 | const slice = target[0..13 :0xff]; | 115 | const slice = target[0..13 :0xff]; |
| 113 | _ = slice; | 116 | _ = slice; |
| ... | @@ -117,14 +120,14 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { | ... | @@ -117,14 +120,14 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { |
| 117 | test "comptime slice-sentinel in bounds (terminated)" { | 120 | test "comptime slice-sentinel in bounds (terminated)" { |
| 118 | // array | 121 | // array |
| 119 | comptime { | 122 | comptime { |
| 120 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 123 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 121 | const slice = target[0..3 :'d']; | 124 | const slice = target[0..3 :'d']; |
| 122 | _ = slice; | 125 | _ = slice; |
| 123 | } | 126 | } |
| 124 | 127 | ||
| 125 | // ptr_array | 128 | // ptr_array |
| 126 | comptime { | 129 | comptime { |
| 127 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 130 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 128 | var target = &buf; | 131 | var target = &buf; |
| 129 | const slice = target[0..3 :'d']; | 132 | const slice = target[0..3 :'d']; |
| 130 | _ = slice; | 133 | _ = slice; |
| ... | @@ -132,7 +135,7 @@ test "comptime slice-sentinel in bounds (terminated)" { | ... | @@ -132,7 +135,7 @@ test "comptime slice-sentinel in bounds (terminated)" { |
| 132 | 135 | ||
| 133 | // vector_ConstPtrSpecialBaseArray | 136 | // vector_ConstPtrSpecialBaseArray |
| 134 | comptime { | 137 | comptime { |
| 135 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 138 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 136 | var target: [*]u8 = &buf; | 139 | var target: [*]u8 = &buf; |
| 137 | const slice = target[0..3 :'d']; | 140 | const slice = target[0..3 :'d']; |
| 138 | _ = slice; | 141 | _ = slice; |
| ... | @@ -140,7 +143,7 @@ test "comptime slice-sentinel in bounds (terminated)" { | ... | @@ -140,7 +143,7 @@ test "comptime slice-sentinel in bounds (terminated)" { |
| 140 | 143 | ||
| 141 | // vector_ConstPtrSpecialRef | 144 | // vector_ConstPtrSpecialRef |
| 142 | comptime { | 145 | comptime { |
| 143 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 146 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 144 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); | 147 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); |
| 145 | const slice = target[0..3 :'d']; | 148 | const slice = target[0..3 :'d']; |
| 146 | _ = slice; | 149 | _ = slice; |
| ... | @@ -148,7 +151,7 @@ test "comptime slice-sentinel in bounds (terminated)" { | ... | @@ -148,7 +151,7 @@ test "comptime slice-sentinel in bounds (terminated)" { |
| 148 | 151 | ||
| 149 | // cvector_ConstPtrSpecialBaseArray | 152 | // cvector_ConstPtrSpecialBaseArray |
| 150 | comptime { | 153 | comptime { |
| 151 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 154 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 152 | var target: [*c]u8 = &buf; | 155 | var target: [*c]u8 = &buf; |
| 153 | const slice = target[0..3 :'d']; | 156 | const slice = target[0..3 :'d']; |
| 154 | _ = slice; | 157 | _ = slice; |
| ... | @@ -156,7 +159,7 @@ test "comptime slice-sentinel in bounds (terminated)" { | ... | @@ -156,7 +159,7 @@ test "comptime slice-sentinel in bounds (terminated)" { |
| 156 | 159 | ||
| 157 | // cvector_ConstPtrSpecialRef | 160 | // cvector_ConstPtrSpecialRef |
| 158 | comptime { | 161 | comptime { |
| 159 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 162 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 160 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); | 163 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); |
| 161 | const slice = target[0..3 :'d']; | 164 | const slice = target[0..3 :'d']; |
| 162 | _ = slice; | 165 | _ = slice; |
| ... | @@ -164,7 +167,7 @@ test "comptime slice-sentinel in bounds (terminated)" { | ... | @@ -164,7 +167,7 @@ test "comptime slice-sentinel in bounds (terminated)" { |
| 164 | 167 | ||
| 165 | // slice | 168 | // slice |
| 166 | comptime { | 169 | comptime { |
| 167 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 170 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 168 | var target: []u8 = &buf; | 171 | var target: []u8 = &buf; |
| 169 | const slice = target[0..3 :'d']; | 172 | const slice = target[0..3 :'d']; |
| 170 | _ = slice; | 173 | _ = slice; |
| ... | @@ -174,14 +177,14 @@ test "comptime slice-sentinel in bounds (terminated)" { | ... | @@ -174,14 +177,14 @@ test "comptime slice-sentinel in bounds (terminated)" { |
| 174 | test "comptime slice-sentinel in bounds (on target sentinel)" { | 177 | test "comptime slice-sentinel in bounds (on target sentinel)" { |
| 175 | // array | 178 | // array |
| 176 | comptime { | 179 | comptime { |
| 177 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 180 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 178 | const slice = target[0..14 :0]; | 181 | const slice = target[0..14 :0]; |
| 179 | _ = slice; | 182 | _ = slice; |
| 180 | } | 183 | } |
| 181 | 184 | ||
| 182 | // ptr_array | 185 | // ptr_array |
| 183 | comptime { | 186 | comptime { |
| 184 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 187 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 185 | var target = &buf; | 188 | var target = &buf; |
| 186 | const slice = target[0..14 :0]; | 189 | const slice = target[0..14 :0]; |
| 187 | _ = slice; | 190 | _ = slice; |
| ... | @@ -189,7 +192,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { | ... | @@ -189,7 +192,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { |
| 189 | 192 | ||
| 190 | // vector_ConstPtrSpecialBaseArray | 193 | // vector_ConstPtrSpecialBaseArray |
| 191 | comptime { | 194 | comptime { |
| 192 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 195 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 193 | var target: [*]u8 = &buf; | 196 | var target: [*]u8 = &buf; |
| 194 | const slice = target[0..14 :0]; | 197 | const slice = target[0..14 :0]; |
| 195 | _ = slice; | 198 | _ = slice; |
| ... | @@ -197,7 +200,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { | ... | @@ -197,7 +200,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { |
| 197 | 200 | ||
| 198 | // vector_ConstPtrSpecialRef | 201 | // vector_ConstPtrSpecialRef |
| 199 | comptime { | 202 | comptime { |
| 200 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 203 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 201 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); | 204 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); |
| 202 | const slice = target[0..14 :0]; | 205 | const slice = target[0..14 :0]; |
| 203 | _ = slice; | 206 | _ = slice; |
| ... | @@ -205,7 +208,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { | ... | @@ -205,7 +208,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { |
| 205 | 208 | ||
| 206 | // cvector_ConstPtrSpecialBaseArray | 209 | // cvector_ConstPtrSpecialBaseArray |
| 207 | comptime { | 210 | comptime { |
| 208 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 211 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 209 | var target: [*c]u8 = &buf; | 212 | var target: [*c]u8 = &buf; |
| 210 | const slice = target[0..14 :0]; | 213 | const slice = target[0..14 :0]; |
| 211 | _ = slice; | 214 | _ = slice; |
| ... | @@ -213,7 +216,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { | ... | @@ -213,7 +216,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { |
| 213 | 216 | ||
| 214 | // cvector_ConstPtrSpecialRef | 217 | // cvector_ConstPtrSpecialRef |
| 215 | comptime { | 218 | comptime { |
| 216 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 219 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 217 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); | 220 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); |
| 218 | const slice = target[0..14 :0]; | 221 | const slice = target[0..14 :0]; |
| 219 | _ = slice; | 222 | _ = slice; |
| ... | @@ -221,7 +224,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { | ... | @@ -221,7 +224,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { |
| 221 | 224 | ||
| 222 | // slice | 225 | // slice |
| 223 | comptime { | 226 | comptime { |
| 224 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 227 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 225 | var target: []u8 = &buf; | 228 | var target: []u8 = &buf; |
| 226 | const slice = target[0..14 :0]; | 229 | const slice = target[0..14 :0]; |
| 227 | _ = slice; | 230 | _ = slice; |
test/behavior/struct.zig+1-1| ... | @@ -634,7 +634,7 @@ test "packed array 24bits" { | ... | @@ -634,7 +634,7 @@ test "packed array 24bits" { |
| 634 | try expect(@sizeOf(FooArray24Bits) == @sizeOf(u96)); | 634 | try expect(@sizeOf(FooArray24Bits) == @sizeOf(u96)); |
| 635 | } | 635 | } |
| 636 | 636 | ||
| 637 | var bytes = [_]u8{0} ** (@sizeOf(FooArray24Bits) + 1); | 637 | var bytes: [@sizeOf(FooArray24Bits) + 1]u8 = @splat(0); |
| 638 | bytes[bytes.len - 1] = 0xbb; | 638 | bytes[bytes.len - 1] = 0xbb; |
| 639 | const ptr = &std.mem.bytesAsSlice(FooArray24Bits, bytes[0 .. bytes.len - 1])[0]; | 639 | const ptr = &std.mem.bytesAsSlice(FooArray24Bits, bytes[0 .. bytes.len - 1])[0]; |
| 640 | try expect(ptr.a == 0); | 640 | try expect(ptr.a == 0); |
test/behavior/tuple.zig+1-24| ... | @@ -26,29 +26,6 @@ test "tuple concatenation" { | ... | @@ -26,29 +26,6 @@ test "tuple concatenation" { |
| 26 | try comptime S.doTheTest(); | 26 | try comptime S.doTheTest(); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | test "tuple multiplication" { | ||
| 30 | const S = struct { | ||
| 31 | fn doTheTest() !void { | ||
| 32 | { | ||
| 33 | const t = .{} ** 4; | ||
| 34 | try expect(@typeInfo(@TypeOf(t)).@"struct".fields.len == 0); | ||
| 35 | } | ||
| 36 | { | ||
| 37 | const t = .{'a'} ** 4; | ||
| 38 | try expect(@typeInfo(@TypeOf(t)).@"struct".fields.len == 4); | ||
| 39 | inline for (t) |x| try expect(x == 'a'); | ||
| 40 | } | ||
| 41 | { | ||
| 42 | const t = .{ 1, 2, 3 } ** 4; | ||
| 43 | try expect(@typeInfo(@TypeOf(t)).@"struct".fields.len == 12); | ||
| 44 | inline for (t, 0..) |x, i| try expect(x == 1 + i % 3); | ||
| 45 | } | ||
| 46 | } | ||
| 47 | }; | ||
| 48 | try S.doTheTest(); | ||
| 49 | try comptime S.doTheTest(); | ||
| 50 | } | ||
| 51 | |||
| 52 | test "more tuple concatenation" { | 29 | test "more tuple concatenation" { |
| 53 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 30 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 54 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 31 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| ... | @@ -357,7 +334,7 @@ test "tuple of struct concatenation and coercion to array" { | ... | @@ -357,7 +334,7 @@ test "tuple of struct concatenation and coercion to array" { |
| 357 | const StructWithDefault = struct { value: f32 = 42 }; | 334 | const StructWithDefault = struct { value: f32 = 42 }; |
| 358 | const SomeStruct = struct { array: [4]StructWithDefault }; | 335 | const SomeStruct = struct { array: [4]StructWithDefault }; |
| 359 | 336 | ||
| 360 | const value1 = SomeStruct{ .array = .{StructWithDefault{}} ++ [_]StructWithDefault{.{}} ** 3 }; | 337 | const value1 = SomeStruct{ .array = .{StructWithDefault{}} ++ @as([3]StructWithDefault, @splat(.{})) }; |
| 361 | const value2 = SomeStruct{ .array = .{ .{}, .{}, .{}, .{} } }; | 338 | const value2 = SomeStruct{ .array = .{ .{}, .{}, .{}, .{} } }; |
| 362 | 339 | ||
| 363 | try expectEqual(value1, value2); | 340 | try expectEqual(value1, value2); |
test/behavior/tuple_declarations.zig-6| ... | @@ -42,12 +42,6 @@ test "tuple declaration usage" { | ... | @@ -42,12 +42,6 @@ test "tuple declaration usage" { |
| 42 | try expect(t[0] == 1); | 42 | try expect(t[0] == 1); |
| 43 | try expectEqualStrings(t[1], "foo"); | 43 | try expectEqualStrings(t[1], "foo"); |
| 44 | 44 | ||
| 45 | const mul = t ** 3; | ||
| 46 | try expect(@TypeOf(mul) != T); | ||
| 47 | try expect(mul.len == 6); | ||
| 48 | try expect(mul[2] == 1); | ||
| 49 | try expectEqualStrings(mul[3], "foo"); | ||
| 50 | |||
| 51 | var t2: T = .{ 2, "bar" }; | 45 | var t2: T = .{ 2, "bar" }; |
| 52 | _ = &t2; | 46 | _ = &t2; |
| 53 | const cat = t ++ t2; | 47 | const cat = t ++ t2; |
test/behavior/undefined.zig+1-1| ... | @@ -90,7 +90,7 @@ test "reslice of undefined global var slice" { | ... | @@ -90,7 +90,7 @@ test "reslice of undefined global var slice" { |
| 90 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 90 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 91 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 91 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 92 | 92 | ||
| 93 | var stack_buf: [100]u8 = [_]u8{0} ** 100; | 93 | var stack_buf: [100]u8 = @splat(0); |
| 94 | buf = &stack_buf; | 94 | buf = &stack_buf; |
| 95 | const x = buf[0..1]; | 95 | const x = buf[0..1]; |
| 96 | try @import("std").testing.expect(x.len == 1 and x[0] == 0); | 96 | try @import("std").testing.expect(x.len == 1 and x[0] == 0); |
test/behavior/union.zig+2-2| ... | @@ -138,7 +138,7 @@ const Agg = struct { | ... | @@ -138,7 +138,7 @@ const Agg = struct { |
| 138 | }; | 138 | }; |
| 139 | 139 | ||
| 140 | const v1 = Value{ .Int = 1234 }; | 140 | const v1 = Value{ .Int = 1234 }; |
| 141 | const v2 = Value{ .Array = [_]u8{3} ** 9 }; | 141 | const v2 = Value{ .Array = @splat(3) }; |
| 142 | 142 | ||
| 143 | const err = @as(anyerror!Agg, Agg{ | 143 | const err = @as(anyerror!Agg, Agg{ |
| 144 | .val1 = v1, | 144 | .val1 = v1, |
| ... | @@ -1156,7 +1156,7 @@ test "extern union most-aligned field is smaller" { | ... | @@ -1156,7 +1156,7 @@ test "extern union most-aligned field is smaller" { |
| 1156 | }, | 1156 | }, |
| 1157 | un: [110]u8, | 1157 | un: [110]u8, |
| 1158 | }; | 1158 | }; |
| 1159 | var a: ?U = .{ .un = [_]u8{0} ** 110 }; | 1159 | var a: ?U = .{ .un = @splat(0) }; |
| 1160 | _ = &a; | 1160 | _ = &a; |
| 1161 | try expect(a != null); | 1161 | try expect(a != null); |
| 1162 | } | 1162 | } |
test/behavior/void.zig+1-1| ... | @@ -44,7 +44,7 @@ test "void optional" { | ... | @@ -44,7 +44,7 @@ test "void optional" { |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | test "void array as a local variable initializer" { | 46 | test "void array as a local variable initializer" { |
| 47 | var x = [_]void{{}} ** 1004; | 47 | var x: [1004]void = @splat({}); |
| 48 | _ = &x[0]; | 48 | _ = &x[0]; |
| 49 | _ = x[0]; | 49 | _ = x[0]; |
| 50 | } | 50 | } |
test/c/unistd.zig+3-3| ... | @@ -22,14 +22,14 @@ test "swab" { | ... | @@ -22,14 +22,14 @@ test "swab" { |
| 22 | // n < 1 | 22 | // n < 1 |
| 23 | @memset(a[0..], '\x00'); | 23 | @memset(a[0..], '\x00'); |
| 24 | c.swab("abcd", &a, 0); | 24 | c.swab("abcd", &a, 0); |
| 25 | try testing.expectEqualSlices(u8, "\x00" ** 4, &a); | 25 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0 }, &a); |
| 26 | c.swab("abcd", &a, -1); | 26 | c.swab("abcd", &a, -1); |
| 27 | try testing.expectEqualSlices(u8, "\x00" ** 4, &a); | 27 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0 }, &a); |
| 28 | 28 | ||
| 29 | // Odd n | 29 | // Odd n |
| 30 | @memset(a[0..], '\x00'); | 30 | @memset(a[0..], '\x00'); |
| 31 | c.swab("abcd", &a, 1); | 31 | c.swab("abcd", &a, 1); |
| 32 | try testing.expectEqualSlices(u8, "\x00" ** 4, &a); | 32 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0 }, &a); |
| 33 | c.swab("abcd", &a, 3); | 33 | c.swab("abcd", &a, 3); |
| 34 | try testing.expectEqualSlices(u8, "ba\x00\x00", &a); | 34 | try testing.expectEqualSlices(u8, "ba\x00\x00", &a); |
| 35 | } | 35 | } |
test/cases/compile_errors/Issue_6823_dont_allow_._to_be_followed_by_.zig deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | fn foo() void { | ||
| 2 | var sequence = "repeat".*** 10; | ||
| 3 | _ = sequence; | ||
| 4 | } | ||
| 5 | |||
| 6 | // error | ||
| 7 | // | ||
| 8 | // :2:28: error: '.*' cannot be followed by '*'; are you missing a space? | ||
test/cases/compile_errors/array_mult_with_number_type.zig deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | const exponent: f32 = 1.0; | ||
| 2 | export fn entry(base: f32) f32 { | ||
| 3 | return base ** exponent; | ||
| 4 | } | ||
| 5 | |||
| 6 | // error | ||
| 7 | // | ||
| 8 | // :3:12: error: expected indexable; found 'f32' | ||
| 9 | // :3:17: note: this operator multiplies arrays; use std.math.pow for exponentiation | ||
test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig+8-7| ... | @@ -1,13 +1,13 @@ | ... | @@ -1,13 +1,13 @@ |
| 1 | export fn foo_array() void { | 1 | export fn foo_array() void { |
| 2 | comptime { | 2 | comptime { |
| 3 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 3 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 4 | const slice = target[0..3 :0]; | 4 | const slice = target[0..3 :0]; |
| 5 | _ = slice; | 5 | _ = slice; |
| 6 | } | 6 | } |
| 7 | } | 7 | } |
| 8 | export fn foo_ptr_array() void { | 8 | export fn foo_ptr_array() void { |
| 9 | comptime { | 9 | comptime { |
| 10 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 10 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 11 | var target = &buf; | 11 | var target = &buf; |
| 12 | const slice = target[0..3 :0]; | 12 | const slice = target[0..3 :0]; |
| 13 | _ = slice; | 13 | _ = slice; |
| ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { | ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { |
| 15 | } | 15 | } |
| 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { | 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 17 | comptime { | 17 | comptime { |
| 18 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 18 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 19 | var target: [*]u8 = &buf; | 19 | var target: [*]u8 = &buf; |
| 20 | const slice = target[0..3 :0]; | 20 | const slice = target[0..3 :0]; |
| 21 | _ = slice; | 21 | _ = slice; |
| ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { | ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 23 | } | 23 | } |
| 24 | export fn foo_vector_ConstPtrSpecialRef() void { | 24 | export fn foo_vector_ConstPtrSpecialRef() void { |
| 25 | comptime { | 25 | comptime { |
| 26 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 26 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 27 | var target: [*]u8 = @ptrCast(&buf); | 27 | var target: [*]u8 = @ptrCast(&buf); |
| 28 | const slice = target[0..3 :0]; | 28 | const slice = target[0..3 :0]; |
| 29 | _ = slice; | 29 | _ = slice; |
| ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { | ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { |
| 31 | } | 31 | } |
| 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 33 | comptime { | 33 | comptime { |
| 34 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 34 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 35 | var target: [*c]u8 = &buf; | 35 | var target: [*c]u8 = &buf; |
| 36 | const slice = target[0..3 :0]; | 36 | const slice = target[0..3 :0]; |
| 37 | _ = slice; | 37 | _ = slice; |
| ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { | ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 39 | } | 39 | } |
| 40 | export fn foo_cvector_ConstPtrSpecialRef() void { | 40 | export fn foo_cvector_ConstPtrSpecialRef() void { |
| 41 | comptime { | 41 | comptime { |
| 42 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 42 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 43 | var target: [*c]u8 = @ptrCast(&buf); | 43 | var target: [*c]u8 = @ptrCast(&buf); |
| 44 | const slice = target[0..3 :0]; | 44 | const slice = target[0..3 :0]; |
| 45 | _ = slice; | 45 | _ = slice; |
| ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { | ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { |
| 47 | } | 47 | } |
| 48 | export fn foo_slice() void { | 48 | export fn foo_slice() void { |
| 49 | comptime { | 49 | comptime { |
| 50 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 50 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 51 | var target: []u8 = &buf; | 51 | var target: []u8 = &buf; |
| 52 | const slice = target[0..3 :0]; | 52 | const slice = target[0..3 :0]; |
| 53 | _ = slice; | 53 | _ = slice; |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | const undef_10_u8: [10]u8 = @splat(undefined); | ||
| 56 | 57 | ||
| 57 | // error | 58 | // error |
| 58 | // | 59 | // |
test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig+8-7| ... | @@ -1,13 +1,13 @@ | ... | @@ -1,13 +1,13 @@ |
| 1 | export fn foo_array() void { | 1 | export fn foo_array() void { |
| 2 | comptime { | 2 | comptime { |
| 3 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 3 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 4 | const slice = target[0..3 :0]; | 4 | const slice = target[0..3 :0]; |
| 5 | _ = slice; | 5 | _ = slice; |
| 6 | } | 6 | } |
| 7 | } | 7 | } |
| 8 | export fn foo_ptr_array() void { | 8 | export fn foo_ptr_array() void { |
| 9 | comptime { | 9 | comptime { |
| 10 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 10 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 11 | var target = &buf; | 11 | var target = &buf; |
| 12 | const slice = target[0..3 :0]; | 12 | const slice = target[0..3 :0]; |
| 13 | _ = slice; | 13 | _ = slice; |
| ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { | ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { |
| 15 | } | 15 | } |
| 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { | 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 17 | comptime { | 17 | comptime { |
| 18 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 18 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 19 | var target: [*]u8 = &buf; | 19 | var target: [*]u8 = &buf; |
| 20 | const slice = target[0..3 :0]; | 20 | const slice = target[0..3 :0]; |
| 21 | _ = slice; | 21 | _ = slice; |
| ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { | ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 23 | } | 23 | } |
| 24 | export fn foo_vector_ConstPtrSpecialRef() void { | 24 | export fn foo_vector_ConstPtrSpecialRef() void { |
| 25 | comptime { | 25 | comptime { |
| 26 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 26 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 27 | var target: [*]u8 = @ptrCast(&buf); | 27 | var target: [*]u8 = @ptrCast(&buf); |
| 28 | const slice = target[0..3 :0]; | 28 | const slice = target[0..3 :0]; |
| 29 | _ = slice; | 29 | _ = slice; |
| ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { | ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { |
| 31 | } | 31 | } |
| 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 33 | comptime { | 33 | comptime { |
| 34 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 34 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 35 | var target: [*c]u8 = &buf; | 35 | var target: [*c]u8 = &buf; |
| 36 | const slice = target[0..3 :0]; | 36 | const slice = target[0..3 :0]; |
| 37 | _ = slice; | 37 | _ = slice; |
| ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { | ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 39 | } | 39 | } |
| 40 | export fn foo_cvector_ConstPtrSpecialRef() void { | 40 | export fn foo_cvector_ConstPtrSpecialRef() void { |
| 41 | comptime { | 41 | comptime { |
| 42 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 42 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 43 | var target: [*c]u8 = @ptrCast(&buf); | 43 | var target: [*c]u8 = @ptrCast(&buf); |
| 44 | const slice = target[0..3 :0]; | 44 | const slice = target[0..3 :0]; |
| 45 | _ = slice; | 45 | _ = slice; |
| ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { | ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { |
| 47 | } | 47 | } |
| 48 | export fn foo_slice() void { | 48 | export fn foo_slice() void { |
| 49 | comptime { | 49 | comptime { |
| 50 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 50 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 51 | var target: []u8 = &buf; | 51 | var target: []u8 = &buf; |
| 52 | const slice = target[0..3 :0]; | 52 | const slice = target[0..3 :0]; |
| 53 | _ = slice; | 53 | _ = slice; |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | const undef_10_u8: [10]u8 = @splat(undefined); | ||
| 56 | 57 | ||
| 57 | // error | 58 | // error |
| 58 | // | 59 | // |
test/cases/compile_errors/comptime_slice-sentinel_does_not_match_target-sentinel.zig+14-13| ... | @@ -1,13 +1,13 @@ | ... | @@ -1,13 +1,13 @@ |
| 1 | export fn foo_array() void { | 1 | export fn foo_array() void { |
| 2 | comptime { | 2 | comptime { |
| 3 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 3 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 4 | const slice = target[0..14 :255]; | 4 | const slice = target[0..14 :255]; |
| 5 | _ = slice; | 5 | _ = slice; |
| 6 | } | 6 | } |
| 7 | } | 7 | } |
| 8 | export fn foo_ptr_array() void { | 8 | export fn foo_ptr_array() void { |
| 9 | comptime { | 9 | comptime { |
| 10 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 10 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 11 | var target = &buf; | 11 | var target = &buf; |
| 12 | const slice = target[0..14 :255]; | 12 | const slice = target[0..14 :255]; |
| 13 | _ = slice; | 13 | _ = slice; |
| ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { | ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { |
| 15 | } | 15 | } |
| 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { | 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 17 | comptime { | 17 | comptime { |
| 18 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 18 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 19 | var target: [*]u8 = &buf; | 19 | var target: [*]u8 = &buf; |
| 20 | const slice = target[0..14 :255]; | 20 | const slice = target[0..14 :255]; |
| 21 | _ = slice; | 21 | _ = slice; |
| ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { | ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 23 | } | 23 | } |
| 24 | export fn foo_vector_ConstPtrSpecialRef() void { | 24 | export fn foo_vector_ConstPtrSpecialRef() void { |
| 25 | comptime { | 25 | comptime { |
| 26 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 26 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 27 | var target: [*]u8 = @ptrCast(&buf); | 27 | var target: [*]u8 = @ptrCast(&buf); |
| 28 | const slice = target[0..14 :255]; | 28 | const slice = target[0..14 :255]; |
| 29 | _ = slice; | 29 | _ = slice; |
| ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { | ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { |
| 31 | } | 31 | } |
| 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 33 | comptime { | 33 | comptime { |
| 34 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 34 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 35 | var target: [*c]u8 = &buf; | 35 | var target: [*c]u8 = &buf; |
| 36 | const slice = target[0..14 :255]; | 36 | const slice = target[0..14 :255]; |
| 37 | _ = slice; | 37 | _ = slice; |
| ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { | ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 39 | } | 39 | } |
| 40 | export fn foo_cvector_ConstPtrSpecialRef() void { | 40 | export fn foo_cvector_ConstPtrSpecialRef() void { |
| 41 | comptime { | 41 | comptime { |
| 42 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 42 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 43 | var target: [*c]u8 = @ptrCast(&buf); | 43 | var target: [*c]u8 = @ptrCast(&buf); |
| 44 | const slice = target[0..14 :255]; | 44 | const slice = target[0..14 :255]; |
| 45 | _ = slice; | 45 | _ = slice; |
| ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { | ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { |
| 47 | } | 47 | } |
| 48 | export fn foo_slice() void { | 48 | export fn foo_slice() void { |
| 49 | comptime { | 49 | comptime { |
| 50 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 50 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 51 | var target: []u8 = &buf; | 51 | var target: []u8 = &buf; |
| 52 | const slice = target[0..14 :255]; | 52 | const slice = target[0..14 :255]; |
| 53 | _ = slice; | 53 | _ = slice; |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | const undef_10_u8: [10]u8 = @splat(undefined); | ||
| 56 | export fn undefined_slice() void { | 57 | export fn undefined_slice() void { |
| 57 | const arr: [100]u16 = undefined; | 58 | const arr: [100]u16 = undefined; |
| 58 | const slice = arr[0..12 :0]; | 59 | const slice = arr[0..12 :0]; |
| ... | @@ -85,9 +86,9 @@ export fn typeName_slice() void { | ... | @@ -85,9 +86,9 @@ export fn typeName_slice() void { |
| 85 | // :44:29: note: expected '255', found '0' | 86 | // :44:29: note: expected '255', found '0' |
| 86 | // :52:29: error: value in memory does not match slice sentinel | 87 | // :52:29: error: value in memory does not match slice sentinel |
| 87 | // :52:29: note: expected '255', found '0' | 88 | // :52:29: note: expected '255', found '0' |
| 88 | // :58:22: error: value in memory does not match slice sentinel | 89 | // :59:22: error: value in memory does not match slice sentinel |
| 89 | // :58:22: note: expected '0', found 'undefined' | 90 | // :59:22: note: expected '0', found 'undefined' |
| 90 | // :63:22: error: value in memory does not match slice sentinel | 91 | // :64:22: error: value in memory does not match slice sentinel |
| 91 | // :63:22: note: expected '12', found '98' | 92 | // :64:22: note: expected '12', found '98' |
| 92 | // :68:22: error: value in memory does not match slice sentinel | 93 | // :69:22: error: value in memory does not match slice sentinel |
| 93 | // :68:22: note: expected '0', found '105' | 94 | // :69:22: note: expected '0', found '105' |
test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_terminated.zig+8-7| ... | @@ -1,13 +1,13 @@ | ... | @@ -1,13 +1,13 @@ |
| 1 | export fn foo_array() void { | 1 | export fn foo_array() void { |
| 2 | comptime { | 2 | comptime { |
| 3 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 3 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 4 | const slice = target[0..15 :1]; | 4 | const slice = target[0..15 :1]; |
| 5 | _ = slice; | 5 | _ = slice; |
| 6 | } | 6 | } |
| 7 | } | 7 | } |
| 8 | export fn foo_ptr_array() void { | 8 | export fn foo_ptr_array() void { |
| 9 | comptime { | 9 | comptime { |
| 10 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 10 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 11 | var target = &buf; | 11 | var target = &buf; |
| 12 | const slice = target[0..15 :0]; | 12 | const slice = target[0..15 :0]; |
| 13 | _ = slice; | 13 | _ = slice; |
| ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { | ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { |
| 15 | } | 15 | } |
| 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { | 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 17 | comptime { | 17 | comptime { |
| 18 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 18 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 19 | var target: [*]u8 = &buf; | 19 | var target: [*]u8 = &buf; |
| 20 | const slice = target[0..15 :0]; | 20 | const slice = target[0..15 :0]; |
| 21 | _ = slice; | 21 | _ = slice; |
| ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { | ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 23 | } | 23 | } |
| 24 | export fn foo_vector_ConstPtrSpecialRef() void { | 24 | export fn foo_vector_ConstPtrSpecialRef() void { |
| 25 | comptime { | 25 | comptime { |
| 26 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 26 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 27 | var target: [*]u8 = @ptrCast(&buf); | 27 | var target: [*]u8 = @ptrCast(&buf); |
| 28 | const slice = target[0..15 :0]; | 28 | const slice = target[0..15 :0]; |
| 29 | _ = slice; | 29 | _ = slice; |
| ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { | ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { |
| 31 | } | 31 | } |
| 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 33 | comptime { | 33 | comptime { |
| 34 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 34 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 35 | var target: [*c]u8 = &buf; | 35 | var target: [*c]u8 = &buf; |
| 36 | const slice = target[0..15 :0]; | 36 | const slice = target[0..15 :0]; |
| 37 | _ = slice; | 37 | _ = slice; |
| ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { | ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 39 | } | 39 | } |
| 40 | export fn foo_cvector_ConstPtrSpecialRef() void { | 40 | export fn foo_cvector_ConstPtrSpecialRef() void { |
| 41 | comptime { | 41 | comptime { |
| 42 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 42 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 43 | var target: [*c]u8 = @ptrCast(&buf); | 43 | var target: [*c]u8 = @ptrCast(&buf); |
| 44 | const slice = target[0..15 :0]; | 44 | const slice = target[0..15 :0]; |
| 45 | _ = slice; | 45 | _ = slice; |
| ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { | ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { |
| 47 | } | 47 | } |
| 48 | export fn foo_slice() void { | 48 | export fn foo_slice() void { |
| 49 | comptime { | 49 | comptime { |
| 50 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 50 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 51 | var target: []u8 = &buf; | 51 | var target: []u8 = &buf; |
| 52 | const slice = target[0..15 :0]; | 52 | const slice = target[0..15 :0]; |
| 53 | _ = slice; | 53 | _ = slice; |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | const undef_10_u8: [10]u8 = @splat(undefined); | ||
| 56 | 57 | ||
| 57 | // error | 58 | // error |
| 58 | // | 59 | // |
test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig+8-7| ... | @@ -1,13 +1,13 @@ | ... | @@ -1,13 +1,13 @@ |
| 1 | export fn foo_array() void { | 1 | export fn foo_array() void { |
| 2 | comptime { | 2 | comptime { |
| 3 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 3 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 4 | const slice = target[0..14 :0]; | 4 | const slice = target[0..14 :0]; |
| 5 | _ = slice; | 5 | _ = slice; |
| 6 | } | 6 | } |
| 7 | } | 7 | } |
| 8 | export fn foo_ptr_array() void { | 8 | export fn foo_ptr_array() void { |
| 9 | comptime { | 9 | comptime { |
| 10 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 10 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 11 | var target = &buf; | 11 | var target = &buf; |
| 12 | const slice = target[0..14 :0]; | 12 | const slice = target[0..14 :0]; |
| 13 | _ = slice; | 13 | _ = slice; |
| ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { | ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { |
| 15 | } | 15 | } |
| 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { | 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 17 | comptime { | 17 | comptime { |
| 18 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 18 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 19 | var target: [*]u8 = &buf; | 19 | var target: [*]u8 = &buf; |
| 20 | const slice = target[0..14 :0]; | 20 | const slice = target[0..14 :0]; |
| 21 | _ = slice; | 21 | _ = slice; |
| ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { | ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 23 | } | 23 | } |
| 24 | export fn foo_vector_ConstPtrSpecialRef() void { | 24 | export fn foo_vector_ConstPtrSpecialRef() void { |
| 25 | comptime { | 25 | comptime { |
| 26 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 26 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 27 | var target: [*]u8 = @ptrCast(&buf); | 27 | var target: [*]u8 = @ptrCast(&buf); |
| 28 | const slice = target[0..14 :0]; | 28 | const slice = target[0..14 :0]; |
| 29 | _ = slice; | 29 | _ = slice; |
| ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { | ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { |
| 31 | } | 31 | } |
| 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 33 | comptime { | 33 | comptime { |
| 34 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 34 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 35 | var target: [*c]u8 = &buf; | 35 | var target: [*c]u8 = &buf; |
| 36 | const slice = target[0..14 :0]; | 36 | const slice = target[0..14 :0]; |
| 37 | _ = slice; | 37 | _ = slice; |
| ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { | ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 39 | } | 39 | } |
| 40 | export fn foo_cvector_ConstPtrSpecialRef() void { | 40 | export fn foo_cvector_ConstPtrSpecialRef() void { |
| 41 | comptime { | 41 | comptime { |
| 42 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 42 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 43 | var target: [*c]u8 = @ptrCast(&buf); | 43 | var target: [*c]u8 = @ptrCast(&buf); |
| 44 | const slice = target[0..14 :0]; | 44 | const slice = target[0..14 :0]; |
| 45 | _ = slice; | 45 | _ = slice; |
| ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { | ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { |
| 47 | } | 47 | } |
| 48 | export fn foo_slice() void { | 48 | export fn foo_slice() void { |
| 49 | comptime { | 49 | comptime { |
| 50 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 50 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 51 | var target: []u8 = &buf; | 51 | var target: []u8 = &buf; |
| 52 | const slice = target[0..14 :0]; | 52 | const slice = target[0..14 :0]; |
| 53 | _ = slice; | 53 | _ = slice; |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | const undef_10_u8: [10]u8 = @splat(undefined); | ||
| 56 | 57 | ||
| 57 | // error | 58 | // error |
| 58 | // | 59 | // |
test/cases/compile_errors/dereference_bad_pointer_via_array_mul.zig deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | const A = struct {}; | ||
| 2 | const B = struct {}; | ||
| 3 | comptime { | ||
| 4 | const val: [1]A = .{.{}}; | ||
| 5 | const ptr: *const [1]B = @ptrCast(&val); | ||
| 6 | _ = ptr ** 2; | ||
| 7 | } | ||
| 8 | |||
| 9 | // error | ||
| 10 | // | ||
| 11 | // :6:9: error: comptime dereference requires '[1]tmp.B' to have a well-defined layout | ||
test/cases/compile_errors/function_call_assigned_to_incorrect_type.zig+1-1| ... | @@ -3,7 +3,7 @@ export fn entry() void { | ... | @@ -3,7 +3,7 @@ export fn entry() void { |
| 3 | arr = concat(); | 3 | arr = concat(); |
| 4 | } | 4 | } |
| 5 | fn concat() [16]f32 { | 5 | fn concat() [16]f32 { |
| 6 | return [1]f32{0} ** 16; | 6 | return @splat(0.0); |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | // error | 9 | // error |
test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | export fn foo() void { | 1 | export fn foo() void { |
| 2 | const bytes align(@alignOf([]const u8)) = [1]u8{0xfa} ** 16; | 2 | const bytes: [16]u8 align(@alignOf([]const u8)) = @splat(0xFA); |
| 3 | _ = @as(*const []const u8, @ptrCast(&bytes)).*; | 3 | _ = @as(*const []const u8, @ptrCast(&bytes)).*; |
| 4 | } | 4 | } |
| 5 | 5 |
test/cases/safety/memcpy_alias.zig+1-1| ... | @@ -8,7 +8,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -8,7 +8,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 8 | std.process.exit(1); | 8 | std.process.exit(1); |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var buffer = [2]u8{ 1, 2 } ** 5; | 11 | var buffer: [10]u8 = .{ 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 }; |
| 12 | var len: usize = 5; | 12 | var len: usize = 5; |
| 13 | _ = &len; | 13 | _ = &len; |
| 14 | @memcpy(buffer[0..len], buffer[4 .. 4 + len]); | 14 | @memcpy(buffer[0..len], buffer[4 .. 4 + len]); |
test/cases/safety/memcpy_len_mismatch.zig+1-1| ... | @@ -8,7 +8,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -8,7 +8,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 8 | std.process.exit(1); | 8 | std.process.exit(1); |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var buffer = [2]u8{ 1, 2 } ** 5; | 11 | var buffer: [10]u8 = .{ 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 }; |
| 12 | var len: usize = 5; | 12 | var len: usize = 5; |
| 13 | _ = &len; | 13 | _ = &len; |
| 14 | @memcpy(buffer[0..len], buffer[len .. len + 4]); | 14 | @memcpy(buffer[0..len], buffer[len .. len + 4]); |
test/cases/safety/memmove_len_mismatch.zig+1-1| ... | @@ -8,7 +8,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -8,7 +8,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 8 | std.process.exit(1); | 8 | std.process.exit(1); |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var buffer = [2]u8{ 1, 2 } ** 5; | 11 | var buffer: [10]u8 = .{ 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 }; |
| 12 | var len: usize = 5; | 12 | var len: usize = 5; |
| 13 | _ = &len; | 13 | _ = &len; |
| 14 | @memmove(buffer[0..len], buffer[len .. len + 4]); | 14 | @memmove(buffer[0..len], buffer[len .. len + 4]); |
tools/fetch_them_macos_headers.zig+1-1| ... | @@ -237,7 +237,7 @@ const Version = struct { | ... | @@ -237,7 +237,7 @@ const Version = struct { |
| 237 | patch: u8, | 237 | patch: u8, |
| 238 | 238 | ||
| 239 | fn parse(raw: []const u8) ?Version { | 239 | fn parse(raw: []const u8) ?Version { |
| 240 | var parsed: [3]u16 = [_]u16{0} ** 3; | 240 | var parsed: [3]u16 = @splat(0); |
| 241 | var count: usize = 0; | 241 | var count: usize = 0; |
| 242 | var it = std.mem.splitAny(u8, raw, "."); | 242 | var it = std.mem.splitAny(u8, raw, "."); |
| 243 | while (it.next()) |comp| { | 243 | while (it.next()) |comp| { |
tools/gen_spirv_spec.zig+1-1| ... | @@ -732,7 +732,7 @@ fn renderBitEnum( | ... | @@ -732,7 +732,7 @@ fn renderBitEnum( |
| 732 | ) !void { | 732 | ) !void { |
| 733 | try writer.print("pub const {f} = packed struct {{\n", .{std.zig.fmtId(enumeration.kind)}); | 733 | try writer.print("pub const {f} = packed struct {{\n", .{std.zig.fmtId(enumeration.kind)}); |
| 734 | 734 | ||
| 735 | var flags_by_bitpos = [_]?usize{null} ** 32; | 735 | var flags_by_bitpos: [32]?usize = @splat(null); |
| 736 | const enumerants = enumeration.enumerants orelse return error.InvalidRegistry; | 736 | const enumerants = enumeration.enumerants orelse return error.InvalidRegistry; |
| 737 | 737 | ||
| 738 | var aliases = std.array_list.Managed(struct { flag: usize, alias: u5 }).init(arena); | 738 | var aliases = std.array_list.Managed(struct { flag: usize, alias: u5 }).init(arena); |
tools/gen_stubs.zig+3-3| ... | @@ -702,12 +702,12 @@ fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: std.builtin.End | ... | @@ -702,12 +702,12 @@ fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: std.builtin.End |
| 702 | } | 702 | } |
| 703 | } else { | 703 | } else { |
| 704 | gop.value_ptr.* = .{ | 704 | gop.value_ptr.* = .{ |
| 705 | .present = [1]bool{false} ** arches.len, | 705 | .present = @splat(false), |
| 706 | .section = section_index_map[this_section], | 706 | .section = section_index_map[this_section], |
| 707 | .ty = ty, | 707 | .ty = ty, |
| 708 | .binding = [1]u4{0} ** arches.len, | 708 | .binding = @splat(0), |
| 709 | .visib = visib, | 709 | .visib = visib, |
| 710 | .size = [1]u64{0} ** arches.len, | 710 | .size = @splat(0), |
| 711 | }; | 711 | }; |
| 712 | } | 712 | } |
| 713 | gop.value_ptr.present[archIndex(parse.arch)] = true; | 713 | gop.value_ptr.present[archIndex(parse.arch)] = true; |
tools/generate_JSONTestSuite.zig+24-11| ... | @@ -4,15 +4,15 @@ const std = @import("std"); | ... | @@ -4,15 +4,15 @@ const std = @import("std"); |
| 4 | const Io = std.Io; | 4 | const Io = std.Io; |
| 5 | 5 | ||
| 6 | pub fn main(init: std.process.Init) !void { | 6 | pub fn main(init: std.process.Init) !void { |
| 7 | const allocator = init.gpa; | 7 | const allocator = init.arena.allocator(); |
| 8 | const io = init.io; | 8 | const io = init.io; |
| 9 | 9 | ||
| 10 | var stdout_buffer: [2000]u8 = undefined; | 10 | var stdout_buffer: [2000]u8 = undefined; |
| 11 | var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer); | 11 | var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer); |
| 12 | const output = &stdout_writer.interface; | 12 | const output = &stdout_writer.interface; |
| 13 | try output.writeAll( | 13 | try output.writeAll( |
| 14 | \\// This file was generated by _generate_JSONTestSuite.zig | 14 | \\//! This file was generated by _generate_JSONTestSuite.zig |
| 15 | \\// These test cases are sourced from: https://github.com/nst/JSONTestSuite | 15 | \\//! These test cases are sourced from: https://github.com/nst/JSONTestSuite |
| 16 | \\const ok = @import("./test.zig").ok; | 16 | \\const ok = @import("./test.zig").ok; |
| 17 | \\const err = @import("./test.zig").err; | 17 | \\const err = @import("./test.zig").err; |
| 18 | \\const any = @import("./test.zig").any; | 18 | \\const any = @import("./test.zig").any; |
| ... | @@ -33,7 +33,7 @@ pub fn main(init: std.process.Init) !void { | ... | @@ -33,7 +33,7 @@ pub fn main(init: std.process.Init) !void { |
| 33 | }).lessThan); | 33 | }).lessThan); |
| 34 | 34 | ||
| 35 | for (names.items) |name| { | 35 | for (names.items) |name| { |
| 36 | const contents = try Io.Dir.cwd().readFileAlloc(io, name, allocator, .limited(250001)); | 36 | const contents = try Io.Dir.cwd().readFileAlloc(io, name, allocator, .limited(300000)); |
| 37 | try output.writeAll("test "); | 37 | try output.writeAll("test "); |
| 38 | try writeString(output, name); | 38 | try writeString(output, name); |
| 39 | try output.writeAll(" {\n try "); | 39 | try output.writeAll(" {\n try "); |
| ... | @@ -51,21 +51,34 @@ pub fn main(init: std.process.Init) !void { | ... | @@ -51,21 +51,34 @@ pub fn main(init: std.process.Init) !void { |
| 51 | try output.flush(); | 51 | try output.flush(); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | const i_structure_500_nested_arrays = "[" ** 500 ++ "]" ** 500; | 54 | const i_structure_500_nested_arrays = &(@as([500]u8, @splat('[')) ++ @as([500]u8, @splat(']'))); |
| 55 | const n_structure_100000_opening_arrays = "[" ** 100000; | 55 | const n_structure_100000_opening_arrays: *const [100000]u8 = &@splat('['); |
| 56 | const n_structure_open_array_object = "[{\"\":" ** 50000 ++ "\n"; | 56 | const n_structure_open_array_object = str: { |
| 57 | const part = "[{\"\":"; | ||
| 58 | const buf: [50000][part.len]u8 = @splat(part.*); | ||
| 59 | const s: []const u8 = @ptrCast(&buf); | ||
| 60 | break :str s ++ "\n"; | ||
| 61 | }; | ||
| 57 | 62 | ||
| 58 | fn writeString(writer: anytype, s: []const u8) !void { | 63 | fn writeString(writer: anytype, s: []const u8) !void { |
| 59 | if (s.len > 200) { | 64 | if (s.len > 200) { |
| 60 | // There are a few of these we can compress with Zig expressions. | 65 | // There are a few of these we can compress with Zig expressions. |
| 61 | if (std.mem.eql(u8, s, i_structure_500_nested_arrays)) { | 66 | if (std.mem.eql(u8, s, i_structure_500_nested_arrays)) { |
| 62 | return writer.writeAll("\"[\" ** 500 ++ \"]\" ** 500"); | 67 | return writer.writeAll("&@as([500]u8, @splat('[')) ++ &@as([500]u8, @splat(']'))"); |
| 63 | } else if (std.mem.eql(u8, s, n_structure_100000_opening_arrays)) { | 68 | } else if (std.mem.eql(u8, s, n_structure_100000_opening_arrays)) { |
| 64 | return writer.writeAll("\"[\" ** 100000"); | 69 | return writer.writeAll("&@as([100000]u8, @splat('['))"); |
| 65 | } else if (std.mem.eql(u8, s, n_structure_open_array_object)) { | 70 | } else if (std.mem.eql(u8, s, n_structure_open_array_object)) { |
| 66 | return writer.writeAll("\"[{\\\"\\\":\" ** 50000 ++ \"\\n\""); | 71 | return writer.writeAll( |
| 72 | \\str: { | ||
| 73 | \\ const part = "[{\"\":"; | ||
| 74 | \\ const buf: [50000][part.len]u8 = @splat(part.*); | ||
| 75 | \\ const s: []const u8 = @ptrCast(&buf); | ||
| 76 | \\ break :str s ++ "\n"; | ||
| 77 | \\ } | ||
| 78 | ); | ||
| 79 | } else { | ||
| 80 | @panic("unhandled long string literal"); | ||
| 67 | } | 81 | } |
| 68 | unreachable; | ||
| 69 | } | 82 | } |
| 70 | try writer.writeByte('"'); | 83 | try writer.writeByte('"'); |
| 71 | for (s) |b| { | 84 | for (s) |b| { |