authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-04-29 19:30:34+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-04-30 08:57:51+01:00
logfdac89d6cd65fa19bd5c6d381b62d980d97e5852
treea8c8ac71faef3ae20f87ad49cda692679cbb97db
parent57634b7809d07c8a07a015bec55829937d5795e1
signaturelock-open Commit is signed but in an unrecognized format.

remove uses of array multiplication

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 {
15571557 const name = try fmt.allocPrint(arena, " -D{s}=[{t}]", .{ option.name, option.type_id });
15581558 try w.print("{s:<30} {s}\n", .{ name, option.description });
15591559 if (option.enum_options) |enum_options| {
1560 const padding = " " ** 33;
1560 const padding: [33]u8 = @splat(' ');
15611561 try w.writeAll(padding ++ "Supported Values:\n");
15621562 for (enum_options) |enum_option| {
15631563 try w.print(padding ++ " {s}\n", .{enum_option});
lib/compiler/resinator/cvtres.zig+4-4
......@@ -321,7 +321,7 @@ pub fn writeCoff(
321321 .checksum = 0,
322322 .number = 0,
323323 .selection = .NONE,
324 .unused = .{0} ** 3,
324 .unused = @splat(0),
325325 });
326326
327327 try writeSymbol(writer, .{
......@@ -342,7 +342,7 @@ pub fn writeCoff(
342342 .checksum = 0,
343343 .number = 0,
344344 .selection = .NONE,
345 .unused = .{0} ** 3,
345 .unused = @splat(0),
346346 });
347347
348348 for (resource_symbols) |resource_symbol| {
......@@ -353,11 +353,11 @@ pub fn writeCoff(
353353 const name_bytes: [8]u8 = name_bytes: {
354354 if (external_symbol_name.len > 8) {
355355 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);
357357 std.mem.writeInt(u32, bytes[4..8], string_table_offset, .little);
358358 break :name_bytes bytes;
359359 } else {
360 var symbol_shortname = [_]u8{0} ** 8;
360 var symbol_shortname: [8]u8 = @splat(0);
361361 @memcpy(symbol_shortname[0..external_symbol_name.len], external_symbol_name);
362362 break :name_bytes symbol_shortname;
363363 }
lib/compiler/resinator/ico.zig+4-4
......@@ -183,7 +183,7 @@ pub const Entry = struct {
183183};
184184
185185test "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));
187187 var fbs: std.Io.Reader = .fixed(data);
188188 const icon = try read(std.testing.allocator, &fbs, data.len);
189189 defer icon.deinit();
......@@ -196,19 +196,19 @@ test "icon too many images" {
196196 // Note that with verifying that all data sizes are within the file bounds and >= 16,
197197 // it's not possible to hit EOF when looking for more RESDIR structures, since they are
198198 // 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));
200200 var fbs: std.Io.Reader = .fixed(data);
201201 try std.testing.expectError(error.ImpossibleDataSize, read(std.testing.allocator, &fbs, data.len));
202202}
203203
204204test "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));
206206 var fbs: std.Io.Reader = .fixed(data);
207207 try std.testing.expectError(error.ImpossibleDataSize, read(std.testing.allocator, &fbs, data.len));
208208}
209209
210210test "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));
212212 var fbs: std.Io.Reader = .fixed(data);
213213 try std.testing.expectError(error.ImpossibleDataSize, read(std.testing.allocator, &fbs, data.len));
214214}
lib/compiler/resinator/parse.zig+2-2
......@@ -138,8 +138,8 @@ pub const Parser = struct {
138138 var optional_statements: std.ArrayList(*Node) = .empty;
139139
140140 const num_statement_types = @typeInfo(rc.OptionalStatements).@"enum".fields.len;
141 var statement_type_has_duplicates = [_]bool{false} ** num_statement_types;
142 var last_statement_per_type = [_]?*Node{null} ** num_statement_types;
141 var statement_type_has_duplicates: [num_statement_types]bool = @splat(false);
142 var last_statement_per_type: [num_statement_types]?*Node = @splat(null);
143143
144144 while (true) {
145145 const lookahead_token = try self.lookaheadToken(.normal);
lib/compiler/resinator/res.zig+1-1
......@@ -1068,7 +1068,7 @@ pub const FixedFileInfo = struct {
10681068 pub const key = std.unicode.utf8ToUtf16LeStringLiteral("VS_VERSION_INFO");
10691069
10701070 pub const Version = struct {
1071 parts: [4]u16 = [_]u16{0} ** 4,
1071 parts: [4]u16 = @splat(0),
10721072
10731073 pub fn mostSignificantCombinedParts(self: Version) u32 {
10741074 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 {
242242
243243 /// array_type{}
244244 empty_array,
245 /// [1]type{val} ** count
245 /// @as([count]type, @splat(val))
246246 array_filler,
247247
248248 /// comptime { if (!(lhs)) @compileError(rhs); }
......@@ -1976,28 +1976,18 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
19761976 .array_filler => {
19771977 const payload = node.castTag(.array_filler).?.data;
19781978
1979 const type_expr = try renderArrayType(c, 1, payload.type);
1980 const l_brace = try c.addToken(.l_brace, "{");
1981 const val = try renderNode(c, payload.filler);
1982 _ = try c.addToken(.r_brace, "}");
1979 const as_tok = try c.addToken(.builtin, "@as");
1980 _ = try c.addToken(.l_paren, "(");
1981 const type_node = try renderArrayType(c, payload.count, payload.type);
1982 _ = try c.addToken(.comma, ",");
1983 const splat_node = try renderBuiltinCall(c, "@splat", &.{payload.filler});
1984 _ = try c.addToken(.r_paren, ")");
19831985
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 });
19911986 return c.addNode(.{
1992 .tag = .array_cat,
1993 .main_token = try c.addToken(.asterisk_asterisk, "**"),
1994 .data = .{ .node_and_node = .{
1995 init,
1996 try c.addNode(.{
1997 .tag = .number_literal,
1998 .main_token = try c.addTokenFmt(.number_literal, "{d}", .{payload.count}),
1999 .data = undefined,
2000 }),
1987 .tag = .builtin_call_two,
1988 .main_token = as_tok,
1989 .data = .{ .opt_node_and_opt_node = .{
1990 .fromOptional(type_node), .fromOptional(splat_node),
20011991 } },
20021992 });
20031993 },
lib/compiler_rt/atomics.zig+1-1
......@@ -94,7 +94,7 @@ const SpinlockTable = struct {
9494 }
9595 };
9696
97 list: [max_spinlocks]Spinlock = [_]Spinlock{.{}} ** max_spinlocks,
97 list: [max_spinlocks]Spinlock = @splat(.{}),
9898
9999 // The spinlock table behaves as a really simple hash table, mapping
100100 // 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 {
4444
4545// TODO: Initialize the canary with random data
4646var __stack_chk_guard: usize = blk: {
47 var buf = [1]u8{0} ** @sizeOf(usize);
47 var buf: [@sizeOf(usize)]u8 = @splat(0);
4848 buf[@sizeOf(usize) - 1] = 255;
4949 buf[@sizeOf(usize) - 2] = '\n';
50 break :blk @as(usize, @bitCast(buf));
50 break :blk @bitCast(buf);
5151};
5252
5353fn __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(
63296329 const MIN_SIZE = @sizeOf(windows.MOUNTMGR_MOUNT_POINT) + windows.MAX_PATH;
63306330 // We initialize the input buffer to all zeros for convenience since
63316331 // `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);
63336333 var output_buf: [MIN_SIZE * 4]u8 align(@alignOf(windows.MOUNTMGR_MOUNT_POINTS)) = undefined;
63346334
63356335 // This surprising path is a filesystem path to the mount manager on Windows.
......@@ -6409,7 +6409,7 @@ pub fn GetFinalPathNameByHandle(
64096409
64106410 // 49 is the maximum length accepted by mountmgrIsVolumeName
64116411 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);
64136413 // Note: If the path exceeds MAX_PATH, the Disk Management GUI doesn't accept the full path,
64146414 // and instead if must be specified using a shortened form (e.g. C:\FOO~1\BAR~1\<...>).
64156415 // 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 {
89148914 // we can use this smaller buffer and just return false on any error from
89158915 // NtQueryInformationFile.
89168916 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);
89188918
89198919 var io_status_block: windows.IO_STATUS_BLOCK = undefined;
89208920 const syscall: Syscall = try .start();
......@@ -16191,7 +16191,7 @@ fn windowsCreateProcessPathExt(
1619116191 var io_status: windows.IO_STATUS_BLOCK = undefined;
1619216192
1619316193 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);
1619516195 var any_pathext_seen = false;
1619616196 var unappended_exists = false;
1619716197
lib/std/Io/Writer.zig+1-1
......@@ -781,7 +781,7 @@ test splatByteAll {
781781 defer aw.deinit();
782782
783783 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());
785785}
786786
787787pub 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 {
7676 try validate("a-b.com");
7777 try validate("a.b.c.d.e.f.g");
7878 try validate("127.0.0.1"); // Also a valid hostname
79 try validate("a" ** 63 ++ ".com"); // Label exactly 63 chars (valid)
80 try validate("a." ** 127 ++ "a"); // Total length 255 (valid)
81 try validate("a." ** 127 ++ "a."); // Total length 255 + trailing dot (valid)
79
80 const many_a: [63]u8 = @splat('a');
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)
8287
8388 // Invalid hostnames
8489 try std.testing.expectError(error.InvalidHostName, validate(""));
......@@ -92,9 +97,9 @@ test validate {
9297 try std.testing.expectError(error.InvalidHostName, validate("host_name.com"));
9398 try std.testing.expectError(error.InvalidHostName, validate("."));
9499 try std.testing.expectError(error.InvalidHostName, validate(".."));
95 try std.testing.expectError(error.InvalidHostName, validate("a" ** 64 ++ ".com")); // Label length 64 (too long)
96 try std.testing.expectError(error.NameTooLong, validate("a." ** 127 ++ "ab")); // Total length 256 (too long)
97 try std.testing.expectError(error.NameTooLong, validate("a." ** 127 ++ "ab.")); // Total length 256 + trailing dot (too long)
100 try std.testing.expectError(error.InvalidHostName, validate(&many_a ++ "a.com")); // Label length 64 (too long)
101 try std.testing.expectError(error.NameTooLong, validate(many_a_dot ++ "ab")); // Total length 256 (too long)
102 try std.testing.expectError(error.NameTooLong, validate(many_a_dot ++ "ab.")); // Total length 256 + trailing dot (too long)
98103}
99104
100105pub 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;
1414state: State,
1515offset: usize,
1616
17const nonce = [_]u8{0} ** Cipher.nonce_length;
17const nonce: [Cipher.nonce_length]u8 = @splat(0);
1818
1919pub const secret_seed_length = Cipher.key_length;
2020
......@@ -38,7 +38,7 @@ pub fn addEntropy(self: *Self, bytes: []const u8) void {
3838 );
3939 }
4040 if (i < bytes.len) {
41 var k = [_]u8{0} ** Cipher.key_length;
41 var k: [Cipher.key_length]u8 = @splat(0);
4242 const src = bytes[i..];
4343 @memcpy(k[0..src.len], src);
4444 Cipher.xor(
lib/std/Random/benchmark.zig+2-2
......@@ -55,12 +55,12 @@ const csprngs = [_]Rng{
5555 Rng{
5656 .ty = Random.Ascon,
5757 .name = "ascon",
58 .init_u8s = &[_]u8{0} ** 32,
58 .init_u8s = &@as([32]u8, @splat(0)),
5959 },
6060 Rng{
6161 .ty = Random.ChaCha,
6262 .name = "chacha",
63 .init_u8s = &[_]u8{0} ** 32,
63 .init_u8s = &@as([32]u8, @splat(0)),
6464 },
6565};
6666
lib/std/Random/test.zig+4-4
......@@ -383,8 +383,8 @@ test "Random shuffle" {
383383 var prng = DefaultPrng.init(0);
384384 const random = prng.random();
385385
386 var seq = [_]u8{ 0, 1, 2, 3, 4 };
387 var seen = [_]bool{false} ** 5;
386 var seq: [5]u8 = .{ 0, 1, 2, 3, 4 };
387 var seen: [5]bool = @splat(false);
388388
389389 var i: usize = 0;
390390 while (i < 1000) : (i += 1) {
......@@ -421,8 +421,8 @@ fn testRange(r: Random, start: i8, end: i8) !void {
421421 try testRangeBias(r, start, end, false);
422422}
423423fn testRangeBias(r: Random, start: i8, end: i8, biased: bool) !void {
424 const count = @as(usize, @intCast(@as(i32, end) - @as(i32, start)));
425 var values_buffer = [_]bool{false} ** 0x100;
424 const count: usize = @intCast(@as(i32, end) - @as(i32, start));
425 var values_buffer: [0x100]bool = @splat(false);
426426 const values = values_buffer[0..count];
427427 var i: usize = 0;
428428 while (i < count) {
lib/std/Thread.zig+2-2
......@@ -1574,9 +1574,9 @@ const LinuxThreadImpl = struct {
15741574};
15751575
15761576fn testThreadName(io: Io, thread: *Thread) !void {
1577 const testCases = &[_][]const u8{
1577 const testCases: []const []const u8 = &.{
15781578 "mythread",
1579 "b" ** max_name_len,
1579 &@as([max_name_len]u8, @splat('b')),
15801580 };
15811581
15821582 inline for (testCases) |tc| {
lib/std/base64.zig+5-5
......@@ -86,7 +86,7 @@ pub const Base64Encoder = struct {
8686 /// A bunch of assertions, then simply pass the data right through.
8787 pub fn init(alphabet_chars: [64]u8, pad_char: ?u8) Base64Encoder {
8888 assert(alphabet_chars.len == 64);
89 var char_in_alphabet = [_]bool{false} ** 256;
89 var char_in_alphabet: [256]bool = @splat(false);
9090 for (alphabet_chars) |c| {
9191 assert(!char_in_alphabet[c]);
9292 assert(pad_char == null or c != pad_char.?);
......@@ -176,12 +176,12 @@ pub const Base64Decoder = struct {
176176
177177 pub fn init(alphabet_chars: [64]u8, pad_char: ?u8) Base64Decoder {
178178 var result = Base64Decoder{
179 .char_to_index = [_]u8{invalid_char} ** 256,
180 .fast_char_to_index = .{[_]u32{invalid_char_tst} ** 256} ** 4,
179 .char_to_index = @splat(invalid_char),
180 .fast_char_to_index = @splat(@splat(invalid_char_tst)),
181181 .pad_char = pad_char,
182182 };
183183
184 var char_in_alphabet = [_]bool{false} ** 256;
184 var char_in_alphabet: [256]bool = @splat(false);
185185 for (alphabet_chars, 0..) |c, i| {
186186 assert(!char_in_alphabet[c]);
187187 assert(pad_char == null or c != pad_char.?);
......@@ -302,7 +302,7 @@ pub const Base64DecoderWithIgnore = struct {
302302 pub fn init(alphabet_chars: [64]u8, pad_char: ?u8, ignore_chars: []const u8) Base64DecoderWithIgnore {
303303 var result = Base64DecoderWithIgnore{
304304 .decoder = Base64Decoder.init(alphabet_chars, pad_char),
305 .char_is_ignored = [_]bool{false} ** 256,
305 .char_is_ignored = @splat(false),
306306 };
307307 for (ignore_chars) |c| {
308308 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 {
406406 /// Deprecated: use `.empty`.
407407 /// Creates a bit set with no elements present.
408408 pub fn initEmpty() Self {
409 return .{ .masks = [_]MaskInt{0} ** num_masks };
409 return .empty;
410410 }
411411
412412 /// Deprecated: use `.full`.
413413 /// Creates a bit set with all elements present.
414414 pub fn initFull() Self {
415 if (num_masks == 0) {
416 return .{ .masks = .{} };
417 } else {
418 return .{ .masks = [_]MaskInt{~@as(MaskInt, 0)} ** (num_masks - 1) ++ [_]MaskInt{last_item_mask} };
419 }
415 return .full;
420416 }
421417
422418 /// A bit set with no elements present.
423419 pub const empty: Self = .{ .masks = @splat(0) };
424420
425421 /// 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 };
427427
428428 /// Returns the number of bits in this bit set
429429 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) {
79147914
79157915pub const pthread_mutex_t = switch (native_os) {
79167916 .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),
79187918
79197919 const data_len = switch (native_abi) {
79207920 .musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24,
......@@ -7930,7 +7930,7 @@ pub const pthread_mutex_t = switch (native_os) {
79307930 },
79317931 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
79327932 sig: c_long = 0x32AAABA7,
7933 data: [data_len]u8 = [_]u8{0} ** data_len,
7933 data: [data_len]u8 = @splat(0),
79347934
79357935 const data_len = if (@sizeOf(usize) == 8) 56 else 40;
79367936 },
......@@ -7966,10 +7966,10 @@ pub const pthread_mutex_t = switch (native_os) {
79667966 data: u64 = 0,
79677967 },
79687968 .fuchsia => extern struct {
7969 data: [40]u8 align(@alignOf(usize)) = [_]u8{0} ** 40,
7969 data: [40]u8 align(@alignOf(usize)) = @splat(0),
79707970 },
79717971 .emscripten => extern struct {
7972 data: [24]u8 align(4) = [_]u8{0} ** 24,
7972 data: [24]u8 align(4) = @splat(0),
79737973 },
79747974 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L68-L73
79757975 .serenity => extern struct {
......@@ -7983,11 +7983,11 @@ pub const pthread_mutex_t = switch (native_os) {
79837983
79847984pub const pthread_cond_t = switch (native_os) {
79857985 .linux => extern struct {
7986 data: [48]u8 align(@alignOf(usize)) = [_]u8{0} ** 48,
7986 data: [48]u8 align(@alignOf(usize)) = @splat(0),
79877987 },
79887988 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
79897989 sig: c_long = 0x3CB0B1BB,
7990 data: [data_len]u8 = [_]u8{0} ** data_len,
7990 data: [data_len]u8 = @splat(0),
79917991 const data_len = if (@sizeOf(usize) == 8) 40 else 24;
79927992 },
79937993 .freebsd, .dragonfly, .openbsd => extern struct {
......@@ -8012,13 +8012,13 @@ pub const pthread_cond_t = switch (native_os) {
80128012 lock: i32 = 0,
80138013 },
80148014 .illumos => extern struct {
8015 flag: [4]u8 = [_]u8{0} ** 4,
8015 flag: [4]u8 = @splat(0),
80168016 type: u16 = 0,
80178017 magic: u16 = 0x4356,
80188018 data: u64 = 0,
80198019 },
80208020 .fuchsia, .emscripten => extern struct {
8021 data: [48]u8 align(@alignOf(usize)) = [_]u8{0} ** 48,
8021 data: [48]u8 align(@alignOf(usize)) = @splat(0),
80228022 },
80238023 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L80-L84
80248024 .serenity => extern struct {
......@@ -8033,20 +8033,20 @@ pub const pthread_rwlock_t = switch (native_os) {
80338033 .linux => switch (native_abi) {
80348034 .android, .androideabi => switch (@sizeOf(usize)) {
80358035 4 => extern struct {
8036 data: [40]u8 align(@alignOf(usize)) = [_]u8{0} ** 40,
8036 data: [40]u8 align(@alignOf(usize)) = @splat(0),
80378037 },
80388038 8 => extern struct {
8039 data: [56]u8 align(@alignOf(usize)) = [_]u8{0} ** 56,
8039 data: [56]u8 align(@alignOf(usize)) = @splat(0),
80408040 },
80418041 else => @compileError("impossible pointer size"),
80428042 },
80438043 else => extern struct {
8044 data: [56]u8 align(@alignOf(usize)) = [_]u8{0} ** 56,
8044 data: [56]u8 align(@alignOf(usize)) = @splat(0),
80458045 },
80468046 },
80478047 .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct {
80488048 sig: c_long = 0x2DA8B3B4,
8049 data: [192]u8 = [_]u8{0} ** 192,
8049 data: [192]u8 = @splat(0),
80508050 },
80518051 .freebsd, .dragonfly, .openbsd => extern struct {
80528052 ptr: ?*anyopaque = null,
......@@ -8079,10 +8079,10 @@ pub const pthread_rwlock_t = switch (native_os) {
80798079 writercv: pthread_cond_t = .{},
80808080 },
80818081 .fuchsia => extern struct {
8082 size: [56]u8 align(@alignOf(usize)) = [_]u8{0} ** 56,
8082 size: [56]u8 align(@alignOf(usize)) = @splat(0),
80838083 },
80848084 .emscripten => extern struct {
8085 size: [32]u8 align(4) = [_]u8{0} ** 32,
8085 size: [32]u8 align(4) = @splat(0),
80868086 },
80878087 // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L86
80888088 .serenity => extern struct {
......@@ -8170,8 +8170,8 @@ pub const sem_t = switch (native_os) {
81708170 count: u32 = 0,
81718171 type: u16 = 0,
81728172 magic: u16 = 0x534d,
8173 __pad1: [3]u64 = [_]u64{0} ** 3,
8174 __pad2: [2]u64 = [_]u64{0} ** 2,
8173 __pad1: [3]u64 = @splat(0),
8174 __pad2: [2]u64 = @splat(0),
81758175 },
81768176 .openbsd, .netbsd, .dragonfly => ?*opaque {},
81778177 .haiku => extern struct {
......@@ -8235,7 +8235,7 @@ pub const Kevent = switch (native_os) {
82358235 /// Opaque user data identifier.
82368236 udata: usize,
82378237 /// Future extensions.
8238 _ext: [4]u64 = [_]u64{0} ** 4,
8238 _ext: [4]u64 = @splat(0),
82398239 },
82408240 .dragonfly => extern struct {
82418241 ident: usize,
lib/std/compress/flate/Decompress.zig+1-1
......@@ -723,7 +723,7 @@ fn HuffmanDecoder(
723723 if (alphabet_size == 286)
724724 if (lens[256] == 0) return error.MissingEndOfBlockCode;
725725
726 var count = [_]u16{0} ** (@as(usize, max_code_bits) + 1);
726 var count: [@as(usize, max_code_bits) + 1]u16 = @splat(0);
727727 var max: usize = 0;
728728 for (lens) |n| {
729729 if (n == 0) continue;
lib/std/crypto.zig+3-3
......@@ -394,7 +394,7 @@ test "issue #4532: no index out of bounds" {
394394 };
395395
396396 inline for (types) |Hasher| {
397 var block = [_]u8{'#'} ** Hasher.block_length;
397 var block: [Hasher.block_length]u8 = @splat('#');
398398 var out1: [Hasher.digest_length]u8 = undefined;
399399 var out2: [Hasher.digest_length]u8 = undefined;
400400 const h0 = Hasher.init(.{});
......@@ -417,8 +417,8 @@ pub fn secureZero(comptime T: type, s: []volatile T) void {
417417}
418418
419419test secureZero {
420 var a = [_]u8{0xfe} ** 8;
421 var b = [_]u8{0xfe} ** 8;
420 var a: [8]u8 = @splat(0xFE);
421 var b: [8]u8 = @splat(0xFE);
422422
423423 @memset(&a, 0);
424424 secureZero(u8, &b);
lib/std/crypto/25519/curve25519.zig+2-2
......@@ -41,7 +41,7 @@ pub const Curve25519 = struct {
4141
4242 /// Multiply a point by the cofactor, returning WeakPublicKey if the element is in a small-order group.
4343 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));
4545 return ladder(p, cofactor, 4) catch return error.WeakPublicKey;
4646 }
4747
......@@ -168,7 +168,7 @@ test "elligator2" {
168168}
169169
170170test "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));
172172 const small_order_ss: [7][32]u8 = .{
173173 .{
174174 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 {
470470 st.final(&hctx);
471471 xctx = hctx[0..];
472472 }
473 const empty_block = [_]u8{0} ** H.block_length;
473 const empty_block: [H.block_length]u8 = @splat(0);
474474 var t = [3]u8{ 0, n * h_l, 0 };
475475 var xctx_len_u8 = [1]u8{@as(u8, @intCast(xctx.len))};
476476 var st = H.init(.{});
......@@ -539,7 +539,7 @@ pub const Edwards25519 = struct {
539539const htest = @import("../test.zig");
540540
541541test "packing/unpacking" {
542 const s = [_]u8{170} ++ [_]u8{0} ** 31;
542 const s = [1]u8{170} ++ @as([31]u8, @splat(0));
543543 var b = Edwards25519.basePoint;
544544 const pk = try b.mul(s);
545545 var buf: [128]u8 = undefined;
......@@ -609,7 +609,7 @@ test "hash-to-curve operation" {
609609}
610610
611611test "implicit reduction of invalid scalars" {
612 const s = [_]u8{0} ** 31 ++ [_]u8{255};
612 const s = @as([31]u8, @splat(0)) ++ [1]u8{255};
613613 const p1 = try Edwards25519.basePoint.mulPublic(s);
614614 const p2 = try Edwards25519.basePoint.mul(s);
615615 const p3 = try p1.mulPublic(s);
lib/std/crypto/25519/ristretto255.zig+2-2
......@@ -183,13 +183,13 @@ test "ristretto255" {
183183 q = q.dbl().add(p);
184184 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&q.toBytes()}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E");
185185
186 const s = [_]u8{15} ++ [_]u8{0} ** 31;
186 const s = [_]u8{15} ++ @as([31]u8, @splat(0));
187187 const w = try p.mul(s);
188188 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&w.toBytes()}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E");
189189
190190 try std.testing.expect(p.dbl().dbl().dbl().dbl().equivalent(w.add(p)));
191191
192 const h = [_]u8{69} ** 32 ++ [_]u8{42} ** 32;
192 const h = @as([32]u8, @splat(69)) ++ @as([32]u8, @splat(42));
193193 const ph = Ristretto255.fromUniform(h);
194194 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&ph.toBytes()}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19");
195195}
lib/std/crypto/25519/scalar.zig+6-6
......@@ -11,7 +11,7 @@ pub const field_order: u256 = 72370055773322622139731865630429942408571163593799
1111pub const CompressedScalar = [32]u8;
1212
1313/// Zero
14pub const zero = [_]u8{0} ** 32;
14pub const zero: [32]u8 = @splat(0);
1515
1616const field_order_s = s: {
1717 var s: [32]u8 = undefined;
......@@ -81,7 +81,7 @@ pub fn add(a: CompressedScalar, b: CompressedScalar) CompressedScalar {
8181
8282/// Return -s (mod L)
8383pub 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));
8585 var sx: [64]u8 = undefined;
8686 sx[0..32].* = s;
8787 @memset(sx[32..], 0);
......@@ -862,9 +862,9 @@ test "non-canonical scalar25519" {
862862}
863863
864864test "mulAdd overflow check" {
865 const a: [32]u8 = [_]u8{0xff} ** 32;
866 const b: [32]u8 = [_]u8{0xff} ** 32;
867 const c: [32]u8 = [_]u8{0xff} ** 32;
865 const a: [32]u8 = @splat(0xff);
866 const b: [32]u8 = @splat(0xff);
867 const c: [32]u8 = @splat(0xff);
868868 const x = mulAdd(a, b, c);
869869 var buf: [128]u8 = undefined;
870870 try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&x}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903");
......@@ -886,7 +886,7 @@ test "random scalar" {
886886}
887887
888888test "64-bit reduction" {
889 const bytes = field_order_s ++ [_]u8{0} ** 32;
889 const bytes = field_order_s ++ @as([32]u8, @splat(0));
890890 const x = Scalar.fromBytes64(bytes);
891891 try std.testing.expect(x.isZero());
892892}
lib/std/crypto/25519/x25519.zig+1-1
......@@ -181,7 +181,7 @@ test "rfc7748 1,000,000 iterations" {
181181}
182182
183183test "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));
185185 const mont_kp = try X25519.KeyPair.fromEd25519(ed_kp);
186186 try htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key);
187187 try htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key);
lib/std/crypto/Certificate.zig+1-1
......@@ -1092,7 +1092,7 @@ pub const rsa = struct {
10921092 }
10931093 var m_p_buf: [8 + Hash.digest_length + Hash.digest_length]u8 = undefined;
10941094 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)));
10961096 std.mem.copyForwards(u8, m_p[8..], &mHash);
10971097 std.mem.copyForwards(u8, m_p[(8 + Hash.digest_length)..], salt);
10981098
lib/std/crypto/Sha1.zig+1-1
......@@ -297,7 +297,7 @@ test "sha1 streaming" {
297297}
298298
299299test "sha1 aligned final" {
300 var block = [_]u8{0} ** Sha1.block_length;
300 var block: [Sha1.block_length]u8 = @splat(0);
301301 var out: [Sha1.digest_length]u8 = undefined;
302302
303303 var h = Sha1.init(.{});
lib/std/crypto/aegis.zig+45-39
......@@ -55,6 +55,14 @@ pub const Aegis256X2_256 = Aegis256XGeneric(2, 256);
5555/// AEGIS-256 with a 256 bit tag
5656pub const Aegis256_256 = Aegis256XGeneric(1, 256);
5757
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.
60inline 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
5866fn State128X(comptime degree: u7) type {
5967 return struct {
6068 const AesBlockVec = crypto.core.aes.BlockVec(degree);
......@@ -67,10 +75,10 @@ fn State128X(comptime degree: u7) type {
6775 const alignment = AesBlockVec.native_word_size;
6876
6977 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);
71 const c2 = AesBlockVec.fromBytes(&[16]u8{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 } ** degree);
72 const key_block = AesBlockVec.fromBytes(&(key ** degree));
73 const nonce_block = AesBlockVec.fromBytes(&(nonce ** degree));
78 const c1 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1, 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd }));
79 const c2 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 }));
80 const key_block = AesBlockVec.fromBytes(&repeat16u8(degree, key));
81 const nonce_block = AesBlockVec.fromBytes(&repeat16u8(degree, nonce));
7482 const blocks = [8]AesBlockVec{
7583 key_block.xorBlocks(nonce_block),
7684 c1,
......@@ -84,7 +92,7 @@ fn State128X(comptime degree: u7) type {
8492 var state = State{ .blocks = blocks };
8593 if (degree > 1) {
8694 const context_block = ctx: {
87 var contexts_bytes = [_]u8{0} ** aes_block_length;
95 var contexts_bytes: [aes_block_length]u8 = @splat(0);
8896 for (0..degree) |i| {
8997 contexts_bytes[i * 16] = @intCast(i);
9098 contexts_bytes[i * 16 + 1] = @intCast(degree - 1);
......@@ -150,7 +158,7 @@ fn State128X(comptime degree: u7) type {
150158 const blocks = &state.blocks;
151159 const z0 = blocks[6].xorBlocks(blocks[1]).xorBlocks(blocks[2].andBlocks(blocks[3]));
152160 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);
154162 pad[0..aes_block_length].* = z0.toBytes();
155163 pad[aes_block_length..].* = z1.toBytes();
156164 for (pad[0..src.len], src) |*p, x| p.* ^= x;
......@@ -214,7 +222,7 @@ fn State128X(comptime degree: u7) type {
214222 state.update(t, t);
215223 }
216224 if (degree > 1) {
217 var v = [_]u8{0} ** rate;
225 var v: [rate]u8 = @splat(0);
218226 switch (tag_bits) {
219227 128 => {
220228 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 {
362370 const alignment = AesBlockVec.native_word_size;
363371
364372 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);
366 const c2 = AesBlockVec.fromBytes(&[16]u8{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 } ** degree);
367 const key_block1 = AesBlockVec.fromBytes(key[0..16] ** degree);
368 const key_block2 = AesBlockVec.fromBytes(key[16..32] ** degree);
369 const nonce_block1 = AesBlockVec.fromBytes(nonce[0..16] ** degree);
370 const nonce_block2 = AesBlockVec.fromBytes(nonce[16..32] ** degree);
373 const c1 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1, 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd }));
374 const c2 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 }));
375 const key_block1 = AesBlockVec.fromBytes(&repeat16u8(degree, key[0..16].*));
376 const key_block2 = AesBlockVec.fromBytes(&repeat16u8(degree, key[16..32].*));
377 const nonce_block1 = AesBlockVec.fromBytes(&repeat16u8(degree, nonce[0..16].*));
378 const nonce_block2 = AesBlockVec.fromBytes(&repeat16u8(degree, nonce[16..32].*));
371379 const kxn1 = key_block1.xorBlocks(nonce_block1);
372380 const kxn2 = key_block2.xorBlocks(nonce_block2);
373381 const blocks = [6]AesBlockVec{
......@@ -381,7 +389,7 @@ fn State256X(comptime degree: u7) type {
381389 var state = State{ .blocks = blocks };
382390 if (degree > 1) {
383391 const context_block = ctx: {
384 var contexts_bytes = [_]u8{0} ** aes_block_length;
392 var contexts_bytes: [aes_block_length]u8 = @splat(0);
385393 for (0..degree) |i| {
386394 contexts_bytes[i * 16] = @intCast(i);
387395 contexts_bytes[i * 16 + 1] = @intCast(degree - 1);
......@@ -509,7 +517,7 @@ fn State256X(comptime degree: u7) type {
509517 state.update(t);
510518 }
511519 if (degree > 1) {
512 var v = [_]u8{0} ** rate;
520 var v: [rate]u8 = @splat(0);
513521 switch (tag_bits) {
514522 128 => {
515523 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 {
746754
747755 /// Initialize a state for the MAC function, with a default nonce
748756 pub fn init(key: *const [key_length]u8) Mac {
749 return Mac{
750 .state = T.State.init(key.*, [_]u8{0} ** nonce_length),
751 };
757 return .{ .state = .init(key.*, @splat(0)) };
752758 }
753759
754760 /// Add data to the state
......@@ -781,7 +787,7 @@ fn AegisMac(comptime T: type) type {
781787 /// Return an authentication tag for the current state
782788 pub fn final(self: *Mac, out: *[mac_length]u8) void {
783789 if (self.off > 0) {
784 var pad = [_]u8{0} ** block_length;
790 var pad: [block_length]u8 = @splat(0);
785791 @memcpy(pad[0..self.off], self.buf[0..self.off]);
786792 self.state.absorb(&pad);
787793 }
......@@ -808,8 +814,8 @@ const htest = @import("test.zig");
808814const testing = std.testing;
809815
810816test "Aegis128L test vector 1" {
811 const key: [Aegis128L.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** 14;
812 const nonce: [Aegis128L.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** 13;
817 const key: [Aegis128L.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ @as([14]u8, @splat(0x00));
818 const nonce: [Aegis128L.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([13]u8, @splat(0x00));
813819 const ad = [8]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
814820 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 };
815821 var c: [m.len]u8 = undefined;
......@@ -831,10 +837,10 @@ test "Aegis128L test vector 1" {
831837}
832838
833839test "Aegis128L test vector 2" {
834 const key: [Aegis128L.key_length]u8 = [_]u8{0x00} ** 16;
835 const nonce: [Aegis128L.nonce_length]u8 = [_]u8{0x00} ** 16;
836 const ad = [_]u8{};
837 const m = [_]u8{0x00} ** 16;
840 const key: [Aegis128L.key_length]u8 = @splat(0x00);
841 const nonce: [Aegis128L.nonce_length]u8 = @splat(0x00);
842 const ad: [0]u8 = .{};
843 const m: [16]u8 = @splat(0x00);
838844 var c: [m.len]u8 = undefined;
839845 var m2: [m.len]u8 = undefined;
840846 var tag: [Aegis128L.tag_length]u8 = undefined;
......@@ -848,8 +854,8 @@ test "Aegis128L test vector 2" {
848854}
849855
850856test "Aegis128L test vector 3" {
851 const key: [Aegis128L.key_length]u8 = [_]u8{0x00} ** 16;
852 const nonce: [Aegis128L.nonce_length]u8 = [_]u8{0x00} ** 16;
857 const key: [Aegis128L.key_length]u8 = @splat(0x00);
858 const nonce: [Aegis128L.nonce_length]u8 = @splat(0x00);
853859 const ad = [_]u8{};
854860 const m = [_]u8{};
855861 var c: [m.len]u8 = undefined;
......@@ -881,8 +887,8 @@ test "Aegis128X2 test vector 1" {
881887}
882888
883889test "Aegis256 test vector 1" {
884 const key: [Aegis256.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** 30;
885 const nonce: [Aegis256.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** 29;
890 const key: [Aegis256.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ @as([30]u8, @splat(0x00));
891 const nonce: [Aegis256.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([29]u8, @splat(0x00));
886892 const ad = [8]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
887893 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 };
888894 var c: [m.len]u8 = undefined;
......@@ -904,10 +910,10 @@ test "Aegis256 test vector 1" {
904910}
905911
906912test "Aegis256 test vector 2" {
907 const key: [Aegis256.key_length]u8 = [_]u8{0x00} ** 32;
908 const nonce: [Aegis256.nonce_length]u8 = [_]u8{0x00} ** 32;
913 const key: [Aegis256.key_length]u8 = @splat(0x00);
914 const nonce: [Aegis256.nonce_length]u8 = @splat(0x00);
909915 const ad = [_]u8{};
910 const m = [_]u8{0x00} ** 16;
916 const m: [16]u8 = @splat(0x00);
911917 var c: [m.len]u8 = undefined;
912918 var m2: [m.len]u8 = undefined;
913919 var tag: [Aegis256.tag_length]u8 = undefined;
......@@ -921,8 +927,8 @@ test "Aegis256 test vector 2" {
921927}
922928
923929test "Aegis256 test vector 3" {
924 const key: [Aegis256.key_length]u8 = [_]u8{0x00} ** 32;
925 const nonce: [Aegis256.nonce_length]u8 = [_]u8{0x00} ** 32;
930 const key: [Aegis256.key_length]u8 = @splat(0x00);
931 const nonce: [Aegis256.nonce_length]u8 = @splat(0x00);
926932 const ad = [_]u8{};
927933 const m = [_]u8{};
928934 var c: [m.len]u8 = undefined;
......@@ -954,7 +960,7 @@ test "Aegis256X4 test vector 1" {
954960}
955961
956962test "Aegis MAC" {
957 const key = [_]u8{0x00} ** Aegis128LMac.key_length;
963 const key: [Aegis128LMac.key_length]u8 = @splat(0x00);
958964 var msg: [64]u8 = undefined;
959965 for (&msg, 0..) |*m, i| {
960966 m.* = @as(u8, @truncate(i));
......@@ -989,8 +995,8 @@ test "Aegis MAC" {
989995}
990996
991997test "AEGISMAC-128* test vectors" {
992 const key = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** (16 - 2);
993 const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** (16 - 3);
998 const key = [_]u8{ 0x10, 0x01 } ++ @as([16 - 2]u8, @splat(0x00));
999 const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([16 - 3]u8, @splat(0x00));
9941000 var msg: [35]u8 = undefined;
9951001 for (&msg, 0..) |*byte, i| byte.* = @truncate(i);
9961002 var mac128: [16]u8 = undefined;
......@@ -1013,8 +1019,8 @@ test "AEGISMAC-128* test vectors" {
10131019}
10141020
10151021test "AEGISMAC-256* test vectors" {
1016 const key = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** (32 - 2);
1017 const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** (32 - 3);
1022 const key = [_]u8{ 0x10, 0x01 } ++ @as([32 - 2]u8, @splat(0x00));
1023 const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([32 - 3]u8, @splat(0x00));
10181024 var msg: [35]u8 = undefined;
10191025 for (&msg, 0..) |*byte, i| byte.* = @truncate(i);
10201026 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
201201 const total_ad_size = ad_len_size + ad.len;
202202 const remainder = total_ad_size % block_length;
203203 if (remainder > 0) {
204 const padding = [_]u8{0} ** block_length;
204 const padding: [block_length]u8 = @splat(0);
205205 ctx.update(padding[0 .. block_length - remainder]);
206206 }
207207 }
......@@ -264,8 +264,8 @@ const fmt = std.fmt;
264264const hexToBytes = fmt.hexToBytes;
265265
266266test "Aes256Ccm8 - Encrypt decrypt round-trip" {
267 const key: [32]u8 = [_]u8{0x42} ** 32;
268 const nonce: [13]u8 = [_]u8{0x11} ** 13;
267 const key: [32]u8 = @splat(0x42);
268 const nonce: [13]u8 = @splat(0x11);
269269 const m = "Hello, World! This is a test message.";
270270 var c: [m.len]u8 = undefined;
271271 var m2: [m.len]u8 = undefined;
......@@ -279,8 +279,8 @@ test "Aes256Ccm8 - Encrypt decrypt round-trip" {
279279}
280280
281281test "Aes256Ccm8 - Associated data" {
282 const key: [32]u8 = [_]u8{0x42} ** 32;
283 const nonce: [13]u8 = [_]u8{0x11} ** 13;
282 const key: [32]u8 = @splat(0x42);
283 const nonce: [13]u8 = @splat(0x11);
284284 const m = "secret message";
285285 const ad = "additional authenticated data";
286286 var c: [m.len]u8 = undefined;
......@@ -299,9 +299,9 @@ test "Aes256Ccm8 - Associated data" {
299299}
300300
301301test "Aes256Ccm8 - Wrong key" {
302 const key: [32]u8 = [_]u8{0x42} ** 32;
303 const wrong_key: [32]u8 = [_]u8{0x43} ** 32;
304 const nonce: [13]u8 = [_]u8{0x11} ** 13;
302 const key: [32]u8 = @splat(0x42);
303 const wrong_key: [32]u8 = @splat(0x43);
304 const nonce: [13]u8 = @splat(0x11);
305305 const m = "secret";
306306 var c: [m.len]u8 = undefined;
307307 var m2: [m.len]u8 = undefined;
......@@ -314,8 +314,8 @@ test "Aes256Ccm8 - Wrong key" {
314314}
315315
316316test "Aes256Ccm8 - Corrupted ciphertext" {
317 const key: [32]u8 = [_]u8{0x42} ** 32;
318 const nonce: [13]u8 = [_]u8{0x11} ** 13;
317 const key: [32]u8 = @splat(0x42);
318 const nonce: [13]u8 = @splat(0x11);
319319 const m = "secret message";
320320 var c: [m.len]u8 = undefined;
321321 var m2: [m.len]u8 = undefined;
......@@ -330,8 +330,8 @@ test "Aes256Ccm8 - Corrupted ciphertext" {
330330}
331331
332332test "Aes256Ccm8 - Empty plaintext" {
333 const key: [32]u8 = [_]u8{0x42} ** 32;
334 const nonce: [13]u8 = [_]u8{0x11} ** 13;
333 const key: [32]u8 = @splat(0x42);
334 const nonce: [13]u8 = @splat(0x11);
335335 const m = "";
336336 var c: [m.len]u8 = undefined;
337337 var m2: [m.len]u8 = undefined;
......@@ -345,8 +345,8 @@ test "Aes256Ccm8 - Empty plaintext" {
345345}
346346
347347test "Aes128Ccm8 - Basic functionality" {
348 const key: [16]u8 = [_]u8{0x42} ** 16;
349 const nonce: [13]u8 = [_]u8{0x11} ** 13;
348 const key: [16]u8 = @splat(0x42);
349 const nonce: [13]u8 = @splat(0x11);
350350 const m = "Test AES-128-CCM";
351351 var c: [m.len]u8 = undefined;
352352 var m2: [m.len]u8 = undefined;
......@@ -360,8 +360,8 @@ test "Aes128Ccm8 - Basic functionality" {
360360}
361361
362362test "Aes256Ccm16 - 16-byte tag" {
363 const key: [32]u8 = [_]u8{0x42} ** 32;
364 const nonce: [13]u8 = [_]u8{0x11} ** 13;
363 const key: [32]u8 = @splat(0x42);
364 const nonce: [13]u8 = @splat(0x11);
365365 const m = "Test 16-byte tag";
366366 var c: [m.len]u8 = undefined;
367367 var m2: [m.len]u8 = undefined;
......@@ -845,8 +845,8 @@ test "Aes128Ccm0 - IEEE 802.15.4 Data Frame (Encryption-only)" {
845845}
846846
847847test "Aes128Ccm0 - Zero-length plaintext with encryption-only" {
848 const key: [16]u8 = [_]u8{0x42} ** 16;
849 const nonce: [13]u8 = [_]u8{0x11} ** 13;
848 const key: [16]u8 = @splat(0x42);
849 const nonce: [13]u8 = @splat(0x11);
850850 const m = "";
851851 const ad = "some associated data";
852852 var c: [m.len]u8 = undefined;
......@@ -861,8 +861,8 @@ test "Aes128Ccm0 - Zero-length plaintext with encryption-only" {
861861}
862862
863863test "Aes256Ccm0 - Basic encryption-only round-trip" {
864 const key: [32]u8 = [_]u8{0x42} ** 32;
865 const nonce: [13]u8 = [_]u8{0x11} ** 13;
864 const key: [32]u8 = @splat(0x42);
865 const nonce: [13]u8 = @splat(0x11);
866866 const m = "Hello, CCM* encryption-only mode!";
867867 var c: [m.len]u8 = undefined;
868868 var m2: [m.len]u8 = undefined;
lib/std/crypto/aes_gcm.zig+10-12
......@@ -19,8 +19,6 @@ fn AesGcm(comptime Aes: anytype) type {
1919 pub const nonce_length = 12;
2020 pub const key_length = Aes.key_bits / 8;
2121
22 const zeros = [_]u8{0} ** 16;
23
2422 /// `c`: The ciphertext buffer to write the encrypted data to.
2523 /// `tag`: The authentication tag buffer to write the computed tag to.
2624 /// `m`: The plaintext message to encrypt.
......@@ -33,7 +31,7 @@ fn AesGcm(comptime Aes: anytype) type {
3331
3432 const aes = Aes.initEnc(key);
3533 var h: [16]u8 = undefined;
36 aes.encrypt(&h, &zeros);
34 aes.encrypt(&h, &@splat(0));
3735
3836 var t: [16]u8 = undefined;
3937 var j: [16]u8 = undefined;
......@@ -75,7 +73,7 @@ fn AesGcm(comptime Aes: anytype) type {
7573
7674 const aes = Aes.initEnc(key);
7775 var h: [16]u8 = undefined;
78 aes.encrypt(&h, &zeros);
76 aes.encrypt(&h, &@splat(0));
7977
8078 var t: [16]u8 = undefined;
8179 var j: [16]u8 = undefined;
......@@ -118,8 +116,8 @@ const htest = @import("test.zig");
118116const testing = std.testing;
119117
120118test "Aes256Gcm - Empty message and no associated data" {
121 const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length;
122 const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length;
119 const key: [Aes256Gcm.key_length]u8 = @splat(0x69);
120 const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42);
123121 const ad = "";
124122 const m = "";
125123 var c: [m.len]u8 = undefined;
......@@ -130,8 +128,8 @@ test "Aes256Gcm - Empty message and no associated data" {
130128}
131129
132130test "Aes256Gcm - Associated data only" {
133 const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length;
134 const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length;
131 const key: [Aes256Gcm.key_length]u8 = @splat(0x69);
132 const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42);
135133 const m = "";
136134 const ad = "Test with associated data";
137135 var c: [m.len]u8 = undefined;
......@@ -142,8 +140,8 @@ test "Aes256Gcm - Associated data only" {
142140}
143141
144142test "Aes256Gcm - Message only" {
145 const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length;
146 const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length;
143 const key: [Aes256Gcm.key_length]u8 = @splat(0x69);
144 const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42);
147145 const m = "Test with message only";
148146 const ad = "";
149147 var c: [m.len]u8 = undefined;
......@@ -159,8 +157,8 @@ test "Aes256Gcm - Message only" {
159157}
160158
161159test "Aes256Gcm - Message and associated data" {
162 const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length;
163 const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length;
160 const key: [Aes256Gcm.key_length]u8 = @splat(0x69);
161 const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42);
164162 const m = "Test with message";
165163 const ad = "Test with associated data";
166164 var c: [m.len]u8 = undefined;
lib/std/crypto/aes_ocb.zig+9-9
......@@ -48,7 +48,7 @@ fn AesOcb(comptime Aes: anytype) type {
4848 }
4949
5050 fn init(aes_enc_ctx: EncryptCtx) Lx {
51 const zeros = [_]u8{0} ** 16;
51 const zeros: [16]u8 = @splat(0);
5252 var star: Block = undefined;
5353 aes_enc_ctx.encrypt(&star, &zeros);
5454 const dol = double(star);
......@@ -62,8 +62,8 @@ fn AesOcb(comptime Aes: anytype) type {
6262 const full_blocks: usize = a.len / 16;
6363 const x_max = if (full_blocks > 0) math.log2_int(usize, full_blocks) else 0;
6464 const lt = lx.precomp(x_max);
65 var sum = [_]u8{0} ** 16;
66 var offset = [_]u8{0} ** 16;
65 var sum: [16]u8 = @splat(0);
66 var offset: [16]u8 = @splat(0);
6767 var i: usize = 0;
6868 while (i < full_blocks) : (i += 1) {
6969 xorWith(&offset, lt[@ctz(i + 1)]);
......@@ -74,7 +74,7 @@ fn AesOcb(comptime Aes: anytype) type {
7474 const leftover = a.len % 16;
7575 if (leftover > 0) {
7676 xorWith(&offset, lx.star);
77 var padded = [_]u8{0} ** 16;
77 var padded: [16]u8 = @splat(0);
7878 @memcpy(padded[0..leftover], a[i * 16 ..][0..leftover]);
7979 padded[leftover] = 0x80;
8080 var e = xorBlocks(offset, padded);
......@@ -85,7 +85,7 @@ fn AesOcb(comptime Aes: anytype) type {
8585 }
8686
8787 fn getOffset(aes_enc_ctx: EncryptCtx, npub: [nonce_length]u8) Block {
88 var nx = [_]u8{0} ** 16;
88 var nx: [16]u8 = @splat(0);
8989 nx[0] = @as(u8, @intCast(@as(u7, @truncate(tag_length * 8)) << 1));
9090 nx[16 - nonce_length - 1] = 1;
9191 nx[nx.len - nonce_length ..].* = npub;
......@@ -121,7 +121,7 @@ fn AesOcb(comptime Aes: anytype) type {
121121 const lt = lx.precomp(x_max);
122122
123123 var offset = getOffset(aes_enc_ctx, npub);
124 var sum = [_]u8{0} ** 16;
124 var sum: [16]u8 = @splat(0);
125125 var i: usize = 0;
126126
127127 while (wb > 0 and i + wb <= full_blocks) : (i += wb) {
......@@ -155,7 +155,7 @@ fn AesOcb(comptime Aes: anytype) type {
155155 xorWith(&offset, lx.star);
156156 var pad = offset;
157157 aes_enc_ctx.encrypt(&pad, &pad);
158 var e = [_]u8{0} ** 16;
158 var e: [16]u8 = @splat(0);
159159 @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]);
160160 e[leftover] = 0x80;
161161 for (m[i * 16 ..], 0..) |x, j| {
......@@ -188,7 +188,7 @@ fn AesOcb(comptime Aes: anytype) type {
188188 const lt = lx.precomp(x_max);
189189
190190 var offset = getOffset(aes_enc_ctx, npub);
191 var sum = [_]u8{0} ** 16;
191 var sum: [16]u8 = @splat(0);
192192 var i: usize = 0;
193193
194194 while (wb > 0 and i + wb <= full_blocks) : (i += wb) {
......@@ -226,7 +226,7 @@ fn AesOcb(comptime Aes: anytype) type {
226226 for (c[i * 16 ..], 0..) |x, j| {
227227 m[i * 16 + j] = pad[j] ^ x;
228228 }
229 var e = [_]u8{0} ** 16;
229 var e: [16]u8 = @splat(0);
230230 @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]);
231231 e[leftover] = 0x80;
232232 xorWith(&sum, e);
lib/std/crypto/argon2.zig+15-15
......@@ -281,9 +281,9 @@ fn processSegment(
281281 slice: u32,
282282 lane: u24,
283283) void {
284 var addresses align(16) = [_]u64{0} ** block_length;
285 var in align(16) = [_]u64{0} ** block_length;
286 const zero align(16) = [_]u64{0} ** block_length;
284 var addresses: [block_length]u64 align(16) = @splat(0);
285 var in: [block_length]u64 align(16) = @splat(0);
286 const zero: [block_length]u64 align(16) = @splat(0);
287287 if (mode == .argon2i or (mode == .argon2id and n == 0 and slice < sync_points / 2)) {
288288 in[0] = n;
289289 in[1] = lane;
......@@ -629,10 +629,10 @@ pub fn strVerify(
629629test "argon2d" {
630630 if (true) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/30074
631631
632 const password = [_]u8{0x01} ** 32;
633 const salt = [_]u8{0x02} ** 16;
634 const secret = [_]u8{0x03} ** 8;
635 const ad = [_]u8{0x04} ** 12;
632 const password: [32]u8 = @splat(0x01);
633 const salt: [16]u8 = @splat(0x02);
634 const secret: [8]u8 = @splat(0x03);
635 const ad: [12]u8 = @splat(0x04);
636636
637637 var dk: [32]u8 = undefined;
638638 try kdf(
......@@ -655,10 +655,10 @@ test "argon2d" {
655655}
656656
657657test "argon2i" {
658 const password = [_]u8{0x01} ** 32;
659 const salt = [_]u8{0x02} ** 16;
660 const secret = [_]u8{0x03} ** 8;
661 const ad = [_]u8{0x04} ** 12;
658 const password: [32]u8 = @splat(0x01);
659 const salt: [16]u8 = @splat(0x02);
660 const secret: [8]u8 = @splat(0x03);
661 const ad: [12]u8 = @splat(0x04);
662662
663663 var dk: [32]u8 = undefined;
664664 try kdf(
......@@ -681,10 +681,10 @@ test "argon2i" {
681681}
682682
683683test "argon2id" {
684 const password = [_]u8{0x01} ** 32;
685 const salt = [_]u8{0x02} ** 16;
686 const secret = [_]u8{0x03} ** 8;
687 const ad = [_]u8{0x04} ** 12;
684 const password: [32]u8 = @splat(0x01);
685 const salt: [16]u8 = @splat(0x02);
686 const secret: [8]u8 = @splat(0x03);
687 const ad: [12]u8 = @splat(0x04);
688688
689689 var dk: [32]u8 = undefined;
690690 try kdf(
lib/std/crypto/bcrypt.zig+20-10
......@@ -868,20 +868,25 @@ test "bcrypt crypt format" {
868868 strVerify(s, "invalid password", verify_options),
869869 );
870870
871 const password_100: []const u8 = password: {
872 const arr: [100][8]u8 = @splat("password".*);
873 break :password @ptrCast(&arr);
874 };
875
871876 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);
873878
874879 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);
876881 try testing.expectError(
877882 error.PasswordVerificationFailed,
878 strVerify(long_s, "password" ** 101, verify_options),
883 strVerify(long_s, password_100 ++ "password", verify_options),
879884 );
880885
881886 hash_options.params.silently_truncate_password = true;
882887 verify_options.silently_truncate_password = true;
883 long_s = try strHash("password" ** 100, hash_options, &long_buf, io);
884 try strVerify(long_s, "password" ** 101, verify_options);
888 long_s = try strHash(password_100, hash_options, &long_buf, io);
889 try strVerify(long_s, password_100 ++ "password", verify_options);
885890
886891 try strVerify(
887892 "$2b$08$WUQKyBCaKpziCwUXHiMVvu40dYVjkTxtWJlftl0PpjY2BxWSvFIEe",
......@@ -909,20 +914,25 @@ test "bcrypt phc format" {
909914 strVerify(s, "invalid password", verify_options),
910915 );
911916
917 const password_100: []const u8 = password: {
918 const arr: [100][8]u8 = @splat("password".*);
919 break :password @ptrCast(&arr);
920 };
921
912922 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);
914924
915925 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);
917927 try testing.expectError(
918928 error.PasswordVerificationFailed,
919 strVerify(long_s, "password" ** 101, verify_options),
929 strVerify(long_s, password_100 ++ "password", verify_options),
920930 );
921931
922932 hash_options.params.silently_truncate_password = true;
923933 verify_options.silently_truncate_password = true;
924 long_s = try strHash("password" ** 100, hash_options, &long_buf, io);
925 try strVerify(long_s, "password" ** 101, verify_options);
934 long_s = try strHash(password_100, hash_options, &long_buf, io);
935 try strVerify(long_s, password_100 ++ "password", verify_options);
926936
927937 try strVerify(
928938 "$bcrypt$r=5$2NopntlgE2lX3cTwr4qz8A$r3T7iKYQNnY4hAhGjk9RmuyvgrYJZwc",
lib/std/crypto/benchmark.zig+7-7
......@@ -173,7 +173,7 @@ const signatures = [_]Crypto{
173173};
174174
175175pub 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);
177177 const key_pair = Signature.KeyPair.generate(io);
178178
179179 const start = benchTime(io);
......@@ -200,7 +200,7 @@ const signature_verifications = [_]Crypto{
200200};
201201
202202pub 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);
204204 const key_pair = Signature.KeyPair.generate(io);
205205 const sig = try key_pair.sign(&msg, null);
206206
......@@ -223,7 +223,7 @@ pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime sign
223223const batch_signature_verifications = [_]Crypto{Crypto{ .ty = crypto.sign.Ed25519, .name = "ed25519" }};
224224
225225pub 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);
227227 const key_pair = Signature.KeyPair.generate(io);
228228 const sig = try key_pair.sign(&msg, null);
229229
......@@ -367,7 +367,7 @@ pub fn benchmarkAes(comptime Aes: anytype, comptime count: comptime_int, io: Io)
367367 random.bytes(key[0..]);
368368 const ctx = Aes.initEnc(key);
369369
370 var in = [_]u8{0} ** 16;
370 var in: [16]u8 = @splat(0);
371371
372372 const start = benchTime(io);
373373 {
......@@ -395,7 +395,7 @@ pub fn benchmarkAes8(comptime Aes: anytype, comptime count: comptime_int, io: Io
395395 random.bytes(key[0..]);
396396 const ctx = Aes.initEnc(key);
397397
398 var in = [_]u8{0} ** (8 * 16);
398 var in: [8 * 16]u8 = @splat(0);
399399
400400 const start = benchTime(io);
401401 {
......@@ -444,7 +444,7 @@ fn benchmarkPwhash(
444444 comptime count: comptime_int,
445445 io: std.Io,
446446) !f64 {
447 const password = "testpass" ** 2;
447 const password = "testpasstestpass";
448448 const opts = ty.HashOptions{
449449 .allocator = allocator,
450450 .params = @as(*const ty.Params, @ptrCast(@alignCast(params))).*,
......@@ -456,7 +456,7 @@ fn benchmarkPwhash(
456456 const strHashFnInfo = @typeInfo(@TypeOf(strHash)).@"fn";
457457 const needs_io = strHashFnInfo.params.len == 4 and strHashFnInfo.params[3].type == std.Io;
458458 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);
460460
461461 const start = benchTime(io);
462462 {
lib/std/crypto/blake2.zig+100-64
......@@ -199,7 +199,9 @@ test "blake2s160 single" {
199199 try htest.assertEqualHash(Blake2s160, h3, "The quick brown fox jumps over the lazy dog");
200200
201201 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);
203205}
204206
205207test "blake2s160 streaming" {
......@@ -227,27 +229,30 @@ test "blake2s160 streaming" {
227229
228230 const h3 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0";
229231
232 const repeat_a_32: [32]u8 = @splat('a');
233 const repeat_b_32: [32]u8 = @splat('b');
234
230235 h = Blake2s160.init(.{});
231 h.update("a" ** 32);
232 h.update("b" ** 32);
236 h.update(&repeat_a_32);
237 h.update(&repeat_b_32);
233238 h.final(out[0..]);
234239 try htest.assertEqual(h3, out[0..]);
235240
236241 h = Blake2s160.init(.{});
237 h.update("a" ** 32 ++ "b" ** 32);
242 h.update(&repeat_a_32 ++ &repeat_b_32);
238243 h.final(out[0..]);
239244 try htest.assertEqual(h3, out[0..]);
240245
241246 const h4 = "4667fd60791a7fe41f939bca646b4529e296bd68";
242247
243 h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
244 h.update("a" ** 32);
245 h.update("b" ** 32);
248 h = Blake2s160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
249 h.update(&repeat_a_32);
250 h.update(&repeat_b_32);
246251 h.final(out[0..]);
247252 try htest.assertEqual(h4, out[0..]);
248253
249 h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
250 h.update("a" ** 32 ++ "b" ** 32);
254 h = Blake2s160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
255 h.update(&repeat_a_32 ++ &repeat_b_32);
251256 h.final(out[0..]);
252257 try htest.assertEqual(h4, out[0..]);
253258}
......@@ -256,7 +261,7 @@ test "comptime blake2s160" {
256261 //comptime
257262 {
258263 @setEvalBranchQuota(10000);
259 var block = [_]u8{0} ** Blake2s160.block_length;
264 var block: [Blake2s160.block_length]u8 = @splat(0);
260265 var out: [Blake2s160.digest_length]u8 = undefined;
261266
262267 const h1 = "2c56ad9d0b2c8b474aafa93ab307db2f0940105f";
......@@ -282,7 +287,9 @@ test "blake2s224 single" {
282287 try htest.assertEqualHash(Blake2s224, h3, "The quick brown fox jumps over the lazy dog");
283288
284289 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);
286293}
287294
288295test "blake2s224 streaming" {
......@@ -308,29 +315,32 @@ test "blake2s224 streaming" {
308315 h.final(out[0..]);
309316 try htest.assertEqual(h2, out[0..]);
310317
318 const repeat_a_32: [32]u8 = @splat('a');
319 const repeat_b_32: [32]u8 = @splat('b');
320
311321 const h3 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01";
312322
313323 h = Blake2s224.init(.{});
314 h.update("a" ** 32);
315 h.update("b" ** 32);
324 h.update(&repeat_a_32);
325 h.update(&repeat_b_32);
316326 h.final(out[0..]);
317327 try htest.assertEqual(h3, out[0..]);
318328
319329 h = Blake2s224.init(.{});
320 h.update("a" ** 32 ++ "b" ** 32);
330 h.update(&repeat_a_32 ++ &repeat_b_32);
321331 h.final(out[0..]);
322332 try htest.assertEqual(h3, out[0..]);
323333
324334 const h4 = "a4d6a9d253441b80e5dfd60a04db169ffab77aec56a2855c402828c3";
325335
326 h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
327 h.update("a" ** 32);
328 h.update("b" ** 32);
336 h = Blake2s224.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
337 h.update(&repeat_a_32);
338 h.update(&repeat_b_32);
329339 h.final(out[0..]);
330340 try htest.assertEqual(h4, out[0..]);
331341
332 h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 });
333 h.update("a" ** 32 ++ "b" ** 32);
342 h = Blake2s224.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
343 h.update(&repeat_a_32 ++ &repeat_b_32);
334344 h.final(out[0..]);
335345 try htest.assertEqual(h4, out[0..]);
336346}
......@@ -338,7 +348,7 @@ test "blake2s224 streaming" {
338348test "comptime blake2s224" {
339349 comptime {
340350 @setEvalBranchQuota(10000);
341 var block = [_]u8{0} ** Blake2s224.block_length;
351 var block: [Blake2s224.block_length]u8 = @splat(0);
342352 var out: [Blake2s224.digest_length]u8 = undefined;
343353
344354 const h1 = "86b7611563293f8c73627df7a6d6ba25ca0548c2a6481f7d116ee576";
......@@ -364,7 +374,9 @@ test "blake2s256 single" {
364374 try htest.assertEqualHash(Blake2s256, h3, "The quick brown fox jumps over the lazy dog");
365375
366376 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);
368380}
369381
370382test "blake2s256 streaming" {
......@@ -390,16 +402,19 @@ test "blake2s256 streaming" {
390402 h.final(out[0..]);
391403 try htest.assertEqual(h2, out[0..]);
392404
405 const repeat_a_32: [32]u8 = @splat('a');
406 const repeat_b_32: [32]u8 = @splat('b');
407
393408 const h3 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977";
394409
395410 h = Blake2s256.init(.{});
396 h.update("a" ** 32);
397 h.update("b" ** 32);
411 h.update(&repeat_a_32);
412 h.update(&repeat_b_32);
398413 h.final(out[0..]);
399414 try htest.assertEqual(h3, out[0..]);
400415
401416 h = Blake2s256.init(.{});
402 h.update("a" ** 32 ++ "b" ** 32);
417 h.update(&repeat_a_32 ++ &repeat_b_32);
403418 h.final(out[0..]);
404419 try htest.assertEqual(h3, out[0..]);
405420}
......@@ -410,18 +425,21 @@ test "blake2s256 keyed" {
410425 const h1 = "10f918da4d74fab3302e48a5d67d03804b1ec95372a62a0f33b7c9fa28ba1ae6";
411426 const key = "secret_key";
412427
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 });
414432 try htest.assertEqual(h1, out[0..]);
415433
416434 var h = Blake2s256.init(.{ .key = key });
417 h.update("a" ** 64 ++ "b" ** 64);
435 h.update(&repeat_a_64 ++ &repeat_b_64);
418436 h.final(out[0..]);
419437
420438 try htest.assertEqual(h1, out[0..]);
421439
422440 h = Blake2s256.init(.{ .key = key });
423 h.update("a" ** 64);
424 h.update("b" ** 64);
441 h.update(&repeat_a_64);
442 h.update(&repeat_b_64);
425443 h.final(out[0..]);
426444
427445 try htest.assertEqual(h1, out[0..]);
......@@ -430,7 +448,7 @@ test "blake2s256 keyed" {
430448test "comptime blake2s256" {
431449 comptime {
432450 @setEvalBranchQuota(10000);
433 var block = [_]u8{0} ** Blake2s256.block_length;
451 var block: [Blake2s256.block_length]u8 = @splat(0);
434452 var out: [Blake2s256.digest_length]u8 = undefined;
435453
436454 const h1 = "ae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3";
......@@ -623,7 +641,9 @@ test "blake2b160 single" {
623641 try htest.assertEqualHash(Blake2b160, h3, "The quick brown fox jumps over the lazy dog");
624642
625643 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);
627647}
628648
629649test "blake2b160 streaming" {
......@@ -649,36 +669,39 @@ test "blake2b160 streaming" {
649669 h.final(out[0..]);
650670 try htest.assertEqual(h2, out[0..]);
651671
672 const repeat_a_64: [64]u8 = @splat('a');
673 const repeat_b_64: [64]u8 = @splat('b');
674
652675 const h3 = "43758f5de1740f651f1ae39de92260fe8bd5a11f";
653676
654677 h = Blake2b160.init(.{});
655 h.update("a" ** 64 ++ "b" ** 64);
678 h.update(&repeat_a_64 ++ &repeat_b_64);
656679 h.final(out[0..]);
657680 try htest.assertEqual(h3, out[0..]);
658681
659682 h = Blake2b160.init(.{});
660 h.update("a" ** 64);
661 h.update("b" ** 64);
683 h.update(&repeat_a_64);
684 h.update(&repeat_b_64);
662685 h.final(out[0..]);
663686 try htest.assertEqual(h3, out[0..]);
664687
665688 h = Blake2b160.init(.{});
666 h.update("a" ** 64);
667 h.update("b" ** 64);
689 h.update(&repeat_a_64);
690 h.update(&repeat_b_64);
668691 h.final(out[0..]);
669692 try htest.assertEqual(h3, out[0..]);
670693
671694 const h4 = "72328f8a8200663752fc302d372b5dd9b49dd8dc";
672695
673 h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
674 h.update("a" ** 64);
675 h.update("b" ** 64);
696 h = Blake2b160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
697 h.update(&repeat_a_64);
698 h.update(&repeat_b_64);
676699 h.final(out[0..]);
677700 try htest.assertEqual(h4, out[0..]);
678701
679 h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
680 h.update("a" ** 64);
681 h.update("b" ** 64);
702 h = Blake2b160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
703 h.update(&repeat_a_64);
704 h.update(&repeat_b_64);
682705 h.final(out[0..]);
683706 try htest.assertEqual(h4, out[0..]);
684707}
......@@ -686,7 +709,7 @@ test "blake2b160 streaming" {
686709test "comptime blake2b160" {
687710 comptime {
688711 @setEvalBranchQuota(10000);
689 var block = [_]u8{0} ** Blake2b160.block_length;
712 var block: [Blake2b160.block_length]u8 = @splat(0);
690713 var out: [Blake2b160.digest_length]u8 = undefined;
691714
692715 const h1 = "8d26f158f564e3293b42f5e3d34263cb173aa9c9";
......@@ -712,7 +735,9 @@ test "blake2b384 single" {
712735 try htest.assertEqualHash(Blake2b384, h3, "The quick brown fox jumps over the lazy dog");
713736
714737 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);
716741}
717742
718743test "blake2b384 streaming" {
......@@ -738,36 +763,39 @@ test "blake2b384 streaming" {
738763 h.final(out[0..]);
739764 try htest.assertEqual(h2, out[0..]);
740765
766 const repeat_a_64: [64]u8 = @splat('a');
767 const repeat_b_64: [64]u8 = @splat('b');
768
741769 const h3 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c";
742770
743771 h = Blake2b384.init(.{});
744 h.update("a" ** 64 ++ "b" ** 64);
772 h.update(&repeat_a_64 ++ &repeat_b_64);
745773 h.final(out[0..]);
746774 try htest.assertEqual(h3, out[0..]);
747775
748776 h = Blake2b384.init(.{});
749 h.update("a" ** 64);
750 h.update("b" ** 64);
777 h.update(&repeat_a_64);
778 h.update(&repeat_b_64);
751779 h.final(out[0..]);
752780 try htest.assertEqual(h3, out[0..]);
753781
754782 h = Blake2b384.init(.{});
755 h.update("a" ** 64);
756 h.update("b" ** 64);
783 h.update(&repeat_a_64);
784 h.update(&repeat_b_64);
757785 h.final(out[0..]);
758786 try htest.assertEqual(h3, out[0..]);
759787
760788 const h4 = "934c48fcb197031c71f583d92f98703510805e72142e0b46f5752d1e971bc86c355d556035613ff7a4154b4de09dac5c";
761789
762 h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
763 h.update("a" ** 64);
764 h.update("b" ** 64);
790 h = Blake2b384.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
791 h.update(&repeat_a_64);
792 h.update(&repeat_b_64);
765793 h.final(out[0..]);
766794 try htest.assertEqual(h4, out[0..]);
767795
768 h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 });
769 h.update("a" ** 64);
770 h.update("b" ** 64);
796 h = Blake2b384.init(.{ .context = @splat(0x69), .salt = @splat(0x42) });
797 h.update(&repeat_a_64);
798 h.update(&repeat_b_64);
771799 h.final(out[0..]);
772800 try htest.assertEqual(h4, out[0..]);
773801}
......@@ -775,7 +803,7 @@ test "blake2b384 streaming" {
775803test "comptime blake2b384" {
776804 comptime {
777805 @setEvalBranchQuota(20000);
778 var block = [_]u8{0} ** Blake2b384.block_length;
806 var block: [Blake2b384.block_length]u8 = @splat(0);
779807 var out: [Blake2b384.digest_length]u8 = undefined;
780808
781809 const h1 = "e8aa1931ea0422e4446fecdd25c16cf35c240b10cb4659dd5c776eddcaa4d922397a589404b46eb2e53d78132d05fd7d";
......@@ -801,7 +829,9 @@ test "blake2b512 single" {
801829 try htest.assertEqualHash(Blake2b512, h3, "The quick brown fox jumps over the lazy dog");
802830
803831 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);
805835}
806836
807837test "blake2b512 streaming" {
......@@ -827,16 +857,19 @@ test "blake2b512 streaming" {
827857 h.final(out[0..]);
828858 try htest.assertEqual(h2, out[0..]);
829859
860 const repeat_a_64: [64]u8 = @splat('a');
861 const repeat_b_64: [64]u8 = @splat('b');
862
830863 const h3 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920";
831864
832865 h = Blake2b512.init(.{});
833 h.update("a" ** 64 ++ "b" ** 64);
866 h.update(&repeat_a_64 ++ &repeat_b_64);
834867 h.final(out[0..]);
835868 try htest.assertEqual(h3, out[0..]);
836869
837870 h = Blake2b512.init(.{});
838 h.update("a" ** 64);
839 h.update("b" ** 64);
871 h.update(&repeat_a_64);
872 h.update(&repeat_b_64);
840873 h.final(out[0..]);
841874 try htest.assertEqual(h3, out[0..]);
842875}
......@@ -847,18 +880,21 @@ test "blake2b512 keyed" {
847880 const h1 = "8a978060ccaf582f388f37454363071ac9a67e3a704585fd879fb8a419a447e389c7c6de790faa20a7a7dccf197de736bc5b40b98a930b36df5bee7555750c4d";
848881 const key = "secret_key";
849882
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 });
851887 try htest.assertEqual(h1, out[0..]);
852888
853889 var h = Blake2b512.init(.{ .key = key });
854 h.update("a" ** 64 ++ "b" ** 64);
890 h.update(&repeat_a_64 ++ &repeat_b_64);
855891 h.final(out[0..]);
856892
857893 try htest.assertEqual(h1, out[0..]);
858894
859895 h = Blake2b512.init(.{ .key = key });
860 h.update("a" ** 64);
861 h.update("b" ** 64);
896 h.update(&repeat_a_64);
897 h.update(&repeat_b_64);
862898 h.final(out[0..]);
863899
864900 try htest.assertEqual(h1, out[0..]);
......@@ -867,7 +903,7 @@ test "blake2b512 keyed" {
867903test "comptime blake2b512" {
868904 comptime {
869905 @setEvalBranchQuota(12000);
870 var block = [_]u8{0} ** Blake2b512.block_length;
906 var block: [Blake2b512.block_length]u8 = @splat(0);
871907 var out: [Blake2b512.digest_length]u8 = undefined;
872908
873909 const h1 = "865939e120e6805438478841afb739ae4250cf372653078a065cdcfffca4caf798e6d462b65d658fc165782640eded70963449ae1500fb0f24981d7727e22c41";
lib/std/crypto/cbc_mac.zig+1-1
......@@ -21,7 +21,7 @@ pub fn CbcMac(comptime BlockCipher: type) type {
2121 pub const mac_length = block_length;
2222
2323 cipher_ctx: BlockCipherCtx,
24 buf: Block = [_]u8{0} ** block_length,
24 buf: Block = @splat(0),
2525 pos: usize = 0,
2626
2727 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 {
648648 assert(c.len == m.len);
649649 assert(m.len <= 64 * (@as(u39, 1 << 32) - 1));
650650
651 var polyKey = [_]u8{0} ** 32;
651 var polyKey: [32]u8 = @splat(0);
652652 ChaChaIETF(rounds_nb).xor(polyKey[0..], polyKey[0..], 0, k, npub);
653653
654654 ChaChaIETF(rounds_nb).xor(c[0..m.len], m, 1, k, npub);
......@@ -656,13 +656,13 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type {
656656 var mac = Poly1305.init(polyKey[0..]);
657657 mac.update(ad);
658658 if (ad.len % 16 != 0) {
659 const zeros = [_]u8{0} ** 16;
659 const zeros: [16]u8 = @splat(0);
660660 const padding = 16 - (ad.len % 16);
661661 mac.update(zeros[0..padding]);
662662 }
663663 mac.update(c[0..m.len]);
664664 if (m.len % 16 != 0) {
665 const zeros = [_]u8{0} ** 16;
665 const zeros: [16]u8 = @splat(0);
666666 const padding = 16 - (m.len % 16);
667667 mac.update(zeros[0..padding]);
668668 }
......@@ -685,20 +685,20 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type {
685685 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 {
686686 assert(c.len == m.len);
687687
688 var polyKey = [_]u8{0} ** 32;
688 var polyKey: [32]u8 = @splat(0);
689689 ChaChaIETF(rounds_nb).xor(polyKey[0..], polyKey[0..], 0, k, npub);
690690
691691 var mac = Poly1305.init(polyKey[0..]);
692692
693693 mac.update(ad);
694694 if (ad.len % 16 != 0) {
695 const zeros = [_]u8{0} ** 16;
695 const zeros: [16]u8 = @splat(0);
696696 const padding = 16 - (ad.len % 16);
697697 mac.update(zeros[0..padding]);
698698 }
699699 mac.update(c);
700700 if (c.len % 16 != 0) {
701 const zeros = [_]u8{0} ** 16;
701 const zeros: [16]u8 = @splat(0);
702702 const padding = 16 - (c.len % 16);
703703 mac.update(zeros[0..padding]);
704704 }
......@@ -759,8 +759,8 @@ test "AEAD API" {
759759 const ad = "Additional data";
760760
761761 inline for (aeads) |aead| {
762 const key = [_]u8{69} ** aead.key_length;
763 const nonce = [_]u8{42} ** aead.nonce_length;
762 const key: [aead.key_length]u8 = @splat(69);
763 const nonce: [aead.nonce_length]u8 = @splat(42);
764764 var c: [m.len]u8 = undefined;
765765 var tag: [aead.tag_length]u8 = undefined;
766766 var out: [m.len]u8 = undefined;
......@@ -1138,8 +1138,8 @@ test "open" {
11381138}
11391139
11401140test "xchacha20" {
1141 const key = [_]u8{69} ** 32;
1142 const nonce = [_]u8{42} ** 24;
1141 const key: [32]u8 = @splat(69);
1142 const nonce: [24]u8 = @splat(42);
11431143 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.";
11441144 {
11451145 var c: [m.len]u8 = undefined;
lib/std/crypto/cmac.zig+2-2
......@@ -20,7 +20,7 @@ pub fn Cmac(comptime BlockCipher: type) type {
2020 cipher_ctx: BlockCipherCtx,
2121 k1: Block,
2222 k2: Block,
23 buf: Block = [_]u8{0} ** block_length,
23 buf: Block = @splat(0),
2424 pos: usize = 0,
2525
2626 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 {
3131
3232 pub fn init(key: *const [key_length]u8) Self {
3333 const cipher_ctx = BlockCipher.initEnc(key.*);
34 const zeros = [_]u8{0} ** block_length;
34 const zeros: [block_length]u8 = @splat(0);
3535 var k1: Block = undefined;
3636 cipher_ctx.encrypt(&k1, &zeros);
3737 k1 = double(k1);
lib/std/crypto/codecs/asn1.zig+1-1
......@@ -233,7 +233,7 @@ test Element {
233233 .slice = Element.Slice{ .start = 2, .end = short_form.len },
234234 }, Element.decode(&short_form, 0));
235235
236 const long_form = [_]u8{ 0x30, 129, 129 } ++ [_]u8{0} ** 129;
236 const long_form = [_]u8{ 0x30, 129, 129 } ++ @as([129]u8, @splat(0));
237237 try std.testing.expectEqual(Element{
238238 .tag = Tag.universal(.sequence, true),
239239 .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 {
212212 fn finalizePrehashed(self: *Signer, msg_hash: [Hash.digest_length]u8) (IdentityElementError || NonCanonicalError)!Signature {
213213 const scalar_encoded_length = Curve.scalar.encoded_length;
214214 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;
216216
217217 std.debug.assert(h.len >= scalar_encoded_length);
218218 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 {
275275 fn verifyPrehashed(self: *Verifier, msg_hash: [Hash.digest_length]u8) VerifyError!void {
276276 const ht = Curve.scalar.encoded_length;
277277 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;
279279
280280 const z = reduceToScalar(ht, h[0..ht].*);
281281 if (z.isZero()) {
......@@ -316,8 +316,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
316316 ///
317317 /// Except in tests, applications should generally call `generate()` instead of this function.
318318 pub fn generateDeterministic(seed: [seed_length]u8) IdentityElementError!KeyPair {
319 const h = [_]u8{0x00} ** Hash.digest_length;
320 const k0 = [_]u8{0x01} ** SecretKey.encoded_length;
319 const h: [Hash.digest_length]u8 = @splat(0x00);
320 const k0: [SecretKey.encoded_length]u8 = @splat(0x01);
321321 const secret_key = deterministicScalar(h, k0, seed).toBytes(.big);
322322 return fromSecretKey(SecretKey{ .bytes = secret_key });
323323 }
......@@ -367,11 +367,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
367367 // Reduce the coordinate of a field element to the scalar field.
368368 fn reduceToScalar(comptime unreduced_len: usize, s: [unreduced_len]u8) Curve.scalar.Scalar {
369369 if (unreduced_len >= 48) {
370 var xs = [_]u8{0} ** 64;
370 var xs: [64]u8 = @splat(0);
371371 @memcpy(xs[xs.len - s.len ..], s[0..]);
372372 return Curve.scalar.Scalar.fromBytes64(xs, .big);
373373 }
374 var xs = [_]u8{0} ** 48;
374 var xs: [48]u8 = @splat(0);
375375 @memcpy(xs[xs.len - s.len ..], s[0..]);
376376 return Curve.scalar.Scalar.fromBytes48(xs, .big);
377377 }
......@@ -379,9 +379,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type {
379379 // Create a deterministic scalar according to a secret key and optional noise.
380380 // This uses the overly conservative scheme from the "Deterministic ECDSA and EdDSA Signatures with Additional Randomness" draft.
381381 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;
383 var m = [_]u8{0x00} ** (h.len + 1 + noise_length + secret_key.len + h.len);
384 var t = [_]u8{0x00} ** Curve.scalar.encoded_length;
382 var k: [h.len]u8 = @splat(0);
383 var m: [h.len + 1 + noise_length + secret_key.len + h.len]u8 = @splat(0);
384 var t: [Curve.scalar.encoded_length]u8 = @splat(0);
385385 const m_v = m[0..h.len];
386386 const m_i = &m[m_v.len];
387387 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 {
9696
9797 /// The zero integer.
9898 pub const zero: Self = .{
99 .limbs_buffer = [1]Limb{0} ** max_limbs_count,
99 .limbs_buffer = @splat(0),
100100 .limbs_len = max_limbs_count,
101101 };
102102
......@@ -738,7 +738,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
738738 }
739739 } else {
740740 // 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));
742742 if (!x.montgomery) {
743743 self.toMontgomery(&pc[0]) catch unreachable;
744744 }
lib/std/crypto/ghash_polyval.zig+4-4
......@@ -417,8 +417,8 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type {
417417const htest = @import("test.zig");
418418
419419test "ghash" {
420 const key = [_]u8{0x42} ** 16;
421 const m = [_]u8{0x69} ** 256;
420 const key: [16]u8 = @splat(0x42);
421 const m: [256]u8 = @splat(0x69);
422422
423423 var st = Ghash.init(&key);
424424 st.update(&m);
......@@ -467,8 +467,8 @@ test "ghash2" {
467467}
468468
469469test "polyval" {
470 const key = [_]u8{0x42} ** 16;
471 const m = [_]u8{0x69} ** 256;
470 const key: [16]u8 = @splat(0x42);
471 const m: [256]u8 = @splat(0x69);
472472
473473 var st = Polyval.init(&key);
474474 st.update(&m);
lib/std/crypto/hkdf.zig+1-1
......@@ -72,7 +72,7 @@ pub fn Hkdf(comptime Hmac: type) type {
7272const htest = @import("test.zig");
7373
7474test "Hkdf" {
75 const ikm = [_]u8{0x0b} ** 22;
75 const ikm: [22]u8 = @splat(0x0b);
7676 const salt = [_]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c };
7777 const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 };
7878 const kdf = HkdfSha256;
lib/std/crypto/isap.zig+3-3
......@@ -42,7 +42,7 @@ pub const IsapA128A = struct {
4242 break;
4343 }
4444 } else {
45 var padded = [_]u8{0} ** 8;
45 var padded: [8]u8 = @splat(0);
4646 @memcpy(padded[0..left], m[i..]);
4747 padded[left] = 0x80;
4848 isap.st.addBytes(&padded);
......@@ -169,8 +169,8 @@ pub const IsapA128A = struct {
169169};
170170
171171test "ISAP" {
172 const k = [_]u8{1} ** 16;
173 const n = [_]u8{2} ** 16;
172 const k: [16]u8 = @splat(1);
173 const n: [16]u8 = @splat(2);
174174 var tag: [16]u8 = undefined;
175175 const ad = "ad";
176176 var msg = "test";
lib/std/crypto/kangarootwelve.zig+1-1
......@@ -881,7 +881,7 @@ fn ktMultiThreaded(
881881 // Buffer for out-of-order results (select_buf slots get reused)
882882 const pending_cv_buf = try allocator.alloc([leaves_per_batch * cv_size]u8, max_concurrent);
883883 defer allocator.free(pending_cv_buf);
884 var pending_cv_lens: [256]usize = .{0} ** 256;
884 var pending_cv_lens: [256]usize = @splat(0);
885885
886886 var select_outstanding: usize = 0;
887887 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 {
4040 break :rc rc;
4141 };
4242
43 st: Block = [_]T{0} ** 25,
43 st: Block = @splat(0),
4444
4545 /// Initialize the state from a slice of bytes.
4646 pub fn init(bytes: [block_bytes]u8) Self {
......@@ -70,7 +70,7 @@ pub fn KeccakF(comptime f: u11) type {
7070 self.st[i / @sizeOf(T)] = mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little);
7171 }
7272 if (i < bytes.len) {
73 var padded = [_]u8{0} ** @sizeOf(T);
73 var padded: [@sizeOf(T)]u8 = @splat(0);
7474 @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
7575 self.st[i / @sizeOf(T)] = mem.readInt(T, padded[0..], .little);
7676 }
......@@ -89,7 +89,7 @@ pub fn KeccakF(comptime f: u11) type {
8989 self.st[i / @sizeOf(T)] ^= mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little);
9090 }
9191 if (i < bytes.len) {
92 var padded = [_]u8{0} ** @sizeOf(T);
92 var padded: [@sizeOf(T)]u8 = @splat(0);
9393 @memcpy(padded[0 .. bytes.len - i], bytes[i..]);
9494 self.st[i / @sizeOf(T)] ^= mem.readInt(T, padded[0..], .little);
9595 }
......@@ -102,7 +102,7 @@ pub fn KeccakF(comptime f: u11) type {
102102 mem.writeInt(T, out[i..][0..@sizeOf(T)], self.st[i / @sizeOf(T)], .little);
103103 }
104104 if (i < out.len) {
105 var padded = [_]u8{0} ** @sizeOf(T);
105 var padded: [@sizeOf(T)]u8 = @splat(0);
106106 mem.writeInt(T, padded[0..], self.st[i / @sizeOf(T)], .little);
107107 @memcpy(out[i..], padded[0 .. out.len - i]);
108108 }
......@@ -118,7 +118,7 @@ pub fn KeccakF(comptime f: u11) type {
118118 mem.writeInt(T, out[i..][0..@sizeOf(T)], x, native_endian);
119119 }
120120 if (i < in.len) {
121 var padded = [_]u8{0} ** @sizeOf(T);
121 var padded: [@sizeOf(T)]u8 = @splat(0);
122122 @memcpy(padded[0 .. in.len - i], in[i..]);
123123 const x = mem.readInt(T, &padded, native_endian) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]);
124124 mem.writeInt(T, &padded, x, native_endian);
......@@ -140,7 +140,7 @@ pub fn KeccakF(comptime f: u11) type {
140140 const st = &self.st;
141141
142142 // theta
143 var t = [_]T{0} ** 5;
143 var t: [5]T = @splat(0);
144144 inline for (0..5) |i| {
145145 inline for (0..5) |j| {
146146 t[i] ^= st[j * 5 + i];
......@@ -382,7 +382,7 @@ test "Keccak-f800" {
382382}
383383
384384test "squeeze" {
385 var st = State(800, 256, 22).init([_]u8{0x80} ** 100, 0x01);
385 var st: State(800, 256, 22) = .init(@splat(0x80), 0x01);
386386
387387 var out0: [15]u8 = undefined;
388388 var out1: [out0.len]u8 = undefined;
lib/std/crypto/md5.zig+1-1
......@@ -272,7 +272,7 @@ test "streaming" {
272272}
273273
274274test "aligned final" {
275 var block = [_]u8{0} ** Md5.block_length;
275 const block: [Md5.block_length]u8 = @splat(0);
276276 var out: [Md5.digest_length]u8 = undefined;
277277
278278 var h = Md5.init(.{});
lib/std/crypto/ml_dsa.zig+33-33
......@@ -156,7 +156,7 @@ const Params = struct {
156156const Poly = struct {
157157 cs: [N]u32,
158158
159 const zero: Poly = .{ .cs = .{0} ** N };
159 const zero: Poly = .{ .cs = @splat(0) };
160160
161161 // Add two polynomials (no normalization)
162162 fn add(a: Poly, b: Poly) Poly {
......@@ -302,7 +302,7 @@ fn PolyVec(comptime len: u8) type {
302302 ps: [len]Poly,
303303
304304 const Self = @This();
305 const zero: Self = .{ .ps = .{Poly.zero} ** len };
305 const zero: Self = .{ .ps = @splat(.zero) };
306306
307307 /// Apply a unary operation to each polynomial in the vector
308308 fn map(v: Self, comptime op: fn (Poly) Poly) Self {
......@@ -581,7 +581,7 @@ fn PolyVec(comptime len: u8) type {
581581
582582 /// Unpack hints from bytes
583583 fn unpackHint(comptime omega: u16, buf: []const u8) ?Self {
584 var result: Self = .{ .ps = .{Poly.zero} ** len };
584 var result: Self = .{ .ps = @splat(.zero) };
585585 var prev_sop: u8 = 0; // previous switch-over-point
586586
587587 for (0..len) |i| {
......@@ -1839,7 +1839,7 @@ fn MLDSAImpl(comptime p: Params) type {
18391839 return Signer{
18401840 .h = h,
18411841 .secret_key = secret_key,
1842 .rnd = noise orelse .{0} ** 32,
1842 .rnd = noise orelse @splat(0),
18431843 };
18441844 }
18451845
......@@ -2324,7 +2324,7 @@ test "decompose correctness for ML-DSA-87" {
23242324
23252325test "polyDeriveUniform deterministic" {
23262326 // 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));
23282328 const nonce: u16 = 0;
23292329
23302330 const p1 = polyDeriveUniform(&seed, nonce);
......@@ -2343,7 +2343,7 @@ test "polyDeriveUniform deterministic" {
23432343
23442344test "polyDeriveUniform different nonces" {
23452345 // 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));
23472347
23482348 const p1 = polyDeriveUniform(&seed, 0);
23492349 const p2 = polyDeriveUniform(&seed, 1);
......@@ -2361,7 +2361,7 @@ test "polyDeriveUniform different nonces" {
23612361
23622362test "expandS with eta=2" {
23632363 // Test eta=2 sampling
2364 const seed: [64]u8 = .{0x02} ++ .{0x00} ** 63;
2364 const seed: [64]u8 = .{0x02} ++ @as([63]u8, @splat(0x00));
23652365 const nonce: u16 = 0;
23662366
23672367 const p = expandS(2, &seed, nonce);
......@@ -2378,7 +2378,7 @@ test "expandS with eta=2" {
23782378
23792379test "expandS with eta=4" {
23802380 // Test eta=4 sampling
2381 const seed: [64]u8 = .{0x03} ++ .{0x00} ** 63;
2381 const seed: [64]u8 = .{0x03} ++ @as([63]u8, @splat(0x00));
23822382 const nonce: u16 = 0;
23832383
23842384 const p = expandS(4, &seed, nonce);
......@@ -2395,7 +2395,7 @@ test "expandS with eta=4" {
23952395test "sampleInBall has correct weight" {
23962396 // Test that ball polynomial has exactly tau non-zero coefficients
23972397 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));
23992399
24002400 const p = sampleInBall(tau, &seed);
24012401
......@@ -2415,7 +2415,7 @@ test "sampleInBall has correct weight" {
24152415test "sampleInBall deterministic" {
24162416 // Test that ball sampling is deterministic
24172417 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));
24192419
24202420 const p1 = sampleInBall(tau, &seed);
24212421 const p2 = sampleInBall(tau, &seed);
......@@ -2851,13 +2851,13 @@ test "Key generation basic - all variants" {
28512851 .{ .variant = MLDSA65, .seed_byte = 0x65 },
28522852 .{ .variant = MLDSA87, .seed_byte = 0x87 },
28532853 }) |config| {
2854 const seed = [_]u8{config.seed_byte} ** 32;
2854 const seed: [32]u8 = @splat(config.seed_byte);
28552855 try testKeyGenerationBasic(config.variant, seed);
28562856 }
28572857}
28582858
28592859test "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));
28612861
28622862 // Generate two key pairs from the same seed
28632863 const result1 = MLDSA44.newKeyFromSeed(&seed);
......@@ -2874,7 +2874,7 @@ test "Key generation determinism" {
28742874}
28752875
28762876test "Private key can compute public key" {
2877 const seed = [_]u8{0xFF} ** 32;
2877 const seed: [32]u8 = @splat(0xFF);
28782878 const result = MLDSA44.newKeyFromSeed(&seed);
28792879 const pk = result.pk;
28802880 const sk = result.sk;
......@@ -2907,13 +2907,13 @@ test "Sign and verify - all variants" {
29072907 .{ .variant = MLDSA65, .seed_byte = 0x65, .message = "Hello, ML-DSA-65!" },
29082908 .{ .variant = MLDSA87, .seed_byte = 0x87, .message = "Hello, ML-DSA-87!" },
29092909 }) |config| {
2910 const seed = [_]u8{config.seed_byte} ** 32;
2910 const seed: [32]u8 = @splat(config.seed_byte);
29112911 try testSignAndVerify(config.variant, seed, config.message);
29122912 }
29132913}
29142914
29152915test "Invalid signature rejection" {
2916 const seed = [_]u8{0x99} ** 32;
2916 const seed: [32]u8 = @splat(0x99);
29172917 const result = MLDSA44.newKeyFromSeed(&seed);
29182918 const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk);
29192919
......@@ -2934,7 +2934,7 @@ test "Invalid signature rejection" {
29342934}
29352935
29362936test "Context string support" {
2937 const seed = [_]u8{0xAA} ** 32;
2937 const seed: [32]u8 = @splat(0xAA);
29382938 const result = MLDSA44.newKeyFromSeed(&seed);
29392939 const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk);
29402940
......@@ -2964,17 +2964,17 @@ test "Context string support" {
29642964 try testing.expectError(error.SignatureVerificationFailed, sig2.verifyWithContext(message, kp.public_key, context1));
29652965
29662966 // Test maximum context length (255 bytes)
2967 const max_context = [_]u8{0xBB} ** 255;
2967 const max_context: [255]u8 = @splat(0xBB);
29682968 const sig3 = try kp.signWithContext(message, null, &max_context);
29692969 try sig3.verifyWithContext(message, kp.public_key, &max_context);
29702970
29712971 // 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);
29732973 try testing.expectError(error.ContextTooLong, kp.signWithContext(message, null, &too_long_context));
29742974}
29752975
29762976test "Context string with streaming API" {
2977 const seed = [_]u8{0xDD} ** 32;
2977 const seed: [32]u8 = @splat(0xDD);
29782978 const result = MLDSA44.newKeyFromSeed(&seed);
29792979 const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk);
29802980
......@@ -3002,12 +3002,12 @@ test "Context string with streaming API" {
30023002}
30033003
30043004test "Signature determinism (same rnd)" {
3005 const seed = [_]u8{0x11} ** 32;
3005 const seed: [32]u8 = @splat(0x11);
30063006 const result = MLDSA44.newKeyFromSeed(&seed);
30073007 const sk = result.sk;
30083008
30093009 const message = "Deterministic test";
3010 const rnd = [_]u8{0x22} ** 32;
3010 const rnd: [32]u8 = @splat(0x22);
30113011
30123012 // Sign twice with same randomness using streaming API
30133013 var st1 = try sk.signer(rnd);
......@@ -3023,7 +3023,7 @@ test "Signature determinism (same rnd)" {
30233023}
30243024
30253025test "Signature toBytes/fromBytes roundtrip" {
3026 const seed = [_]u8{0x33} ** 32;
3026 const seed: [32]u8 = @splat(0x33);
30273027 const result = MLDSA44.newKeyFromSeed(&seed);
30283028 const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk);
30293029
......@@ -3043,7 +3043,7 @@ test "Signature toBytes/fromBytes roundtrip" {
30433043}
30443044
30453045test "Empty message signing" {
3046 const seed = [_]u8{0x44} ** 32;
3046 const seed: [32]u8 = @splat(0x44);
30473047 const result = MLDSA44.newKeyFromSeed(&seed);
30483048 const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk);
30493049
......@@ -3057,12 +3057,12 @@ test "Empty message signing" {
30573057}
30583058
30593059test "Long message signing" {
3060 const seed = [_]u8{0x55} ** 32;
3060 const seed: [32]u8 = @splat(0x55);
30613061 const result = MLDSA44.newKeyFromSeed(&seed);
30623062 const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk);
30633063
30643064 // Create a long message (1KB)
3065 const long_message = [_]u8{0xAB} ** 1024;
3065 const long_message: [1024]u8 = @splat(0xAB);
30663066
30673067 // Sign long message
30683068 const sig = try kp.sign(&long_message, null);
......@@ -3209,7 +3209,7 @@ test "KeyPair API - generate and sign" {
32093209
32103210test "KeyPair API - generateDeterministic" {
32113211 // Test deterministic key generation
3212 const seed = [_]u8{42} ** 32;
3212 const seed: [32]u8 = @splat(42);
32133213 const kp1 = try MLDSA44.KeyPair.generateDeterministic(seed);
32143214 const kp2 = try MLDSA44.KeyPair.generateDeterministic(seed);
32153215
......@@ -3240,7 +3240,7 @@ test "Signature verification with noise" {
32403240 const msg = "Message to be signed with randomness";
32413241
32423242 // 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));
32443244
32453245 // Sign with noise
32463246 const sig = try kp.sign(msg, noise);
......@@ -3262,7 +3262,7 @@ test "Signature verification failure" {
32623262}
32633263
32643264test "Streaming API - sign and verify" {
3265 const seed = [_]u8{0x55} ** 32;
3265 const seed: [32]u8 = @splat(0x55);
32663266 const kp = try MLDSA44.KeyPair.generateDeterministic(seed);
32673267
32683268 const msg = "Test message for streaming API";
......@@ -3279,7 +3279,7 @@ test "Streaming API - sign and verify" {
32793279}
32803280
32813281test "Streaming API - chunked message" {
3282 const seed = [_]u8{0x66} ** 32;
3282 const seed: [32]u8 = @splat(0x66);
32833283 const kp = try MLDSA44.KeyPair.generateDeterministic(seed);
32843284
32853285 // Create a message in chunks
......@@ -3313,7 +3313,7 @@ test "Streaming API - chunked message" {
33133313}
33143314
33153315test "Streaming API - large message" {
3316 const seed = [_]u8{0x77} ** 32;
3316 const seed: [32]u8 = @splat(0x77);
33173317 const kp = try MLDSA44.KeyPair.generateDeterministic(seed);
33183318
33193319 // Create a large message (1MB)
......@@ -3344,7 +3344,7 @@ test "Streaming API - all parameter sets" {
33443344
33453345 // ML-DSA-44
33463346 {
3347 const seed = [_]u8{0x44} ** 32;
3347 const seed: [32]u8 = @splat(0x44);
33483348 const kp = try MLDSA44.KeyPair.generateDeterministic(seed);
33493349 var signer = try kp.signer(null);
33503350 signer.update(test_msg);
......@@ -3356,7 +3356,7 @@ test "Streaming API - all parameter sets" {
33563356
33573357 // ML-DSA-65
33583358 {
3359 const seed = [_]u8{0x65} ** 32;
3359 const seed: [32]u8 = @splat(0x65);
33603360 const kp = try MLDSA65.KeyPair.generateDeterministic(seed);
33613361 var signer = try kp.signer(null);
33623362 signer.update(test_msg);
......@@ -3368,7 +3368,7 @@ test "Streaming API - all parameter sets" {
33683368
33693369 // ML-DSA-87
33703370 {
3371 const seed = [_]u8{0x87} ** 32;
3371 const seed: [32]u8 = @splat(0x87);
33723372 const kp = try MLDSA87.KeyPair.generateDeterministic(seed);
33733373 var signer = try kp.signer(null);
33743374 signer.update(test_msg);
lib/std/crypto/ml_kem.zig+4-4
......@@ -615,7 +615,7 @@ const inv_ntt_reductions = [_]i16{
615615test "invNTTReductions bounds" {
616616 // Checks whether the reductions proposed by invNTTReductions
617617 // 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
619619
620620 var r: usize = 0;
621621 var layer: math.Log2Int(usize) = 1;
......@@ -797,7 +797,7 @@ const Poly = struct {
797797 cs: [N]i16,
798798
799799 const encoded_length = N / 2 * 3;
800 const zero: Poly = .{ .cs = .{0} ** N };
800 const zero: Poly = .{ .cs = @splat(0) };
801801
802802 // Add two polynomials (coefficients not normalized)
803803 fn add(a: Poly, b: Poly) Poly {
......@@ -1011,7 +1011,7 @@ const Poly = struct {
10111011
10121012 const out_length: usize = comptime @divTrunc(N * d, 8);
10131013 comptime assert(out_length * 8 == d * N);
1014 var out = [_]u8{0} ** out_length;
1014 var out: [out_length]u8 = @splat(0);
10151015
10161016 while (in_off < N) {
10171017 // First we compress into in.
......@@ -1754,7 +1754,7 @@ const NistDRBG = struct {
17541754 }
17551755
17561756 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) };
17581758 ret.update(seed);
17591759 return ret;
17601760 }
lib/std/crypto/modes.zig+1-1
......@@ -183,7 +183,7 @@ test "ctr mode" {
183183 // Test 9: Large input (> 2*block_length, 100 bytes)
184184 {
185185 // Create a 100-byte input by extending with zeros
186 var in: [100]u8 = [_]u8{0} ** 100;
186 var in: [100]u8 = @splat(0);
187187 @memcpy(in[0..64], &[_]u8{
188188 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
189189 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" {
206206 const c = 16777216;
207207 const dk_len = 20;
208208
209 var dk = [_]u8{0} ** dk_len;
209 var dk: [dk_len]u8 = @splat(0);
210210
211211 try pbkdf2(&dk, p, s, c, HmacSha1);
212212
lib/std/crypto/pcurves/p256/scalar.zig+3-3
......@@ -196,19 +196,19 @@ const ScalarDouble = struct {
196196 }
197197 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
198198 {
199 var b = [_]u8{0} ** encoded_length;
199 var b: [encoded_length]u8 = @splat(0);
200200 const len = @min(s.len, 24);
201201 b[0..len].* = s[0..len].*;
202202 t.x1 = Fe.fromBytes(b, .little) catch unreachable;
203203 }
204204 if (s_.len >= 24) {
205 var b = [_]u8{0} ** encoded_length;
205 var b: [encoded_length]u8 = @splat(0);
206206 const len = @min(s.len - 24, 24);
207207 b[0..len].* = s[24..][0..len].*;
208208 t.x2 = Fe.fromBytes(b, .little) catch unreachable;
209209 }
210210 if (s_.len >= 48) {
211 var b = [_]u8{0} ** encoded_length;
211 var b: [encoded_length]u8 = @splat(0);
212212 const len = s.len - 48;
213213 b[0..len].* = s[48..][0..len].*;
214214 t.x3 = Fe.fromBytes(b, .little) catch unreachable;
lib/std/crypto/pcurves/p384/scalar.zig+2-2
......@@ -184,13 +184,13 @@ const ScalarDouble = struct {
184184 }
185185 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero };
186186 {
187 var b = [_]u8{0} ** encoded_length;
187 var b: [encoded_length]u8 = @splat(0);
188188 const len = @min(s.len, 32);
189189 b[0..len].* = s[0..len].*;
190190 t.x1 = Fe.fromBytes(b, .little) catch unreachable;
191191 }
192192 if (s_.len >= 32) {
193 var b = [_]u8{0} ** encoded_length;
193 var b: [encoded_length]u8 = @splat(0);
194194 const len = @min(s.len - 32, 32);
195195 b[0..len].* = s[32..][0..len].*;
196196 t.x2 = Fe.fromBytes(b, .little) catch unreachable;
lib/std/crypto/pcurves/secp256k1/scalar.zig+3-3
......@@ -196,19 +196,19 @@ const ScalarDouble = struct {
196196 }
197197 var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero };
198198 {
199 var b = [_]u8{0} ** encoded_length;
199 var b: [encoded_length]u8 = @splat(0);
200200 const len = @min(s.len, 24);
201201 b[0..len].* = s[0..len].*;
202202 t.x1 = Fe.fromBytes(b, .little) catch unreachable;
203203 }
204204 if (s_.len >= 24) {
205 var b = [_]u8{0} ** encoded_length;
205 var b: [encoded_length]u8 = @splat(0);
206206 const len = @min(s.len - 24, 24);
207207 b[0..len].* = s[24..][0..len].*;
208208 t.x2 = Fe.fromBytes(b, .little) catch unreachable;
209209 }
210210 if (s_.len >= 48) {
211 var b = [_]u8{0} ** encoded_length;
211 var b: [encoded_length]u8 = @splat(0);
212212 const len = s.len - 48;
213213 b[0..len].* = s[48..][0..len].*;
214214 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)" {
9797}
9898
9999test "p256 field element non-canonical encoding" {
100 const s = [_]u8{0xff} ** 32;
100 const s: [32]u8 = @splat(0xff);
101101 try testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .little));
102102}
103103
......@@ -110,8 +110,8 @@ test "p256 neutral element decoding" {
110110test "p256 double base multiplication" {
111111 const p1 = P256.basePoint;
112112 const p2 = P256.basePoint.dbl();
113 const s1 = [_]u8{0x01} ** 32;
114 const s2 = [_]u8{0x02} ** 32;
113 const s1: [32]u8 = @splat(0x01);
114 const s2: [32]u8 = @splat(0x02);
115115 const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little);
116116 const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little));
117117 try testing.expect(pr1.equivalent(pr2));
......@@ -120,8 +120,8 @@ test "p256 double base multiplication" {
120120test "p256 double base multiplication with large scalars" {
121121 const p1 = P256.basePoint;
122122 const p2 = P256.basePoint.dbl();
123 const s1 = [_]u8{0xee} ** 32;
124 const s2 = [_]u8{0xdd} ** 32;
123 const s1: [32]u8 = @splat(0xee);
124 const s2: [32]u8 = @splat(0xdd);
125125 const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little);
126126 const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little));
127127 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)" {
100100}
101101
102102test "p384 field element non-canonical encoding" {
103 const s = [_]u8{0xff} ** 48;
103 const s: [48]u8 = @splat(0xff);
104104 try testing.expectError(error.NonCanonical, P384.Fe.fromBytes(s, .little));
105105}
106106
......@@ -113,8 +113,8 @@ test "p384 neutral element decoding" {
113113test "p384 double base multiplication" {
114114 const p1 = P384.basePoint;
115115 const p2 = P384.basePoint.dbl();
116 const s1 = [_]u8{0x01} ** 48;
117 const s2 = [_]u8{0x02} ** 48;
116 const s1: [48]u8 = @splat(0x01);
117 const s2: [48]u8 = @splat(0x02);
118118 const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .little);
119119 const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little));
120120 try testing.expect(pr1.equivalent(pr2));
......@@ -123,8 +123,8 @@ test "p384 double base multiplication" {
123123test "p384 double base multiplication with large scalars" {
124124 const p1 = P384.basePoint;
125125 const p2 = P384.basePoint.dbl();
126 const s1 = [_]u8{0xee} ** 48;
127 const s2 = [_]u8{0xdd} ** 48;
126 const s1: [48]u8 = @splat(0xee);
127 const s2: [48]u8 = @splat(0xdd);
128128 const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .little);
129129 const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little));
130130 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)" {
109109}
110110
111111test "secp256k1 field element non-canonical encoding" {
112 const s = [_]u8{0xff} ** 32;
112 const s: [32]u8 = @splat(0xff);
113113 try testing.expectError(error.NonCanonical, Secp256k1.Fe.fromBytes(s, .little));
114114}
115115
......@@ -122,8 +122,8 @@ test "secp256k1 neutral element decoding" {
122122test "secp256k1 double base multiplication" {
123123 const p1 = Secp256k1.basePoint;
124124 const p2 = Secp256k1.basePoint.dbl();
125 const s1 = [_]u8{0x01} ** 32;
126 const s2 = [_]u8{0x02} ** 32;
125 const s1: [32]u8 = @splat(0x01);
126 const s2: [32]u8 = @splat(0x02);
127127 const pr1 = try Secp256k1.mulDoubleBasePublic(p1, s1, p2, s2, .little);
128128 const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little));
129129 try testing.expect(pr1.equivalent(pr2));
lib/std/crypto/salsa20.zig+8-8
......@@ -384,7 +384,7 @@ pub const XSalsa20Poly1305 = struct {
384384 pub fn encrypt(c: []u8, tag: *[tag_length]u8, m: []const u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) void {
385385 debug.assert(c.len == m.len);
386386 const extended = extend(rounds, k, npub);
387 var block0 = [_]u8{0} ** 64;
387 var block0: [64]u8 = @splat(0);
388388 const mlen0 = @min(32, m.len);
389389 @memcpy(block0[32..][0..mlen0], m[0..mlen0]);
390390 Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);
......@@ -408,7 +408,7 @@ pub const XSalsa20Poly1305 = struct {
408408 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 {
409409 debug.assert(c.len == m.len);
410410 const extended = extend(rounds, k, npub);
411 var block0 = [_]u8{0} ** 64;
411 var block0: [64]u8 = @splat(0);
412412 const mlen0 = @min(32, c.len);
413413 @memcpy(block0[32..][0..mlen0], c[0..mlen0]);
414414 Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce);
......@@ -489,7 +489,7 @@ pub const Box = struct {
489489 /// Compute a secret suitable for `secretbox` given a recipient's public key and a sender's secret key.
490490 pub fn createSharedSecret(public_key: [public_length]u8, secret_key: [secret_length]u8) (IdentityElementError || WeakPublicKeyError)![shared_length]u8 {
491491 const p = try X25519.scalarmult(secret_key, public_key);
492 const zero = [_]u8{0} ** 16;
492 const zero: [16]u8 = @splat(0);
493493 return SalsaImpl(20).hsalsa(zero, p);
494494 }
495495
......@@ -559,15 +559,15 @@ const htest = @import("test.zig");
559559test "(x)salsa20" {
560560 if (builtin.cpu.has(.riscv, .v) and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/24299
561561
562 const key = [_]u8{0x69} ** 32;
563 const nonce = [_]u8{0x42} ** 8;
564 const msg = [_]u8{0} ** 20;
562 const key: [32]u8 = @splat(0x69);
563 const nonce: [8]u8 = @splat(0x42);
564 const msg: [20]u8 = @splat(0);
565565 var c: [msg.len]u8 = undefined;
566566
567567 Salsa20.xor(&c, msg[0..], 0, key, nonce);
568568 try htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]);
569569
570 const extended_nonce = [_]u8{0x42} ** 24;
570 const extended_nonce: [24]u8 = @splat(0x42);
571571 XSalsa20.xor(&c, msg[0..], 0, key, extended_nonce);
572572 try htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]);
573573}
......@@ -637,7 +637,7 @@ test "xsalsa20poly1305 sealedbox" {
637637test "secretbox twoblocks" {
638638 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 };
639639 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');
641641 var ciphertext: [msg.len + SecretBox.tag_length]u8 = undefined;
642642 SecretBox.seal(&ciphertext, &msg, nonce, key);
643643 try htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext);
lib/std/crypto/sha2.zig+2-2
......@@ -461,7 +461,7 @@ test "sha256 streaming" {
461461}
462462
463463test "sha256 aligned final" {
464 var block = [_]u8{0} ** Sha256.block_length;
464 var block: [Sha256.block_length]u8 = @splat(0);
465465 var out: [Sha256.digest_length]u8 = undefined;
466466
467467 var h = Sha256.init(.{});
......@@ -833,7 +833,7 @@ test "sha512 streaming" {
833833}
834834
835835test "sha512 aligned final" {
836 var block = [_]u8{0} ** Sha512.block_length;
836 var block: [Sha512.block_length]u8 = @splat(0);
837837 var out: [Sha512.digest_length]u8 = undefined;
838838
839839 var h = Sha512.init(.{});
lib/std/crypto/sha3.zig+2-2
......@@ -543,7 +543,7 @@ test "sha3-256 streaming" {
543543}
544544
545545test "sha3-256 aligned final" {
546 var block = [_]u8{0} ** Sha3_256.block_length;
546 var block: [Sha3_256.block_length]u8 = @splat(0);
547547 var out: [Sha3_256.digest_length]u8 = undefined;
548548
549549 var h = Sha3_256.init(.{});
......@@ -616,7 +616,7 @@ test "sha3-512 streaming" {
616616}
617617
618618test "sha3-512 aligned final" {
619 var block = [_]u8{0} ** Sha3_512.block_length;
619 var block: [Sha3_512.block_length]u8 = @splat(0);
620620 var out: [Sha3_512.digest_length]u8 = undefined;
621621
622622 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
9191
9292 self.msg_len +%= @as(u8, @truncate(b.len));
9393
94 var buf = [_]u8{0} ** 8;
94 var buf: [8]u8 = @splat(0);
9595 @memcpy(buf[0..b.len], b);
9696 buf[7] = self.msg_len;
9797 self.round(buf);
lib/std/crypto/timing_safe.zig+5-4
......@@ -207,8 +207,8 @@ test "eql (vectors)" {
207207
208208test compare {
209209 const expectEqual = std.testing.expectEqual;
210 var a = [_]u8{10} ** 32;
211 var b = [_]u8{10} ** 32;
210 var a: [32]u8 = @splat(10);
211 var b: [32]u8 = @splat(10);
212212 try expectEqual(compare(u8, &a, &b, .big), .eq);
213213 try expectEqual(compare(u8, &a, &b, .little), .eq);
214214 a[31] = 1;
......@@ -228,7 +228,7 @@ test "add and sub" {
228228 var a: [len]u8 = undefined;
229229 var b: [len]u8 = undefined;
230230 var c: [len]u8 = undefined;
231 const zero = [_]u8{0} ** len;
231 const zero: [len]u8 = @splat(0);
232232 var iterations: usize = 100;
233233 while (iterations != 0) : (iterations -= 1) {
234234 io.random(&a);
......@@ -262,7 +262,8 @@ test classify {
262262 declassify(&out);
263263
264264 // 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));
266267
267268 // Comparing secret data must be done in constant time. The result
268269 // 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
375375 const auth_tag = record_decoder.array(P.AEAD.tag_length).*;
376376 const nonce = nonce: {
377377 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);
379379 const operand: V = pad ++ @as([8]u8, @bitCast(big(read_seq)));
380380 break :nonce @as(V, pv.server_handshake_iv) ^ operand;
381381 };
......@@ -415,7 +415,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client
415415 comptime std.math.shl(u64, std.math.maxInt(u64), 8 * P.record_iv_length);
416416 const nonce: [P.AEAD.nonce_length]u8 = nonce: {
417417 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);
419419 const operand: V = pad ++ @as([8]u8, @bitCast(big(masked_read_seq)));
420420 break :nonce @as(V, pv.app_cipher.server_write_IV ++ record_iv) ^ operand;
421421 };
......@@ -539,7 +539,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client
539539 const p = &@field(handshake_cipher, @tagName(tag.with()));
540540 const P = @TypeOf(p.*).A;
541541 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);
543543 const early_secret = P.Hkdf.extract(&[1]u8{0}, &zeroes);
544544 const empty_hash = tls.emptyHash(P.Hash);
545545 p.version = .{ .tls_1_3 = undefined };
......@@ -791,7 +791,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client
791791 const pv = &p.version.tls_1_2;
792792 const nonce: [P.AEAD.nonce_length]u8 = nonce: {
793793 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);
795795 const operand: V = pad ++ @as([8]u8, @bitCast(big(write_seq)));
796796 break :nonce @as(V, pv.app_cipher.client_write_IV ++ pv.app_cipher.client_salt) ^ operand;
797797 };
......@@ -832,8 +832,9 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client
832832 }
833833 switch (handshake_cipher) {
834834 inline else => |*p| {
835 const pad: [64]u8 = @splat(' ');
835836 try main_cert_pub_key.verifySignature(&hsd, &.{
836 " " ** 64 ++ "TLS 1.3, server CertificateVerify\x00",
837 pad ++ "TLS 1.3, server CertificateVerify\x00",
837838 &p.transcript_hash.peek(),
838839 });
839840 p.transcript_hash.update(wrapped_handshake);
......@@ -1066,7 +1067,7 @@ fn prepareCiphertextRecord(
10661067 ciphertext_end += auth_tag.len;
10671068 const nonce = nonce: {
10681069 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);
10701071 const operand: V = pad ++ mem.toBytes(big(c.write_seq));
10711072 break :nonce @as(V, pv.client_iv) ^ operand;
10721073 };
......@@ -1103,7 +1104,7 @@ fn prepareCiphertextRecord(
11031104 ciphertext_end += P.record_iv_length;
11041105 const nonce: [P.AEAD.nonce_length]u8 = nonce: {
11051106 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);
11071108 const operand: V = pad ++ @as([8]u8, @bitCast(big(c.write_seq)));
11081109 break :nonce @as(V, pv.client_write_IV ++ pv.client_salt) ^ operand;
11091110 };
......@@ -1185,7 +1186,7 @@ fn readIndirect(c: *Client) Reader.Error!usize {
11851186 const auth_tag = (input.takeArray(P.AEAD.tag_length) catch unreachable).*; // already peeked
11861187 const nonce = nonce: {
11871188 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);
11891190 const operand: V = pad ++ mem.toBytes(big(c.read_seq));
11901191 break :nonce @as(V, pv.server_iv) ^ operand;
11911192 };
......@@ -1211,7 +1212,7 @@ fn readIndirect(c: *Client) Reader.Error!usize {
12111212 comptime std.math.shl(u64, std.math.maxInt(u64), 8 * P.record_iv_length);
12121213 const nonce: [P.AEAD.nonce_length]u8 = nonce: {
12131214 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);
12151216 const operand: V = pad ++ @as([8]u8, @bitCast(big(masked_read_seq)));
12161217 break :nonce @as(V, pv.server_write_IV ++ record_iv) ^ operand;
12171218 };
lib/std/debug.zig+6-4
......@@ -1381,7 +1381,7 @@ test printLineFromFile {
13811381 try writer.flush();
13821382
13831383 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());
13851385 aw.clearRetainingCapacity();
13861386 }
13871387 {
......@@ -1395,7 +1395,7 @@ test printLineFromFile {
13951395 try writer.splatByteAll('a', std.heap.page_size_max);
13961396
13971397 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());
13991399 aw.clearRetainingCapacity();
14001400 }
14011401 {
......@@ -1410,14 +1410,16 @@ test printLineFromFile {
14101410
14111411 try expectError(error.EndOfStream, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }));
14121412
1413 const many_a: [3 * std.heap.page_size_max]u8 = @splat('a');
1414
14131415 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());
14151417 aw.clearRetainingCapacity();
14161418
14171419 try writer.writeAll("a\na");
14181420
14191421 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());
14211423 aw.clearRetainingCapacity();
14221424
14231425 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 {
13461346 dir_index: u32 = 0,
13471347 mtime: u64 = 0,
13481348 size: u64 = 0,
1349 md5: [16]u8 = [1]u8{0} ** 16,
1349 md5: [16]u8 = @splat(0),
13501350};
13511351
13521352const LineNumberProgram = struct {
lib/std/elf.zig+1-1
......@@ -3054,7 +3054,7 @@ pub const ar_hdr = extern struct {
30543054fn genSpecialMemberName(comptime name: []const u8) *const [16]u8 {
30553055 assert(name.len <= 16);
30563056 const padding = 16 - name.len;
3057 return name ++ &[_]u8{0x20} ** padding;
3057 return name ++ @as([padding]u8, @splat(0x20));
30583058}
30593059
30603060// Archive files start with the ARMAG identifying string. Then follows a
lib/std/enums.zig+1-1
......@@ -166,7 +166,7 @@ pub fn directEnumArrayDefault(
166166 init_values: EnumFieldStruct(E, Data, default),
167167) [directEnumArrayLen(E, max_unused_slots)]Data {
168168 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);
170170 inline for (@typeInfo(@TypeOf(init_values)).@"struct".fields) |f| {
171171 const enum_value = @field(E, f.name);
172172 const index = @as(usize, @intCast(@intFromEnum(enum_value)));
lib/std/fmt.zig+5-1
......@@ -1194,8 +1194,12 @@ test bytesToHex {
11941194}
11951195
11961196test hexToBytes {
1197 const repeated: []const u8 = repeated: {
1198 const buf: [32][2]u8 = @splat("90".*);
1199 break :repeated @ptrCast(&buf);
1200 };
11971201 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)});
11991203 try expectFmt("ABCD", "{X}", .{try hexToBytes(&buf, "ABCD")});
12001204 try expectFmt("", "{X}", .{try hexToBytes(&buf, "")});
12011205 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 {
8080 .num_digits = 0,
8181 .decimal_point = 0,
8282 .truncated = false,
83 .digits = [_]u8{0} ** max_digits,
83 .digits = @splat(0),
8484 };
8585 }
8686
lib/std/fs/test.zig+7-3
......@@ -1449,11 +1449,15 @@ test "max file name component lengths" {
14491449 if (native_os == .windows) {
14501450 // U+FFFF is the character with the largest code point that is encoded as a single
14511451 // 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);
14531455 // This is also a code point that is encoded as one WTF-16 code unit, but
14541456 // 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;
1456 try testFilenameLimits(io, tmp.dir, &maxed_windows_filename1, &maxed_windows_filename2);
1457 const codepoint2 = "€".*;
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);
14571461 } else if (native_os == .wasi) {
14581462 // On WASI, the maxed filename depends on the host OS, so in order for this test to
14591463 // 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" {
8888}
8989
9090test "long" {
91 const long1 = [_]u8{1} ** 1024;
91 const long1: [1024]u8 = @splat(1);
9292 try testing.expectEqual(@as(u32, 0x06780401), hash(long1[0..]));
9393
94 const long2 = [_]u8{1} ** 1025;
94 const long2: [1025]u8 = @splat(1);
9595 try testing.expectEqual(@as(u32, 0x0a7a0402), hash(long2[0..]));
9696}
9797
9898test "very long" {
99 const long = [_]u8{1} ** 5553;
99 const long: [5553]u8 = @splat(1);
100100 try testing.expectEqual(@as(u32, 0x707f15b2), hash(long[0..]));
101101}
102102
lib/std/hash/benchmark.zig+2-2
......@@ -93,13 +93,13 @@ const hashes = [_]Hash{
9393 .ty = hash.SipHash64(1, 3),
9494 .name = "siphash64",
9595 .has_crypto_api = true,
96 .init_u8s = &[_]u8{0} ** 16,
96 .init_u8s = &@as([16]u8, @splat(0)),
9797 },
9898 Hash{
9999 .ty = hash.SipHash128(1, 3),
100100 .name = "siphash128",
101101 .has_crypto_api = true,
102 .init_u8s = &[_]u8{0} ** 16,
102 .init_u8s = &@as([16]u8, @splat(0)),
103103 },
104104};
105105
lib/std/hash/wyhash.zig+1-1
......@@ -253,7 +253,7 @@ test "iterative api" {
253253}
254254
255255test "iterative maintains last sixteen" {
256 const input = "Z" ** 48 ++ "01234567890abcdefg";
256 const input = &@as([48]u8, @splat('Z')) ++ "01234567890abcdefg";
257257 const seed = 0;
258258
259259 for (0..17) |i| {
lib/std/heap/debug_allocator.zig+1-1
......@@ -164,7 +164,7 @@ pub fn DebugAllocator(comptime config: Config) type {
164164 return struct {
165165 backing_allocator: Allocator = std.heap.page_allocator,
166166 /// 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),
168168 large_allocations: LargeAllocTable = .empty,
169169 total_requested_bytes: @TypeOf(total_requested_bytes_init) = total_requested_bytes_init,
170170 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 {
749749 /// How many zeroes to reserve for hex-encoded chunk length.
750750 const chunk_len_digits = 8;
751751 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";
753753
754754 comptime {
755755 assert(max_chunk_len == std.math.maxInt(u32));
lib/std/json/JSONTestSuite_test.zig+10-5
......@@ -1,5 +1,5 @@
1// This file was generated by _generate_JSONTestSuite.zig
2// These test cases are sourced from: https://github.com/nst/JSONTestSuite
1//! This file was generated by _generate_JSONTestSuite.zig
2//! These test cases are sourced from: https://github.com/nst/JSONTestSuite
33const ok = @import("./test.zig").ok;
44const err = @import("./test.zig").err;
55const any = @import("./test.zig").any;
......@@ -104,7 +104,7 @@ test "i_string_utf16LE_no_BOM.json" {
104104 try any("[\x00\"\x00\xe9\x00\"\x00]\x00");
105105}
106106test "i_structure_500_nested_arrays.json" {
107 try any("[" ** 500 ++ "]" ** 500);
107 try any(&@as([500]u8, @splat('[')) ++ &@as([500]u8, @splat(']')));
108108}
109109test "i_structure_UTF-8_BOM_empty_object.json" {
110110 try any("\xef\xbb\xbf{}");
......@@ -527,7 +527,7 @@ test "n_string_with_trailing_garbage.json" {
527527 try err("\"\"x");
528528}
529529test "n_structure_100000_opening_arrays.json" {
530 try err("[" ** 100000);
530 try err(&@as([100000]u8, @splat('[')));
531531}
532532test "n_structure_U+2060_word_joined.json" {
533533 try err("[\xe2\x81\xa0]");
......@@ -605,7 +605,12 @@ test "n_structure_open_array_comma.json" {
605605 try err("[,");
606606}
607607test "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 });
609614}
610615test "n_structure_open_array_open_object.json" {
611616 try err("[{");
lib/std/json/scanner_test.zig+28-17
......@@ -261,19 +261,28 @@ test "strings" {
261261 }
262262}
263263
264const nesting_test_cases = .{
265 .{ null, "[]" },
266 .{ null, "{}" },
267 .{ error.SyntaxError, "[}" },
268 .{ error.SyntaxError, "{]" },
269 .{ null, "[" ** 1000 ++ "]" ** 1000 },
270 .{ null, "{\"\":" ** 1000 ++ "0" ++ "}" ** 1000 },
271 .{ error.SyntaxError, "[" ** 1000 ++ "]" ** 999 ++ "}" },
272 .{ error.SyntaxError, "{\"\":" ** 1000 ++ "0" ++ "}" ** 999 ++ "]" },
273 .{ error.SyntaxError, "[" ** 1000 ++ "]" ** 1001 },
274 .{ error.SyntaxError, "{\"\":" ** 1000 ++ "0" ++ "}" ** 1001 },
275 .{ error.UnexpectedEndOfInput, "[" ** 1000 ++ "]" ** 999 },
276 .{ error.UnexpectedEndOfInput, "{\"\":" ** 1000 ++ "0" ++ "}" ** 999 },
264const nesting_test_cases = cases: {
265 const open_arrays: *const [1000]u8 = &@splat('[');
266 const close_arrays: *const [1000]u8 = &@splat(']');
267
268 const open_objects_buf: [1000][4]u8 = @splat("{\"\":".*);
269 const open_objects: []const u8 = @ptrCast(&open_objects_buf);
270 const close_objects: *const [1000]u8 = &@splat('}');
271
272 break :cases .{
273 .{ null, "[]" },
274 .{ null, "{}" },
275 .{ error.SyntaxError, "[}" },
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 };
277286};
278287
279288test "nesting" {
......@@ -421,11 +430,12 @@ test "skipValue" {
421430 try testSkipValue("{\"foo\": \"bar\\nbaz\"}");
422431
423432 // An absurd number of nestings
424 const nestings = 1000;
425 try testSkipValue("[" ** nestings ++ "]" ** nestings);
433 const open_all: [1000]u8 = @splat('[');
434 const close_all: [1000]u8 = @splat(']');
435 try testSkipValue(&(open_all ++ close_all));
426436
427437 // 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);
429439
430440 // Mismatched brace/square bracket
431441 try std.testing.expectError(error.SyntaxError, testSkipValue("[102, 111, 111}"));
......@@ -474,7 +484,8 @@ test "enableDiagnostics" {
474484
475485 inline for ([_]comptime_int{ 5, 6, 7, 99 }) |reps| {
476486 // The error happens 1 byte before the end.
477 const s = "[" ** reps ++ "}";
487 const open_all: [reps]u8 = @splat('[');
488 const s = &open_all ++ "}";
478489 try testDiagnostics(error.SyntaxError, 1, s.len, s.len - 1, s);
479490 }
480491}
lib/std/json/static.zig+2-2
......@@ -334,7 +334,7 @@ pub fn innerParse(
334334 if (.object_begin != try source.next()) return error.UnexpectedToken;
335335
336336 var r: T = undefined;
337 var fields_seen = [_]bool{false} ** structInfo.fields.len;
337 var fields_seen: [structInfo.fields.len]bool = @splat(false);
338338
339339 while (true) {
340340 var name_token: ?Token = try source.nextAllocMax(allocator, .alloc_if_needed, options.max_value_len.?);
......@@ -649,7 +649,7 @@ pub fn innerParseFromValue(
649649 if (source != .object) return error.UnexpectedToken;
650650
651651 var r: T = undefined;
652 var fields_seen = [_]bool{false} ** structInfo.fields.len;
652 var fields_seen: [structInfo.fields.len]bool = @splat(false);
653653
654654 var it = source.object.iterator();
655655 while (it.next()) |kv| {
lib/std/math/big/int.zig+3-3
......@@ -29,8 +29,8 @@ const Constants = struct {
2929};
3030const constants: Constants = blk: {
3131 @setEvalBranchQuota(2000);
32 var digits_per_limb = [_]u8{0} ** 37;
33 var bases = [_]Limb{0} ** 37;
32 var digits_per_limb: [37]u8 = @splat(0);
33 var bases: [37]Limb = @splat(0);
3434 for (2..37) |base| {
3535 digits_per_limb[base] = @intCast(math.log(Limb, base, math.maxInt(Limb)));
3636 bases[base] = std.math.pow(Limb, base, digits_per_limb[base]);
......@@ -2391,7 +2391,7 @@ pub const Const = struct {
23912391 var limbs: [calcToStringLimbsBufferLen(available_len, 10)]Limb = undefined;
23922392
23932393 const biggest: Const = .{
2394 .limbs = &([1]Limb{comptime math.maxInt(Limb)} ** available_len),
2394 .limbs = &@as([available_len]Limb, @splat(comptime math.maxInt(Limb))),
23952395 .positive = false,
23962396 };
23972397 var buf: [biggest.sizeInBaseUpperBound(2)]u8 = undefined;
lib/std/math/big/int_test.zig+13-13
......@@ -3351,7 +3351,7 @@ test "big int popcount" {
33513351 try popCountTest(&a, limb_bits * 2 + 1, limb_bits * 2 + 1);
33523352
33533353 // Check very large numbers.
3354 try a.setString(16, "ff00000100000100" ++ ("0000000000000000" ** 62));
3354 try a.setString(16, "ff00000100000100" ++ &@as([16 * 62]u8, @splat('0')));
33553355 try popCountTest(&a, 4032, 10);
33563356 try popCountTest(&a, 6000, 10);
33573357 a.negate();
......@@ -3459,13 +3459,13 @@ test "big int write twos complement +/- zero" {
34593459 // Test zero
34603460
34613461 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);
34633463 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);
34653465 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);
34673467 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);
34693469
34703470 @memset(buffer1, 0xaa);
34713471 m.positive = false;
......@@ -3473,13 +3473,13 @@ test "big int write twos complement +/- zero" {
34733473 // Test negative zero
34743474
34753475 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);
34773477 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);
34793479 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);
34813481 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);
34833483}
34843484
34853485test "big int conversion write twos complement with padding" {
......@@ -3556,7 +3556,7 @@ test "big int conversion write twos complement with padding" {
35563556
35573557 // Test 0
35583558
3559 buffer = &([_]u8{0} ** 16);
3559 buffer = &@as([16]u8, @splat(0));
35603560 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);
35613561 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
35623562 m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned);
......@@ -3567,7 +3567,7 @@ test "big int conversion write twos complement with padding" {
35673567 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
35683568
35693569 bit_count = 0;
3570 buffer = &([_]u8{0xaa} ** 16);
3570 buffer = &@as([16]u8, @splat(0xaa));
35713571 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);
35723572 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
35733573 m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned);
......@@ -3592,13 +3592,13 @@ test "big int conversion write twos complement zero" {
35923592 const bit_count: usize = 12 * 8 + 1;
35933593 var buffer: []const u8 = undefined;
35943594
3595 buffer = &([_]u8{0} ** 13);
3595 buffer = &@as([13]u8, @splat(0));
35963596 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);
35973597 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
35983598 m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned);
35993599 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
36003600
3601 buffer = &([_]u8{0} ** 16);
3601 buffer = &@as([16]u8, @splat(0));
36023602 m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned);
36033603 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
36043604 m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned);
lib/std/mem.zig+9-6
......@@ -359,7 +359,10 @@ test zeroes {
359359 var a = zeroes(C_struct);
360360
361361 // 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 }
363366
364367 a.y += 10;
365368
......@@ -1587,7 +1590,7 @@ test find {
15871590test "find multibyte" {
15881591 {
15891592 // 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 };
15911594 const needle = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee };
15921595 try testing.expectEqual(findPos(u16, &haystack, 0, &needle), 100);
15931596
......@@ -1600,7 +1603,7 @@ test "find multibyte" {
16001603
16011604 {
16021605 // 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));
16041607 const needle = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee };
16051608 try testing.expectEqual(lastIndexOf(u16, &haystack, &needle), 0);
16061609
......@@ -4645,7 +4648,7 @@ test "sliceAsBytes with sentinel slice" {
46454648}
46464649
46474650test "sliceAsBytes with zero-bit element type" {
4648 const lots_of_nothing = [1]void{{}} ** 10_000;
4651 const lots_of_nothing: [10_000]void = @splat({});
46494652 const bytes = sliceAsBytes(&lots_of_nothing);
46504653 try testing.expect(bytes.len == 0);
46514654}
......@@ -4863,8 +4866,8 @@ test doNotOptimizeAway {
48634866 doNotOptimizeAway(@as(u200, 0));
48644867 doNotOptimizeAway(@as(f32, 0.0));
48654868 doNotOptimizeAway(@as(f64, 0.0));
4866 doNotOptimizeAway([_]u8{0} ** 4);
4867 doNotOptimizeAway([_]u8{0} ** 100);
4869 doNotOptimizeAway(@as([4]u8, @splat(0)));
4870 doNotOptimizeAway(@as([100]u8, @splat(0)));
48684871 doNotOptimizeAway(@as(std.builtin.Endian, .little));
48694872}
48704873
lib/std/os/emscripten.zig+2-2
......@@ -373,7 +373,7 @@ pub const rusage = extern struct {
373373 nsignals: isize,
374374 nvcsw: isize,
375375 nivcsw: isize,
376 __reserved: [16]isize = [1]isize{0} ** 16,
376 __reserved: [16]isize = @splat(0),
377377
378378 pub const SELF = 0;
379379 pub const CHILDREN = -1;
......@@ -481,7 +481,7 @@ pub const Sigaction = extern struct {
481481
482482pub const sigset_t = [1024 / 32]u32;
483483pub fn sigemptyset() sigset_t {
484 return [_]u32{0} ** @typeInfo(sigset_t).array.len;
484 return @splat(0);
485485}
486486pub const siginfo_t = extern struct {
487487 signo: i32,
lib/std/os/linux.zig+4-4
......@@ -2262,12 +2262,12 @@ pub fn sigrtmax() u8 {
22622262
22632263/// Zig's version of sigemptyset. Returns initialized sigset_t.
22642264pub fn sigemptyset() sigset_t {
2265 return [_]SigsetElement{0} ** sigset_len;
2265 return @splat(0);
22662266}
22672267
22682268/// Zig's version of sigfillset. Returns initalized sigset_t.
22692269pub fn sigfillset() sigset_t {
2270 return [_]SigsetElement{~@as(SigsetElement, 0)} ** sigset_len;
2270 return @splat(~@as(SigsetElement, 0));
22712271}
22722272
22732273fn sigset_bit_index(sig: SIG) struct { word: usize, mask: SigsetElement } {
......@@ -6129,7 +6129,7 @@ pub const sockaddr = extern struct {
61296129 flags: u8,
61306130
61316131 /// 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),
61336133 comptime {
61346134 std.debug.assert(@sizeOf(vm) == @sizeOf(sockaddr));
61356135 }
......@@ -7475,7 +7475,7 @@ pub const rusage = extern struct {
74757475 nsignals: isize,
74767476 nvcsw: isize,
74777477 nivcsw: isize,
7478 __reserved: [16]isize = [1]isize{0} ** 16,
7478 __reserved: [16]isize = @splat(0),
74797479
74807480 pub const SELF = 0;
74817481 pub const CHILDREN = -1;
lib/std/os/linux/IoUring/test.zig+34-30
......@@ -115,12 +115,12 @@ test "readv" {
115115 // https://github.com/torvalds/linux/blob/v5.4/fs/io_uring.c#L3119-L3124 vs
116116 // https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L6687-L6691
117117 // 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};
119119 const fd_index = 0;
120120 registered_fds[fd_index] = file.handle;
121121 try ring.register_files(registered_fds[0..]);
122122
123 var buffer = [_]u8{42} ** 128;
123 var buffer: [128]u8 = @splat(42);
124124 var iovecs = [_]iovec{iovec{ .base = &buffer, .len = buffer.len }};
125125 const sqe = try ring.read(0xcccccccc, fd_index, .{ .iovecs = iovecs[0..] }, 0);
126126 try testing.expectEqual(linux.IORING_OP.READV, sqe.opcode);
......@@ -133,7 +133,7 @@ test "readv" {
133133 .res = buffer.len,
134134 .flags = 0,
135135 }, 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..]);
137137
138138 try ring.unregister_files();
139139}
......@@ -156,11 +156,11 @@ test "writev/fsync/readv" {
156156 defer file.close(io);
157157 const fd = file.handle;
158158
159 const buffer_write = [_]u8{42} ** 128;
159 const buffer_write: [128]u8 = @splat(42);
160160 const iovecs_write = [_]iovec_const{
161161 iovec_const{ .base = &buffer_write, .len = buffer_write.len },
162162 };
163 var buffer_read = [_]u8{0} ** 128;
163 var buffer_read: [128]u8 = @splat(0);
164164 var iovecs_read = [_]iovec{
165165 iovec{ .base = &buffer_read, .len = buffer_read.len },
166166 };
......@@ -225,8 +225,8 @@ test "write/read" {
225225 defer file.close(io);
226226 const fd = file.handle;
227227
228 const buffer_write = [_]u8{97} ** 20;
229 var buffer_read = [_]u8{98} ** 20;
228 const buffer_write: [20]u8 = @splat(97);
229 var buffer_read: [20]u8 = @splat(98);
230230 const sqe_write = try ring.write(0x11111111, fd, buffer_write[0..], 10);
231231 try testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode);
232232 try testing.expectEqual(@as(u64, 10), sqe_write.off);
......@@ -276,8 +276,8 @@ test "splice/read" {
276276 defer file_dst.close(io);
277277 const fd_dst = file_dst.handle;
278278
279 const buffer_write = [_]u8{97} ** 20;
280 var buffer_read = [_]u8{98} ** 20;
279 const buffer_write: [20]u8 = @splat(97);
280 var buffer_read: [20]u8 = @splat(98);
281281 try file_src.writeStreamingAll(io, &buffer_write);
282282
283283 const fds = try std.Io.Threaded.pipe2(.{});
......@@ -542,7 +542,7 @@ test "sendmsg/recvmsg" {
542542 const client = try socket(address_server.family, posix.SOCK.DGRAM, 0);
543543 defer _ = linux.close(client);
544544
545 const buffer_send = [_]u8{42} ** 128;
545 const buffer_send: [128]u8 = @splat(42);
546546 const iovecs_send = [_]iovec_const{
547547 iovec_const{ .base = &buffer_send, .len = buffer_send.len },
548548 };
......@@ -560,7 +560,7 @@ test "sendmsg/recvmsg" {
560560 try testing.expectEqual(linux.IORING_OP.SENDMSG, sqe_sendmsg.opcode);
561561 try testing.expectEqual(client, sqe_sendmsg.fd);
562562
563 var buffer_recv = [_]u8{0} ** 128;
563 var buffer_recv: [128]u8 = @splat(0);
564564 var iovecs_recv = [_]iovec{
565565 iovec{ .base = &buffer_recv, .len = buffer_recv.len },
566566 };
......@@ -944,7 +944,7 @@ test "register_files_update" {
944944 const file = try Io.Dir.openFileAbsolute(io, "/dev/zero", .{});
945945 defer file.close(io);
946946
947 var registered_fds = [_]linux.fd_t{0} ** 2;
947 var registered_fds: [2]linux.fd_t = @splat(0);
948948 const fd_index = 0;
949949 const fd_index2 = 1;
950950 registered_fds[fd_index] = file.handle;
......@@ -966,7 +966,7 @@ test "register_files_update" {
966966 registered_fds[fd_index2] = -1;
967967 try ring.register_files_update(0, registered_fds[0..]);
968968
969 var buffer = [_]u8{42} ** 128;
969 var buffer: [128]u8 = @splat(42);
970970 {
971971 const sqe = try ring.read(0xcccccccc, fd_index, .{ .buffer = &buffer }, 0);
972972 try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode);
......@@ -978,7 +978,7 @@ test "register_files_update" {
978978 .res = buffer.len,
979979 .flags = 0,
980980 }, 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..]);
982982 }
983983
984984 // Test with a non-zero offset
......@@ -999,7 +999,7 @@ test "register_files_update" {
999999 .res = buffer.len,
10001000 .flags = 0,
10011001 }, 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..]);
10031003 }
10041004
10051005 try ring.register_files_update(0, registered_fds[0..]);
......@@ -1404,7 +1404,7 @@ test "provide_buffers: read" {
14041404 try testing.expectEqual(@as(i32, buffer_len), cqe.res);
14051405
14061406 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))]);
14081408 }
14091409
14101410 // This read should fail
......@@ -1468,7 +1468,7 @@ test "provide_buffers: read" {
14681468 try testing.expectEqual(used_buffer_id, reprovided_buffer_id);
14691469 try testing.expectEqual(@as(i32, buffer_len), cqe.res);
14701470 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))]);
14721472 }
14731473}
14741474
......@@ -1542,7 +1542,7 @@ test "remove_buffers" {
15421542 try testing.expect(used_buffer_id >= 0 and used_buffer_id < 4);
15431543 try testing.expectEqual(@as(i32, buffer_len), cqe.res);
15441544 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))]);
15461546 }
15471547
15481548 // Final read should _not_ work
......@@ -1608,7 +1608,7 @@ test "provide_buffers: accept/connect/send/recv" {
16081608 {
16091609 var i: usize = 0;
16101610 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);
16121612 try testing.expectEqual(@as(u32, 1), try ring.submit());
16131613 }
16141614
......@@ -1646,7 +1646,7 @@ test "provide_buffers: accept/connect/send/recv" {
16461646
16471647 try testing.expectEqual(@as(u64, 0xdededede), cqe.user_data);
16481648 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);
16501650 }
16511651
16521652 // This recv should fail
......@@ -1690,7 +1690,7 @@ test "provide_buffers: accept/connect/send/recv" {
16901690 // Redo 1 send on the server socket
16911691
16921692 {
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);
16941694 try testing.expectEqual(@as(u32, 1), try ring.submit());
16951695
16961696 _ = try ring.copy_cqe();
......@@ -1724,7 +1724,7 @@ test "provide_buffers: accept/connect/send/recv" {
17241724 try testing.expectEqual(@as(i32, buffer_len), cqe.res);
17251725 try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data);
17261726 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);
17281728 }
17291729}
17301730
......@@ -1784,8 +1784,8 @@ test "accept/connect/send_zc/recv" {
17841784 const socket_test_harness = try createSocketTestHarness(&ring);
17851785 defer socket_test_harness.close();
17861786
1787 const buffer_send = [_]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe };
1788 var buffer_recv = [_]u8{0} ** 10;
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: [10]u8 = @splat(0);
17891789
17901790 // zero-copy send
17911791 const sqe_send = try ring.send_zc(0xeeeeeeee, socket_test_harness.client, buffer_send[0..], 0, 0);
......@@ -1844,7 +1844,7 @@ test "accept_direct" {
18441844 };
18451845
18461846 // register direct file descriptors
1847 var registered_fds = [_]linux.fd_t{-1} ** 2;
1847 var registered_fds: [2]linux.fd_t = @splat(-1);
18481848 try ring.register_files(registered_fds[0..]);
18491849
18501850 const listener_socket = try createListenerSocket(&address);
......@@ -1856,7 +1856,7 @@ test "accept_direct" {
18561856
18571857 for (0..2) |_| {
18581858 for (registered_fds, 0..) |_, i| {
1859 var buffer_recv = [_]u8{0} ** 16;
1859 var buffer_recv: [16]u8 = @splat(0);
18601860 const buffer_send: []const u8 = data[0 .. data.len - i]; // make it different at each loop
18611861
18621862 // submit accept, will chose registered fd and return index in cqe
......@@ -1932,7 +1932,7 @@ test "accept_multishot_direct" {
19321932 .addr = @bitCast([4]u8{ 127, 0, 0, 1 }),
19331933 };
19341934
1935 var registered_fds = [_]linux.fd_t{-1} ** 2;
1935 var registered_fds: [2]linux.fd_t = @splat(-1);
19361936 try ring.register_files(registered_fds[0..]);
19371937
19381938 const listener_socket = try createListenerSocket(&address);
......@@ -2011,7 +2011,7 @@ test "socket_direct/socket_direct_alloc/close_direct" {
20112011 };
20122012 defer ring.deinit();
20132013
2014 var registered_fds = [_]linux.fd_t{-1} ** 3;
2014 var registered_fds: [3]linux.fd_t = @splat(-1);
20152015 try ring.register_files(registered_fds[0..]);
20162016
20172017 // create socket in registered file descriptor at index 0 (last param)
......@@ -2092,7 +2092,7 @@ test "openat_direct/close_direct" {
20922092 };
20932093 defer ring.deinit();
20942094
2095 var registered_fds = [_]linux.fd_t{-1} ** 3;
2095 var registered_fds: [3]linux.fd_t = @splat(-1);
20962096 try ring.register_files(registered_fds[0..]);
20972097
20982098 var tmp = std.testing.tmpDir(.{});
......@@ -2562,7 +2562,11 @@ fn expect_buf_grp_cqe(
25622562}
25632563
25642564fn 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 };
25662570 var buffer_recv: [buffer_send.len * 2]u8 = undefined;
25672571
25682572 // 2 sends
lib/std/os/linux/test.zig+1-1
......@@ -70,7 +70,7 @@ test "timer" {
7070 try expect(err == .SUCCESS);
7171
7272 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);
7474
7575 err = linux.errno(linux.epoll_wait(@as(i32, @intCast(epoll_fd)), &events, 8, -1));
7676 try expect(err == .SUCCESS);
lib/std/os/uefi/hii.zig+1-1
......@@ -66,7 +66,7 @@ pub const WideGlyph = extern struct {
6666 attributes: WideGlyphAttributes,
6767 glyph_col_1: [19]u8,
6868 glyph_col_2: [19]u8,
69 _pad: [3]u8 = [_]u8{0} ** 3,
69 _pad: [3]u8 = @splat(0),
7070};
7171
7272pub const StringPackage = extern struct {
lib/std/posix/test.zig+2-2
......@@ -187,11 +187,11 @@ test "mmap" {
187187 try expectEqual(@as(usize, 1234), data.len);
188188
189189 // 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))));
191191
192192 // Make sure the memory is writeable as requested
193193 @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))));
195195 }
196196
197197 const test_out_file = "os_tmp_test";
lib/std/tar.zig+8-4
......@@ -734,6 +734,10 @@ test PaxIterator {
734734 value: []const u8 = undefined,
735735 err: ?anyerror = null,
736736 };
737 const long_path: *const [1000]u8 = comptime path: {
738 const buf: [100][10]u8 = @splat("0123456789".*);
739 break :path @ptrCast(&buf);
740 };
737741 const cases = [_]struct {
738742 data: []const u8,
739743 attrs: []const Attr,
......@@ -816,9 +820,9 @@ test PaxIterator {
816820 },
817821 },
818822 .{ // 1000 characters path
819 .data = "1011 path=" ++ "0123456789" ** 100 ++ "\n",
823 .data = "1011 path=" ++ long_path ++ "\n",
820824 .attrs = &[_]Attr{
821 .{ .kind = .path, .value = "0123456789" ** 100 },
825 .{ .kind = .path, .value = long_path },
822826 },
823827 },
824828 };
......@@ -879,7 +883,7 @@ test "header parse size" {
879883 };
880884
881885 for (cases) |case| {
882 var bytes = [_]u8{0} ** Header.SIZE;
886 var bytes: [Header.SIZE]u8 = @splat(0);
883887 @memcpy(bytes[124 .. 124 + case.in.len], case.in);
884888 var header = Header{ .bytes = &bytes };
885889 if (case.err) |err| {
......@@ -904,7 +908,7 @@ test "header parse mode" {
904908 .{ .in = "777777777777", .want = 0o77777777 },
905909 };
906910 for (cases) |case| {
907 var bytes = [_]u8{0} ** Header.SIZE;
911 var bytes: [Header.SIZE]u8 = @splat(0);
908912 @memcpy(bytes[100 .. 100 + case.in.len], case.in);
909913 var header = Header{ .bytes = &bytes };
910914 if (case.err) |err| {
lib/std/tar/Writer.zig+39-33
......@@ -193,23 +193,23 @@ pub const Header = extern struct {
193193 // numeric field of width w contains w minus 1 digits, and a null.
194194 // Reference: https://www.gnu.org/software/tar/manual/html_node/Standard.html
195195 // POSIX header: byte offset
196 name: [100]u8 = [_]u8{0} ** 100, // 0
196 name: [100]u8 = @splat(0), // 0
197197 mode: [7:0]u8 = default_mode.file, // 100
198 uid: [7:0]u8 = [_:0]u8{0} ** 7, // unused 108
199 gid: [7:0]u8 = [_:0]u8{0} ** 7, // unused 116
200 size: [11:0]u8 = [_:0]u8{'0'} ** 11, // 124
201 mtime: [11:0]u8 = [_:0]u8{'0'} ** 11, // 136
202 checksum: [7:0]u8 = [_:0]u8{' '} ** 7, // 148
198 uid: [7:0]u8 = @splat(0), // unused 108
199 gid: [7:0]u8 = @splat(0), // unused 116
200 size: [11:0]u8 = @splat('0'), // 124
201 mtime: [11:0]u8 = @splat('0'), // 136
202 checksum: [7:0]u8 = @splat(' '), // 148
203203 typeflag: FileType = .regular, // 156
204 linkname: [100]u8 = [_]u8{0} ** 100, // 157
205 magic: [6]u8 = [_]u8{ 'u', 's', 't', 'a', 'r', 0 }, // 257
206 version: [2]u8 = [_]u8{ '0', '0' }, // 263
207 uname: [32]u8 = [_]u8{0} ** 32, // unused 265
208 gname: [32]u8 = [_]u8{0} ** 32, // unused 297
209 devmajor: [7:0]u8 = [_:0]u8{0} ** 7, // unused 329
210 devminor: [7:0]u8 = [_:0]u8{0} ** 7, // unused 337
211 prefix: [155]u8 = [_]u8{0} ** 155, // 345
212 pad: [12]u8 = [_]u8{0} ** 12, // unused 500
204 linkname: [100]u8 = @splat(0), // 157
205 magic: [6]u8 = .{ 'u', 's', 't', 'a', 'r', 0 }, // 257
206 version: [2]u8 = .{ '0', '0' }, // 263
207 uname: [32]u8 = @splat(0), // unused 265
208 gname: [32]u8 = @splat(0), // unused 297
209 devmajor: [7:0]u8 = @splat(0), // unused 329
210 devminor: [7:0]u8 = @splat(0), // unused 337
211 prefix: [155]u8 = @splat(0), // 345
212 pad: [12]u8 = @splat(0), // unused 500
213213
214214 pub const FileType = enum(u8) {
215215 regular = '0',
......@@ -342,26 +342,26 @@ pub const Header = extern struct {
342342 },
343343 // no more both fits into name
344344 .{
345 .in = &.{ "prefix", "0123456789/" ** 8 ++ "basename" },
346 .out = &.{ "prefix", "0123456789/" ** 8 ++ "basename" },
345 .in = &.{ "prefix", repeatString(8, "0123456789/") ++ "basename" },
346 .out = &.{ "prefix", repeatString(8, "0123456789/") ++ "basename" },
347347 },
348348 // put as much as you can into prefix the rest goes into name
349349 .{
350 .in = &.{ "prefix", "0123456789/" ** 10 ++ "basename" },
351 .out = &.{ "prefix/" ++ "0123456789/" ** 9 ++ "0123456789", "basename" },
350 .in = &.{ "prefix", repeatString(10, "0123456789/") ++ "basename" },
351 .out = &.{ "prefix/" ++ repeatString(9, "0123456789/") ++ "0123456789", "basename" },
352352 },
353353
354354 .{
355 .in = &.{ "prefix", "0123456789/" ** 15 ++ "basename" },
356 .out = &.{ "prefix/" ++ "0123456789/" ** 12 ++ "0123456789", "0123456789/0123456789/basename" },
355 .in = &.{ "prefix", repeatString(15, "0123456789/") ++ "basename" },
356 .out = &.{ "prefix/" ++ repeatString(12, "0123456789/") ++ "0123456789", "0123456789/0123456789/basename" },
357357 },
358358 .{
359 .in = &.{ "prefix", "0123456789/" ** 21 ++ "basename" },
360 .out = &.{ "prefix/" ++ "0123456789/" ** 12 ++ "0123456789", "0123456789/" ** 8 ++ "basename" },
359 .in = &.{ "prefix", repeatString(21, "0123456789/") ++ "basename" },
360 .out = &.{ "prefix/" ++ repeatString(12, "0123456789/") ++ "0123456789", repeatString(8, "0123456789/") ++ "basename" },
361361 },
362362 .{
363 .in = &.{ "", "012345678/" ** 10 ++ "foo" },
364 .out = &.{ "012345678/" ** 9 ++ "012345678", "foo" },
363 .in = &.{ "", repeatString(10, "012345678/") ++ "foo" },
364 .out = &.{ repeatString(9, "012345678/") ++ "012345678", "foo" },
365365 },
366366 };
367367
......@@ -378,10 +378,10 @@ pub const Header = extern struct {
378378 // basename can't fit into name (106 characters)
379379 .{ .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" } },
380380 // cant fit into 255 + sep
381 .{ .in = &.{ "prefix", "0123456789/" ** 22 ++ "basename" } },
381 .{ .in = &.{ "prefix", repeatString(22, "0123456789/") ++ "basename" } },
382382 // can fit but sub_path can't be split (there is no separator)
383 .{ .in = &.{ "prefix", "0123456789" ** 10 ++ "a" } },
384 .{ .in = &.{ "prefix", "0123456789" ** 14 ++ "basename" } },
383 .{ .in = &.{ "prefix", repeatString(10, "0123456789") ++ "a" } },
384 .{ .in = &.{ "prefix", repeatString(14, "0123456789") ++ "basename" } },
385385 };
386386
387387 for (error_cases) |case| {
......@@ -404,11 +404,11 @@ test "write files" {
404404 content: []const u8,
405405 }{
406406 .{ .path = "foo", .content = "bar" },
407 .{ .path = "a12345678/" ** 10 ++ "foo", .content = "a" ** 511 },
408 .{ .path = "b12345678/" ** 24 ++ "foo", .content = "b" ** 512 },
409 .{ .path = "c12345678/" ** 25 ++ "foo", .content = "c" ** 513 },
410 .{ .path = "d12345678/" ** 51 ++ "foo", .content = "d" ** 1025 },
411 .{ .path = "e123456789" ** 11, .content = "e" },
407 .{ .path = repeatString(10, "a12345678/") ++ "foo", .content = repeatString(511, "a") },
408 .{ .path = repeatString(24, "b12345678/") ++ "foo", .content = repeatString(512, "b") },
409 .{ .path = repeatString(25, "c12345678/") ++ "foo", .content = repeatString(513, "c") },
410 .{ .path = repeatString(51, "d12345678/") ++ "foo", .content = repeatString(1025, "d") },
411 .{ .path = repeatString(11, "e123456789"), .content = "e" },
412412 };
413413
414414 var file_name_buffer: [std.fs.max_path_bytes]u8 = undefined;
......@@ -482,3 +482,9 @@ test "write files" {
482482 try w.finishPedantically();
483483 }
484484}
485
486/// Marked `inline` to avoid unnecessary binary float, since arguments are always comptime-known.
487inline 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 = .{
5353 .data = @embedFile("testdata/trailing-slash.tar"),
5454 .files = &[_]Case.File{
5555 .{
56 .name = "123456789/" ** 30,
56 .name = @ptrCast(&@as([30][10]u8, @splat("123456789/".*))),
5757 .kind = .directory,
5858 },
5959 },
......@@ -64,7 +64,11 @@ const writer_big_long_case: Case = .{
6464 .data = @embedFile("testdata/writer-big-long.tar"),
6565 .files = &[_]Case.File{
6666 .{
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 },
6872 .size = 16 * 1024 * 1024 * 1024,
6973 .mode = 0o644,
7074 .truncated = true,
lib/std/unicode.zig+13-8
......@@ -275,11 +275,16 @@ fn utf8ValidateSliceImpl(input: []const u8, comptime surrogates: Surrogates) boo
275275 const s7 = 0x44; // accept 4, size 4
276276
277277 // Information about the first byte in a UTF-8 sequence.
278 const first = comptime ([_]u8{as} ** 128) ++ ([_]u8{xx} ** 64) ++ [_]u8{
279 xx, xx, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1,
280 s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1,
281 s2, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s4, s3, s3,
282 s5, s6, s6, s6, s7, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
278 const first = comptime first: {
279 const a: [128]u8 = @splat(as);
280 const b: [64]u8 = @splat(xx);
281 const c: [64]u8 = .{
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;
283288 };
284289
285290 const n = remaining.len;
......@@ -647,7 +652,7 @@ test "validate slice" {
647652
648653 // We skip a variable (based on recommended vector size) chunks of
649654 // 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";
651656 for (0..str.len - 3) |i| {
652657 try testing.expect(!utf8ValidateSlice(str[i..]));
653658 }
......@@ -1394,7 +1399,7 @@ test "ArrayList functions on a re-used list" {
13941399fn utf8ToUtf16LeStringLiteralImpl(comptime utf8: []const u8, comptime surrogates: Surrogates) *const [calcUtf16LeLenImpl(utf8, surrogates) catch |err| @compileError(err):0]u16 {
13951400 return comptime blk: {
13961401 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);
13981403 const utf16le_len = utf8ToUtf16LeImpl(&utf16le, utf8[0..], surrogates) catch |err| @compileError(err);
13991404 assert(len == utf16le_len);
14001405 const final = utf16le;
......@@ -1640,7 +1645,7 @@ test "validate WTF-8 slice" {
16401645
16411646 // We skip a variable (based on recommended vector size) chunks of
16421647 // 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";
16441649 for (0..str.len - 3) |i| {
16451650 try testing.expect(!wtf8ValidateSlice(str[i..]));
16461651 }
lib/std/unicode/throughput_test.zig+9-3
......@@ -63,21 +63,27 @@ pub fn main(init: std.process.Init) !void {
6363 try stdout.print("pure ASCII strings\n", .{});
6464 try stdout.flush();
6565 {
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);
6769 try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });
6870 }
6971
7072 try stdout.print("pure Unicode strings\n", .{});
7173 try stdout.flush();
7274 {
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);
7478 try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });
7579 }
7680
7781 try stdout.print("mixed ASCII/Unicode strings\n", .{});
7882 try stdout.flush();
7983 {
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);
8187 try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });
8288 }
8389 try stdout.flush();
lib/std/zig/AstGen.zig+1-1
......@@ -4795,7 +4795,7 @@ fn testDecl(
47954795 .noalias_bits = 0,
47964796
47974797 // Tests don't have a prototype that needs hashing
4798 .proto_hash = .{0} ** 16,
4798 .proto_hash = @splat(0),
47994799 });
48004800
48014801 _ = 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
4646 found: bool,
4747 allocated: ?[:0]u8,
4848 };
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 });
5050 errdefer {
5151 self = .{};
5252 for (found_keys) |found_key| {
lib/std/zig/WindowsSdk.zig+1-1
......@@ -120,7 +120,7 @@ fn iterateAndFilterByVersion(
120120 if (!std.mem.startsWith(u8, entry.name, prefix)) continue;
121121
122122 var version: Version = .{
123 .nums = .{0} ** 4,
123 .nums = @splat(0),
124124 .build = "",
125125 };
126126 const suffix = entry.name[prefix.len..];
lib/std/zig/llvm/Builder.zig+3-7
......@@ -7628,9 +7628,7 @@ pub const Constant = enum(u32) {
76287628 const expected_limbs = @divExact(512, @bitSizeOf(std.math.big.Limb));
76297629 string: [
76307630 (std.math.big.int.Const{
7631 .limbs = &([1]std.math.big.Limb{
7632 maxInt(std.math.big.Limb),
7633 } ** expected_limbs),
7631 .limbs = &@splat(maxInt(std.math.big.Limb)),
76347632 .positive = false,
76357633 }).sizeInBaseUpperBound(10)
76367634 ]u8,
......@@ -9347,7 +9345,7 @@ pub fn nanConst(self: *Builder, ty: Type) Allocator.Error!Constant {
93479345 .double => try self.doubleConst(std.math.nan(f64)),
93489346 .fp128 => try self.fp128Const(std.math.nan(f128)),
93499347 .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)})),
93519349 else => unreachable,
93529350 };
93539351}
......@@ -10597,9 +10595,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
1059710595 const expected_limbs = @divExact(512, @bitSizeOf(std.math.big.Limb));
1059810596 string: [
1059910597 (std.math.big.int.Const{
10600 .limbs = &([1]std.math.big.Limb{
10601 maxInt(std.math.big.Limb),
10602 } ** expected_limbs),
10598 .limbs = &@splat(maxInt(std.math.big.Limb)),
1060310599 .positive = false,
1060410600 }).sizeInBaseUpperBound(10)
1060510601 ]u8,
src/Air/Liveness.zig+4-4
......@@ -611,7 +611,7 @@ fn analyzeInst(
611611 const call = a.air.unwrapCall(inst);
612612 const args = call.args;
613613 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);
615615 buf[0] = call.callee;
616616 @memcpy(buf[1..][0..args.len], args);
617617 return analyzeOperands(a, pass, data, inst, buf);
......@@ -655,7 +655,7 @@ fn analyzeInst(
655655 const elements = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra.items[ty_pl.payload..][0..len]));
656656
657657 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);
659659 @memcpy(buf[0..elements.len], elements);
660660 return analyzeOperands(a, pass, data, inst, buf);
661661 }
......@@ -711,7 +711,7 @@ fn analyzeInst(
711711 const inputs = unwrapped_asm.inputs;
712712
713713 const num_operands = simple: {
714 var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1);
714 var buf: [bpi - 1]Air.Inst.Ref = @splat(.none);
715715 var buf_index: usize = 0;
716716 for (unwrapped_asm.outputs) |output| {
717717 if (output != .none) {
......@@ -1421,7 +1421,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
14211421 inst: Air.Inst.Index,
14221422
14231423 operands_remaining: u32,
1424 small: [bpi - 1]Air.Inst.Ref = .{.none} ** (bpi - 1),
1424 small: [bpi - 1]Air.Inst.Ref = @splat(.none),
14251425 extra_tombs: []u32,
14261426
14271427 // 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,
43454345 try isel.emit(.ldr(neg_zero_ra.q(), .{
43464346 .literal = @intCast((isel.instructions.items.len + 1 + isel.literals.items.len) << 2),
43474347 }));
4348 try isel.emitLiteral(&(.{0} ** 15 ++ .{0x80}));
4348 try isel.emitLiteral(&(@as([15]u8, @splat(0)) ++ .{0x80}));
43494349 try src_mat.finish(isel);
43504350 },
43514351 }
......@@ -4425,7 +4425,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory,
44254425 try isel.emit(.ldr(neg_zero_ra.q(), .{
44264426 .literal = @intCast((isel.instructions.items.len + 1 + isel.literals.items.len) << 2),
44274427 }));
4428 try isel.emitLiteral(&(.{0} ** 15 ++ .{0x80}));
4428 try isel.emitLiteral(&(@as([15]u8, @splat(0)) ++ .{0x80}));
44294429 try src_mat.finish(isel);
44304430 },
44314431 }
src/codegen/llvm.zig+6-2
......@@ -647,7 +647,11 @@ pub const Object = struct {
647647 debug_enums_fwd_ref.toOptional(),
648648 debug_globals_fwd_ref.toOptional(),
649649 };
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 };
651655
652656 const obj = try arena.create(Object);
653657 obj.* = .{
......@@ -1439,7 +1443,7 @@ pub const Object = struct {
14391443 );
14401444 llvm_function.setSubprogram(subprogram, &o.builder);
14411445 break :debug_info .{ file, subprogram };
1442 } else .{undefined} ** 2;
1446 } else .{ undefined, undefined };
14431447
14441448 const fuzz: ?FuncGen.Fuzz = f: {
14451449 if (!owner_mod.fuzz) break :f null;
src/codegen/llvm/FuncGen.zig+1-1
......@@ -3981,7 +3981,7 @@ fn buildFloatOp(
39813981 const scalar_llvm_ty = try o.lowerType(scalar_ty);
39823982 const libc_fn = try o.getLibcFunction(
39833983 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],
39853985 scalar_llvm_ty,
39863986 );
39873987 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 {
62306230 sym: SymbolOffset,
62316231 };
62326232
6233 var ops: [4]Operand = .{.none} ** 4;
6233 var ops: [4]Operand = @splat(.none);
62346234 var last_op = false;
62356235 var op_it = mem.splitAny(u8, mnem_it.rest(), ",(");
62366236 next_op: for (&ops) |*op| {
......@@ -6466,7 +6466,7 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void {
64666466 }
64676467
64686468 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);
64706470 var buf_index: usize = 0;
64716471 for (outputs) |output| {
64726472 if (output == .none) continue;
......@@ -6581,7 +6581,7 @@ fn genInlineMemcpy(
65816581 src_ptr: MCValue,
65826582 len: MCValue,
65836583) !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);
65856585 const locks = func.register_manager.lockRegsAssumeUnused(4, regs);
65866586 defer for (locks) |lock| func.register_manager.unlockReg(lock);
65876587
......@@ -6691,7 +6691,7 @@ fn genInlineMemset(
66916691 src_value: MCValue,
66926692 len: MCValue,
66936693) !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);
66956695 const locks = func.register_manager.lockRegsAssumeUnused(3, regs);
66966696 defer for (locks) |lock| func.register_manager.unlockReg(lock);
66976697
......@@ -8076,7 +8076,7 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {
80768076 };
80778077
80788078 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);
80808080 @memcpy(buf[0..elements.len], elements);
80818081 return func.finishAir(inst, result, buf);
80828082 }
src/codegen/riscv64/abi.zig+1-1
......@@ -98,7 +98,7 @@ pub const SystemClass = enum { integer, float, memory, none };
9898/// There are a maximum of 8 possible return slots. Returned values are in
9999/// the beginning of the array; unused slots are filled with .none.
100100pub fn classifySystem(ty: Type, zcu: *Zcu) [8]SystemClass {
101 var result = [1]SystemClass{.none} ** 8;
101 var result: [8]SystemClass = @splat(.none);
102102 const memory_class = [_]SystemClass{
103103 .memory, .none, .none, .none,
104104 .none, .none, .none, .none,
src/codegen/sparc64/CodeGen.zig+3-3
......@@ -833,7 +833,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
833833 };
834834
835835 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);
837837 @memcpy(buf[0..elements.len], elements);
838838 return self.finishAir(inst, result, buf);
839839 }
......@@ -944,7 +944,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
944944 };
945945
946946 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);
948948 var buf_index: usize = 0;
949949 for (outputs) |output| {
950950 if (output == .none) continue;
......@@ -1344,7 +1344,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
13441344 const result = info.return_value;
13451345
13461346 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);
13481348 buf[0] = call.callee;
13491349 @memcpy(buf[1..][0..args.len], args);
13501350 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
181601181601 const ip = &zcu.intern_pool;
181602181602 var parts: [parts_len]Type = undefined;
181603181603 switch (ip.indexToKey(ty.toIntern())) {
181604 .vector_type => |vector_type| if (std.math.divExact(u32, vector_type.len, parts_len)) |vec_len| return .{
181605 try pt.vectorType(.{ .len = vec_len, .child = vector_type.child }),
181606 } ** parts_len else |err| switch (err) {
181604 .vector_type => |vector_type| if (std.math.divExact(u32, vector_type.len, parts_len)) |vec_len| {
181605 return @splat(try pt.vectorType(.{ .len = vec_len, .child = vector_type.child }));
181606 } else |err| switch (err) {
181607181607 error.DivisionByZero => unreachable,
181608181608 error.UnexpectedRemainder => {},
181609181609 },
......@@ -188774,7 +188774,9 @@ const Select = struct {
188774188774 try pt.aggregateValue(try pt.vectorType(.{ .len = 4, .child = .u32_type }), &(.{
188775188775 (try pt.intValue(.u32, @as(u64, @bitCast(@as(f64, 0x1p52))) >> 32)).toIntern(),
188776188776 (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 })),
188778188780 ), true },
188779188781 .f32_0_0x1p64_mem => .{ try cg.tempMemFromValue(
188780188782 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: {
10441044 const index = &mnemonic_index[@intFromEnum(entry[0])];
10451045 mnemonic_map[@intFromEnum(entry[0])][index.*] = .{
10461046 .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 },
10481052 .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 },
10501058 .modrm_ext = entry[4],
10511059 .mode = entry[5],
10521060 .feature = entry[6],
src/codegen/x86_64/encoder.zig+2-2
......@@ -14,7 +14,7 @@ const Symbol = bits.Symbol;
1414pub const Instruction = struct {
1515 prefix: Prefix = .none,
1616 encoding: Encoding,
17 ops: [4]Operand = .{.none} ** 4,
17 ops: [4]Operand = @splat(.none),
1818
1919 pub const Mnemonic = Encoding.Mnemonic;
2020
......@@ -335,7 +335,7 @@ pub const Instruction = struct {
335335 var inst: Instruction = .{
336336 .prefix = prefix,
337337 .encoding = encoding,
338 .ops = [1]Operand{.none} ** 4,
338 .ops = @splat(.none),
339339 };
340340 @memcpy(inst.ops[0..ops.len], ops);
341341 return inst;
src/libs/mingw/implib.zig+1-1
......@@ -387,7 +387,7 @@ const first_string_table_entry = getNameBytesForStringTableOffset(first_string_t
387387const byte_size_of_relocation = 10;
388388
389389fn getNameBytesForStringTableOffset(offset: u32) [8]u8 {
390 var bytes = [_]u8{0} ** 8;
390 var bytes: [8]u8 = @splat(0);
391391 std.mem.writeInt(u32, bytes[4..8], offset, .little);
392392 return bytes;
393393}
src/link/Coff.zig+20-4
......@@ -81,15 +81,31 @@ pub const msdos_stub: [120]u8 = .{
8181 0x00, 0x00, // Overlay number. Zero means this is the main executable.
8282}
8383 // Reserved words.
84 ++ .{ 0x00, 0x00 } ** 4
85 // OEM-related fields.
84 ++ .{
85 0x00, 0x00,
86 0x00, 0x00,
87 0x00, 0x00,
88 0x00, 0x00,
89 }
90 // OEM-related fields.
8691 ++ .{
8792 0x00, 0x00, // OEM identifier.
8893 0x00, 0x00, // OEM information.
8994 }
9095 // Reserved words.
91 ++ .{ 0x00, 0x00 } ** 10
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.
96 ++ .{
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.
93109 ++ .{ 0x78, 0x00, 0x00, 0x00 }
94110 // What follows is a 16-bit x86 MS-DOS program of 7 instructions that prints the bytes after these instructions and then exits.
95111 ++ .{
src/link/Dwarf.zig+1-1
......@@ -2975,7 +2975,7 @@ fn finishWipNavFuncWriterError(
29752975 wip_nav.unit,
29762976 wip_nav.entry,
29772977 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)],
29792979 );
29802980 }
29812981
src/link/Elf.zig+1-1
......@@ -3943,7 +3943,7 @@ fn formatPhdr(ctx: FormatPhdr, writer: *std.Io.Writer) std.Io.Writer.Error!void
39433943 const write = phdr.p_flags & elf.PF_W != 0;
39443944 const read = phdr.p_flags & elf.PF_R != 0;
39453945 const exec = phdr.p_flags & elf.PF_X != 0;
3946 var flags: [3]u8 = [_]u8{'_'} ** 3;
3946 var flags: [3]u8 = @splat('_');
39473947 if (exec) flags[0] = 'X';
39483948 if (write) flags[1] = 'W';
39493949 if (read) flags[2] = 'R';
src/link/Elf/Symbol.zig+1-1
......@@ -363,7 +363,7 @@ const Format = struct {
363363 if (symbol.atom(elf_file)) |atom_ptr| {
364364 try writer.print(" : atom({d})", .{atom_ptr.atom_index});
365365 }
366 var buf: [2]u8 = .{'_'} ** 2;
366 var buf: [2]u8 = @splat('_');
367367 if (symbol.flags.@"export") buf[0] = 'E';
368368 if (symbol.flags.import) buf[1] = 'I';
369369 try writer.print(" : {s}", .{&buf});
src/link/MachO.zig+2-2
......@@ -38,7 +38,7 @@ symtab_cmd: macho.symtab_command = .{},
3838dysymtab_cmd: macho.dysymtab_command = .{},
3939function_starts_cmd: macho.linkedit_data_command = .{ .cmd = .FUNCTION_STARTS },
4040data_in_code_cmd: macho.linkedit_data_command = .{ .cmd = .DATA_IN_CODE },
41uuid_cmd: macho.uuid_command = .{ .uuid = [_]u8{0} ** 16 },
41uuid_cmd: macho.uuid_command = .{ .uuid = @splat(0) },
4242codesig_cmd: macho.linkedit_data_command = .{ .cmd = .CODE_SIGNATURE },
4343
4444pagezero_seg_index: ?u8 = null,
......@@ -3763,7 +3763,7 @@ pub fn addSection(
37633763}
37643764
37653765pub fn makeStaticString(bytes: []const u8) [16]u8 {
3766 var buf = [_]u8{0} ** 16;
3766 var buf: [16]u8 = @splat(0);
37673767 @memcpy(buf[0..bytes.len], bytes);
37683768 return buf;
37693769}
src/link/MachO/CodeSignature.zig+1-1
......@@ -95,7 +95,7 @@ const CodeDirectory = struct {
9595 };
9696 comptime var i = 0;
9797 inline while (i < n_special_slots) : (i += 1) {
98 cdir.special_slots[i] = [_]u8{0} ** hash_size;
98 cdir.special_slots[i] = @splat(0);
9999 }
100100 return cdir;
101101 }
src/link/MachO/DebugSymbols.zig+1-1
......@@ -25,7 +25,7 @@ allocator: Allocator,
2525file: ?Io.File,
2626
2727symtab_cmd: macho.symtab_command = .{},
28uuid_cmd: macho.uuid_command = .{ .uuid = [_]u8{0} ** 16 },
28uuid_cmd: macho.uuid_command = .{ .uuid = @splat(0) },
2929
3030segments: std.ArrayList(macho.segment_command_64) = .empty,
3131sections: std.ArrayList(macho.section_64) = .empty,
src/link/MachO/InternalObject.zig+1-1
......@@ -11,7 +11,7 @@ symbols_extra: std.ArrayList(u32) = .empty,
1111globals: std.ArrayList(MachO.SymbolResolver.Index) = .empty,
1212
1313objc_methnames: std.ArrayList(u8) = .empty,
14objc_selrefs: [@sizeOf(u64)]u8 = [_]u8{0} ** @sizeOf(u64),
14objc_selrefs: [@sizeOf(u64)]u8 = @splat(0),
1515
1616force_undefined: std.ArrayList(Symbol.Index) = .empty,
1717entry_index: ?Symbol.Index = null,
src/link/MachO/Symbol.zig+1-1
......@@ -325,7 +325,7 @@ const Format = struct {
325325 if (symbol.getAtom(f.macho_file)) |atom| {
326326 try w.print(" : atom({d})", .{atom.atom_index});
327327 }
328 var buf: [3]u8 = .{'_'} ** 3;
328 var buf: [3]u8 = @splat('_');
329329 if (symbol.flags.@"export") buf[0] = 'E';
330330 if (symbol.flags.import) buf[1] = 'I';
331331 switch (symbol.visibility) {
test/behavior/array.zig+4-16
......@@ -104,18 +104,6 @@ test "array init with concat" {
104104 try expect(std.mem.eql(u8, &i, "abcd"));
105105}
106106
107test "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
119107test "array literal with explicit type" {
120108 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
121109
......@@ -320,7 +308,7 @@ test "set global var array via slice embedded in struct" {
320308 try expect(s_array[2].b == 3);
321309}
322310
323test "read/write through global variable array of struct fields initialized via array mult" {
311test "read/write through global variable array of struct fields initialized via splat" {
324312 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
325313 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
326314
......@@ -335,7 +323,7 @@ test "read/write through global variable array of struct fields initialized via
335323 term: usize,
336324 };
337325
338 var storage: [1]MyStruct = [_]MyStruct{MyStruct{ .term = 1 }} ** 1;
326 var storage: [1]MyStruct = @splat(.{ .term = 1 });
339327 };
340328 try S.doTheTest();
341329}
......@@ -641,8 +629,8 @@ test "array of array agregate init" {
641629 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
642630 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
643631
644 var a = [1]u32{11} ** 10;
645 var b = [1][10]u32{a} ** 2;
632 var a: [10]u32 = @splat(11);
633 var b: [2][10]u32 = @splat(a);
646634 _ = .{ &a, &b };
647635 try std.testing.expect(b[1][1] == 11);
648636}
test/behavior/basic.zig+1-8
......@@ -294,13 +294,6 @@ test "string concatenation simple" {
294294 try expect(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED"));
295295}
296296
297test "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
304297const global_a: i32 = 1234;
305298const global_b: *const i32 = &global_a;
306299const 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" {
10411034 positive: bool,
10421035 };
10431036 const biggest: Const = .{
1044 .limbs = &([1]usize{comptime std.math.maxInt(usize)} ** 128),
1037 .limbs = &@as([128]usize, @splat(comptime std.math.maxInt(usize))),
10451038 .positive = false,
10461039 };
10471040 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
1515 shards: [1 << shard_key_bits]?*Node,
1616
1717 pub fn create() Self {
18 return Self{ .shards = [_]?*Node{null} ** (1 << shard_key_bits) };
18 return .{ .shards = @splat(null) };
1919 }
2020
2121 fn getShardKey(key: Key) ShardKey {
test/behavior/cast.zig+1-1
......@@ -3036,7 +3036,7 @@ test "bitcast vector" {
30363036 const u8x32 = @Vector(32, u8);
30373037 const u32x8 = @Vector(8, u32);
30383038
3039 const zerox32: u8x32 = [_]u8{0} ** 32;
3039 const zerox32: u8x32 = @splat(0);
30403040 const bigsum: u32x8 = @bitCast(zerox32);
30413041 try std.testing.expectEqual(0, @reduce(.Add, bigsum));
30423042}
test/behavior/eval.zig+1-45
......@@ -727,15 +727,6 @@ test "array concatenation of function calls" {
727727 try expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 }));
728728}
729729
730test "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
739730fn oneItem(x: i32) [1]i32 {
740731 return [_]i32{x};
741732}
......@@ -814,41 +805,6 @@ test "array concatenation sets the sentinel - pointer" {
814805 try expect(ptr[5] == 69);
815806}
816807
817test "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
835test "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
852808test "comptime assign int to optional int" {
853809 comptime {
854810 var x: ?i32 = null;
......@@ -1094,7 +1050,7 @@ test "storing an array of type in a field" {
10941050
10951051 fn foo() @This() {
10961052 comptime var foobar: Foobar = undefined;
1097 foobar.str = [_]u8{'a'} ** 1024;
1053 foobar.str = @splat('a');
10981054 return foobar;
10991055 }
11001056 };
test/behavior/extern_struct_zero_size_fields.zig+2-2
......@@ -10,9 +10,9 @@ const T = extern struct {
1010 baz: struct {} = .{},
1111 ayy: E = .the_only_possible_value,
1212 arr: [0]u0 = .{},
13 matey: [128]void = [_]void{{}} ** 128,
13 matey: [128]void = @splat({}),
1414 running_out_of_ideas: packed struct {} = .{},
15 one_more: [256]S = [_]S{.{}} ** 256,
15 one_more: [256]S = @splat(.{}),
1616};
1717
1818test {
test/behavior/for.zig+5-1
......@@ -69,7 +69,11 @@ test "basic for loop" {
6969 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
7070 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
7171
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 };
7377
7478 var buffer: [expected_result.len]u8 = undefined;
7579 var buf_index: usize = 0;
test/behavior/memset.zig+2-2
......@@ -109,7 +109,7 @@ test "memset with large array element, runtime known" {
109109
110110 const A = [128]u64;
111111 var buf: [5]A = undefined;
112 var runtime_known_element = [_]u64{0} ** 128;
112 var runtime_known_element: A = @splat(0);
113113 _ = &runtime_known_element;
114114 @memset(&buf, runtime_known_element);
115115 for (buf[0]) |elem| try expect(elem == 0);
......@@ -127,7 +127,7 @@ test "memset with large array element, comptime known" {
127127
128128 const A = [128]u64;
129129 var buf: [5]A = undefined;
130 const comptime_known_element = [_]u64{0} ** 128;
130 const comptime_known_element: A = @splat(0);
131131 @memset(&buf, comptime_known_element);
132132 for (buf[0]) |elem| try expect(elem == 0);
133133 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" {
621621 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
622622 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
623623
624 var opt_x: ?[3]f32 = [_]f32{0.0} ** 3;
624 var opt_x: ?[3]f32 = @splat(0.0);
625625
626626 const x = opt_x.?;
627627 opt_x.?[0] = 15.0;
test/behavior/packed-struct.zig+1-1
......@@ -883,7 +883,7 @@ test "pointer to container level packed struct field" {
883883 enable_5: bool,
884884 enable_6: bool,
885885 },
886 var arr = [_]u32{0} ** 2;
886 var arr: [2]u32 = @splat(0);
887887 };
888888 @as(*S, @ptrCast(&S.arr[0])).other_bits.enable_3 = true;
889889 try expect(S.arr[0] == 0x10000000);
test/behavior/pointers.zig+1-1
......@@ -627,7 +627,7 @@ test "pointer to array has explicit alignment" {
627627 return @alignCast(@as(*[4]Base2, @ptrCast(ptr)));
628628 }
629629 };
630 var bases = [_]S.Base{.{ .a = 2 }} ** 4;
630 var bases: [4]S.Base = @splat(.{ .a = 2 });
631631 const casted = S.func(&bases);
632632 try expect(casted[0].a == 2);
633633}
test/behavior/popcount.zig+4-4
......@@ -88,16 +88,16 @@ test "@popCount vectors" {
8888
8989fn testPopCountVectors() !void {
9090 {
91 var x: @Vector(8, u32) = [1]u32{0xffffffff} ** 8;
91 var x: @Vector(8, u32) = @splat(0xffffffff);
9292 _ = &x;
93 const expected = [1]u6{32} ** 8;
93 const expected: [8]u6 = @splat(32);
9494 const result: [8]u6 = @popCount(x);
9595 try expect(std.mem.eql(u6, &expected, &result));
9696 }
9797 {
98 var x: @Vector(8, i16) = [1]i16{-1} ** 8;
98 var x: @Vector(8, i16) = @splat(-1);
9999 _ = &x;
100 const expected = [1]u5{16} ** 8;
100 const expected: [8]u5 = @splat(16);
101101 const result: [8]u5 = @popCount(x);
102102 try expect(std.mem.eql(u5, &expected, &result));
103103 }
test/behavior/slice.zig+1-11
......@@ -314,7 +314,7 @@ test "C pointer slice access" {
314314 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
315315 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
316316
317 var buf: [10]u32 = [1]u32{42} ** 10;
317 var buf: [10]u32 = @splat(42);
318318 const c_ptr = @as([*c]const u32, @ptrCast(&buf));
319319
320320 var runtime_zero: usize = 0;
......@@ -768,16 +768,6 @@ test "array concat of slices gives ptr to array" {
768768 }
769769}
770770
771test "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
781771test "slice bounds in comptime concatenation" {
782772 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
783773 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
test/behavior/slice_sentinel_comptime.zig+31-28
......@@ -1,16 +1,19 @@
11const builtin = @import("builtin");
22
3const undef_10_u8: [10]u8 = @splat(undefined);
4const ff_10_u8: [10]u8 = @splat(0xFF);
5
36test "comptime slice-sentinel in bounds (unterminated)" {
47 // array
58 comptime {
6 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
9 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
710 const slice = target[0..3 :'d'];
811 _ = slice;
912 }
1013
1114 // ptr_array
1215 comptime {
13 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
16 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
1417 var target = &buf;
1518 const slice = target[0..3 :'d'];
1619 _ = slice;
......@@ -18,7 +21,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
1821
1922 // vector_ConstPtrSpecialBaseArray
2023 comptime {
21 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
24 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
2225 var target: [*]u8 = &buf;
2326 const slice = target[0..3 :'d'];
2427 _ = slice;
......@@ -26,7 +29,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
2629
2730 // vector_ConstPtrSpecialRef
2831 comptime {
29 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
32 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
3033 var target: [*]u8 = @as([*]u8, @ptrCast(&buf));
3134 const slice = target[0..3 :'d'];
3235 _ = slice;
......@@ -34,7 +37,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
3437
3538 // cvector_ConstPtrSpecialBaseArray
3639 comptime {
37 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
40 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
3841 var target: [*c]u8 = &buf;
3942 const slice = target[0..3 :'d'];
4043 _ = slice;
......@@ -42,7 +45,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
4245
4346 // cvector_ConstPtrSpecialRef
4447 comptime {
45 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
48 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
4649 var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf));
4750 const slice = target[0..3 :'d'];
4851 _ = slice;
......@@ -50,7 +53,7 @@ test "comptime slice-sentinel in bounds (unterminated)" {
5053
5154 // slice
5255 comptime {
53 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
56 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
5457 var target: []u8 = &buf;
5558 const slice = target[0..3 :'d'];
5659 _ = slice;
......@@ -60,14 +63,14 @@ test "comptime slice-sentinel in bounds (unterminated)" {
6063test "comptime slice-sentinel in bounds (end,unterminated)" {
6164 // array
6265 comptime {
63 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
66 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8;
6467 const slice = target[0..13 :0xff];
6568 _ = slice;
6669 }
6770
6871 // ptr_array
6972 comptime {
70 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
73 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8;
7174 var target = &buf;
7275 const slice = target[0..13 :0xff];
7376 _ = slice;
......@@ -75,7 +78,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
7578
7679 // vector_ConstPtrSpecialBaseArray
7780 comptime {
78 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
81 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8;
7982 var target: [*]u8 = &buf;
8083 const slice = target[0..13 :0xff];
8184 _ = slice;
......@@ -83,7 +86,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
8386
8487 // vector_ConstPtrSpecialRef
8588 comptime {
86 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
89 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8;
8790 var target: [*]u8 = @as([*]u8, @ptrCast(&buf));
8891 const slice = target[0..13 :0xff];
8992 _ = slice;
......@@ -91,7 +94,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
9194
9295 // cvector_ConstPtrSpecialBaseArray
9396 comptime {
94 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
97 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8;
9598 var target: [*c]u8 = &buf;
9699 const slice = target[0..13 :0xff];
97100 _ = slice;
......@@ -99,7 +102,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
99102
100103 // cvector_ConstPtrSpecialRef
101104 comptime {
102 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
105 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8;
103106 var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf));
104107 const slice = target[0..13 :0xff];
105108 _ = slice;
......@@ -107,7 +110,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
107110
108111 // slice
109112 comptime {
110 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10;
113 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8;
111114 var target: []u8 = &buf;
112115 const slice = target[0..13 :0xff];
113116 _ = slice;
......@@ -117,14 +120,14 @@ test "comptime slice-sentinel in bounds (end,unterminated)" {
117120test "comptime slice-sentinel in bounds (terminated)" {
118121 // array
119122 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;
121124 const slice = target[0..3 :'d'];
122125 _ = slice;
123126 }
124127
125128 // ptr_array
126129 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;
128131 var target = &buf;
129132 const slice = target[0..3 :'d'];
130133 _ = slice;
......@@ -132,7 +135,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
132135
133136 // vector_ConstPtrSpecialBaseArray
134137 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;
136139 var target: [*]u8 = &buf;
137140 const slice = target[0..3 :'d'];
138141 _ = slice;
......@@ -140,7 +143,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
140143
141144 // vector_ConstPtrSpecialRef
142145 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;
144147 var target: [*]u8 = @as([*]u8, @ptrCast(&buf));
145148 const slice = target[0..3 :'d'];
146149 _ = slice;
......@@ -148,7 +151,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
148151
149152 // cvector_ConstPtrSpecialBaseArray
150153 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;
152155 var target: [*c]u8 = &buf;
153156 const slice = target[0..3 :'d'];
154157 _ = slice;
......@@ -156,7 +159,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
156159
157160 // cvector_ConstPtrSpecialRef
158161 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;
160163 var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf));
161164 const slice = target[0..3 :'d'];
162165 _ = slice;
......@@ -164,7 +167,7 @@ test "comptime slice-sentinel in bounds (terminated)" {
164167
165168 // slice
166169 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;
168171 var target: []u8 = &buf;
169172 const slice = target[0..3 :'d'];
170173 _ = slice;
......@@ -174,14 +177,14 @@ test "comptime slice-sentinel in bounds (terminated)" {
174177test "comptime slice-sentinel in bounds (on target sentinel)" {
175178 // array
176179 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;
178181 const slice = target[0..14 :0];
179182 _ = slice;
180183 }
181184
182185 // ptr_array
183186 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;
185188 var target = &buf;
186189 const slice = target[0..14 :0];
187190 _ = slice;
......@@ -189,7 +192,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
189192
190193 // vector_ConstPtrSpecialBaseArray
191194 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;
193196 var target: [*]u8 = &buf;
194197 const slice = target[0..14 :0];
195198 _ = slice;
......@@ -197,7 +200,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
197200
198201 // vector_ConstPtrSpecialRef
199202 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;
201204 var target: [*]u8 = @as([*]u8, @ptrCast(&buf));
202205 const slice = target[0..14 :0];
203206 _ = slice;
......@@ -205,7 +208,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
205208
206209 // cvector_ConstPtrSpecialBaseArray
207210 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;
209212 var target: [*c]u8 = &buf;
210213 const slice = target[0..14 :0];
211214 _ = slice;
......@@ -213,7 +216,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
213216
214217 // cvector_ConstPtrSpecialRef
215218 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;
217220 var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf));
218221 const slice = target[0..14 :0];
219222 _ = slice;
......@@ -221,7 +224,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" {
221224
222225 // slice
223226 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;
225228 var target: []u8 = &buf;
226229 const slice = target[0..14 :0];
227230 _ = slice;
test/behavior/struct.zig+1-1
......@@ -634,7 +634,7 @@ test "packed array 24bits" {
634634 try expect(@sizeOf(FooArray24Bits) == @sizeOf(u96));
635635 }
636636
637 var bytes = [_]u8{0} ** (@sizeOf(FooArray24Bits) + 1);
637 var bytes: [@sizeOf(FooArray24Bits) + 1]u8 = @splat(0);
638638 bytes[bytes.len - 1] = 0xbb;
639639 const ptr = &std.mem.bytesAsSlice(FooArray24Bits, bytes[0 .. bytes.len - 1])[0];
640640 try expect(ptr.a == 0);
test/behavior/tuple.zig+1-24
......@@ -26,29 +26,6 @@ test "tuple concatenation" {
2626 try comptime S.doTheTest();
2727}
2828
29test "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
5229test "more tuple concatenation" {
5330 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
5431 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
......@@ -357,7 +334,7 @@ test "tuple of struct concatenation and coercion to array" {
357334 const StructWithDefault = struct { value: f32 = 42 };
358335 const SomeStruct = struct { array: [4]StructWithDefault };
359336
360 const value1 = SomeStruct{ .array = .{StructWithDefault{}} ++ [_]StructWithDefault{.{}} ** 3 };
337 const value1 = SomeStruct{ .array = .{StructWithDefault{}} ++ @as([3]StructWithDefault, @splat(.{})) };
361338 const value2 = SomeStruct{ .array = .{ .{}, .{}, .{}, .{} } };
362339
363340 try expectEqual(value1, value2);
test/behavior/tuple_declarations.zig-6
......@@ -42,12 +42,6 @@ test "tuple declaration usage" {
4242 try expect(t[0] == 1);
4343 try expectEqualStrings(t[1], "foo");
4444
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
5145 var t2: T = .{ 2, "bar" };
5246 _ = &t2;
5347 const cat = t ++ t2;
test/behavior/undefined.zig+1-1
......@@ -90,7 +90,7 @@ test "reslice of undefined global var slice" {
9090 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
9191 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
9292
93 var stack_buf: [100]u8 = [_]u8{0} ** 100;
93 var stack_buf: [100]u8 = @splat(0);
9494 buf = &stack_buf;
9595 const x = buf[0..1];
9696 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 {
138138};
139139
140140const v1 = Value{ .Int = 1234 };
141const v2 = Value{ .Array = [_]u8{3} ** 9 };
141const v2 = Value{ .Array = @splat(3) };
142142
143143const err = @as(anyerror!Agg, Agg{
144144 .val1 = v1,
......@@ -1156,7 +1156,7 @@ test "extern union most-aligned field is smaller" {
11561156 },
11571157 un: [110]u8,
11581158 };
1159 var a: ?U = .{ .un = [_]u8{0} ** 110 };
1159 var a: ?U = .{ .un = @splat(0) };
11601160 _ = &a;
11611161 try expect(a != null);
11621162}
test/behavior/void.zig+1-1
......@@ -44,7 +44,7 @@ test "void optional" {
4444}
4545
4646test "void array as a local variable initializer" {
47 var x = [_]void{{}} ** 1004;
47 var x: [1004]void = @splat({});
4848 _ = &x[0];
4949 _ = x[0];
5050}
test/c/unistd.zig+3-3
......@@ -22,14 +22,14 @@ test "swab" {
2222 // n < 1
2323 @memset(a[0..], '\x00');
2424 c.swab("abcd", &a, 0);
25 try testing.expectEqualSlices(u8, "\x00" ** 4, &a);
25 try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0 }, &a);
2626 c.swab("abcd", &a, -1);
27 try testing.expectEqualSlices(u8, "\x00" ** 4, &a);
27 try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0 }, &a);
2828
2929 // Odd n
3030 @memset(a[0..], '\x00');
3131 c.swab("abcd", &a, 1);
32 try testing.expectEqualSlices(u8, "\x00" ** 4, &a);
32 try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0 }, &a);
3333 c.swab("abcd", &a, 3);
3434 try testing.expectEqualSlices(u8, "ba\x00\x00", &a);
3535}
test/cases/compile_errors/Issue_6823_dont_allow_._to_be_followed_by_.zig deleted-8
......@@ -1,8 +0,0 @@
1fn 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 @@
1const exponent: f32 = 1.0;
2export 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 @@
11export fn foo_array() void {
22 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;
44 const slice = target[0..3 :0];
55 _ = slice;
66 }
77}
88export fn foo_ptr_array() void {
99 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;
1111 var target = &buf;
1212 const slice = target[0..3 :0];
1313 _ = slice;
......@@ -15,7 +15,7 @@ export fn foo_ptr_array() void {
1515}
1616export fn foo_vector_ConstPtrSpecialBaseArray() void {
1717 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;
1919 var target: [*]u8 = &buf;
2020 const slice = target[0..3 :0];
2121 _ = slice;
......@@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void {
2323}
2424export fn foo_vector_ConstPtrSpecialRef() void {
2525 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;
2727 var target: [*]u8 = @ptrCast(&buf);
2828 const slice = target[0..3 :0];
2929 _ = slice;
......@@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void {
3131}
3232export fn foo_cvector_ConstPtrSpecialBaseArray() void {
3333 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;
3535 var target: [*c]u8 = &buf;
3636 const slice = target[0..3 :0];
3737 _ = slice;
......@@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {
3939}
4040export fn foo_cvector_ConstPtrSpecialRef() void {
4141 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;
4343 var target: [*c]u8 = @ptrCast(&buf);
4444 const slice = target[0..3 :0];
4545 _ = slice;
......@@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void {
4747}
4848export fn foo_slice() void {
4949 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;
5151 var target: []u8 = &buf;
5252 const slice = target[0..3 :0];
5353 _ = slice;
5454 }
5555}
56const undef_10_u8: [10]u8 = @splat(undefined);
5657
5758// error
5859//
test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig+8-7
......@@ -1,13 +1,13 @@
11export fn foo_array() void {
22 comptime {
3 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
3 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
44 const slice = target[0..3 :0];
55 _ = slice;
66 }
77}
88export fn foo_ptr_array() void {
99 comptime {
10 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
10 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
1111 var target = &buf;
1212 const slice = target[0..3 :0];
1313 _ = slice;
......@@ -15,7 +15,7 @@ export fn foo_ptr_array() void {
1515}
1616export fn foo_vector_ConstPtrSpecialBaseArray() void {
1717 comptime {
18 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
18 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
1919 var target: [*]u8 = &buf;
2020 const slice = target[0..3 :0];
2121 _ = slice;
......@@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void {
2323}
2424export fn foo_vector_ConstPtrSpecialRef() void {
2525 comptime {
26 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
26 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
2727 var target: [*]u8 = @ptrCast(&buf);
2828 const slice = target[0..3 :0];
2929 _ = slice;
......@@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void {
3131}
3232export fn foo_cvector_ConstPtrSpecialBaseArray() void {
3333 comptime {
34 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
34 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
3535 var target: [*c]u8 = &buf;
3636 const slice = target[0..3 :0];
3737 _ = slice;
......@@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {
3939}
4040export fn foo_cvector_ConstPtrSpecialRef() void {
4141 comptime {
42 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
42 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
4343 var target: [*c]u8 = @ptrCast(&buf);
4444 const slice = target[0..3 :0];
4545 _ = slice;
......@@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void {
4747}
4848export fn foo_slice() void {
4949 comptime {
50 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
50 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
5151 var target: []u8 = &buf;
5252 const slice = target[0..3 :0];
5353 _ = slice;
5454 }
5555}
56const undef_10_u8: [10]u8 = @splat(undefined);
5657
5758// error
5859//
test/cases/compile_errors/comptime_slice-sentinel_does_not_match_target-sentinel.zig+14-13
......@@ -1,13 +1,13 @@
11export fn foo_array() void {
22 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;
44 const slice = target[0..14 :255];
55 _ = slice;
66 }
77}
88export fn foo_ptr_array() void {
99 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;
1111 var target = &buf;
1212 const slice = target[0..14 :255];
1313 _ = slice;
......@@ -15,7 +15,7 @@ export fn foo_ptr_array() void {
1515}
1616export fn foo_vector_ConstPtrSpecialBaseArray() void {
1717 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;
1919 var target: [*]u8 = &buf;
2020 const slice = target[0..14 :255];
2121 _ = slice;
......@@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void {
2323}
2424export fn foo_vector_ConstPtrSpecialRef() void {
2525 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;
2727 var target: [*]u8 = @ptrCast(&buf);
2828 const slice = target[0..14 :255];
2929 _ = slice;
......@@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void {
3131}
3232export fn foo_cvector_ConstPtrSpecialBaseArray() void {
3333 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;
3535 var target: [*c]u8 = &buf;
3636 const slice = target[0..14 :255];
3737 _ = slice;
......@@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {
3939}
4040export fn foo_cvector_ConstPtrSpecialRef() void {
4141 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;
4343 var target: [*c]u8 = @ptrCast(&buf);
4444 const slice = target[0..14 :255];
4545 _ = slice;
......@@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void {
4747}
4848export fn foo_slice() void {
4949 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;
5151 var target: []u8 = &buf;
5252 const slice = target[0..14 :255];
5353 _ = slice;
5454 }
5555}
56const undef_10_u8: [10]u8 = @splat(undefined);
5657export fn undefined_slice() void {
5758 const arr: [100]u16 = undefined;
5859 const slice = arr[0..12 :0];
......@@ -85,9 +86,9 @@ export fn typeName_slice() void {
8586// :44:29: note: expected '255', found '0'
8687// :52:29: error: value in memory does not match slice sentinel
8788// :52:29: note: expected '255', found '0'
88// :58:22: error: value in memory does not match slice sentinel
89// :58:22: note: expected '0', found 'undefined'
90// :63:22: error: value in memory does not match slice sentinel
91// :63:22: note: expected '12', found '98'
92// :68:22: error: value in memory does not match slice sentinel
93// :68:22: note: expected '0', found '105'
89// :59:22: error: value in memory does not match slice sentinel
90// :59:22: note: expected '0', found 'undefined'
91// :64:22: error: value in memory does not match slice sentinel
92// :64:22: note: expected '12', found '98'
93// :69:22: error: value in memory does not match slice sentinel
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 @@
11export fn foo_array() void {
22 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;
44 const slice = target[0..15 :1];
55 _ = slice;
66 }
77}
88export fn foo_ptr_array() void {
99 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;
1111 var target = &buf;
1212 const slice = target[0..15 :0];
1313 _ = slice;
......@@ -15,7 +15,7 @@ export fn foo_ptr_array() void {
1515}
1616export fn foo_vector_ConstPtrSpecialBaseArray() void {
1717 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;
1919 var target: [*]u8 = &buf;
2020 const slice = target[0..15 :0];
2121 _ = slice;
......@@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void {
2323}
2424export fn foo_vector_ConstPtrSpecialRef() void {
2525 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;
2727 var target: [*]u8 = @ptrCast(&buf);
2828 const slice = target[0..15 :0];
2929 _ = slice;
......@@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void {
3131}
3232export fn foo_cvector_ConstPtrSpecialBaseArray() void {
3333 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;
3535 var target: [*c]u8 = &buf;
3636 const slice = target[0..15 :0];
3737 _ = slice;
......@@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {
3939}
4040export fn foo_cvector_ConstPtrSpecialRef() void {
4141 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;
4343 var target: [*c]u8 = @ptrCast(&buf);
4444 const slice = target[0..15 :0];
4545 _ = slice;
......@@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void {
4747}
4848export fn foo_slice() void {
4949 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;
5151 var target: []u8 = &buf;
5252 const slice = target[0..15 :0];
5353 _ = slice;
5454 }
5555}
56const undef_10_u8: [10]u8 = @splat(undefined);
5657
5758// error
5859//
test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig+8-7
......@@ -1,13 +1,13 @@
11export fn foo_array() void {
22 comptime {
3 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
3 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
44 const slice = target[0..14 :0];
55 _ = slice;
66 }
77}
88export fn foo_ptr_array() void {
99 comptime {
10 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
10 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
1111 var target = &buf;
1212 const slice = target[0..14 :0];
1313 _ = slice;
......@@ -15,7 +15,7 @@ export fn foo_ptr_array() void {
1515}
1616export fn foo_vector_ConstPtrSpecialBaseArray() void {
1717 comptime {
18 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
18 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
1919 var target: [*]u8 = &buf;
2020 const slice = target[0..14 :0];
2121 _ = slice;
......@@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void {
2323}
2424export fn foo_vector_ConstPtrSpecialRef() void {
2525 comptime {
26 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
26 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
2727 var target: [*]u8 = @ptrCast(&buf);
2828 const slice = target[0..14 :0];
2929 _ = slice;
......@@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void {
3131}
3232export fn foo_cvector_ConstPtrSpecialBaseArray() void {
3333 comptime {
34 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
34 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
3535 var target: [*c]u8 = &buf;
3636 const slice = target[0..14 :0];
3737 _ = slice;
......@@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void {
3939}
4040export fn foo_cvector_ConstPtrSpecialRef() void {
4141 comptime {
42 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
42 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
4343 var target: [*c]u8 = @ptrCast(&buf);
4444 const slice = target[0..14 :0];
4545 _ = slice;
......@@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void {
4747}
4848export fn foo_slice() void {
4949 comptime {
50 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
50 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8;
5151 var target: []u8 = &buf;
5252 const slice = target[0..14 :0];
5353 _ = slice;
5454 }
5555}
56const undef_10_u8: [10]u8 = @splat(undefined);
5657
5758// error
5859//
test/cases/compile_errors/dereference_bad_pointer_via_array_mul.zig deleted-11
......@@ -1,11 +0,0 @@
1const A = struct {};
2const B = struct {};
3comptime {
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 {
33 arr = concat();
44}
55fn concat() [16]f32 {
6 return [1]f32{0} ** 16;
6 return @splat(0.0);
77}
88
99// error
test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig+1-1
......@@ -1,5 +1,5 @@
11export 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);
33 _ = @as(*const []const u8, @ptrCast(&bytes)).*;
44}
55
test/cases/safety/memcpy_alias.zig+1-1
......@@ -8,7 +8,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
88 std.process.exit(1);
99}
1010pub 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 };
1212 var len: usize = 5;
1313 _ = &len;
1414 @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
88 std.process.exit(1);
99}
1010pub 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 };
1212 var len: usize = 5;
1313 _ = &len;
1414 @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
88 std.process.exit(1);
99}
1010pub 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 };
1212 var len: usize = 5;
1313 _ = &len;
1414 @memmove(buffer[0..len], buffer[len .. len + 4]);
tools/fetch_them_macos_headers.zig+1-1
......@@ -237,7 +237,7 @@ const Version = struct {
237237 patch: u8,
238238
239239 fn parse(raw: []const u8) ?Version {
240 var parsed: [3]u16 = [_]u16{0} ** 3;
240 var parsed: [3]u16 = @splat(0);
241241 var count: usize = 0;
242242 var it = std.mem.splitAny(u8, raw, ".");
243243 while (it.next()) |comp| {
tools/gen_spirv_spec.zig+1-1
......@@ -732,7 +732,7 @@ fn renderBitEnum(
732732) !void {
733733 try writer.print("pub const {f} = packed struct {{\n", .{std.zig.fmtId(enumeration.kind)});
734734
735 var flags_by_bitpos = [_]?usize{null} ** 32;
735 var flags_by_bitpos: [32]?usize = @splat(null);
736736 const enumerants = enumeration.enumerants orelse return error.InvalidRegistry;
737737
738738 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
702702 }
703703 } else {
704704 gop.value_ptr.* = .{
705 .present = [1]bool{false} ** arches.len,
705 .present = @splat(false),
706706 .section = section_index_map[this_section],
707707 .ty = ty,
708 .binding = [1]u4{0} ** arches.len,
708 .binding = @splat(0),
709709 .visib = visib,
710 .size = [1]u64{0} ** arches.len,
710 .size = @splat(0),
711711 };
712712 }
713713 gop.value_ptr.present[archIndex(parse.arch)] = true;
tools/generate_JSONTestSuite.zig+24-11
......@@ -4,15 +4,15 @@ const std = @import("std");
44const Io = std.Io;
55
66pub fn main(init: std.process.Init) !void {
7 const allocator = init.gpa;
7 const allocator = init.arena.allocator();
88 const io = init.io;
99
1010 var stdout_buffer: [2000]u8 = undefined;
1111 var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer);
1212 const output = &stdout_writer.interface;
1313 try output.writeAll(
14 \\// This file was generated by _generate_JSONTestSuite.zig
15 \\// These test cases are sourced from: https://github.com/nst/JSONTestSuite
14 \\//! This file was generated by _generate_JSONTestSuite.zig
15 \\//! These test cases are sourced from: https://github.com/nst/JSONTestSuite
1616 \\const ok = @import("./test.zig").ok;
1717 \\const err = @import("./test.zig").err;
1818 \\const any = @import("./test.zig").any;
......@@ -33,7 +33,7 @@ pub fn main(init: std.process.Init) !void {
3333 }).lessThan);
3434
3535 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));
3737 try output.writeAll("test ");
3838 try writeString(output, name);
3939 try output.writeAll(" {\n try ");
......@@ -51,21 +51,34 @@ pub fn main(init: std.process.Init) !void {
5151 try output.flush();
5252}
5353
54const i_structure_500_nested_arrays = "[" ** 500 ++ "]" ** 500;
55const n_structure_100000_opening_arrays = "[" ** 100000;
56const n_structure_open_array_object = "[{\"\":" ** 50000 ++ "\n";
54const i_structure_500_nested_arrays = &(@as([500]u8, @splat('[')) ++ @as([500]u8, @splat(']')));
55const n_structure_100000_opening_arrays: *const [100000]u8 = &@splat('[');
56const 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};
5762
5863fn writeString(writer: anytype, s: []const u8) !void {
5964 if (s.len > 200) {
6065 // There are a few of these we can compress with Zig expressions.
6166 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(']'))");
6368 } 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('['))");
6570 } 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");
6781 }
68 unreachable;
6982 }
7083 try writer.writeByte('"');
7184 for (s) |b| {