authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-22 20:10:16-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-02-22 20:10:16-05:00
log6769806213ab28ed629221085325d8f143e515b0
treee621eb6aa4ab49bb72018d33c373b258f55922df
parentb6a1fdd3fa167878f75b4f12ac170d1a10e4e9a2
parenteb3c7f570601a6e00cbf03f0a026b3493887a534
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #21727 from 87flowers/fmt-render2

std/zig/render: Rewrite indentation

44 files changed, 1725 insertions(+), 1499 deletions(-)

lib/compiler/aro/aro/Parser.zig+1-1
......@@ -979,7 +979,7 @@ fn decl(p: *Parser) Error!bool {
979979 _ = try p.expectToken(.semicolon);
980980 if (decl_spec.ty.is(.@"enum") or
981981 (decl_spec.ty.isRecord() and !decl_spec.ty.isAnonymousRecord(p.comp) and
982 !decl_spec.ty.isTypeof())) // we follow GCC and clang's behavior here
982 !decl_spec.ty.isTypeof())) // we follow GCC and clang's behavior here
983983 {
984984 const specifier = decl_spec.ty.canonicalize(.standard).specifier;
985985 const attrs = p.attr_buf.items(.attr)[attr_buf_top..];
lib/compiler/aro/aro/pragmas/gcc.zig+3-3
......@@ -114,9 +114,9 @@ fn preprocessorHandler(pragma: *Pragma, pp: *Preprocessor, start_idx: TokenIndex
114114
115115 const gcc_pragma = std.meta.stringToEnum(Directive, pp.expandedSlice(directive_tok)) orelse
116116 return pp.comp.addDiagnostic(.{
117 .tag = .unknown_gcc_pragma,
118 .loc = directive_tok.loc,
119 }, pp.expansionSlice(start_idx + 1));
117 .tag = .unknown_gcc_pragma,
118 .loc = directive_tok.loc,
119 }, pp.expansionSlice(start_idx + 1));
120120
121121 switch (gcc_pragma) {
122122 .warning, .@"error" => {
lib/compiler/resinator/lang.zig+1-1
......@@ -255,7 +255,7 @@ pub fn parse(lang_tag: []const u8) error{InvalidLanguageTag}!Parsed {
255255 // Special case for qps-ploca and qps-plocm
256256 else if (std.ascii.eqlIgnoreCase(lang_code, "qps") and
257257 (std.ascii.eqlIgnoreCase(part_str, "ploca") or
258 std.ascii.eqlIgnoreCase(part_str, "plocm")))
258 std.ascii.eqlIgnoreCase(part_str, "plocm")))
259259 {
260260 parsed.suffix = part_str;
261261 } else {
lib/compiler_rt/count0bits.zig+1-1
......@@ -143,7 +143,7 @@ pub const __clzsi2 = switch (builtin.cpu.arch) {
143143 .arm, .armeb, .thumb, .thumbeb => impl: {
144144 const use_thumb1 =
145145 (builtin.cpu.arch.isThumb() or
146 std.Target.arm.featureSetHas(builtin.cpu.features, .noarm)) and
146 std.Target.arm.featureSetHas(builtin.cpu.features, .noarm)) and
147147 !std.Target.arm.featureSetHas(builtin.cpu.features, .thumb2);
148148
149149 if (use_thumb1) {
lib/compiler_rt/int.zig+26-26
......@@ -81,19 +81,19 @@ fn test_one_divmoddi4(a: i64, b: i64, expected_q: i64, expected_r: i64) !void {
8181
8282const cases__divmoddi4 =
8383 [_][4]i64{
84 [_]i64{ 0, 1, 0, 0 },
85 [_]i64{ 0, -1, 0, 0 },
86 [_]i64{ 2, 1, 2, 0 },
87 [_]i64{ 2, -1, -2, 0 },
88 [_]i64{ -2, 1, -2, 0 },
89 [_]i64{ -2, -1, 2, 0 },
90 [_]i64{ 7, 5, 1, 2 },
91 [_]i64{ -7, 5, -1, -2 },
92 [_]i64{ 19, 5, 3, 4 },
93 [_]i64{ 19, -5, -3, 4 },
94 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000000))), 0 },
95 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000007))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000001))), -1 },
96};
84 [_]i64{ 0, 1, 0, 0 },
85 [_]i64{ 0, -1, 0, 0 },
86 [_]i64{ 2, 1, 2, 0 },
87 [_]i64{ 2, -1, -2, 0 },
88 [_]i64{ -2, 1, -2, 0 },
89 [_]i64{ -2, -1, 2, 0 },
90 [_]i64{ 7, 5, 1, 2 },
91 [_]i64{ -7, 5, -1, -2 },
92 [_]i64{ 19, 5, 3, 4 },
93 [_]i64{ 19, -5, -3, 4 },
94 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000000))), 0 },
95 [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000007))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000001))), -1 },
96 };
9797
9898test "test_divmoddi4" {
9999 for (cases__divmoddi4) |case| {
......@@ -215,19 +215,19 @@ pub fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 {
215215
216216const cases__divmodsi4 =
217217 [_][4]i32{
218 [_]i32{ 0, 1, 0, 0 },
219 [_]i32{ 0, -1, 0, 0 },
220 [_]i32{ 2, 1, 2, 0 },
221 [_]i32{ 2, -1, -2, 0 },
222 [_]i32{ -2, 1, -2, 0 },
223 [_]i32{ -2, -1, 2, 0 },
224 [_]i32{ 7, 5, 1, 2 },
225 [_]i32{ -7, 5, -1, -2 },
226 [_]i32{ 19, 5, 3, 4 },
227 [_]i32{ 19, -5, -3, 4 },
228 [_]i32{ @bitCast(@as(u32, 0x80000000)), 8, @bitCast(@as(u32, 0xf0000000)), 0 },
229 [_]i32{ @bitCast(@as(u32, 0x80000007)), 8, @bitCast(@as(u32, 0xf0000001)), -1 },
230};
218 [_]i32{ 0, 1, 0, 0 },
219 [_]i32{ 0, -1, 0, 0 },
220 [_]i32{ 2, 1, 2, 0 },
221 [_]i32{ 2, -1, -2, 0 },
222 [_]i32{ -2, 1, -2, 0 },
223 [_]i32{ -2, -1, 2, 0 },
224 [_]i32{ 7, 5, 1, 2 },
225 [_]i32{ -7, 5, -1, -2 },
226 [_]i32{ 19, 5, 3, 4 },
227 [_]i32{ 19, -5, -3, 4 },
228 [_]i32{ @bitCast(@as(u32, 0x80000000)), 8, @bitCast(@as(u32, 0xf0000000)), 0 },
229 [_]i32{ @bitCast(@as(u32, 0x80000007)), 8, @bitCast(@as(u32, 0xf0000001)), -1 },
230 };
231231
232232fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) !void {
233233 var r: i32 = undefined;
lib/compiler_rt/popcount.zig+1-1
......@@ -40,7 +40,7 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 {
4040 var x: UT = @bitCast(a);
4141 x -= (x >> 1) & (~@as(UT, 0) / 3); // 0x55...55, aggregate duos
4242 x = ((x >> 2) & (~@as(UT, 0) / 5)) // 0x33...33, aggregate nibbles
43 + (x & (~@as(UT, 0) / 5));
43 + (x & (~@as(UT, 0) / 5));
4444 x += x >> 4;
4545 x &= ~@as(UT, 0) / 17; // 0x0F...0F, aggregate bytes
4646 // 8 most significant bits of x + (x<<8) + (x<<16) + ..
lib/docs/wasm/markdown/Parser.zig+1-1
......@@ -374,7 +374,7 @@ fn appendBlockStart(p: *Parser, block_start: BlockStart) !void {
374374 // or not of the same marker type.
375375 const should_close_list = last_pending_block.tag == .list and
376376 (block_start.tag != .list_item or
377 block_start.data.list_item.marker != last_pending_block.data.list.marker);
377 block_start.data.list_item.marker != last_pending_block.data.list.marker);
378378 // The last block should also be closed if the new block is not a table
379379 // row, which is the only allowed child of a table.
380380 const should_close_table = last_pending_block.tag == .table and
lib/std/Target.zig+1-1
......@@ -299,7 +299,7 @@ pub const Os = struct {
299299 pub fn parse(str: []const u8) !WindowsVersion {
300300 return std.meta.stringToEnum(WindowsVersion, str) orelse
301301 @enumFromInt(std.fmt.parseInt(u32, str, 0) catch
302 return error.InvalidOperatingSystemVersion);
302 return error.InvalidOperatingSystemVersion);
303303 }
304304
305305 /// This function is defined to serialize a Zig source code representation of this
lib/std/c.zig+4-4
......@@ -9879,10 +9879,10 @@ pub extern "c" fn setlocale(category: LC, locale: ?[*:0]const u8) ?[*:0]const u8
98799879
98809880pub const getcontext = if (builtin.target.abi.isAndroid() or builtin.target.os.tag == .openbsd)
98819881{} // android bionic and openbsd libc does not implement getcontext
9882else if (native_os == .linux and builtin.target.abi.isMusl())
9883 linux.getcontext
9884else
9885 private.getcontext;
9882 else if (native_os == .linux and builtin.target.abi.isMusl())
9883 linux.getcontext
9884 else
9885 private.getcontext;
98869886
98879887pub const max_align_t = if (native_abi == .msvc or native_abi == .itanium)
98889888 f64
lib/std/crypto/tls/Client.zig+7-7
......@@ -692,7 +692,7 @@ pub fn init(stream: anytype, options: Options) InitError(@TypeOf(stream))!Client
692692 const client_key_exchange_msg = .{@intFromEnum(tls.ContentType.handshake)} ++
693693 int(u16, @intFromEnum(tls.ProtocolVersion.tls_1_2)) ++
694694 array(u16, u8, .{@intFromEnum(tls.HandshakeType.client_key_exchange)} ++
695 array(u24, u8, array(u8, u8, key_share.secp256r1_kp.public_key.toUncompressedSec1())));
695 array(u24, u8, array(u8, u8, key_share.secp256r1_kp.public_key.toUncompressedSec1())));
696696 const client_change_cipher_spec_msg = .{@intFromEnum(tls.ContentType.change_cipher_spec)} ++
697697 int(u16, @intFromEnum(tls.ProtocolVersion.tls_1_2)) ++
698698 array(u16, tls.ChangeCipherSpecType, .{.change_cipher_spec});
......@@ -720,11 +720,11 @@ pub fn init(stream: anytype, options: Options) InitError(@TypeOf(stream))!Client
720720 );
721721 const client_verify_cleartext = .{@intFromEnum(tls.HandshakeType.finished)} ++
722722 array(u24, u8, hmacExpandLabel(
723 P.Hmac,
724 &master_secret,
725 &.{ "client finished", &p.transcript_hash.peek() },
726 P.verify_data_length,
727 ));
723 P.Hmac,
724 &master_secret,
725 &.{ "client finished", &p.transcript_hash.peek() },
726 P.verify_data_length,
727 ));
728728 p.transcript_hash.update(&client_verify_cleartext);
729729 p.version = .{ .tls_1_2 = .{
730730 .expected_server_verify_data = hmacExpandLabel(
......@@ -745,7 +745,7 @@ pub fn init(stream: anytype, options: Options) InitError(@TypeOf(stream))!Client
745745 var client_verify_msg = .{@intFromEnum(tls.ContentType.handshake)} ++
746746 int(u16, @intFromEnum(tls.ProtocolVersion.tls_1_2)) ++
747747 array(u16, u8, nonce[P.fixed_iv_length..].* ++
748 @as([client_verify_cleartext.len + P.mac_length]u8, undefined));
748 @as([client_verify_cleartext.len + P.mac_length]u8, undefined));
749749 P.AEAD.encrypt(
750750 client_verify_msg[client_verify_msg.len - P.mac_length -
751751 client_verify_cleartext.len ..][0..client_verify_cleartext.len],
lib/std/debug/SelfInfo.zig+9-9
......@@ -689,15 +689,15 @@ pub const Module = switch (native_os) {
689689 const o_file_path = mem.sliceTo(self.strings[symbol.ofile..], 0);
690690 const o_file_info = self.ofiles.getPtr(o_file_path) orelse
691691 (self.loadOFile(allocator, o_file_path) catch |err| switch (err) {
692 error.FileNotFound,
693 error.MissingDebugInfo,
694 error.InvalidDebugInfo,
695 => return .{
696 .relocated_address = relocated_address,
697 .symbol = symbol,
698 },
699 else => return err,
700 });
692 error.FileNotFound,
693 error.MissingDebugInfo,
694 error.InvalidDebugInfo,
695 => return .{
696 .relocated_address = relocated_address,
697 .symbol = symbol,
698 },
699 else => return err,
700 });
701701
702702 return .{
703703 .relocated_address = relocated_address,
lib/std/http/Client.zig+14-14
......@@ -959,14 +959,14 @@ pub const Request = struct {
959959
960960 pub const WaitError = RequestError || SendError || TransferReadError ||
961961 proto.HeadersParser.CheckCompleteHeadError || Response.ParseError ||
962 error{ // TODO: file zig fmt issue for this bad indentation
963 TooManyHttpRedirects,
964 RedirectRequiresResend,
965 HttpRedirectLocationMissing,
966 HttpRedirectLocationInvalid,
967 CompressionInitializationFailed,
968 CompressionUnsupported,
969 };
962 error{
963 TooManyHttpRedirects,
964 RedirectRequiresResend,
965 HttpRedirectLocationMissing,
966 HttpRedirectLocationInvalid,
967 CompressionInitializationFailed,
968 CompressionUnsupported,
969 };
970970
971971 /// Waits for a response from the server and parses any headers that are sent.
972972 /// This function will block until the final response is received.
......@@ -1539,13 +1539,13 @@ pub fn connect(
15391539
15401540pub const RequestError = ConnectTcpError || ConnectErrorPartial || Request.SendError ||
15411541 std.fmt.ParseIntError || Connection.WriteError ||
1542 error{ // TODO: file a zig fmt issue for this bad indentation
1543 UnsupportedUriScheme,
1544 UriMissingHost,
1542 error{
1543 UnsupportedUriScheme,
1544 UriMissingHost,
15451545
1546 CertificateBundleLoadFailure,
1547 UnsupportedTransferEncoding,
1548};
1546 CertificateBundleLoadFailure,
1547 UnsupportedTransferEncoding,
1548 };
15491549
15501550pub const RequestOptions = struct {
15511551 version: http.Version = .@"HTTP/1.1",
lib/std/posix.zig+6-6
......@@ -2851,12 +2851,12 @@ pub fn renameatW(
28512851
28522852 rc =
28532853 windows.ntdll.NtSetInformationFile(
2854 src_fd,
2855 &io_status_block,
2856 rename_info,
2857 @intCast(struct_len), // already checked for error.NameTooLong
2858 .FileRenameInformation,
2859 );
2854 src_fd,
2855 &io_status_block,
2856 rename_info,
2857 @intCast(struct_len), // already checked for error.NameTooLong
2858 .FileRenameInformation,
2859 );
28602860 }
28612861
28622862 switch (rc) {
lib/std/zig.zig+12-12
......@@ -535,16 +535,12 @@ test isUnderscore {
535535 try std.testing.expect(!isUnderscore("\\x5f"));
536536}
537537
538pub fn readSourceFileToEndAlloc(
539 allocator: Allocator,
540 input: std.fs.File,
541 size_hint: ?usize,
542) ![:0]u8 {
538pub fn readSourceFileToEndAlloc(gpa: Allocator, input: std.fs.File, size_hint: ?usize) ![:0]u8 {
543539 const source_code = input.readToEndAllocOptions(
544 allocator,
540 gpa,
545541 max_src_size,
546542 size_hint,
547 @alignOf(u16),
543 @alignOf(u8),
548544 0,
549545 ) catch |err| switch (err) {
550546 error.ConnectionResetByPeer => unreachable,
......@@ -552,7 +548,7 @@ pub fn readSourceFileToEndAlloc(
552548 error.NotOpenForReading => unreachable,
553549 else => |e| return e,
554550 };
555 errdefer allocator.free(source_code);
551 errdefer gpa.free(source_code);
556552
557553 // Detect unsupported file types with their Byte Order Mark
558554 const unsupported_boms = [_][]const u8{
......@@ -568,15 +564,19 @@ pub fn readSourceFileToEndAlloc(
568564
569565 // If the file starts with a UTF-16 little endian BOM, translate it to UTF-8
570566 if (std.mem.startsWith(u8, source_code, "\xff\xfe")) {
571 const source_code_utf16_le = std.mem.bytesAsSlice(u16, source_code);
572 const source_code_utf8 = std.unicode.utf16LeToUtf8AllocZ(allocator, source_code_utf16_le) catch |err| switch (err) {
567 if (source_code.len % 2 != 0) return error.InvalidEncoding;
568 // TODO: after wrangle-writer-buffering branch is merged,
569 // avoid this unnecessary allocation
570 const aligned_copy = try gpa.alloc(u16, source_code.len / 2);
571 defer gpa.free(aligned_copy);
572 @memcpy(std.mem.sliceAsBytes(aligned_copy), source_code);
573 const source_code_utf8 = std.unicode.utf16LeToUtf8AllocZ(gpa, aligned_copy) catch |err| switch (err) {
573574 error.DanglingSurrogateHalf => error.UnsupportedEncoding,
574575 error.ExpectedSecondSurrogateHalf => error.UnsupportedEncoding,
575576 error.UnexpectedSecondSurrogateHalf => error.UnsupportedEncoding,
576577 else => |e| return e,
577578 };
578
579 allocator.free(source_code);
579 gpa.free(source_code);
580580 return source_code_utf8;
581581 }
582582
lib/std/zig/parser_test.zig+165-20
......@@ -1776,7 +1776,7 @@ test "zig fmt: if nested" {
17761776 \\ GE_EQUAL
17771777 \\ else
17781778 \\ GE_GREATER
1779 \\ // comment
1779 \\ // comment
17801780 \\ else if (aInt > bInt)
17811781 \\ GE_LESS
17821782 \\ else if (aInt == bInt)
......@@ -4670,7 +4670,7 @@ test "zig fmt: test comments in field access chain" {
46704670 \\ .more() //
46714671 \\ .more().more() //
46724672 \\ .more() //
4673 \\ // .more() //
4673 \\ // .more() //
46744674 \\ .more() //
46754675 \\ .more();
46764676 \\ data: Data,
......@@ -4679,9 +4679,9 @@ test "zig fmt: test comments in field access chain" {
46794679 \\pub const str = struct {
46804680 \\ pub const Thing = more.more //
46814681 \\ .more() //
4682 \\ // .more() //
4683 \\ // .more() //
4684 \\ // .more() //
4682 \\ // .more() //
4683 \\ // .more() //
4684 \\ // .more() //
46854685 \\ .more() //
46864686 \\ .more();
46874687 \\ data: Data,
......@@ -4706,7 +4706,7 @@ test "zig fmt: allow line break before field access" {
47064706 \\ const x = foo
47074707 \\ .bar()
47084708 \\ . // comment
4709 \\ // comment
4709 \\ // comment
47104710 \\ swooop().zippy(zag)
47114711 \\ .iguessthisisok();
47124712 \\
......@@ -4716,7 +4716,7 @@ test "zig fmt: allow line break before field access" {
47164716 \\ .input_manager //
47174717 \\ .default_seat
47184718 \\ . // comment
4719 \\ // another comment
4719 \\ // another comment
47204720 \\ wlr_seat.name;
47214721 \\}
47224722 \\
......@@ -4955,19 +4955,19 @@ test "zig fmt: use of comments and multiline string literals may force the param
49554955 \\
49564956 \\// This looks like garbage don't do this
49574957 \\const rparen = tree.prevToken(
4958 \\// the first token for the annotation expressions is the left
4959 \\// parenthesis, hence the need for two prevToken
4960 \\if (fn_proto.getAlignExpr()) |align_expr|
4961 \\ tree.prevToken(tree.prevToken(align_expr.firstToken()))
4962 \\else if (fn_proto.getSectionExpr()) |section_expr|
4963 \\ tree.prevToken(tree.prevToken(section_expr.firstToken()))
4964 \\else if (fn_proto.getCallconvExpr()) |callconv_expr|
4965 \\ tree.prevToken(tree.prevToken(callconv_expr.firstToken()))
4966 \\else switch (fn_proto.return_type) {
4967 \\ .Explicit => |node| node.firstToken(),
4968 \\ .InferErrorSet => |node| tree.prevToken(node.firstToken()),
4969 \\ .Invalid => unreachable,
4970 \\});
4958 \\ // the first token for the annotation expressions is the left
4959 \\ // parenthesis, hence the need for two prevToken
4960 \\ if (fn_proto.getAlignExpr()) |align_expr|
4961 \\ tree.prevToken(tree.prevToken(align_expr.firstToken()))
4962 \\ else if (fn_proto.getSectionExpr()) |section_expr|
4963 \\ tree.prevToken(tree.prevToken(section_expr.firstToken()))
4964 \\ else if (fn_proto.getCallconvExpr()) |callconv_expr|
4965 \\ tree.prevToken(tree.prevToken(callconv_expr.firstToken()))
4966 \\ else switch (fn_proto.return_type) {
4967 \\ .Explicit => |node| node.firstToken(),
4968 \\ .InferErrorSet => |node| tree.prevToken(node.firstToken()),
4969 \\ .Invalid => unreachable,
4970 \\ });
49714971 \\
49724972 );
49734973}
......@@ -5962,6 +5962,151 @@ test "zig fmt: pointer type syntax to index" {
59625962 );
59635963}
59645964
5965test "zig fmt: binop indentation in if statement" {
5966 try testCanonical(
5967 \\test {
5968 \\ if (first_param_type.isGenericPoison() or
5969 \\ (first_param_type.zigTypeTag(zcu) == .pointer and
5970 \\ (first_param_type.ptrSize(zcu) == .One or
5971 \\ first_param_type.ptrSize(zcu) == .C) and
5972 \\ first_param_type.childType(zcu).eql(concrete_ty, zcu)))
5973 \\ {
5974 \\ f(x);
5975 \\ }
5976 \\}
5977 \\
5978 );
5979}
5980
5981test "zig fmt: test indentation after equals sign" {
5982 try testCanonical(
5983 \\test {
5984 \\ const foo =
5985 \\ if (1 == 2)
5986 \\ 1
5987 \\ else if (3 > 4)
5988 \\ 2
5989 \\ else
5990 \\ 0;
5991 \\
5992 \\ const foo, const bar =
5993 \\ if (1 == 2)
5994 \\ .{ 0, 0 }
5995 \\ else if (3 > 4)
5996 \\ .{ 1, 1 }
5997 \\ else
5998 \\ .{ 2, 2 };
5999 \\
6000 \\ while (foo) if (bar)
6001 \\ f(x);
6002 \\
6003 \\ foobar =
6004 \\ if (true)
6005 \\ 1
6006 \\ else
6007 \\ 0;
6008 \\
6009 \\ const foo = if (1 == 2)
6010 \\ 1
6011 \\ else if (3 > 4)
6012 \\ 2
6013 \\ else
6014 \\ 0;
6015 \\
6016 \\ const foo, const bar = if (1 == 2)
6017 \\ .{ 0, 0 }
6018 \\ else if (3 > 4)
6019 \\ .{ 1, 1 }
6020 \\ else
6021 \\ .{ 2, 2 };
6022 \\
6023 \\ foobar = if (true)
6024 \\ 1
6025 \\ else
6026 \\ 0;
6027 \\
6028 \\ const is_alphanum =
6029 \\ (ch >= 'a' and ch <= 'z') or
6030 \\ (ch >= 'A' and ch <= 'Z') or
6031 \\ (ch >= '0' and ch <= '9');
6032 \\
6033 \\ const bar = 100 + calculate(
6034 \\ 200,
6035 \\ 300,
6036 \\ );
6037 \\
6038 \\ const gcc_pragma = std.meta.stringToEnum(Directive, pp.expandedSlice(directive_tok)) orelse
6039 \\ return pp.comp.addDiagnostic(.{
6040 \\ .tag = .unknown_gcc_pragma,
6041 \\ .loc = directive_tok.loc,
6042 \\ }, pp.expansionSlice(start_idx + 1));
6043 \\
6044 \\ const vec4s =
6045 \\ [_][4]i32{
6046 \\ [_]i32{ 0, 1, 0, 0 },
6047 \\ [_]i32{ 0, -1, 0, 0 },
6048 \\ [_]i32{ 2, 1, 2, 0 },
6049 \\ };
6050 \\}
6051 \\
6052 );
6053}
6054
6055test "zig fmt: test indentation of if expressions" {
6056 try testCanonical(
6057 \\test {
6058 \\ const foo = 1 +
6059 \\ if (1 == 2)
6060 \\ 2
6061 \\ else
6062 \\ 0;
6063 \\
6064 \\ const foo = 1 + if (1 == 2)
6065 \\ 2
6066 \\ else
6067 \\ 0;
6068 \\
6069 \\ errval catch |e|
6070 \\ if (e == error.Meow)
6071 \\ return 0x1F408
6072 \\ else
6073 \\ unreachable;
6074 \\
6075 \\ errval catch |e| if (e == error.Meow)
6076 \\ return 0x1F408
6077 \\ else
6078 \\ unreachable;
6079 \\
6080 \\ return if (1 == 2)
6081 \\ 1
6082 \\ else if (3 > 4)
6083 \\ 2
6084 \\ else
6085 \\ 0;
6086 \\}
6087 \\
6088 );
6089}
6090
6091test "zig fmt: indentation of comments within catch, else, orelse" {
6092 try testCanonical(
6093 \\comptime {
6094 \\ _ = foo() catch
6095 \\ //
6096 \\ bar();
6097 \\
6098 \\ _ = if (foo) bar() else
6099 \\ //
6100 \\ qux();
6101 \\
6102 \\ _ = foo() orelse
6103 \\ //
6104 \\ qux();
6105 \\}
6106 \\
6107 );
6108}
6109
59656110test "recovery: top level" {
59666111 try testError(
59676112 \\test "" {inline}
lib/std/zig/render.zig+299-215
......@@ -81,10 +81,8 @@ const Render = struct {
8181
8282pub fn renderTree(buffer: *std.ArrayList(u8), tree: Ast, fixups: Fixups) Error!void {
8383 assert(tree.errors.len == 0); // Cannot render an invalid tree.
84 var auto_indenting_stream = Ais{
85 .indent_delta = indent_delta,
86 .underlying_writer = buffer.writer(),
87 };
84 var auto_indenting_stream = Ais.init(buffer, indent_delta);
85 defer auto_indenting_stream.deinit();
8886 var r: Render = .{
8987 .gpa = buffer.allocator,
9088 .ais = &auto_indenting_stream,
......@@ -198,7 +196,7 @@ fn renderMember(
198196 try renderExpression(r, fn_proto, .space);
199197 const body_node = datas[decl].rhs;
200198 if (r.fixups.gut_functions.contains(decl)) {
201 ais.pushIndent();
199 try ais.pushIndent(.normal);
202200 const lbrace = tree.nodes.items(.main_token)[body_node];
203201 try renderToken(r, lbrace, .newline);
204202 try discardAllParams(r, fn_proto);
......@@ -207,7 +205,7 @@ fn renderMember(
207205 try ais.insertNewline();
208206 try renderToken(r, tree.lastToken(body_node), space); // rbrace
209207 } else if (r.fixups.unused_var_decls.count() != 0) {
210 ais.pushIndentNextLine();
208 try ais.pushIndent(.normal);
211209 const lbrace = tree.nodes.items(.main_token)[body_node];
212210 try renderToken(r, lbrace, .newline);
213211
......@@ -297,7 +295,11 @@ fn renderMember(
297295 .local_var_decl,
298296 .simple_var_decl,
299297 .aligned_var_decl,
300 => return renderVarDecl(r, tree.fullVarDecl(decl).?, false, .semicolon),
298 => {
299 try ais.pushSpace(.semicolon);
300 try renderVarDecl(r, tree.fullVarDecl(decl).?, false, .semicolon);
301 ais.popSpace();
302 },
301303
302304 .test_decl => {
303305 const test_token = main_tokens[decl];
......@@ -361,18 +363,25 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
361363 => return renderToken(r, main_tokens[node], space),
362364
363365 .multiline_string_literal => {
364 var locked_indents = ais.lockOneShotIndent();
365366 try ais.maybeInsertNewline();
366367
367368 var i = datas[node].lhs;
368369 while (i <= datas[node].rhs) : (i += 1) try renderToken(r, i, .newline);
369370
370 while (locked_indents > 0) : (locked_indents -= 1) ais.popIndent();
371 // dedent the next thing that comes after a multiline string literal
372 if (!ais.indentStackEmpty() and
373 token_tags[i] != .colon and
374 ((token_tags[i] != .semicolon and token_tags[i] != .comma) or
375 ais.lastSpaceModeIndent() < ais.currentIndent()))
376 {
377 ais.popIndent();
378 try ais.pushIndent(.normal);
379 }
371380
372381 switch (space) {
373382 .none, .space, .newline, .skip => {},
374 .semicolon => if (token_tags[i] == .semicolon) try renderToken(r, i, .newline),
375 .comma => if (token_tags[i] == .comma) try renderToken(r, i, .newline),
383 .semicolon => if (token_tags[i] == .semicolon) try renderTokenOverrideSpaceMode(r, i, .newline, .semicolon),
384 .comma => if (token_tags[i] == .comma) try renderTokenOverrideSpaceMode(r, i, .newline, .comma),
376385 .comma_space => if (token_tags[i] == .comma) try renderToken(r, i, .space),
377386 }
378387 },
......@@ -445,6 +454,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
445454
446455 try renderExpression(r, datas[node].lhs, .space); // target
447456
457 try ais.pushIndent(.normal);
448458 if (token_tags[fallback_first - 1] == .pipe) {
449459 try renderToken(r, main_token, .space); // catch keyword
450460 try renderToken(r, main_token + 1, .none); // pipe
......@@ -454,38 +464,27 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
454464 assert(token_tags[fallback_first - 1] == .keyword_catch);
455465 try renderToken(r, main_token, after_op_space); // catch keyword
456466 }
457
458 ais.pushIndentOneShot();
459467 try renderExpression(r, datas[node].rhs, space); // fallback
468 ais.popIndent();
460469 },
461470
462471 .field_access => {
463472 const main_token = main_tokens[node];
464473 const field_access = datas[node];
465474
475 try ais.pushIndent(.field_access);
466476 try renderExpression(r, field_access.lhs, .none);
467477
468478 // Allow a line break between the lhs and the dot if the lhs and rhs
469479 // are on different lines.
470480 const lhs_last_token = tree.lastToken(field_access.lhs);
471481 const same_line = tree.tokensOnSameLine(lhs_last_token, main_token + 1);
472 if (!same_line) {
473 if (!hasComment(tree, lhs_last_token, main_token)) try ais.insertNewline();
474 ais.pushIndentOneShot();
475 }
482 if (!same_line and !hasComment(tree, lhs_last_token, main_token)) try ais.insertNewline();
476483
477484 try renderToken(r, main_token, .none); // .
478485
479 // This check ensures that zag() is indented in the following example:
480 // const x = foo
481 // .bar()
482 // . // comment
483 // zag();
484 if (!same_line and hasComment(tree, main_token, main_token + 1)) {
485 ais.pushIndentOneShot();
486 }
487
488 return renderIdentifier(r, field_access.rhs, space, .eagerly_unquote); // field
486 try renderIdentifier(r, field_access.rhs, space, .eagerly_unquote); // field
487 ais.popIndent();
489488 },
490489
491490 .error_union,
......@@ -507,11 +506,6 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
507506 }
508507 },
509508
510 .add,
511 .add_wrap,
512 .add_sat,
513 .array_cat,
514 .array_mult,
515509 .assign,
516510 .assign_bit_and,
517511 .assign_bit_or,
......@@ -530,6 +524,25 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
530524 .assign_mul,
531525 .assign_mul_wrap,
532526 .assign_mul_sat,
527 => {
528 const infix = datas[node];
529 try renderExpression(r, infix.lhs, .space);
530 const op_token = main_tokens[node];
531 try ais.pushIndent(.after_equals);
532 if (tree.tokensOnSameLine(op_token, op_token + 1)) {
533 try renderToken(r, op_token, .space);
534 } else {
535 try renderToken(r, op_token, .newline);
536 }
537 try renderExpression(r, infix.rhs, space);
538 ais.popIndent();
539 },
540
541 .add,
542 .add_wrap,
543 .add_sat,
544 .array_cat,
545 .array_mult,
533546 .bang_equal,
534547 .bit_and,
535548 .bit_or,
......@@ -558,15 +571,14 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
558571 const infix = datas[node];
559572 try renderExpression(r, infix.lhs, .space);
560573 const op_token = main_tokens[node];
574 try ais.pushIndent(.binop);
561575 if (tree.tokensOnSameLine(op_token, op_token + 1)) {
562576 try renderToken(r, op_token, .space);
563577 } else {
564 ais.pushIndent();
565578 try renderToken(r, op_token, .newline);
566 ais.popIndent();
567579 }
568 ais.pushIndentOneShot();
569 return renderExpression(r, infix.rhs, space);
580 try renderExpression(r, infix.rhs, space);
581 ais.popIndent();
570582 },
571583
572584 .assign_destructure => {
......@@ -588,15 +600,14 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
588600 else => try renderExpression(r, variable_node, variable_space),
589601 }
590602 }
603 try ais.pushIndent(.after_equals);
591604 if (tree.tokensOnSameLine(full.ast.equal_token, full.ast.equal_token + 1)) {
592605 try renderToken(r, full.ast.equal_token, .space);
593606 } else {
594 ais.pushIndent();
595607 try renderToken(r, full.ast.equal_token, .newline);
596 ais.popIndent();
597608 }
598 ais.pushIndentOneShot();
599 return renderExpression(r, full.ast.value_expr, space);
609 try renderExpression(r, full.ast.value_expr, space);
610 ais.popIndent();
600611 },
601612
602613 .bit_not,
......@@ -674,7 +685,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
674685 const one_line = tree.tokensOnSameLine(lbracket, rbracket);
675686 const inner_space = if (one_line) Space.none else Space.newline;
676687 try renderExpression(r, suffix.lhs, .none);
677 ais.pushIndentNextLine();
688 try ais.pushIndent(.normal);
678689 try renderToken(r, lbracket, inner_space); // [
679690 try renderExpression(r, suffix.rhs, inner_space);
680691 ais.popIndent();
......@@ -725,9 +736,10 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
725736 },
726737
727738 .grouped_expression => {
739 try ais.pushIndent(.normal);
728740 try renderToken(r, main_tokens[node], .none); // lparen
729 ais.pushIndentOneShot();
730741 try renderExpression(r, datas[node].lhs, .none);
742 ais.popIndent();
731743 return renderToken(r, datas[node].rhs, space); // rparen
732744 },
733745
......@@ -767,14 +779,18 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
767779 return renderToken(r, rbrace, space);
768780 } else if (token_tags[rbrace - 1] == .comma) {
769781 // There is a trailing comma so render each member on a new line.
770 ais.pushIndentNextLine();
782 try ais.pushIndent(.normal);
771783 try renderToken(r, lbrace, .newline);
772784 var i = lbrace + 1;
773785 while (i < rbrace) : (i += 1) {
774786 if (i > lbrace + 1) try renderExtraNewlineToken(r, i);
775787 switch (token_tags[i]) {
776788 .doc_comment => try renderToken(r, i, .newline),
777 .identifier => try renderIdentifier(r, i, .comma, .eagerly_unquote),
789 .identifier => {
790 try ais.pushSpace(.comma);
791 try renderIdentifier(r, i, .comma, .eagerly_unquote);
792 ais.popSpace();
793 },
778794 .comma => {},
779795 else => unreachable,
780796 }
......@@ -848,12 +864,14 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
848864 try renderExpression(r, full.ast.condition, .none); // condition expression
849865 try renderToken(r, rparen, .space); // )
850866
851 ais.pushIndentNextLine();
867 try ais.pushIndent(.normal);
852868 if (full.ast.cases.len == 0) {
853869 try renderToken(r, rparen + 1, .none); // {
854870 } else {
855871 try renderToken(r, rparen + 1, .newline); // {
872 try ais.pushSpace(.comma);
856873 try renderExpressions(r, full.ast.cases, .comma);
874 ais.popSpace();
857875 }
858876 ais.popIndent();
859877 return renderToken(r, tree.lastToken(node), space); // }
......@@ -923,7 +941,7 @@ fn renderArrayType(
923941 const rbracket = tree.firstToken(array_type.ast.elem_type) - 1;
924942 const one_line = tree.tokensOnSameLine(array_type.ast.lbracket, rbracket);
925943 const inner_space = if (one_line) Space.none else Space.newline;
926 ais.pushIndentNextLine();
944 try ais.pushIndent(.normal);
927945 try renderToken(r, array_type.ast.lbracket, inner_space); // lbracket
928946 try renderExpression(r, array_type.ast.elem_count, inner_space);
929947 if (array_type.ast.sentinel != 0) {
......@@ -1167,9 +1185,9 @@ fn renderVarDeclWithoutFixups(
11671185 {
11681186 const name_space = if (var_decl.ast.type_node == 0 and
11691187 (var_decl.ast.align_node != 0 or
1170 var_decl.ast.addrspace_node != 0 or
1171 var_decl.ast.section_node != 0 or
1172 var_decl.ast.init_node != 0))
1188 var_decl.ast.addrspace_node != 0 or
1189 var_decl.ast.section_node != 0 or
1190 var_decl.ast.init_node != 0))
11731191 Space.space
11741192 else
11751193 Space.none;
......@@ -1239,13 +1257,10 @@ fn renderVarDeclWithoutFixups(
12391257
12401258 const eq_token = tree.firstToken(var_decl.ast.init_node) - 1;
12411259 const eq_space: Space = if (tree.tokensOnSameLine(eq_token, eq_token + 1)) .space else .newline;
1242 {
1243 ais.pushIndent();
1244 try renderToken(r, eq_token, eq_space); // =
1245 ais.popIndent();
1246 }
1247 ais.pushIndentOneShot();
1248 return renderExpression(r, var_decl.ast.init_node, space); // ;
1260 try ais.pushIndent(.after_equals);
1261 try renderToken(r, eq_token, eq_space); // =
1262 try renderExpression(r, var_decl.ast.init_node, space); // ;
1263 ais.popIndent();
12491264}
12501265
12511266fn renderIf(r: *Render, if_node: Ast.full.If, space: Space) Error!void {
......@@ -1345,23 +1360,28 @@ fn renderThenElse(
13451360 const then_expr_is_block = nodeIsBlock(node_tags[then_expr]);
13461361 const indent_then_expr = !then_expr_is_block and
13471362 !tree.tokensOnSameLine(last_prefix_token, tree.firstToken(then_expr));
1348 if (indent_then_expr or (then_expr_is_block and ais.isLineOverIndented())) {
1349 ais.pushIndentNextLine();
1363
1364 if (indent_then_expr) try ais.pushIndent(.normal);
1365
1366 if (then_expr_is_block and ais.isLineOverIndented()) {
1367 ais.disableIndentCommitting();
1368 try renderToken(r, last_prefix_token, .newline);
1369 ais.enableIndentCommitting();
1370 } else if (indent_then_expr) {
13501371 try renderToken(r, last_prefix_token, .newline);
1351 ais.popIndent();
13521372 } else {
13531373 try renderToken(r, last_prefix_token, .space);
13541374 }
13551375
13561376 if (else_expr != 0) {
13571377 if (indent_then_expr) {
1358 ais.pushIndent();
13591378 try renderExpression(r, then_expr, .newline);
1360 ais.popIndent();
13611379 } else {
13621380 try renderExpression(r, then_expr, .space);
13631381 }
13641382
1383 if (indent_then_expr) ais.popIndent();
1384
13651385 var last_else_token = else_token;
13661386
13671387 if (maybe_error_token) |error_token| {
......@@ -1375,20 +1395,17 @@ fn renderThenElse(
13751395 !nodeIsBlock(node_tags[else_expr]) and
13761396 !nodeIsIfForWhileSwitch(node_tags[else_expr]);
13771397 if (indent_else_expr) {
1378 ais.pushIndentNextLine();
1398 try ais.pushIndent(.normal);
13791399 try renderToken(r, last_else_token, .newline);
1400 try renderExpression(r, else_expr, space);
13801401 ais.popIndent();
1381 try renderExpressionIndented(r, else_expr, space);
13821402 } else {
13831403 try renderToken(r, last_else_token, .space);
13841404 try renderExpression(r, else_expr, space);
13851405 }
13861406 } else {
1387 if (indent_then_expr) {
1388 try renderExpressionIndented(r, then_expr, space);
1389 } else {
1390 try renderExpression(r, then_expr, space);
1391 }
1407 try renderExpression(r, then_expr, space);
1408 if (indent_then_expr) ais.popIndent();
13921409 }
13931410}
13941411
......@@ -1414,7 +1431,7 @@ fn renderFor(r: *Render, for_node: Ast.full.For, space: Space) Error!void {
14141431 var cur = for_node.payload_token;
14151432 const pipe = std.mem.indexOfScalarPos(std.zig.Token.Tag, token_tags, cur, .pipe).?;
14161433 if (token_tags[pipe - 1] == .comma) {
1417 ais.pushIndentNextLine();
1434 try ais.pushIndent(.normal);
14181435 try renderToken(r, cur - 1, .newline); // |
14191436 while (true) {
14201437 if (token_tags[cur] == .asterisk) {
......@@ -1542,25 +1559,24 @@ fn renderContainerField(
15421559 }
15431560 const eq_token = tree.firstToken(field.ast.value_expr) - 1;
15441561 const eq_space: Space = if (tree.tokensOnSameLine(eq_token, eq_token + 1)) .space else .newline;
1545 {
1546 ais.pushIndent();
1547 try renderToken(r, eq_token, eq_space); // =
1562
1563 try ais.pushIndent(.after_equals);
1564 try renderToken(r, eq_token, eq_space); // =
1565
1566 if (eq_space == .space) {
15481567 ais.popIndent();
1568 try renderExpressionComma(r, field.ast.value_expr, space); // value
1569 return;
15491570 }
15501571
1551 if (eq_space == .space)
1552 return renderExpressionComma(r, field.ast.value_expr, space); // value
1553
15541572 const token_tags = tree.tokens.items(.tag);
15551573 const maybe_comma = tree.lastToken(field.ast.value_expr) + 1;
15561574
15571575 if (token_tags[maybe_comma] == .comma) {
1558 ais.pushIndent();
15591576 try renderExpression(r, field.ast.value_expr, .none); // value
15601577 ais.popIndent();
15611578 try renderToken(r, maybe_comma, .newline);
15621579 } else {
1563 ais.pushIndent();
15641580 try renderExpression(r, field.ast.value_expr, space); // value
15651581 ais.popIndent();
15661582 }
......@@ -1617,9 +1633,12 @@ fn renderBuiltinCall(
16171633 if (token_tags[first_param_token] == .multiline_string_literal_line or
16181634 hasSameLineComment(tree, first_param_token - 1))
16191635 {
1620 ais.pushIndentOneShot();
1636 try ais.pushIndent(.normal);
1637 try renderExpression(r, param_node, .none);
1638 ais.popIndent();
1639 } else {
1640 try renderExpression(r, param_node, .none);
16211641 }
1622 try renderExpression(r, param_node, .none);
16231642
16241643 if (i + 1 < params.len) {
16251644 const comma_token = tree.lastToken(param_node) + 1;
......@@ -1629,11 +1648,13 @@ fn renderBuiltinCall(
16291648 return renderToken(r, after_last_param_token, space); // )
16301649 } else {
16311650 // Render one param per line.
1632 ais.pushIndent();
1651 try ais.pushIndent(.normal);
16331652 try renderToken(r, builtin_token + 1, Space.newline); // (
16341653
16351654 for (params) |param_node| {
1655 try ais.pushSpace(.comma);
16361656 try renderExpression(r, param_node, .comma);
1657 ais.popSpace();
16371658 }
16381659 ais.popIndent();
16391660
......@@ -1755,7 +1776,7 @@ fn renderFnProto(r: *Render, fn_proto: Ast.full.FnProto, space: Space) Error!voi
17551776 }
17561777 } else {
17571778 // One param per line.
1758 ais.pushIndent();
1779 try ais.pushIndent(.normal);
17591780 try renderToken(r, lparen, .newline); // (
17601781
17611782 var param_i: usize = 0;
......@@ -1801,7 +1822,9 @@ fn renderFnProto(r: *Render, fn_proto: Ast.full.FnProto, space: Space) Error!voi
18011822 }
18021823 const param = fn_proto.ast.params[param_i];
18031824 param_i += 1;
1825 try ais.pushSpace(.comma);
18041826 try renderExpression(r, param, .comma);
1827 ais.popSpace();
18051828 last_param_token = tree.lastToken(param);
18061829 if (token_tags[last_param_token + 1] == .comma) last_param_token += 1;
18071830 }
......@@ -1864,6 +1887,7 @@ fn renderSwitchCase(
18641887 switch_case: Ast.full.SwitchCase,
18651888 space: Space,
18661889) Error!void {
1890 const ais = r.ais;
18671891 const tree = r.tree;
18681892 const node_tags = tree.nodes.items(.tag);
18691893 const token_tags = tree.tokens.items(.tag);
......@@ -1883,7 +1907,9 @@ fn renderSwitchCase(
18831907 try renderToken(r, switch_case.ast.arrow_token - 1, .space); // else keyword
18841908 } else if (trailing_comma or has_comment_before_arrow) {
18851909 // Render each value on a new line
1910 try ais.pushSpace(.comma);
18861911 try renderExpressions(r, switch_case.ast.values, .comma);
1912 ais.popSpace();
18871913 } else {
18881914 // Render on one line
18891915 for (switch_case.ast.values) |value_expr| {
......@@ -1936,7 +1962,7 @@ fn renderBlock(
19361962 try renderIdentifier(r, lbrace - 2, .none, .eagerly_unquote); // identifier
19371963 try renderToken(r, lbrace - 1, .space); // :
19381964 }
1939 ais.pushIndentNextLine();
1965 try ais.pushIndent(.normal);
19401966 if (statements.len == 0) {
19411967 try renderToken(r, lbrace, .none);
19421968 ais.popIndent();
......@@ -1959,6 +1985,7 @@ fn finishRenderBlock(
19591985 for (statements, 0..) |stmt, i| {
19601986 if (i != 0) try renderExtraNewline(r, stmt);
19611987 if (r.fixups.omit_nodes.contains(stmt)) continue;
1988 try ais.pushSpace(.semicolon);
19621989 switch (node_tags[stmt]) {
19631990 .global_var_decl,
19641991 .local_var_decl,
......@@ -1968,6 +1995,7 @@ fn finishRenderBlock(
19681995
19691996 else => try renderExpression(r, stmt, .semicolon),
19701997 }
1998 ais.popSpace();
19711999 }
19722000 ais.popIndent();
19732001
......@@ -1989,7 +2017,7 @@ fn renderStructInit(
19892017 try renderExpression(r, struct_init.ast.type_expr, .none); // T
19902018 }
19912019 if (struct_init.ast.fields.len == 0) {
1992 ais.pushIndentNextLine();
2020 try ais.pushIndent(.normal);
19932021 try renderToken(r, struct_init.ast.lbrace, .none); // lbrace
19942022 ais.popIndent();
19952023 return renderToken(r, struct_init.ast.lbrace + 1, space); // rbrace
......@@ -1999,7 +2027,7 @@ fn renderStructInit(
19992027 const trailing_comma = token_tags[rbrace - 1] == .comma;
20002028 if (trailing_comma or hasComment(tree, struct_init.ast.lbrace, rbrace)) {
20012029 // Render one field init per line.
2002 ais.pushIndentNextLine();
2030 try ais.pushIndent(.normal);
20032031 try renderToken(r, struct_init.ast.lbrace, .newline);
20042032
20052033 try renderToken(r, struct_init.ast.lbrace + 1, .none); // .
......@@ -2011,7 +2039,10 @@ fn renderStructInit(
20112039 const expr = nodes[field_node];
20122040 var space_after_equal: Space = if (expr == .multiline_string_literal) .none else .space;
20132041 try renderToken(r, struct_init.ast.lbrace + 3, space_after_equal); // =
2042
2043 try ais.pushSpace(.comma);
20142044 try renderExpressionFixup(r, field_node, .comma);
2045 ais.popSpace();
20152046
20162047 for (struct_init.ast.fields[1..]) |field_init| {
20172048 const init_token = tree.firstToken(field_init);
......@@ -2020,7 +2051,10 @@ fn renderStructInit(
20202051 try renderIdentifier(r, init_token - 2, .space, .eagerly_unquote); // name
20212052 space_after_equal = if (nodes[field_init] == .multiline_string_literal) .none else .space;
20222053 try renderToken(r, init_token - 1, space_after_equal); // =
2054
2055 try ais.pushSpace(.comma);
20232056 try renderExpressionFixup(r, field_init, .comma);
2057 ais.popSpace();
20242058 }
20252059
20262060 ais.popIndent();
......@@ -2057,7 +2091,7 @@ fn renderArrayInit(
20572091 }
20582092
20592093 if (array_init.ast.elements.len == 0) {
2060 ais.pushIndentNextLine();
2094 try ais.pushIndent(.normal);
20612095 try renderToken(r, array_init.ast.lbrace, .none); // lbrace
20622096 ais.popIndent();
20632097 return renderToken(r, array_init.ast.lbrace + 1, space); // rbrace
......@@ -2099,7 +2133,7 @@ fn renderArrayInit(
20992133 return renderToken(r, last_elem_token + 1, space); // rbrace
21002134 }
21012135
2102 ais.pushIndentNextLine();
2136 try ais.pushIndent(.normal);
21032137 try renderToken(r, array_init.ast.lbrace, .newline);
21042138
21052139 var expr_index: usize = 0;
......@@ -2152,10 +2186,8 @@ fn renderArrayInit(
21522186 const sub_expr_buffer_starts = try gpa.alloc(usize, section_exprs.len + 1);
21532187 defer gpa.free(sub_expr_buffer_starts);
21542188
2155 var auto_indenting_stream = Ais{
2156 .indent_delta = indent_delta,
2157 .underlying_writer = sub_expr_buffer.writer(),
2158 };
2189 var auto_indenting_stream = Ais.init(&sub_expr_buffer, indent_delta);
2190 defer auto_indenting_stream.deinit();
21592191 var sub_render: Render = .{
21602192 .gpa = r.gpa,
21612193 .ais = &auto_indenting_stream,
......@@ -2192,7 +2224,10 @@ fn renderArrayInit(
21922224 column_counter = 0;
21932225 }
21942226 } else {
2227 try ais.pushSpace(.comma);
21952228 try renderExpression(&sub_render, expr, .comma);
2229 ais.popSpace();
2230
21962231 const width = sub_expr_buffer.items.len - start - 2;
21972232 const this_contains_newline = mem.indexOfScalar(u8, sub_expr_buffer.items[start .. sub_expr_buffer.items.len - 1], '\n') != null;
21982233 contains_newline = contains_newline or this_contains_newline;
......@@ -2318,7 +2353,7 @@ fn renderContainerDecl(
23182353
23192354 const rbrace = tree.lastToken(container_decl_node);
23202355 if (container_decl.ast.members.len == 0) {
2321 ais.pushIndentNextLine();
2356 try ais.pushIndent(.normal);
23222357 if (token_tags[lbrace + 1] == .container_doc_comment) {
23232358 try renderToken(r, lbrace, .newline); // lbrace
23242359 try renderContainerDocComments(r, lbrace + 1);
......@@ -2360,7 +2395,7 @@ fn renderContainerDecl(
23602395 }
23612396
23622397 // One member per line.
2363 ais.pushIndentNextLine();
2398 try ais.pushIndent(.normal);
23642399 try renderToken(r, lbrace, .newline); // lbrace
23652400 if (token_tags[lbrace + 1] == .container_doc_comment) {
23662401 try renderContainerDocComments(r, lbrace + 1);
......@@ -2372,7 +2407,11 @@ fn renderContainerDecl(
23722407 .container_field_init,
23732408 .container_field_align,
23742409 .container_field,
2375 => try renderMember(r, container, member, .comma),
2410 => {
2411 try ais.pushSpace(.comma);
2412 try renderMember(r, container, member, .comma);
2413 ais.popSpace();
2414 },
23762415
23772416 else => try renderMember(r, container, member, .newline),
23782417 }
......@@ -2401,7 +2440,7 @@ fn renderAsm(
24012440 }
24022441
24032442 if (asm_node.ast.items.len == 0) {
2404 ais.pushIndent();
2443 try ais.forcePushIndent(.normal);
24052444 if (asm_node.first_clobber) |first_clobber| {
24062445 // asm ("foo" ::: "a", "b")
24072446 // asm ("foo" ::: "a", "b",)
......@@ -2439,7 +2478,7 @@ fn renderAsm(
24392478 }
24402479 }
24412480
2442 ais.pushIndent();
2481 try ais.forcePushIndent(.normal);
24432482 try renderExpression(r, asm_node.ast.template, .newline);
24442483 ais.setIndentDelta(asm_indent_delta);
24452484 const colon1 = tree.lastToken(asm_node.ast.template) + 1;
......@@ -2450,7 +2489,7 @@ fn renderAsm(
24502489 } else colon2: {
24512490 try renderToken(r, colon1, .space); // :
24522491
2453 ais.pushIndent();
2492 try ais.forcePushIndent(.normal);
24542493 for (asm_node.outputs, 0..) |asm_output, i| {
24552494 if (i + 1 < asm_node.outputs.len) {
24562495 const next_asm_output = asm_node.outputs[i + 1];
......@@ -2460,13 +2499,17 @@ fn renderAsm(
24602499 try renderToken(r, comma, .newline); // ,
24612500 try renderExtraNewlineToken(r, tree.firstToken(next_asm_output));
24622501 } else if (asm_node.inputs.len == 0 and asm_node.first_clobber == null) {
2502 try ais.pushSpace(.comma);
24632503 try renderAsmOutput(r, asm_output, .comma);
2504 ais.popSpace();
24642505 ais.popIndent();
24652506 ais.setIndentDelta(indent_delta);
24662507 ais.popIndent();
24672508 return renderToken(r, asm_node.ast.rparen, space); // rparen
24682509 } else {
2510 try ais.pushSpace(.comma);
24692511 try renderAsmOutput(r, asm_output, .comma);
2512 ais.popSpace();
24702513 const comma_or_colon = tree.lastToken(asm_output) + 1;
24712514 ais.popIndent();
24722515 break :colon2 switch (token_tags[comma_or_colon]) {
......@@ -2482,7 +2525,7 @@ fn renderAsm(
24822525 break :colon3 colon2 + 1;
24832526 } else colon3: {
24842527 try renderToken(r, colon2, .space); // :
2485 ais.pushIndent();
2528 try ais.forcePushIndent(.normal);
24862529 for (asm_node.inputs, 0..) |asm_input, i| {
24872530 if (i + 1 < asm_node.inputs.len) {
24882531 const next_asm_input = asm_node.inputs[i + 1];
......@@ -2492,13 +2535,17 @@ fn renderAsm(
24922535 try renderToken(r, first_token - 1, .newline); // ,
24932536 try renderExtraNewlineToken(r, first_token);
24942537 } else if (asm_node.first_clobber == null) {
2538 try ais.pushSpace(.comma);
24952539 try renderAsmInput(r, asm_input, .comma);
2540 ais.popSpace();
24962541 ais.popIndent();
24972542 ais.setIndentDelta(indent_delta);
24982543 ais.popIndent();
24992544 return renderToken(r, asm_node.ast.rparen, space); // rparen
25002545 } else {
2546 try ais.pushSpace(.comma);
25012547 try renderAsmInput(r, asm_input, .comma);
2548 ais.popSpace();
25022549 const comma_or_colon = tree.lastToken(asm_input) + 1;
25032550 ais.popIndent();
25042551 break :colon3 switch (token_tags[comma_or_colon]) {
......@@ -2517,16 +2564,16 @@ fn renderAsm(
25172564 switch (token_tags[tok_i + 1]) {
25182565 .r_paren => {
25192566 ais.setIndentDelta(indent_delta);
2520 ais.popIndent();
25212567 try renderToken(r, tok_i, .newline);
2568 ais.popIndent();
25222569 return renderToken(r, tok_i + 1, space);
25232570 },
25242571 .comma => {
25252572 switch (token_tags[tok_i + 2]) {
25262573 .r_paren => {
25272574 ais.setIndentDelta(indent_delta);
2528 ais.popIndent();
25292575 try renderToken(r, tok_i, .newline);
2576 ais.popIndent();
25302577 return renderToken(r, tok_i + 2, space);
25312578 },
25322579 else => {
......@@ -2564,7 +2611,7 @@ fn renderParamList(
25642611 const token_tags = tree.tokens.items(.tag);
25652612
25662613 if (params.len == 0) {
2567 ais.pushIndentNextLine();
2614 try ais.pushIndent(.normal);
25682615 try renderToken(r, lparen, .none);
25692616 ais.popIndent();
25702617 return renderToken(r, lparen + 1, space); // )
......@@ -2573,40 +2620,29 @@ fn renderParamList(
25732620 const last_param = params[params.len - 1];
25742621 const after_last_param_tok = tree.lastToken(last_param) + 1;
25752622 if (token_tags[after_last_param_tok] == .comma) {
2576 ais.pushIndentNextLine();
2623 try ais.pushIndent(.normal);
25772624 try renderToken(r, lparen, .newline); // (
25782625 for (params, 0..) |param_node, i| {
25792626 if (i + 1 < params.len) {
25802627 try renderExpression(r, param_node, .none);
25812628
2582 // Unindent the comma for multiline string literals.
2583 const is_multiline_string =
2584 token_tags[tree.firstToken(param_node)] == .multiline_string_literal_line;
2585 if (is_multiline_string) ais.popIndent();
2586
25872629 const comma = tree.lastToken(param_node) + 1;
25882630 try renderToken(r, comma, .newline); // ,
25892631
2590 if (is_multiline_string) ais.pushIndent();
2591
25922632 try renderExtraNewline(r, params[i + 1]);
25932633 } else {
2634 try ais.pushSpace(.comma);
25942635 try renderExpression(r, param_node, .comma);
2636 ais.popSpace();
25952637 }
25962638 }
25972639 ais.popIndent();
25982640 return renderToken(r, after_last_param_tok + 1, space); // )
25992641 }
26002642
2643 try ais.pushIndent(.normal);
26012644 try renderToken(r, lparen, .none); // (
2602
26032645 for (params, 0..) |param_node, i| {
2604 const first_param_token = tree.firstToken(param_node);
2605 if (token_tags[first_param_token] == .multiline_string_literal_line or
2606 hasSameLineComment(tree, first_param_token - 1))
2607 {
2608 ais.pushIndentOneShot();
2609 }
26102646 try renderExpression(r, param_node, .none);
26112647
26122648 if (i + 1 < params.len) {
......@@ -2617,68 +2653,8 @@ fn renderParamList(
26172653 try renderToken(r, comma, comma_space);
26182654 }
26192655 }
2620
2621 return renderToken(r, after_last_param_tok, space); // )
2622}
2623
2624/// Renders the given expression indented, popping the indent before rendering
2625/// any following line comments
2626fn renderExpressionIndented(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
2627 const tree = r.tree;
2628 const ais = r.ais;
2629 const token_starts = tree.tokens.items(.start);
2630 const token_tags = tree.tokens.items(.tag);
2631
2632 ais.pushIndent();
2633
2634 var last_token = tree.lastToken(node);
2635 const punctuation = switch (space) {
2636 .none, .space, .newline, .skip => false,
2637 .comma => true,
2638 .comma_space => token_tags[last_token + 1] == .comma,
2639 .semicolon => token_tags[last_token + 1] == .semicolon,
2640 };
2641
2642 try renderExpression(r, node, if (punctuation) .none else .skip);
2643
2644 switch (space) {
2645 .none, .space, .newline, .skip => {},
2646 .comma => {
2647 if (token_tags[last_token + 1] == .comma) {
2648 try renderToken(r, last_token + 1, .skip);
2649 last_token += 1;
2650 } else {
2651 try ais.writer().writeByte(',');
2652 }
2653 },
2654 .comma_space => if (token_tags[last_token + 1] == .comma) {
2655 try renderToken(r, last_token + 1, .skip);
2656 last_token += 1;
2657 },
2658 .semicolon => if (token_tags[last_token + 1] == .semicolon) {
2659 try renderToken(r, last_token + 1, .skip);
2660 last_token += 1;
2661 },
2662 }
2663
26642656 ais.popIndent();
2665
2666 if (space == .skip) return;
2667
2668 const comment_start = token_starts[last_token] + tokenSliceForRender(tree, last_token).len;
2669 const comment = try renderComments(r, comment_start, token_starts[last_token + 1]);
2670
2671 if (!comment) switch (space) {
2672 .none => {},
2673 .space,
2674 .comma_space,
2675 => try ais.writer().writeByte(' '),
2676 .newline,
2677 .comma,
2678 .semicolon,
2679 => try ais.insertNewline(),
2680 .skip => unreachable,
2681 };
2657 return renderToken(r, after_last_param_tok, space); // )
26822658}
26832659
26842660/// Render an expression, and the comma that follows it, if it is present in the source.
......@@ -2752,6 +2728,16 @@ fn renderToken(r: *Render, token_index: Ast.TokenIndex, space: Space) Error!void
27522728 try renderSpace(r, token_index, lexeme.len, space);
27532729}
27542730
2731fn renderTokenOverrideSpaceMode(r: *Render, token_index: Ast.TokenIndex, space: Space, override_space: Space) Error!void {
2732 const tree = r.tree;
2733 const ais = r.ais;
2734 const lexeme = tokenSliceForRender(tree, token_index);
2735 try ais.writer().writeAll(lexeme);
2736 ais.enableSpaceMode(override_space);
2737 defer ais.disableSpaceMode();
2738 try renderSpace(r, token_index, lexeme.len, space);
2739}
2740
27552741fn renderSpace(r: *Render, token_index: Ast.TokenIndex, lexeme_len: usize, space: Space) Error!void {
27562742 const tree = r.tree;
27572743 const ais = r.ais;
......@@ -2765,7 +2751,8 @@ fn renderSpace(r: *Render, token_index: Ast.TokenIndex, lexeme_len: usize, space
27652751 if (space == .comma and token_tags[token_index + 1] != .comma) {
27662752 try ais.writer().writeByte(',');
27672753 }
2768
2754 if (space == .semicolon or space == .comma) ais.enableSpaceMode(space);
2755 defer ais.disableSpaceMode();
27692756 const comment = try renderComments(r, token_start + lexeme_len, token_starts[token_index + 1]);
27702757 switch (space) {
27712758 .none => {},
......@@ -3315,12 +3302,47 @@ fn rowSize(tree: Ast, exprs: []const Ast.Node.Index, rtoken: Ast.TokenIndex) usi
33153302
33163303/// Automatically inserts indentation of written data by keeping
33173304/// track of the current indentation level
3305///
3306/// We introduce a new indentation scope with pushIndent/popIndent whenever
3307/// we potentially want to introduce an indent after the next newline.
3308///
3309/// Indentation should only ever increment by one from one line to the next,
3310/// no matter how many new indentation scopes are introduced. This is done by
3311/// only realizing the indentation from the most recent scope. As an example:
3312///
3313/// while (foo) if (bar)
3314/// f(x);
3315///
3316/// The body of `while` introduces a new indentation scope and the body of
3317/// `if` also introduces a new indentation scope. When the newline is seen,
3318/// only the indentation scope of the `if` is realized, and the `while` is
3319/// not.
3320///
3321/// As comments are rendered during space rendering, we need to keep track
3322/// of the appropriate indentation level for them with pushSpace/popSpace.
3323/// This should be done whenever a scope that ends in a .semicolon or a
3324/// .comma is introduced.
33183325fn AutoIndentingStream(comptime UnderlyingWriter: type) type {
33193326 return struct {
33203327 const Self = @This();
33213328 pub const WriteError = UnderlyingWriter.Error;
33223329 pub const Writer = std.io.Writer(*Self, WriteError, write);
33233330
3331 pub const IndentType = enum {
3332 normal,
3333 after_equals,
3334 binop,
3335 field_access,
3336 };
3337 const StackElem = struct {
3338 indent_type: IndentType,
3339 realized: bool,
3340 };
3341 const SpaceElem = struct {
3342 space: Space,
3343 indent_count: usize,
3344 };
3345
33243346 underlying_writer: UnderlyingWriter,
33253347
33263348 /// Offset into the source at which formatting has been disabled with
......@@ -3333,13 +3355,27 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type {
33333355
33343356 indent_count: usize = 0,
33353357 indent_delta: usize,
3358 indent_stack: std.ArrayList(StackElem),
3359 space_stack: std.ArrayList(SpaceElem),
3360 space_mode: ?usize = null,
3361 disable_indent_committing: usize = 0,
33363362 current_line_empty: bool = true,
3337 /// automatically popped when applied
3338 indent_one_shot_count: usize = 0,
33393363 /// the most recently applied indent
33403364 applied_indent: usize = 0,
3341 /// not used until the next line
3342 indent_next_line: usize = 0,
3365
3366 pub fn init(buffer: *std.ArrayList(u8), indent_delta_: usize) Self {
3367 return .{
3368 .underlying_writer = buffer.writer(),
3369 .indent_delta = indent_delta_,
3370 .indent_stack = std.ArrayList(StackElem).init(buffer.allocator),
3371 .space_stack = std.ArrayList(SpaceElem).init(buffer.allocator),
3372 };
3373 }
3374
3375 pub fn deinit(self: *Self) void {
3376 self.indent_stack.deinit();
3377 self.space_stack.deinit();
3378 }
33433379
33443380 pub fn writer(self: *Self) Writer {
33453381 return .{ .context = self };
......@@ -3384,7 +3420,73 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type {
33843420
33853421 fn resetLine(self: *Self) void {
33863422 self.current_line_empty = true;
3387 self.indent_next_line = 0;
3423
3424 if (self.disable_indent_committing > 0) return;
3425
3426 if (self.indent_stack.items.len > 0) {
3427 // By default, we realize the most recent indentation scope.
3428 var to_realize = self.indent_stack.items.len - 1;
3429
3430 if (self.indent_stack.items.len >= 2 and
3431 self.indent_stack.items[to_realize - 1].indent_type == .after_equals and
3432 self.indent_stack.items[to_realize - 1].realized and
3433 self.indent_stack.items[to_realize].indent_type == .binop)
3434 {
3435 // If we are in a .binop scope and our direct parent is .after_equals, don't indent.
3436 // This ensures correct indentation in the below example:
3437 //
3438 // const foo =
3439 // (x >= 'a' and x <= 'z') or //<-- we are here
3440 // (x >= 'A' and x <= 'Z');
3441 //
3442 return;
3443 }
3444
3445 if (self.indent_stack.items[to_realize].indent_type == .field_access) {
3446 // Only realize the top-most field_access in a chain.
3447 while (to_realize > 0 and self.indent_stack.items[to_realize - 1].indent_type == .field_access)
3448 to_realize -= 1;
3449 }
3450
3451 if (self.indent_stack.items[to_realize].realized) return;
3452 self.indent_stack.items[to_realize].realized = true;
3453 self.indent_count += 1;
3454 }
3455 }
3456
3457 /// Disables indentation level changes during the next newlines until re-enabled.
3458 pub fn disableIndentCommitting(self: *Self) void {
3459 self.disable_indent_committing += 1;
3460 }
3461
3462 pub fn enableIndentCommitting(self: *Self) void {
3463 assert(self.disable_indent_committing > 0);
3464 self.disable_indent_committing -= 1;
3465 }
3466
3467 pub fn pushSpace(self: *Self, space: Space) !void {
3468 try self.space_stack.append(.{ .space = space, .indent_count = self.indent_count });
3469 }
3470
3471 pub fn popSpace(self: *Self) void {
3472 _ = self.space_stack.pop();
3473 }
3474
3475 /// Sets current indentation level to be the same as that of the last pushSpace.
3476 pub fn enableSpaceMode(self: *Self, space: Space) void {
3477 if (self.space_stack.items.len == 0) return;
3478 const curr = self.space_stack.getLast();
3479 if (curr.space != space) return;
3480 self.space_mode = curr.indent_count;
3481 }
3482
3483 pub fn disableSpaceMode(self: *Self) void {
3484 self.space_mode = null;
3485 }
3486
3487 pub fn lastSpaceModeIndent(self: *Self) usize {
3488 if (self.space_stack.items.len == 0) return 0;
3489 return self.space_stack.getLast().indent_count * self.indent_delta;
33883490 }
33893491
33903492 /// Insert a newline unless the current line is blank
......@@ -3396,36 +3498,25 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type {
33963498 /// Push default indentation
33973499 /// Doesn't actually write any indentation.
33983500 /// Just primes the stream to be able to write the correct indentation if it needs to.
3399 pub fn pushIndent(self: *Self) void {
3400 self.indent_count += 1;
3501 pub fn pushIndent(self: *Self, indent_type: IndentType) !void {
3502 try self.indent_stack.append(.{ .indent_type = indent_type, .realized = false });
34013503 }
34023504
3403 /// Push an indent that is automatically popped after being applied
3404 pub fn pushIndentOneShot(self: *Self) void {
3405 self.indent_one_shot_count += 1;
3406 self.pushIndent();
3407 }
3408
3409 /// Turns all one-shot indents into regular indents
3410 /// Returns number of indents that must now be manually popped
3411 pub fn lockOneShotIndent(self: *Self) usize {
3412 const locked_count = self.indent_one_shot_count;
3413 self.indent_one_shot_count = 0;
3414 return locked_count;
3415 }
3416
3417 /// Push an indent that should not take effect until the next line
3418 pub fn pushIndentNextLine(self: *Self) void {
3419 self.indent_next_line += 1;
3420 self.pushIndent();
3505 /// Forces an indentation level to be realized.
3506 pub fn forcePushIndent(self: *Self, indent_type: IndentType) !void {
3507 try self.indent_stack.append(.{ .indent_type = indent_type, .realized = true });
3508 self.indent_count += 1;
34213509 }
34223510
34233511 pub fn popIndent(self: *Self) void {
3424 assert(self.indent_count != 0);
3425 self.indent_count -= 1;
3512 if (self.indent_stack.pop().?.realized) {
3513 assert(self.indent_count > 0);
3514 self.indent_count -= 1;
3515 }
3516 }
34263517
3427 if (self.indent_next_line > 0)
3428 self.indent_next_line -= 1;
3518 pub fn indentStackEmpty(self: *Self) bool {
3519 return self.indent_stack.items.len == 0;
34293520 }
34303521
34313522 /// Writes ' ' bytes if the current line is empty
......@@ -3437,9 +3528,6 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type {
34373528 }
34383529 self.applied_indent = current_indent;
34393530 }
3440
3441 self.indent_count -= self.indent_one_shot_count;
3442 self.indent_one_shot_count = 0;
34433531 self.current_line_empty = false;
34443532 }
34453533
......@@ -3450,12 +3538,8 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type {
34503538 }
34513539
34523540 fn currentIndent(self: *Self) usize {
3453 var indent_current: usize = 0;
3454 if (self.indent_count > 0) {
3455 const indent_count = self.indent_count - self.indent_next_line;
3456 indent_current = indent_count * self.indent_delta;
3457 }
3458 return indent_current;
3541 const indent_count = self.space_mode orelse self.indent_count;
3542 return indent_count * self.indent_delta;
34593543 }
34603544 };
34613545}
src/Sema.zig+11-11
......@@ -23443,7 +23443,7 @@ fn ptrCastFull(
2344323443 errdefer msg.destroy(sema.gpa);
2344423444 if (dest_info.flags.size == .many and
2344523445 (src_info.flags.size == .slice or
23446 (src_info.flags.size == .one and Type.fromInterned(src_info.child).zigTypeTag(zcu) == .array)))
23446 (src_info.flags.size == .one and Type.fromInterned(src_info.child).zigTypeTag(zcu) == .array)))
2344723447 {
2344823448 try sema.errNote(src, msg, "use 'ptr' field to convert slice to many pointer", .{});
2344923449 } else {
......@@ -28136,9 +28136,9 @@ fn fieldCallBind(
2813628136 const first_param_type = Type.fromInterned(func_type.param_types.get(ip)[0]);
2813728137 if (first_param_type.isGenericPoison() or
2813828138 (first_param_type.zigTypeTag(zcu) == .pointer and
28139 (first_param_type.ptrSize(zcu) == .one or
28140 first_param_type.ptrSize(zcu) == .c) and
28141 first_param_type.childType(zcu).eql(concrete_ty, zcu)))
28139 (first_param_type.ptrSize(zcu) == .one or
28140 first_param_type.ptrSize(zcu) == .c) and
28141 first_param_type.childType(zcu).eql(concrete_ty, zcu)))
2814228142 {
2814328143 // Note that if the param type is generic poison, we know that it must
2814428144 // specifically be `anytype` since it's the first parameter, meaning we
......@@ -29652,7 +29652,7 @@ fn coerceExtra(
2965229652
2965329653 if (dest_info.sentinel == .none or inst_info.sentinel == .none or
2965429654 Air.internedToRef(dest_info.sentinel) !=
29655 try sema.coerceInMemory(Value.fromInterned(inst_info.sentinel), Type.fromInterned(dest_info.child)))
29655 try sema.coerceInMemory(Value.fromInterned(inst_info.sentinel), Type.fromInterned(dest_info.child)))
2965629656 break :p;
2965729657
2965829658 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);
......@@ -30492,12 +30492,12 @@ pub fn coerceInMemoryAllowed(
3049230492 }
3049330493 const ok_sent = (dest_info.sentinel == null and src_info.sentinel == null) or
3049430494 (src_info.sentinel != null and
30495 dest_info.sentinel != null and
30496 dest_info.sentinel.?.eql(
30497 try pt.getCoerced(src_info.sentinel.?, dest_info.elem_type),
30498 dest_info.elem_type,
30499 zcu,
30500 ));
30495 dest_info.sentinel != null and
30496 dest_info.sentinel.?.eql(
30497 try pt.getCoerced(src_info.sentinel.?, dest_info.elem_type),
30498 dest_info.elem_type,
30499 zcu,
30500 ));
3050130501 if (!ok_sent) {
3050230502 return .{ .array_sentinel = .{
3050330503 .actual = src_info.sentinel orelse Value.@"unreachable",
src/Type.zig+6-5
......@@ -610,11 +610,12 @@ pub fn hasRuntimeBitsInner(
610610 // in which case we want control flow to continue down below.
611611 if (tag_ty != .none and
612612 try Type.fromInterned(tag_ty).hasRuntimeBitsInner(
613 ignore_comptime_only,
614 strat,
615 zcu,
616 tid,
617 )) {
613 ignore_comptime_only,
614 strat,
615 zcu,
616 tid,
617 ))
618 {
618619 return true;
619620 }
620621 },
src/Zcu.zig+4-4
......@@ -1496,8 +1496,8 @@ pub const SrcLoc = struct {
14961496 const case = tree.fullSwitchCase(case_node).?;
14971497 const is_special = (case.ast.values.len == 0) or
14981498 (case.ast.values.len == 1 and
1499 node_tags[case.ast.values[0]] == .identifier and
1500 mem.eql(u8, tree.tokenSlice(main_tokens[case.ast.values[0]]), "_"));
1499 node_tags[case.ast.values[0]] == .identifier and
1500 mem.eql(u8, tree.tokenSlice(main_tokens[case.ast.values[0]]), "_"));
15011501 if (!is_special) continue;
15021502
15031503 return tree.nodeToSpan(case_node);
......@@ -1516,8 +1516,8 @@ pub const SrcLoc = struct {
15161516 const case = tree.fullSwitchCase(case_node).?;
15171517 const is_special = (case.ast.values.len == 0) or
15181518 (case.ast.values.len == 1 and
1519 node_tags[case.ast.values[0]] == .identifier and
1520 mem.eql(u8, tree.tokenSlice(main_tokens[case.ast.values[0]]), "_"));
1519 node_tags[case.ast.values[0]] == .identifier and
1520 mem.eql(u8, tree.tokenSlice(main_tokens[case.ast.values[0]]), "_"));
15211521 if (is_special) continue;
15221522
15231523 for (case.ast.values) |item_node| {
src/arch/riscv64/CodeGen.zig+10-11
......@@ -685,8 +685,7 @@ fn restoreState(func: *Func, state: State, deaths: []const Air.Inst.Index, compt
685685
686686 const ExpectedContents = [@typeInfo(RegisterManager.TrackedRegisters).array.len]RegisterLock;
687687 var stack align(@max(@alignOf(ExpectedContents), @alignOf(std.heap.StackFallbackAllocator(0)))) =
688 if (opts.update_tracking)
689 {} else std.heap.stackFallback(@sizeOf(ExpectedContents), func.gpa);
688 if (opts.update_tracking) {} else std.heap.stackFallback(@sizeOf(ExpectedContents), func.gpa);
690689
691690 var reg_locks = if (opts.update_tracking) {} else try std.ArrayList(RegisterLock).initCapacity(
692691 stack.get(),
......@@ -2260,7 +2259,7 @@ fn airIntCast(func: *Func, inst: Air.Inst.Index) !void {
22602259
22612260 const dst_mcv = if (dst_int_info.bits <= src_storage_bits and
22622261 math.divCeil(u16, dst_int_info.bits, 64) catch unreachable ==
2263 math.divCeil(u32, src_storage_bits, 64) catch unreachable and
2262 math.divCeil(u32, src_storage_bits, 64) catch unreachable and
22642263 func.reuseOperand(inst, ty_op.operand, 0, src_mcv)) src_mcv else dst: {
22652264 const dst_mcv = try func.allocRegOrMem(dst_ty, inst, true);
22662265 try func.genCopy(min_ty, dst_mcv, src_mcv);
......@@ -2311,9 +2310,9 @@ fn airNot(func: *Func, inst: Air.Inst.Index) !void {
23112310
23122311 const dst_reg: Register =
23132312 if (func.reuseOperand(inst, ty_op.operand, 0, operand) and operand == .register)
2314 operand.register
2315 else
2316 (try func.allocRegOrMem(func.typeOfIndex(inst), inst, true)).register;
2313 operand.register
2314 else
2315 (try func.allocRegOrMem(func.typeOfIndex(inst), inst, true)).register;
23172316
23182317 switch (ty.zigTypeTag(zcu)) {
23192318 .bool => {
......@@ -6222,11 +6221,11 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void {
62226221
62236222 const instruction: union(enum) { mnem: Mnemonic, pseudo: Pseudo } =
62246223 if (std.meta.stringToEnum(Mnemonic, mnem_str)) |mnem|
6225 .{ .mnem = mnem }
6226 else if (std.meta.stringToEnum(Pseudo, mnem_str)) |pseudo|
6227 .{ .pseudo = pseudo }
6228 else
6229 return func.fail("invalid mnem str '{s}'", .{mnem_str});
6224 .{ .mnem = mnem }
6225 else if (std.meta.stringToEnum(Pseudo, mnem_str)) |pseudo|
6226 .{ .pseudo = pseudo }
6227 else
6228 return func.fail("invalid mnem str '{s}'", .{mnem_str});
62306229
62316230 const Operand = union(enum) {
62326231 none,
src/arch/sparc64/CodeGen.zig+6-6
......@@ -4394,12 +4394,12 @@ fn processDeath(self: *Self, inst: Air.Inst.Index) void {
43944394
43954395/// Turns stack_offset MCV into a real SPARCv9 stack offset usable for asm.
43964396fn realStackOffset(off: u32) u32 {
4397 return off
4398 // SPARCv9 %sp points away from the stack by some amount.
4399 + abi.stack_bias
4400 // The first couple bytes of each stack frame is reserved
4401 // for ABI and hardware purposes.
4402 + abi.stack_reserved_area;
4397 return off +
4398 // SPARCv9 %sp points away from the stack by some amount.
4399 abi.stack_bias +
4400 // The first couple bytes of each stack frame is reserved
4401 // for ABI and hardware purposes.
4402 abi.stack_reserved_area;
44034403 // Only after that we have the usable stack frame portion.
44044404}
44054405
src/arch/x86_64/CodeGen.zig+41-42
......@@ -82655,8 +82655,7 @@ fn restoreState(self: *CodeGen, state: State, deaths: []const Air.Inst.Index, co
8265582655
8265682656 const ExpectedContents = [@typeInfo(RegisterManager.TrackedRegisters).array.len]RegisterLock;
8265782657 var stack align(@max(@alignOf(ExpectedContents), @alignOf(std.heap.StackFallbackAllocator(0)))) =
82658 if (opts.update_tracking)
82659 {} else std.heap.stackFallback(@sizeOf(ExpectedContents), self.gpa);
82658 if (opts.update_tracking) {} else std.heap.stackFallback(@sizeOf(ExpectedContents), self.gpa);
8266082659
8266182660 var reg_locks = if (opts.update_tracking) {} else try std.ArrayList(RegisterLock).initCapacity(
8266282661 stack.get(),
......@@ -83216,7 +83215,7 @@ fn airIntCast(self: *CodeGen, inst: Air.Inst.Index) !void {
8321683215 const dst_mcv = if ((if (src_mcv.getReg()) |src_reg| src_reg.class() == .general_purpose else src_abi_size > 8) and
8321783216 dst_int_info.bits <= src_storage_bits and
8321883217 std.math.divCeil(u16, dst_int_info.bits, 64) catch unreachable ==
83219 std.math.divCeil(u32, src_storage_bits, 64) catch unreachable and
83218 std.math.divCeil(u32, src_storage_bits, 64) catch unreachable and
8322083219 self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) src_mcv else dst: {
8322183220 const dst_mcv = try self.allocRegOrMem(inst, true);
8322283221 try self.genCopy(min_ty, dst_mcv, src_mcv, .{});
......@@ -84695,10 +84694,10 @@ fn genIntMulDivOpMir(self: *CodeGen, tag: Mir.Inst.FixedTag, ty: Type, lhs: MCVa
8469584694 ._ => {
8469684695 const hi_reg: Register =
8469784696 switch (bit_size) {
84698 8 => .ah,
84699 16, 32, 64 => .edx,
84700 else => unreachable,
84701 };
84697 8 => .ah,
84698 16, 32, 64 => .edx,
84699 else => unreachable,
84700 };
8470284701 try self.asmRegisterRegister(.{ ._, .xor }, hi_reg, hi_reg);
8470384702 },
8470484703 .i_ => try self.asmOpOnly(.{ ._, switch (bit_size) {
......@@ -89019,9 +89018,9 @@ fn genShiftBinOpMir(
8901989018 .size = .fromSize(abi_size),
8902089019 .disp = std.math.cast(i32, @as(i64, @bitCast(addr))) orelse
8902189020 return self.fail("TODO genShiftBinOpMir between {s} and {s}", .{
89022 @tagName(lhs_mcv),
89023 @tagName(shift_mcv),
89024 }),
89021 @tagName(lhs_mcv),
89022 @tagName(shift_mcv),
89023 }),
8902589024 } },
8902689025 },
8902789026 .indirect => |reg_off| .{
......@@ -89761,17 +89760,17 @@ fn genBinOp(
8976189760
8976289761 const ordered_air: [2]Air.Inst.Ref = if (lhs_ty.isVector(zcu) and
8976389762 switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
89764 .bool => false,
89765 .int => switch (air_tag) {
89766 .cmp_lt, .cmp_gte => true,
89767 else => false,
89768 },
89769 .float => switch (air_tag) {
89770 .cmp_gte, .cmp_gt => true,
89771 else => false,
89772 },
89773 else => unreachable,
89774 }) .{ rhs_air, lhs_air } else .{ lhs_air, rhs_air };
89763 .bool => false,
89764 .int => switch (air_tag) {
89765 .cmp_lt, .cmp_gte => true,
89766 else => false,
89767 },
89768 .float => switch (air_tag) {
89769 .cmp_gte, .cmp_gt => true,
89770 else => false,
89771 },
89772 else => unreachable,
89773 }) .{ rhs_air, lhs_air } else .{ lhs_air, rhs_air };
8977589774
8977689775 if (lhs_ty.isAbiInt(zcu)) for (ordered_air) |op_air| {
8977789776 switch (try self.resolveInst(op_air)) {
......@@ -91776,13 +91775,13 @@ fn genIntMulComplexOpMir(self: *CodeGen, dst_ty: Type, dst_mcv: MCValue, src_mcv
9177691775 .size = .fromSize(abi_size),
9177791776 .disp = std.math.cast(i32, @as(i64, @bitCast(addr))) orelse
9177891777 return self.asmRegisterRegister(
91779 .{ .i_, .mul },
91780 dst_alias,
91781 registerAlias(
91782 try self.copyToTmpRegister(dst_ty, resolved_src_mcv),
91783 abi_size,
91778 .{ .i_, .mul },
91779 dst_alias,
91780 registerAlias(
91781 try self.copyToTmpRegister(dst_ty, resolved_src_mcv),
91782 abi_size,
91783 ),
9178491784 ),
91785 ),
9178691785 } },
9178791786 },
9178891787 .indirect => |reg_off| .{
......@@ -94101,9 +94100,9 @@ fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {
9410194100 std.mem.eql(u8, rest, "r,m") or std.mem.eql(u8, rest, "m,r"))
9410294101 self.register_manager.tryAllocReg(maybe_inst, abi.RegisterClass.gp) orelse
9410394102 if (output != .none)
94104 null
94105 else
94106 return self.fail("ran out of registers lowering inline asm", .{})
94103 null
94104 else
94105 return self.fail("ran out of registers lowering inline asm", .{})
9410794106 else if (std.mem.startsWith(u8, rest, "{") and std.mem.endsWith(u8, rest, "}"))
9410894107 parseRegName(rest["{".len .. rest.len - "}".len]) orelse
9410994108 return self.fail("invalid register constraint: '{s}'", .{constraint})
......@@ -96965,9 +96964,9 @@ fn airAtomicLoad(self: *CodeGen, inst: Air.Inst.Index) !void {
9696596964
9696696965 const dst_mcv =
9696796966 if (self.reuseOperand(inst, atomic_load.ptr, 0, ptr_mcv))
96968 ptr_mcv
96969 else
96970 try self.allocRegOrMem(inst, true);
96967 ptr_mcv
96968 else
96969 try self.allocRegOrMem(inst, true);
9697196970
9697296971 try self.load(dst_mcv, ptr_ty, ptr_mcv);
9697396972 return self.finishAir(inst, dst_mcv, .{ atomic_load.ptr, .none, .none });
......@@ -103712,9 +103711,9 @@ const Select = struct {
103712103711 if (cg.intInfo(ty.childType(zcu))) |int_info| int_info.signedness == .signed else false,
103713103712 .signed_int_or_full_vec => |size| ty.isVector(zcu) and @divExact(size.bitSize(cg.target), 8) >= ty.abiSize(zcu) and
103714103713 if (cg.intInfo(ty.childType(zcu))) |int_info| switch (int_info.signedness) {
103715 .signed => true,
103716 .unsigned => int_info.bits >= 8 and std.math.isPowerOfTwo(int_info.bits),
103717 } else false,
103714 .signed => true,
103715 .unsigned => int_info.bits >= 8 and std.math.isPowerOfTwo(int_info.bits),
103716 } else false,
103718103717 .unsigned_int_vec => |size| ty.isVector(zcu) and @divExact(size.bitSize(cg.target), 8) >= ty.abiSize(zcu) and
103719103718 if (cg.intInfo(ty.childType(zcu))) |int_info| int_info.signedness == .unsigned else false,
103720103719 .size => |size| @divExact(size.bitSize(cg.target), 8) >= ty.abiSize(zcu),
......@@ -103736,26 +103735,26 @@ const Select = struct {
103736103735 if (cg.intInfo(ty.scalarType(zcu))) |int_info| of_is.is.bitSize(cg.target) >= int_info.bits else false,
103737103736 .scalar_signed_int => |of_is| @divExact(of_is.of.bitSize(cg.target), 8) >= cg.unalignedSize(ty) and
103738103737 if (cg.intInfo(ty.scalarType(zcu))) |int_info| int_info.signedness == .signed and
103739 of_is.is.bitSize(cg.target) >= int_info.bits else false,
103738 of_is.is.bitSize(cg.target) >= int_info.bits else false,
103740103739 .scalar_unsigned_int => |of_is| @divExact(of_is.of.bitSize(cg.target), 8) >= cg.unalignedSize(ty) and
103741103740 if (cg.intInfo(ty.scalarType(zcu))) |int_info| int_info.signedness == .unsigned and
103742 of_is.is.bitSize(cg.target) >= int_info.bits else false,
103741 of_is.is.bitSize(cg.target) >= int_info.bits else false,
103743103742 .multiple_scalar_int => |of_is| ty.abiSize(zcu) % @divExact(of_is.of.bitSize(cg.target), 8) == 0 and
103744103743 if (cg.intInfo(ty.scalarType(zcu))) |int_info| of_is.is.bitSize(cg.target) >= int_info.bits else false,
103745103744 .multiple_scalar_signed_int => |of_is| ty.abiSize(zcu) % @divExact(of_is.of.bitSize(cg.target), 8) == 0 and
103746103745 if (cg.intInfo(ty.scalarType(zcu))) |int_info| int_info.signedness == .signed and
103747 of_is.is.bitSize(cg.target) >= int_info.bits else false,
103746 of_is.is.bitSize(cg.target) >= int_info.bits else false,
103748103747 .multiple_scalar_unsigned_int => |of_is| ty.abiSize(zcu) % @divExact(of_is.of.bitSize(cg.target), 8) == 0 and
103749103748 if (cg.intInfo(ty.scalarType(zcu))) |int_info| int_info.signedness == .unsigned and
103750 of_is.is.bitSize(cg.target) >= int_info.bits else false,
103749 of_is.is.bitSize(cg.target) >= int_info.bits else false,
103751103750 .multiple_scalar_exact_int => |of_is| ty.abiSize(zcu) % @divExact(of_is.of.bitSize(cg.target), 8) == 0 and
103752103751 if (cg.intInfo(ty.scalarType(zcu))) |int_info| of_is.is == int_info.bits else false,
103753103752 .multiple_scalar_exact_signed_int => |of_is| ty.abiSize(zcu) % @divExact(of_is.of.bitSize(cg.target), 8) == 0 and
103754103753 if (cg.intInfo(ty.scalarType(zcu))) |int_info| int_info.signedness == .signed and
103755 of_is.is == int_info.bits else false,
103754 of_is.is == int_info.bits else false,
103756103755 .multiple_scalar_exact_unsigned_int => |of_is| ty.abiSize(zcu) % @divExact(of_is.of.bitSize(cg.target), 8) == 0 and
103757103756 if (cg.intInfo(ty.scalarType(zcu))) |int_info| int_info.signedness == .unsigned and
103758 of_is.is == int_info.bits else false,
103757 of_is.is == int_info.bits else false,
103759103758 .scalar_remainder_int => |of_is| if (cg.intInfo(ty.scalarType(zcu))) |int_info|
103760103759 of_is.is.bitSize(cg.target) >= (int_info.bits - 1) % of_is.of.bitSize(cg.target) + 1
103761103760 else
src/codegen.zig+1-1
......@@ -423,7 +423,7 @@ pub fn generateSymbol(
423423
424424 const padding = abi_size -
425425 (math.cast(usize, Type.fromInterned(vector_type.child).abiSize(zcu) * vector_type.len) orelse
426 return error.Overflow);
426 return error.Overflow);
427427 if (padding > 0) try code.appendNTimes(gpa, 0, padding);
428428 }
429429 },
src/codegen/c.zig+3-3
......@@ -1990,7 +1990,7 @@ pub const DeclGen = struct {
19901990 if (dest_bits <= 64 and src_bits <= 64) {
19911991 const needs_cast = src_int_info == null or
19921992 (toCIntBits(dest_int_info.bits) != toCIntBits(src_int_info.?.bits) or
1993 dest_int_info.signedness != src_int_info.?.signedness);
1993 dest_int_info.signedness != src_int_info.?.signedness);
19941994 return !needs_cast and !src_is_ptr;
19951995 } else return false;
19961996 }
......@@ -2031,7 +2031,7 @@ pub const DeclGen = struct {
20312031 if (dest_bits <= 64 and src_bits <= 64) {
20322032 const needs_cast = src_int_info == null or
20332033 (toCIntBits(dest_int_info.bits) != toCIntBits(src_int_info.?.bits) or
2034 dest_int_info.signedness != src_int_info.?.signedness);
2034 dest_int_info.signedness != src_int_info.?.signedness);
20352035
20362036 if (needs_cast) {
20372037 try w.writeByte('(');
......@@ -4348,7 +4348,7 @@ fn airEquality(
43484348 .aligned, .array, .vector, .fwd_decl, .function => unreachable,
43494349 .aggregate => |aggregate| if (aggregate.fields.len == 2 and
43504350 (aggregate.fields.at(0, ctype_pool).name.index == .is_null or
4351 aggregate.fields.at(1, ctype_pool).name.index == .is_null))
4351 aggregate.fields.at(1, ctype_pool).name.index == .is_null))
43524352 {
43534353 try f.writeCValueMember(writer, lhs, .{ .identifier = "is_null" });
43544354 try writer.writeAll(" || ");
src/codegen/c/Type.zig+34-35
......@@ -758,12 +758,12 @@ pub const Info = union(enum) {
758758 fn tag(pointer_info: Pointer) Pool.Tag {
759759 return @enumFromInt(@intFromEnum(Pool.Tag.pointer) +
760760 @as(u2, @bitCast(packed struct(u2) {
761 @"const": bool,
762 @"volatile": bool,
763 }{
764 .@"const" = pointer_info.@"const",
765 .@"volatile" = pointer_info.@"volatile",
766 })));
761 @"const": bool,
762 @"volatile": bool,
763 }{
764 .@"const" = pointer_info.@"const",
765 .@"volatile" = pointer_info.@"volatile",
766 })));
767767 }
768768 };
769769
......@@ -887,24 +887,24 @@ pub const Info = union(enum) {
887887 pool_adapter.eql(lhs_vector_info.elem_ctype, rhs_info.vector.elem_ctype),
888888 .fwd_decl => |lhs_fwd_decl_info| lhs_fwd_decl_info.tag == rhs_info.fwd_decl.tag and
889889 switch (lhs_fwd_decl_info.name) {
890 .anon => |lhs_anon| rhs_info.fwd_decl.name == .anon and lhs_anon.eqlAdapted(
891 lhs_pool,
892 rhs_info.fwd_decl.name.anon,
893 rhs_pool,
894 pool_adapter,
895 ),
896 .index => |lhs_index| rhs_info.fwd_decl.name == .index and
897 lhs_index == rhs_info.fwd_decl.name.index,
898 },
890 .anon => |lhs_anon| rhs_info.fwd_decl.name == .anon and lhs_anon.eqlAdapted(
891 lhs_pool,
892 rhs_info.fwd_decl.name.anon,
893 rhs_pool,
894 pool_adapter,
895 ),
896 .index => |lhs_index| rhs_info.fwd_decl.name == .index and
897 lhs_index == rhs_info.fwd_decl.name.index,
898 },
899899 .aggregate => |lhs_aggregate_info| lhs_aggregate_info.tag == rhs_info.aggregate.tag and
900900 lhs_aggregate_info.@"packed" == rhs_info.aggregate.@"packed" and
901901 switch (lhs_aggregate_info.name) {
902 .anon => |lhs_anon| rhs_info.aggregate.name == .anon and
903 lhs_anon.index == rhs_info.aggregate.name.anon.index and
904 lhs_anon.id == rhs_info.aggregate.name.anon.id,
905 .fwd_decl => |lhs_fwd_decl| rhs_info.aggregate.name == .fwd_decl and
906 pool_adapter.eql(lhs_fwd_decl, rhs_info.aggregate.name.fwd_decl),
907 } and lhs_aggregate_info.fields.eqlAdapted(
902 .anon => |lhs_anon| rhs_info.aggregate.name == .anon and
903 lhs_anon.index == rhs_info.aggregate.name.anon.index and
904 lhs_anon.id == rhs_info.aggregate.name.anon.id,
905 .fwd_decl => |lhs_fwd_decl| rhs_info.aggregate.name == .fwd_decl and
906 pool_adapter.eql(lhs_fwd_decl, rhs_info.aggregate.name.fwd_decl),
907 } and lhs_aggregate_info.fields.eqlAdapted(
908908 lhs_pool,
909909 rhs_info.aggregate.fields,
910910 rhs_pool,
......@@ -913,13 +913,12 @@ pub const Info = union(enum) {
913913 .function => |lhs_function_info| lhs_function_info.param_ctypes.len ==
914914 rhs_info.function.param_ctypes.len and
915915 pool_adapter.eql(lhs_function_info.return_ctype, rhs_info.function.return_ctype) and
916 for (0..lhs_function_info.param_ctypes.len) |param_index|
917 {
918 if (!pool_adapter.eql(
919 lhs_function_info.param_ctypes.at(param_index, lhs_pool),
920 rhs_info.function.param_ctypes.at(param_index, rhs_pool),
921 )) break false;
922 } else true,
916 for (0..lhs_function_info.param_ctypes.len) |param_index| {
917 if (!pool_adapter.eql(
918 lhs_function_info.param_ctypes.at(param_index, lhs_pool),
919 rhs_info.function.param_ctypes.at(param_index, rhs_pool),
920 )) break false;
921 } else true,
923922 };
924923 }
925924};
......@@ -2301,13 +2300,13 @@ pub const Pool = struct {
23012300 const return_type = Type.fromInterned(func_info.return_type);
23022301 const return_ctype: CType =
23032302 if (!ip.isNoReturn(func_info.return_type)) try pool.fromType(
2304 allocator,
2305 scratch,
2306 return_type,
2307 pt,
2308 mod,
2309 kind.asParameter(),
2310 ) else .void;
2303 allocator,
2304 scratch,
2305 return_type,
2306 pt,
2307 mod,
2308 kind.asParameter(),
2309 ) else .void;
23112310 for (0..func_info.param_types.len) |param_index| {
23122311 const param_type = Type.fromInterned(
23132312 func_info.param_types.get(ip)[param_index],
src/codegen/llvm.zig+55-56
......@@ -388,7 +388,7 @@ const DataLayoutBuilder = struct {
388388 self.target.cpu.arch != .riscv64 and
389389 self.target.cpu.arch != .loongarch64 and
390390 !(self.target.cpu.arch == .aarch64 and
391 (self.target.os.tag == .uefi or self.target.os.tag == .windows)) and
391 (self.target.os.tag == .uefi or self.target.os.tag == .windows)) and
392392 self.target.cpu.arch != .bpfeb and self.target.cpu.arch != .bpfel) continue;
393393 try writer.writeAll("-p");
394394 if (info.llvm != .default) try writer.print("{d}", .{@intFromEnum(info.llvm)});
......@@ -859,55 +859,54 @@ pub const Object = struct {
859859 builder.data_layout = try builder.fmt("{}", .{DataLayoutBuilder{ .target = target }});
860860
861861 const debug_compile_unit, const debug_enums_fwd_ref, const debug_globals_fwd_ref =
862 if (!builder.strip)
863 debug_info: {
864 // We fully resolve all paths at this point to avoid lack of
865 // source line info in stack traces or lack of debugging
866 // information which, if relative paths were used, would be
867 // very location dependent.
868 // TODO: the only concern I have with this is WASI as either host or target, should
869 // we leave the paths as relative then?
870 // TODO: This is totally wrong. In dwarf, paths are encoded as relative to
871 // a particular directory, and then the directory path is specified elsewhere.
872 // In the compiler frontend we have it stored correctly in this
873 // way already, but here we throw all that sweet information
874 // into the garbage can by converting into absolute paths. What
875 // a terrible tragedy.
876 const compile_unit_dir = blk: {
877 if (comp.zcu) |zcu| m: {
878 const d = try zcu.main_mod.root.joinString(arena, "");
879 if (d.len == 0) break :m;
880 if (std.fs.path.isAbsolute(d)) break :blk d;
881 break :blk std.fs.realpathAlloc(arena, d) catch break :blk d;
882 }
883 break :blk try std.process.getCwdAlloc(arena);
884 };
862 if (!builder.strip) debug_info: {
863 // We fully resolve all paths at this point to avoid lack of
864 // source line info in stack traces or lack of debugging
865 // information which, if relative paths were used, would be
866 // very location dependent.
867 // TODO: the only concern I have with this is WASI as either host or target, should
868 // we leave the paths as relative then?
869 // TODO: This is totally wrong. In dwarf, paths are encoded as relative to
870 // a particular directory, and then the directory path is specified elsewhere.
871 // In the compiler frontend we have it stored correctly in this
872 // way already, but here we throw all that sweet information
873 // into the garbage can by converting into absolute paths. What
874 // a terrible tragedy.
875 const compile_unit_dir = blk: {
876 if (comp.zcu) |zcu| m: {
877 const d = try zcu.main_mod.root.joinString(arena, "");
878 if (d.len == 0) break :m;
879 if (std.fs.path.isAbsolute(d)) break :blk d;
880 break :blk std.fs.realpathAlloc(arena, d) catch break :blk d;
881 }
882 break :blk try std.process.getCwdAlloc(arena);
883 };
885884
886 const debug_file = try builder.debugFile(
887 try builder.metadataString(comp.root_name),
888 try builder.metadataString(compile_unit_dir),
889 );
885 const debug_file = try builder.debugFile(
886 try builder.metadataString(comp.root_name),
887 try builder.metadataString(compile_unit_dir),
888 );
890889
891 const debug_enums_fwd_ref = try builder.debugForwardReference();
892 const debug_globals_fwd_ref = try builder.debugForwardReference();
893
894 const debug_compile_unit = try builder.debugCompileUnit(
895 debug_file,
896 // Don't use the version string here; LLVM misparses it when it
897 // includes the git revision.
898 try builder.metadataStringFmt("zig {d}.{d}.{d}", .{
899 build_options.semver.major,
900 build_options.semver.minor,
901 build_options.semver.patch,
902 }),
903 debug_enums_fwd_ref,
904 debug_globals_fwd_ref,
905 .{ .optimized = comp.root_mod.optimize_mode != .Debug },
906 );
890 const debug_enums_fwd_ref = try builder.debugForwardReference();
891 const debug_globals_fwd_ref = try builder.debugForwardReference();
892
893 const debug_compile_unit = try builder.debugCompileUnit(
894 debug_file,
895 // Don't use the version string here; LLVM misparses it when it
896 // includes the git revision.
897 try builder.metadataStringFmt("zig {d}.{d}.{d}", .{
898 build_options.semver.major,
899 build_options.semver.minor,
900 build_options.semver.patch,
901 }),
902 debug_enums_fwd_ref,
903 debug_globals_fwd_ref,
904 .{ .optimized = comp.root_mod.optimize_mode != .Debug },
905 );
907906
908 try builder.metadataNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit});
909 break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref };
910 } else .{.none} ** 3;
907 try builder.metadataNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit});
908 break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref };
909 } else .{.none} ** 3;
911910
912911 const obj = try arena.create(Object);
913912 obj.* = .{
......@@ -2759,9 +2758,9 @@ pub const Object = struct {
27592758
27602759 const full_fields: [2]Builder.Metadata =
27612760 if (layout.tag_align.compare(.gte, layout.payload_align))
2762 .{ debug_tag_type, debug_payload_type }
2763 else
2764 .{ debug_payload_type, debug_tag_type };
2761 .{ debug_tag_type, debug_payload_type }
2762 else
2763 .{ debug_payload_type, debug_tag_type };
27652764
27662765 const debug_tagged_union_type = try o.builder.debugStructType(
27672766 try o.builder.metadataString(name),
......@@ -4551,11 +4550,11 @@ pub const Object = struct {
45514550 // instruction is followed by a `wrap_optional`, it will return this value
45524551 // verbatim, and the result should test as non-null.
45534552 switch (zcu.getTarget().ptrBitWidth()) {
4554 16 => 0xaaaa,
4555 32 => 0xaaaaaaaa,
4556 64 => 0xaaaaaaaa_aaaaaaaa,
4557 else => unreachable,
4558 };
4553 16 => 0xaaaa,
4554 32 => 0xaaaaaaaa,
4555 64 => 0xaaaaaaaa_aaaaaaaa,
4556 else => unreachable,
4557 };
45594558 const llvm_usize = try o.lowerType(Type.usize);
45604559 const llvm_ptr_ty = try o.lowerType(ptr_ty);
45614560 return o.builder.castConst(.inttoptr, try o.builder.intConst(llvm_usize, int), llvm_ptr_ty);
......@@ -9544,7 +9543,7 @@ pub const FuncGen = struct {
95449543
95459544 if (llvm_dest_ty.isStruct(&o.builder) or
95469545 ((operand_ty.zigTypeTag(zcu) == .vector or inst_ty.zigTypeTag(zcu) == .vector) and
9547 operand_ty.bitSize(zcu) != inst_ty.bitSize(zcu)))
9546 operand_ty.bitSize(zcu) != inst_ty.bitSize(zcu)))
95489547 {
95499548 // Both our operand and our result are values, not pointers,
95509549 // but LLVM won't let us bitcast struct values or vectors with padding bits.
src/fmt.zig+1
......@@ -214,6 +214,7 @@ const FmtError = error{
214214 Unseekable,
215215 NotOpenForWriting,
216216 UnsupportedEncoding,
217 InvalidEncoding,
217218 ConnectionResetByPeer,
218219 SocketNotConnected,
219220 LockViolation,
src/link/Coff.zig+35-35
......@@ -3821,38 +3821,38 @@ const msdos_stub: [120]u8 = .{
38213821 0x40, 0x00, // Absolute offset to relocation table. 64 matches the header size (all bytes before the MS-DOS stub program).
38223822 0x00, 0x00, // Overlay number. Zero means this is the main executable.
38233823}
3824// Reserved words.
3825++ .{ 0x00, 0x00 } ** 4
3826// OEM-related fields.
3827++ .{
3828 0x00, 0x00, // OEM identifier.
3829 0x00, 0x00, // OEM information.
3830}
3831// Reserved words.
3832++ .{ 0x00, 0x00 } ** 10
3833// 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.
3834++ .{ 0x78, 0x00, 0x00, 0x00 }
3835// What follows is a 16-bit x86 MS-DOS program of 7 instructions that prints the bytes after these instructions and then exits.
3836++ .{
3837 // Set the value of the data segment to the same value as the code segment.
3838 0x0e, // push cs
3839 0x1f, // pop ds
3840 // Set the DX register to the address of the message.
3841 // If you count all bytes of these 7 instructions you get 14, so that's the address of what's after these instructions.
3842 0xba, 14, 0x00, // mov dx, 14
3843 // Set AH to the system call code for printing a message.
3844 0xb4, 0x09, // mov ah, 0x09
3845 // Perform the system call to print the message.
3846 0xcd, 0x21, // int 0x21
3847 // Set AH to 0x4c which is the system call code for exiting, and set AL to 0x01 which is the exit code.
3848 0xb8, 0x01, 0x4c, // mov ax, 0x4c01
3849 // Peform the system call to exit the program with exit code 1.
3850 0xcd, 0x21, // int 0x21
3851}
3852// Message to print.
3853++ "This program cannot be run in DOS mode.".*
3854// Message terminators.
3855++ .{
3856 '$', // We do not pass a length to the print system call; the string is terminated by this character.
3857 0x00, 0x00, // Terminating zero bytes.
3858};
3824 // Reserved words.
3825 ++ .{ 0x00, 0x00 } ** 4
3826 // OEM-related fields.
3827 ++ .{
3828 0x00, 0x00, // OEM identifier.
3829 0x00, 0x00, // OEM information.
3830 }
3831 // Reserved words.
3832 ++ .{ 0x00, 0x00 } ** 10
3833 // 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.
3834 ++ .{ 0x78, 0x00, 0x00, 0x00 }
3835 // What follows is a 16-bit x86 MS-DOS program of 7 instructions that prints the bytes after these instructions and then exits.
3836 ++ .{
3837 // Set the value of the data segment to the same value as the code segment.
3838 0x0e, // push cs
3839 0x1f, // pop ds
3840 // Set the DX register to the address of the message.
3841 // If you count all bytes of these 7 instructions you get 14, so that's the address of what's after these instructions.
3842 0xba, 14, 0x00, // mov dx, 14
3843 // Set AH to the system call code for printing a message.
3844 0xb4, 0x09, // mov ah, 0x09
3845 // Perform the system call to print the message.
3846 0xcd, 0x21, // int 0x21
3847 // Set AH to 0x4c which is the system call code for exiting, and set AL to 0x01 which is the exit code.
3848 0xb8, 0x01, 0x4c, // mov ax, 0x4c01
3849 // Peform the system call to exit the program with exit code 1.
3850 0xcd, 0x21, // int 0x21
3851 }
3852 // Message to print.
3853 ++ "This program cannot be run in DOS mode.".*
3854 // Message terminators.
3855 ++ .{
3856 '$', // We do not pass a length to the print system call; the string is terminated by this character.
3857 0x00, 0x00, // Terminating zero bytes.
3858 };
src/link/Dwarf.zig+24-24
......@@ -1995,30 +1995,30 @@ pub const WipNav = struct {
19951995 errdefer _ = if (!decl_gop.found_existing) dwarf.decls.pop();
19961996 const was_generic_decl = decl_gop.found_existing and
19971997 switch (try dwarf.debug_info.declAbbrevCode(wip_nav.unit, decl_gop.value_ptr.*)) {
1998 .null,
1999 .decl_alias,
2000 .decl_empty_enum,
2001 .decl_enum,
2002 .decl_namespace_struct,
2003 .decl_struct,
2004 .decl_packed_struct,
2005 .decl_union,
2006 .decl_var,
2007 .decl_const,
2008 .decl_const_runtime_bits,
2009 .decl_const_comptime_state,
2010 .decl_const_runtime_bits_comptime_state,
2011 .decl_empty_func,
2012 .decl_func,
2013 .decl_empty_func_generic,
2014 .decl_func_generic,
2015 => false,
2016 .generic_decl_var,
2017 .generic_decl_const,
2018 .generic_decl_func,
2019 => true,
2020 else => unreachable,
2021 };
1998 .null,
1999 .decl_alias,
2000 .decl_empty_enum,
2001 .decl_enum,
2002 .decl_namespace_struct,
2003 .decl_struct,
2004 .decl_packed_struct,
2005 .decl_union,
2006 .decl_var,
2007 .decl_const,
2008 .decl_const_runtime_bits,
2009 .decl_const_comptime_state,
2010 .decl_const_runtime_bits_comptime_state,
2011 .decl_empty_func,
2012 .decl_func,
2013 .decl_empty_func_generic,
2014 .decl_func_generic,
2015 => false,
2016 .generic_decl_var,
2017 .generic_decl_const,
2018 .generic_decl_func,
2019 => true,
2020 else => unreachable,
2021 };
20222022 if (parent_type.getCaptures(zcu).len == 0) {
20232023 if (was_generic_decl) try dwarf.freeCommonEntry(wip_nav.unit, decl_gop.value_ptr.*);
20242024 decl_gop.value_ptr.* = orig_entry;
src/link/Elf/Object.zig+5-5
......@@ -236,11 +236,11 @@ pub fn validateEFlags(
236236
237237 const fabi: riscv.Eflags.FloatAbi =
238238 if (std.Target.riscv.featureSetHas(features, .d))
239 .double
240 else if (std.Target.riscv.featureSetHas(features, .f))
241 .single
242 else
243 .soft;
239 .double
240 else if (std.Target.riscv.featureSetHas(features, .f))
241 .single
242 else
243 .soft;
244244
245245 if (flags.fabi != fabi) {
246246 any_errors = true;
src/link/Elf/relocatable.zig+11-11
......@@ -217,20 +217,20 @@ fn initSections(elf_file: *Elf) !void {
217217 if (elf_file.section_indexes.eh_frame == null) {
218218 elf_file.section_indexes.eh_frame = elf_file.sectionByName(".eh_frame") orelse
219219 try elf_file.addSection(.{
220 .name = try elf_file.insertShString(".eh_frame"),
221 .type = if (elf_file.getTarget().cpu.arch == .x86_64)
222 elf.SHT_X86_64_UNWIND
223 else
224 elf.SHT_PROGBITS,
225 .flags = elf.SHF_ALLOC,
226 .addralign = elf_file.ptrWidthBytes(),
227 });
220 .name = try elf_file.insertShString(".eh_frame"),
221 .type = if (elf_file.getTarget().cpu.arch == .x86_64)
222 elf.SHT_X86_64_UNWIND
223 else
224 elf.SHT_PROGBITS,
225 .flags = elf.SHF_ALLOC,
226 .addralign = elf_file.ptrWidthBytes(),
227 });
228228 }
229229 elf_file.section_indexes.eh_frame_rela = elf_file.sectionByName(".rela.eh_frame") orelse
230230 try elf_file.addRelaShdr(
231 try elf_file.insertShString(".rela.eh_frame"),
232 elf_file.section_indexes.eh_frame.?,
233 );
231 try elf_file.insertShString(".rela.eh_frame"),
232 elf_file.section_indexes.eh_frame.?,
233 );
234234 }
235235
236236 try initComdatGroups(elf_file);
src/link/Elf/synthetic_sections.zig+1-1
......@@ -551,7 +551,7 @@ pub const GotSection = struct {
551551 switch (entry.tag) {
552552 .got => if (symbol.?.flags.import or symbol.?.isIFunc(elf_file) or
553553 ((elf_file.isEffectivelyDynLib() or (elf_file.base.isExe() and comp.config.pie)) and
554 !symbol.?.isAbs(elf_file)))
554 !symbol.?.isAbs(elf_file)))
555555 {
556556 num += 1;
557557 },
src/link/MachO.zig+8-8
......@@ -1617,14 +1617,14 @@ fn initOutputSections(self: *MachO) !void {
16171617 }
16181618 self.text_sect_index = self.getSectionByName("__TEXT", "__text") orelse
16191619 try self.addSection("__TEXT", "__text", .{
1620 .alignment = switch (self.getTarget().cpu.arch) {
1621 .x86_64 => 0,
1622 .aarch64 => 2,
1623 else => unreachable,
1624 },
1625 .flags = macho.S_REGULAR |
1626 macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS,
1627 });
1620 .alignment = switch (self.getTarget().cpu.arch) {
1621 .x86_64 => 0,
1622 .aarch64 => 2,
1623 else => unreachable,
1624 },
1625 .flags = macho.S_REGULAR |
1626 macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS,
1627 });
16281628 self.data_sect_index = self.getSectionByName("__DATA", "__data") orelse
16291629 try self.addSection("__DATA", "__data", .{});
16301630}
src/link/MachO/Atom.zig+4-4
......@@ -149,10 +149,10 @@ pub fn initOutputSection(sect: macho.section_64, macho_file: *MachO) !u8 {
149149 if (macho_file.base.isRelocatable()) {
150150 const osec = macho_file.getSectionByName(sect.segName(), sect.sectName()) orelse
151151 try macho_file.addSection(
152 sect.segName(),
153 sect.sectName(),
154 .{ .flags = sect.flags },
155 );
152 sect.segName(),
153 sect.sectName(),
154 .{ .flags = sect.flags },
155 );
156156 return osec;
157157 }
158158
src/link/MachO/ZigObject.zig+2-2
......@@ -1104,8 +1104,8 @@ fn createTlvDescriptor(
11041104
11051105 const sect_index = macho_file.getSectionByName("__DATA", "__thread_vars") orelse
11061106 try macho_file.addSection("__DATA", "__thread_vars", .{
1107 .flags = macho.S_THREAD_LOCAL_VARIABLES,
1108 });
1107 .flags = macho.S_THREAD_LOCAL_VARIABLES,
1108 });
11091109 sym.out_n_sect = sect_index;
11101110 atom.out_n_sect = sect_index;
11111111
src/link/MachO/dead_strip.zig+2-2
......@@ -102,8 +102,8 @@ fn mark(roots: []*Atom, objects: []const File.Index, macho_file: *MachO) void {
102102 const isec = atom.getInputSection(macho_file);
103103 if (isec.isDontDeadStripIfReferencesLive() and
104104 !(mem.eql(u8, isec.sectName(), "__eh_frame") or
105 mem.eql(u8, isec.sectName(), "__compact_unwind") or
106 isec.attrs() & macho.S_ATTR_DEBUG != 0) and
105 mem.eql(u8, isec.sectName(), "__compact_unwind") or
106 isec.attrs() & macho.S_ATTR_DEBUG != 0) and
107107 !atom.isAlive() and refersLive(atom, macho_file))
108108 {
109109 markLive(atom, macho_file);
src/main.zig+4-4
......@@ -5919,8 +5919,8 @@ pub const ClangArgIterator = struct {
59195919
59205920 self.arg_iterator_response_file =
59215921 initArgIteratorResponseFile(arena, resp_file_path) catch |err| {
5922 fatal("unable to read response file '{s}': {s}", .{ resp_file_path, @errorName(err) });
5923 };
5922 fatal("unable to read response file '{s}': {s}", .{ resp_file_path, @errorName(err) });
5923 };
59245924 // NOTE: The ArgIteratorResponseFile returns tokens from next() that are slices of an
59255925 // internal buffer. This internal buffer is arena allocated, so it is not cleaned up here.
59265926
......@@ -6233,8 +6233,8 @@ fn cmdAstCheck(
62336233 file.tree.?.tokens.len * (@sizeOf(std.zig.Token.Tag) + @sizeOf(Ast.ByteOffset));
62346234 const tree_bytes = @sizeOf(Ast) + file.tree.?.nodes.len *
62356235 (@sizeOf(Ast.Node.Tag) +
6236 @sizeOf(Ast.Node.Data) +
6237 @sizeOf(Ast.TokenIndex));
6236 @sizeOf(Ast.Node.Data) +
6237 @sizeOf(Ast.TokenIndex));
62386238 const instruction_bytes = file.zir.?.instructions.len *
62396239 // Here we don't use @sizeOf(Zir.Inst.Data) because it would include
62406240 // the debug safety tag but we want to measure release size.
src/translate_c.zig+14-15
......@@ -2570,9 +2570,9 @@ fn transInitListExprRecord(
25702570 // Unions and Structs are both represented as RecordDecl
25712571 const record_ty = ty.getAsRecordType() orelse
25722572 blk: {
2573 is_union_type = true;
2574 break :blk ty.getAsUnionType();
2575 } orelse unreachable;
2573 is_union_type = true;
2574 break :blk ty.getAsUnionType();
2575 } orelse unreachable;
25762576 const record_decl = record_ty.getDecl();
25772577 const record_def = record_decl.getDefinition() orelse
25782578 unreachable;
......@@ -4006,7 +4006,7 @@ fn transCPtrCast(
40064006 if (!src_ty.isArrayType() and ((src_child_type.isConstQualified() and
40074007 !child_type.isConstQualified()) or
40084008 (src_child_type.isVolatileQualified() and
4009 !child_type.isVolatileQualified())))
4009 !child_type.isVolatileQualified())))
40104010 {
40114011 return removeCVQualifiers(c, dst_type_node, expr);
40124012 } else {
......@@ -4092,8 +4092,8 @@ fn transFloatingLiteralQuad(c: *Context, expr: *const clang.FloatingLiteral, use
40924092 false;
40934093 break :fmt_decimal if (could_roundtrip) try c.arena.dupe(u8, temp_str) else null;
40944094 }
4095 // otherwise, fall back to the hexadecimal format
4096 orelse try std.fmt.allocPrint(c.arena, "{x}", .{quad});
4095 // otherwise, fall back to the hexadecimal format
4096 orelse try std.fmt.allocPrint(c.arena, "{x}", .{quad});
40974097
40984098 var node = try Tag.float_literal.create(c.arena, str);
40994099 if (is_negative) node = try Tag.negate.create(c.arena, node);
......@@ -5080,15 +5080,14 @@ fn finishTransFnProto(
50805080 const is_noalias = param_qt.isRestrictQualified();
50815081
50825082 const param_name: ?[]const u8 =
5083 if (fn_decl) |decl|
5084 blk: {
5085 const param = decl.getParamDecl(@as(c_uint, @intCast(i)));
5086 const param_name: []const u8 = try c.str(@as(*const clang.NamedDecl, @ptrCast(param)).getName_bytes_begin());
5087 if (param_name.len < 1)
5088 break :blk null;
5089
5090 break :blk param_name;
5091 } else null;
5083 if (fn_decl) |decl| blk: {
5084 const param = decl.getParamDecl(@as(c_uint, @intCast(i)));
5085 const param_name: []const u8 = try c.str(@as(*const clang.NamedDecl, @ptrCast(param)).getName_bytes_begin());
5086 if (param_name.len < 1)
5087 break :blk null;
5088
5089 break :blk param_name;
5090 } else null;
50925091 const type_node = try transQualType(c, scope, param_qt, source_loc);
50935092
50945093 fn_params.addOneAssumeCapacity().* = .{
test/behavior/export_builtin.zig+2-2
......@@ -59,8 +59,8 @@ test "exporting comptime-known value" {
5959 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
6060 if (builtin.zig_backend == .stage2_x86_64 and
6161 (builtin.target.ofmt != .elf and
62 builtin.target.ofmt != .macho and
63 builtin.target.ofmt != .coff)) return error.SkipZigTest;
62 builtin.target.ofmt != .macho and
63 builtin.target.ofmt != .coff)) return error.SkipZigTest;
6464 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
6565 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
6666 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
test/link/elf.zig+70-70
......@@ -475,7 +475,7 @@ fn testCommentString(b: *Build, opts: Options) *Step {
475475 const test_step = addTestStep(b, "comment-string", opts);
476476
477477 const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes =
478 \\pub fn main() void {}
478 \\pub fn main() void {}
479479 });
480480
481481 const check = exe.checkObject();
......@@ -490,7 +490,7 @@ fn testCommentStringStaticLib(b: *Build, opts: Options) *Step {
490490 const test_step = addTestStep(b, "comment-string-static-lib", opts);
491491
492492 const lib = addStaticLibrary(b, opts, .{ .name = "lib", .zig_source_bytes =
493 \\export fn foo() void {}
493 \\export fn foo() void {}
494494 });
495495
496496 const check = lib.checkObject();
......@@ -861,23 +861,23 @@ fn testEmitRelocatable(b: *Build, opts: Options) *Step {
861861 const test_step = addTestStep(b, "emit-relocatable", opts);
862862
863863 const a_o = addObject(b, opts, .{ .name = "a", .zig_source_bytes =
864 \\const std = @import("std");
865 \\extern var bar: i32;
866 \\export fn foo() i32 {
867 \\ return bar;
868 \\}
869 \\export fn printFoo() void {
870 \\ std.debug.print("foo={d}\n", .{foo()});
871 \\}
864 \\const std = @import("std");
865 \\extern var bar: i32;
866 \\export fn foo() i32 {
867 \\ return bar;
868 \\}
869 \\export fn printFoo() void {
870 \\ std.debug.print("foo={d}\n", .{foo()});
871 \\}
872872 });
873873 a_o.linkLibC();
874874
875875 const b_o = addObject(b, opts, .{ .name = "b", .c_source_bytes =
876 \\#include <stdio.h>
877 \\int bar = 42;
878 \\void printBar() {
879 \\ fprintf(stderr, "bar=%d\n", bar);
880 \\}
876 \\#include <stdio.h>
877 \\int bar = 42;
878 \\void printBar() {
879 \\ fprintf(stderr, "bar=%d\n", bar);
880 \\}
881881 });
882882 b_o.linkLibC();
883883
......@@ -886,13 +886,13 @@ fn testEmitRelocatable(b: *Build, opts: Options) *Step {
886886 c_o.addObject(b_o);
887887
888888 const exe = addExecutable(b, opts, .{ .name = "test", .zig_source_bytes =
889 \\const std = @import("std");
890 \\extern fn printFoo() void;
891 \\extern fn printBar() void;
892 \\pub fn main() void {
893 \\ printFoo();
894 \\ printBar();
895 \\}
889 \\const std = @import("std");
890 \\extern fn printFoo() void;
891 \\extern fn printBar() void;
892 \\pub fn main() void {
893 \\ printFoo();
894 \\ printBar();
895 \\}
896896 });
897897 exe.addObject(c_o);
898898 exe.linkLibC();
......@@ -1920,8 +1920,8 @@ fn testInitArrayOrder(b: *Build, opts: Options) *Step {
19201920 g_o.linkLibC();
19211921
19221922 const h_o = addObject(b, opts, .{ .name = "h", .c_source_bytes =
1923 \\#include <stdio.h>
1924 \\__attribute__((destructor)) void fini2() { printf("8"); }
1923 \\#include <stdio.h>
1924 \\__attribute__((destructor)) void fini2() { printf("8"); }
19251925 });
19261926 h_o.linkLibC();
19271927
......@@ -2495,23 +2495,23 @@ fn testMergeStrings2(b: *Build, opts: Options) *Step {
24952495 const test_step = addTestStep(b, "merge-strings2", opts);
24962496
24972497 const obj1 = addObject(b, opts, .{ .name = "a", .zig_source_bytes =
2498 \\const std = @import("std");
2499 \\export fn foo() void {
2500 \\ var arr: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };
2501 \\ const slice = std.mem.sliceTo(&arr, 3);
2502 \\ std.testing.expectEqualSlices(u16, arr[0..2], slice) catch unreachable;
2503 \\}
2498 \\const std = @import("std");
2499 \\export fn foo() void {
2500 \\ var arr: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };
2501 \\ const slice = std.mem.sliceTo(&arr, 3);
2502 \\ std.testing.expectEqualSlices(u16, arr[0..2], slice) catch unreachable;
2503 \\}
25042504 });
25052505
25062506 const obj2 = addObject(b, opts, .{ .name = "b", .zig_source_bytes =
2507 \\const std = @import("std");
2508 \\extern fn foo() void;
2509 \\pub fn main() void {
2510 \\ foo();
2511 \\ var arr: [5:0]u16 = [_:0]u16{ 5, 4, 3, 2, 1 };
2512 \\ const slice = std.mem.sliceTo(&arr, 3);
2513 \\ std.testing.expectEqualSlices(u16, arr[0..2], slice) catch unreachable;
2514 \\}
2507 \\const std = @import("std");
2508 \\extern fn foo() void;
2509 \\pub fn main() void {
2510 \\ foo();
2511 \\ var arr: [5:0]u16 = [_:0]u16{ 5, 4, 3, 2, 1 };
2512 \\ const slice = std.mem.sliceTo(&arr, 3);
2513 \\ std.testing.expectEqualSlices(u16, arr[0..2], slice) catch unreachable;
2514 \\}
25152515 });
25162516
25172517 {
......@@ -2752,17 +2752,17 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step {
27522752 });
27532753 obj2.linkLibCpp();
27542754 const obj3 = addObject(b, opts, .{ .name = "obj3", .cpp_source_bytes =
2755 \\#include <iostream>
2756 \\#include <stdexcept>
2757 \\extern int try_again();
2758 \\int main() {
2759 \\ try {
2760 \\ try_again();
2761 \\ } catch (const std::exception &e) {
2762 \\ std::cout << "exception=" << e.what();
2763 \\ }
2764 \\ return 0;
2765 \\}
2755 \\#include <iostream>
2756 \\#include <stdexcept>
2757 \\extern int try_again();
2758 \\int main() {
2759 \\ try {
2760 \\ try_again();
2761 \\ } catch (const std::exception &e) {
2762 \\ std::cout << "exception=" << e.what();
2763 \\ }
2764 \\ return 0;
2765 \\}
27662766 });
27672767 obj3.linkLibCpp();
27682768
......@@ -2864,15 +2864,15 @@ fn testRelocatableMergeStrings(b: *Build, opts: Options) *Step {
28642864 const test_step = addTestStep(b, "relocatable-merge-strings", opts);
28652865
28662866 const obj1 = addObject(b, opts, .{ .name = "a", .asm_source_bytes =
2867 \\.section .rodata.str1.1,"aMS",@progbits,1
2868 \\val1:
2869 \\.ascii "Hello \0"
2870 \\.section .rodata.str1.1,"aMS",@progbits,1
2871 \\val5:
2872 \\.ascii "World \0"
2873 \\.section .rodata.str1.1,"aMS",@progbits,1
2874 \\val7:
2875 \\.ascii "Hello \0"
2867 \\.section .rodata.str1.1,"aMS",@progbits,1
2868 \\val1:
2869 \\.ascii "Hello \0"
2870 \\.section .rodata.str1.1,"aMS",@progbits,1
2871 \\val5:
2872 \\.ascii "World \0"
2873 \\.section .rodata.str1.1,"aMS",@progbits,1
2874 \\val7:
2875 \\.ascii "Hello \0"
28762876 });
28772877
28782878 const obj2 = addObject(b, opts, .{ .name = "b" });
......@@ -3030,18 +3030,18 @@ fn testThunks(b: *Build, opts: Options) *Step {
30303030 const test_step = addTestStep(b, "thunks", opts);
30313031
30323032 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
3033 \\void foo();
3034 \\__attribute__((section(".bar"))) void bar() {
3035 \\ return foo();
3036 \\}
3037 \\__attribute__((section(".foo"))) void foo() {
3038 \\ return bar();
3039 \\}
3040 \\int main() {
3041 \\ foo();
3042 \\ bar();
3043 \\ return 0;
3044 \\}
3033 \\void foo();
3034 \\__attribute__((section(".bar"))) void bar() {
3035 \\ return foo();
3036 \\}
3037 \\__attribute__((section(".foo"))) void foo() {
3038 \\ return bar();
3039 \\}
3040 \\int main() {
3041 \\ foo();
3042 \\ bar();
3043 \\ return 0;
3044 \\}
30453045 });
30463046
30473047 const check = exe.checkObject();
test/link/macho.zig+816-816
......@@ -109,20 +109,20 @@ fn testDeadStrip(b: *Build, opts: Options) *Step {
109109 const test_step = addTestStep(b, "dead-strip", opts);
110110
111111 const obj = addObject(b, opts, .{ .name = "a", .cpp_source_bytes =
112 \\#include <stdio.h>
113 \\int two() { return 2; }
114 \\int live_var1 = 1;
115 \\int live_var2 = two();
116 \\int dead_var1 = 3;
117 \\int dead_var2 = 4;
118 \\void live_fn1() {}
119 \\void live_fn2() { live_fn1(); }
120 \\void dead_fn1() {}
121 \\void dead_fn2() { dead_fn1(); }
122 \\int main() {
123 \\ printf("%d %d\n", live_var1, live_var2);
124 \\ live_fn2();
125 \\}
112 \\#include <stdio.h>
113 \\int two() { return 2; }
114 \\int live_var1 = 1;
115 \\int live_var2 = two();
116 \\int dead_var1 = 3;
117 \\int dead_var2 = 4;
118 \\void live_fn1() {}
119 \\void live_fn2() { live_fn1(); }
120 \\void dead_fn1() {}
121 \\void dead_fn2() { dead_fn1(); }
122 \\int main() {
123 \\ printf("%d %d\n", live_var1, live_var2);
124 \\ live_fn2();
125 \\}
126126 });
127127
128128 {
......@@ -190,21 +190,21 @@ fn testDuplicateDefinitions(b: *Build, opts: Options) *Step {
190190 const test_step = addTestStep(b, "duplicate-definitions", opts);
191191
192192 const obj = addObject(b, opts, .{ .name = "a", .zig_source_bytes =
193 \\var x: usize = 1;
194 \\export fn strong() void { x += 1; }
195 \\export fn weak() void { x += 1; }
193 \\var x: usize = 1;
194 \\export fn strong() void { x += 1; }
195 \\export fn weak() void { x += 1; }
196196 });
197197
198198 const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes =
199 \\var x: usize = 1;
200 \\export fn strong() void { x += 1; }
201 \\comptime { @export(&weakImpl, .{ .name = "weak", .linkage = .weak }); }
202 \\fn weakImpl() callconv(.C) void { x += 1; }
203 \\extern fn weak() void;
204 \\pub fn main() void {
205 \\ weak();
206 \\ strong();
207 \\}
199 \\var x: usize = 1;
200 \\export fn strong() void { x += 1; }
201 \\comptime { @export(&weakImpl, .{ .name = "weak", .linkage = .weak }); }
202 \\fn weakImpl() callconv(.C) void { x += 1; }
203 \\extern fn weak() void;
204 \\pub fn main() void {
205 \\ weak();
206 \\ strong();
207 \\}
208208 });
209209 exe.addObject(obj);
210210
......@@ -221,16 +221,16 @@ fn testDeadStripDylibs(b: *Build, opts: Options) *Step {
221221 const test_step = addTestStep(b, "dead-strip-dylibs", opts);
222222
223223 const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes =
224 \\#include <objc/runtime.h>
225 \\int main() {
226 \\ if (objc_getClass("NSObject") == 0) {
227 \\ return -1;
228 \\ }
229 \\ if (objc_getClass("NSApplication") == 0) {
230 \\ return -2;
231 \\ }
232 \\ return 0;
233 \\}
224 \\#include <objc/runtime.h>
225 \\int main() {
226 \\ if (objc_getClass("NSObject") == 0) {
227 \\ return -1;
228 \\ }
229 \\ if (objc_getClass("NSApplication") == 0) {
230 \\ return -2;
231 \\ }
232 \\ return 0;
233 \\}
234234 });
235235
236236 {
......@@ -270,11 +270,11 @@ fn testDylib(b: *Build, opts: Options) *Step {
270270 const test_step = addTestStep(b, "dylib", opts);
271271
272272 const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes =
273 \\#include<stdio.h>
274 \\char world[] = "world";
275 \\char* hello() {
276 \\ return "Hello";
277 \\}
273 \\#include<stdio.h>
274 \\char world[] = "world";
275 \\char* hello() {
276 \\ return "Hello";
277 \\}
278278 });
279279
280280 const check = dylib.checkObject();
......@@ -284,13 +284,13 @@ fn testDylib(b: *Build, opts: Options) *Step {
284284 test_step.dependOn(&check.step);
285285
286286 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
287 \\#include<stdio.h>
288 \\char* hello();
289 \\extern char world[];
290 \\int main() {
291 \\ printf("%s %s", hello(), world);
292 \\ return 0;
293 \\}
287 \\#include<stdio.h>
288 \\char* hello();
289 \\extern char world[];
290 \\int main() {
291 \\ printf("%s %s", hello(), world);
292 \\ return 0;
293 \\}
294294 });
295295 exe.root_module.linkSystemLibrary("a", .{});
296296 exe.root_module.addLibraryPath(dylib.getEmittedBinDirectory());
......@@ -345,10 +345,10 @@ fn testEmptyObject(b: *Build, opts: Options) *Step {
345345 const empty = addObject(b, opts, .{ .name = "empty", .c_source_bytes = "" });
346346
347347 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
348 \\#include <stdio.h>
349 \\int main() {
350 \\ printf("Hello world!");
351 \\}
348 \\#include <stdio.h>
349 \\int main() {
350 \\ printf("Hello world!");
351 \\}
352352 });
353353 exe.addObject(empty);
354354
......@@ -375,11 +375,11 @@ fn testEntryPoint(b: *Build, opts: Options) *Step {
375375 const test_step = addTestStep(b, "entry-point", opts);
376376
377377 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
378 \\#include<stdio.h>
379 \\int non_main() {
380 \\ printf("%d", 42);
381 \\ return 0;
382 \\}
378 \\#include<stdio.h>
379 \\int non_main() {
380 \\ printf("%d", 42);
381 \\ return 0;
382 \\}
383383 });
384384 exe.entry = .{ .symbol_name = "_non_main" };
385385
......@@ -597,10 +597,10 @@ fn testHeaderWeakFlags(b: *Build, opts: Options) *Step {
597597 const test_step = addTestStep(b, "header-weak-flags", opts);
598598
599599 const obj1 = addObject(b, opts, .{ .name = "a", .asm_source_bytes =
600 \\.globl _x
601 \\.weak_definition _x
602 \\_x:
603 \\ ret
600 \\.globl _x
601 \\.weak_definition _x
602 \\_x:
603 \\ ret
604604 });
605605
606606 const lib = addSharedLibrary(b, opts, .{ .name = "a" });
......@@ -659,11 +659,11 @@ fn testHeaderWeakFlags(b: *Build, opts: Options) *Step {
659659
660660 {
661661 const exe = addExecutable(b, opts, .{ .name = "main3", .asm_source_bytes =
662 \\.globl _main, _x
663 \\_x:
664 \\
665 \\_main:
666 \\ ret
662 \\.globl _main, _x
663 \\_x:
664 \\
665 \\_main:
666 \\ ret
667667 });
668668 exe.linkLibrary(lib);
669669
......@@ -684,11 +684,11 @@ fn testHelloC(b: *Build, opts: Options) *Step {
684684 const test_step = addTestStep(b, "hello-c", opts);
685685
686686 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
687 \\#include <stdio.h>
688 \\int main() {
689 \\ printf("Hello world!\n");
690 \\ return 0;
691 \\}
687 \\#include <stdio.h>
688 \\int main() {
689 \\ printf("Hello world!\n");
690 \\ return 0;
691 \\}
692692 });
693693
694694 const run = addRunArtifact(exe);
......@@ -708,10 +708,10 @@ fn testHelloZig(b: *Build, opts: Options) *Step {
708708 const test_step = addTestStep(b, "hello-zig", opts);
709709
710710 const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes =
711 \\const std = @import("std");
712 \\pub fn main() void {
713 \\ std.io.getStdOut().writer().print("Hello world!\n", .{}) catch unreachable;
714 \\}
711 \\const std = @import("std");
712 \\pub fn main() void {
713 \\ std.io.getStdOut().writer().print("Hello world!\n", .{}) catch unreachable;
714 \\}
715715 });
716716
717717 const run = addRunArtifact(exe);
......@@ -729,10 +729,10 @@ fn testLargeBss(b: *Build, opts: Options) *Step {
729729 // maybe S_GB_ZEROFILL section is an answer to this but it doesn't seem supported by dyld
730730 // anymore. When I get some free time I will re-investigate this.
731731 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
732 \\char arr[0x1000000];
733 \\int main() {
734 \\ return arr[2000];
735 \\}
732 \\char arr[0x1000000];
733 \\int main() {
734 \\ return arr[2000];
735 \\}
736736 });
737737
738738 const run = addRunArtifact(exe);
......@@ -746,11 +746,11 @@ fn testLayout(b: *Build, opts: Options) *Step {
746746 const test_step = addTestStep(b, "layout", opts);
747747
748748 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
749 \\#include <stdio.h>
750 \\int main() {
751 \\ printf("Hello world!");
752 \\ return 0;
753 \\}
749 \\#include <stdio.h>
750 \\int main() {
751 \\ printf("Hello world!");
752 \\ return 0;
753 \\}
754754 });
755755
756756 const check = exe.checkObject();
......@@ -936,15 +936,15 @@ fn testLinksection(b: *Build, opts: Options) *Step {
936936 const test_step = addTestStep(b, "linksection", opts);
937937
938938 const obj = addObject(b, opts, .{ .name = "main", .zig_source_bytes =
939 \\export var test_global: u32 linksection("__DATA,__TestGlobal") = undefined;
940 \\export fn testFn() linksection("__TEXT,__TestFn") callconv(.C) void {
941 \\ TestGenericFn("A").f();
942 \\}
943 \\fn TestGenericFn(comptime suffix: []const u8) type {
944 \\ return struct {
945 \\ fn f() linksection("__TEXT,__TestGenFn" ++ suffix) void {}
946 \\ };
947 \\}
939 \\export var test_global: u32 linksection("__DATA,__TestGlobal") = undefined;
940 \\export fn testFn() linksection("__TEXT,__TestFn") callconv(.C) void {
941 \\ TestGenericFn("A").f();
942 \\}
943 \\fn TestGenericFn(comptime suffix: []const u8) type {
944 \\ return struct {
945 \\ fn f() linksection("__TEXT,__TestGenFn" ++ suffix) void {}
946 \\ };
947 \\}
948948 });
949949
950950 const check = obj.checkObject();
......@@ -967,71 +967,71 @@ fn testMergeLiteralsX64(b: *Build, opts: Options) *Step {
967967 const test_step = addTestStep(b, "merge-literals-x64", opts);
968968
969969 const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes =
970 \\.globl _q1
971 \\.globl _s1
972 \\
973 \\.align 4
974 \\_q1:
975 \\ lea L._q1(%rip), %rax
976 \\ mov (%rax), %xmm0
977 \\ ret
978 \\
979 \\.section __TEXT,__cstring,cstring_literals
980 \\l._s1:
981 \\ .asciz "hello"
982 \\
983 \\.section __TEXT,__literal8,8byte_literals
984 \\.align 8
985 \\L._q1:
986 \\ .double 1.2345
987 \\
988 \\.section __DATA,__data
989 \\.align 8
990 \\_s1:
991 \\ .quad l._s1
970 \\.globl _q1
971 \\.globl _s1
972 \\
973 \\.align 4
974 \\_q1:
975 \\ lea L._q1(%rip), %rax
976 \\ mov (%rax), %xmm0
977 \\ ret
978 \\
979 \\.section __TEXT,__cstring,cstring_literals
980 \\l._s1:
981 \\ .asciz "hello"
982 \\
983 \\.section __TEXT,__literal8,8byte_literals
984 \\.align 8
985 \\L._q1:
986 \\ .double 1.2345
987 \\
988 \\.section __DATA,__data
989 \\.align 8
990 \\_s1:
991 \\ .quad l._s1
992992 });
993993
994994 const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes =
995 \\.globl _q2
996 \\.globl _s2
997 \\.globl _s3
998 \\
999 \\.align 4
1000 \\_q2:
1001 \\ lea L._q2(%rip), %rax
1002 \\ mov (%rax), %xmm0
1003 \\ ret
1004 \\
1005 \\.section __TEXT,__cstring,cstring_literals
1006 \\l._s2:
1007 \\ .asciz "hello"
1008 \\l._s3:
1009 \\ .asciz "world"
1010 \\
1011 \\.section __TEXT,__literal8,8byte_literals
1012 \\.align 8
1013 \\L._q2:
1014 \\ .double 1.2345
1015 \\
1016 \\.section __DATA,__data
1017 \\.align 8
1018 \\_s2:
1019 \\ .quad l._s2
1020 \\_s3:
1021 \\ .quad l._s3
995 \\.globl _q2
996 \\.globl _s2
997 \\.globl _s3
998 \\
999 \\.align 4
1000 \\_q2:
1001 \\ lea L._q2(%rip), %rax
1002 \\ mov (%rax), %xmm0
1003 \\ ret
1004 \\
1005 \\.section __TEXT,__cstring,cstring_literals
1006 \\l._s2:
1007 \\ .asciz "hello"
1008 \\l._s3:
1009 \\ .asciz "world"
1010 \\
1011 \\.section __TEXT,__literal8,8byte_literals
1012 \\.align 8
1013 \\L._q2:
1014 \\ .double 1.2345
1015 \\
1016 \\.section __DATA,__data
1017 \\.align 8
1018 \\_s2:
1019 \\ .quad l._s2
1020 \\_s3:
1021 \\ .quad l._s3
10221022 });
10231023
10241024 const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes =
1025 \\#include <stdio.h>
1026 \\extern double q1();
1027 \\extern double q2();
1028 \\extern const char* s1;
1029 \\extern const char* s2;
1030 \\extern const char* s3;
1031 \\int main() {
1032 \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2());
1033 \\ return 0;
1034 \\}
1025 \\#include <stdio.h>
1026 \\extern double q1();
1027 \\extern double q2();
1028 \\extern const char* s1;
1029 \\extern const char* s2;
1030 \\extern const char* s3;
1031 \\int main() {
1032 \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2());
1033 \\ return 0;
1034 \\}
10351035 });
10361036
10371037 const runWithChecks = struct {
......@@ -1083,71 +1083,71 @@ fn testMergeLiteralsArm64(b: *Build, opts: Options) *Step {
10831083 const test_step = addTestStep(b, "merge-literals-arm64", opts);
10841084
10851085 const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes =
1086 \\.globl _q1
1087 \\.globl _s1
1088 \\
1089 \\.align 4
1090 \\_q1:
1091 \\ adrp x8, L._q1@PAGE
1092 \\ ldr d0, [x8, L._q1@PAGEOFF]
1093 \\ ret
1094 \\
1095 \\.section __TEXT,__cstring,cstring_literals
1096 \\l._s1:
1097 \\ .asciz "hello"
1098 \\
1099 \\.section __TEXT,__literal8,8byte_literals
1100 \\.align 8
1101 \\L._q1:
1102 \\ .double 1.2345
1103 \\
1104 \\.section __DATA,__data
1105 \\.align 8
1106 \\_s1:
1107 \\ .quad l._s1
1086 \\.globl _q1
1087 \\.globl _s1
1088 \\
1089 \\.align 4
1090 \\_q1:
1091 \\ adrp x8, L._q1@PAGE
1092 \\ ldr d0, [x8, L._q1@PAGEOFF]
1093 \\ ret
1094 \\
1095 \\.section __TEXT,__cstring,cstring_literals
1096 \\l._s1:
1097 \\ .asciz "hello"
1098 \\
1099 \\.section __TEXT,__literal8,8byte_literals
1100 \\.align 8
1101 \\L._q1:
1102 \\ .double 1.2345
1103 \\
1104 \\.section __DATA,__data
1105 \\.align 8
1106 \\_s1:
1107 \\ .quad l._s1
11081108 });
11091109
11101110 const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes =
1111 \\.globl _q2
1112 \\.globl _s2
1113 \\.globl _s3
1114 \\
1115 \\.align 4
1116 \\_q2:
1117 \\ adrp x8, L._q2@PAGE
1118 \\ ldr d0, [x8, L._q2@PAGEOFF]
1119 \\ ret
1120 \\
1121 \\.section __TEXT,__cstring,cstring_literals
1122 \\l._s2:
1123 \\ .asciz "hello"
1124 \\l._s3:
1125 \\ .asciz "world"
1126 \\
1127 \\.section __TEXT,__literal8,8byte_literals
1128 \\.align 8
1129 \\L._q2:
1130 \\ .double 1.2345
1131 \\
1132 \\.section __DATA,__data
1133 \\.align 8
1134 \\_s2:
1135 \\ .quad l._s2
1136 \\_s3:
1137 \\ .quad l._s3
1111 \\.globl _q2
1112 \\.globl _s2
1113 \\.globl _s3
1114 \\
1115 \\.align 4
1116 \\_q2:
1117 \\ adrp x8, L._q2@PAGE
1118 \\ ldr d0, [x8, L._q2@PAGEOFF]
1119 \\ ret
1120 \\
1121 \\.section __TEXT,__cstring,cstring_literals
1122 \\l._s2:
1123 \\ .asciz "hello"
1124 \\l._s3:
1125 \\ .asciz "world"
1126 \\
1127 \\.section __TEXT,__literal8,8byte_literals
1128 \\.align 8
1129 \\L._q2:
1130 \\ .double 1.2345
1131 \\
1132 \\.section __DATA,__data
1133 \\.align 8
1134 \\_s2:
1135 \\ .quad l._s2
1136 \\_s3:
1137 \\ .quad l._s3
11381138 });
11391139
11401140 const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes =
1141 \\#include <stdio.h>
1142 \\extern double q1();
1143 \\extern double q2();
1144 \\extern const char* s1;
1145 \\extern const char* s2;
1146 \\extern const char* s3;
1147 \\int main() {
1148 \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2());
1149 \\ return 0;
1150 \\}
1141 \\#include <stdio.h>
1142 \\extern double q1();
1143 \\extern double q2();
1144 \\extern const char* s1;
1145 \\extern const char* s2;
1146 \\extern const char* s3;
1147 \\int main() {
1148 \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2());
1149 \\ return 0;
1150 \\}
11511151 });
11521152
11531153 const runWithChecks = struct {
......@@ -1203,59 +1203,59 @@ fn testMergeLiteralsArm642(b: *Build, opts: Options) *Step {
12031203 const test_step = addTestStep(b, "merge-literals-arm64-2", opts);
12041204
12051205 const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes =
1206 \\.globl _q1
1207 \\.globl _s1
1208 \\
1209 \\.align 4
1210 \\_q1:
1211 \\ adrp x0, L._q1@PAGE
1212 \\ ldr x0, [x0, L._q1@PAGEOFF]
1213 \\ ret
1214 \\
1215 \\.section __TEXT,__cstring,cstring_literals
1216 \\_s1:
1217 \\ .asciz "hello"
1218 \\
1219 \\.section __TEXT,__literal8,8byte_literals
1220 \\.align 8
1221 \\L._q1:
1222 \\ .double 1.2345
1206 \\.globl _q1
1207 \\.globl _s1
1208 \\
1209 \\.align 4
1210 \\_q1:
1211 \\ adrp x0, L._q1@PAGE
1212 \\ ldr x0, [x0, L._q1@PAGEOFF]
1213 \\ ret
1214 \\
1215 \\.section __TEXT,__cstring,cstring_literals
1216 \\_s1:
1217 \\ .asciz "hello"
1218 \\
1219 \\.section __TEXT,__literal8,8byte_literals
1220 \\.align 8
1221 \\L._q1:
1222 \\ .double 1.2345
12231223 });
12241224
12251225 const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes =
1226 \\.globl _q2
1227 \\.globl _s2
1228 \\.globl _s3
1229 \\
1230 \\.align 4
1231 \\_q2:
1232 \\ adrp x0, L._q2@PAGE
1233 \\ ldr x0, [x0, L._q2@PAGEOFF]
1234 \\ ret
1235 \\
1236 \\.section __TEXT,__cstring,cstring_literals
1237 \\_s2:
1238 \\ .asciz "hello"
1239 \\_s3:
1240 \\ .asciz "world"
1241 \\
1242 \\.section __TEXT,__literal8,8byte_literals
1243 \\.align 8
1244 \\L._q2:
1245 \\ .double 1.2345
1226 \\.globl _q2
1227 \\.globl _s2
1228 \\.globl _s3
1229 \\
1230 \\.align 4
1231 \\_q2:
1232 \\ adrp x0, L._q2@PAGE
1233 \\ ldr x0, [x0, L._q2@PAGEOFF]
1234 \\ ret
1235 \\
1236 \\.section __TEXT,__cstring,cstring_literals
1237 \\_s2:
1238 \\ .asciz "hello"
1239 \\_s3:
1240 \\ .asciz "world"
1241 \\
1242 \\.section __TEXT,__literal8,8byte_literals
1243 \\.align 8
1244 \\L._q2:
1245 \\ .double 1.2345
12461246 });
12471247
12481248 const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes =
1249 \\#include <stdio.h>
1250 \\extern double q1();
1251 \\extern double q2();
1252 \\extern const char* s1;
1253 \\extern const char* s2;
1254 \\extern const char* s3;
1255 \\int main() {
1256 \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2());
1257 \\ return 0;
1258 \\}
1249 \\#include <stdio.h>
1250 \\extern double q1();
1251 \\extern double q2();
1252 \\extern const char* s1;
1253 \\extern const char* s2;
1254 \\extern const char* s3;
1255 \\int main() {
1256 \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2());
1257 \\ return 0;
1258 \\}
12591259 });
12601260
12611261 const exe = addExecutable(b, opts, .{ .name = "main1" });
......@@ -1277,43 +1277,43 @@ fn testMergeLiteralsAlignment(b: *Build, opts: Options) *Step {
12771277 const test_step = addTestStep(b, "merge-literals-alignment", opts);
12781278
12791279 const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes =
1280 \\.globl _s1
1281 \\.globl _s2
1282 \\
1283 \\.section __TEXT,__cstring,cstring_literals
1284 \\.align 3
1285 \\_s1:
1286 \\ .asciz "str1"
1287 \\_s2:
1288 \\ .asciz "str2"
1280 \\.globl _s1
1281 \\.globl _s2
1282 \\
1283 \\.section __TEXT,__cstring,cstring_literals
1284 \\.align 3
1285 \\_s1:
1286 \\ .asciz "str1"
1287 \\_s2:
1288 \\ .asciz "str2"
12891289 });
12901290
12911291 const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes =
1292 \\.globl _s3
1293 \\.globl _s4
1294 \\
1295 \\.section __TEXT,__cstring,cstring_literals
1296 \\.align 2
1297 \\_s3:
1298 \\ .asciz "str1"
1299 \\_s4:
1300 \\ .asciz "str2"
1292 \\.globl _s3
1293 \\.globl _s4
1294 \\
1295 \\.section __TEXT,__cstring,cstring_literals
1296 \\.align 2
1297 \\_s3:
1298 \\ .asciz "str1"
1299 \\_s4:
1300 \\ .asciz "str2"
13011301 });
13021302
13031303 const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes =
1304 \\#include <assert.h>
1305 \\#include <stdint.h>
1306 \\#include <stdio.h>
1307 \\extern const char* s1;
1308 \\extern const char* s2;
1309 \\extern const char* s3;
1310 \\extern const char* s4;
1311 \\int main() {
1312 \\ assert((uintptr_t)(&s1) % 8 == 0 && s1 == s3);
1313 \\ assert((uintptr_t)(&s2) % 8 == 0 && s2 == s4);
1314 \\ printf("%s%s%s%s", &s1, &s2, &s3, &s4);
1315 \\ return 0;
1316 \\}
1304 \\#include <assert.h>
1305 \\#include <stdint.h>
1306 \\#include <stdio.h>
1307 \\extern const char* s1;
1308 \\extern const char* s2;
1309 \\extern const char* s3;
1310 \\extern const char* s4;
1311 \\int main() {
1312 \\ assert((uintptr_t)(&s1) % 8 == 0 && s1 == s3);
1313 \\ assert((uintptr_t)(&s2) % 8 == 0 && s2 == s4);
1314 \\ printf("%s%s%s%s", &s1, &s2, &s3, &s4);
1315 \\ return 0;
1316 \\}
13171317 , .c_source_flags = &.{"-Wno-format"} });
13181318
13191319 const runWithChecks = struct {
......@@ -1356,39 +1356,39 @@ fn testMergeLiteralsObjc(b: *Build, opts: Options) *Step {
13561356 const test_step = addTestStep(b, "merge-literals-objc", opts);
13571357
13581358 const main_o = addObject(b, opts, .{ .name = "main", .objc_source_bytes =
1359 \\#import <Foundation/Foundation.h>;
1360 \\
1361 \\extern void foo();
1362 \\
1363 \\int main() {
1364 \\ NSString *thing = @"aaa";
1365 \\
1366 \\ SEL sel = @selector(lowercaseString);
1367 \\ NSString *lower = (([thing respondsToSelector:sel]) ? @"YES" : @"NO");
1368 \\ NSLog (@"Responds to lowercaseString: %@", lower);
1369 \\ if ([thing respondsToSelector:sel]) //(lower == @"YES")
1370 \\ NSLog(@"lowercaseString is: %@", [thing lowercaseString]);
1371 \\
1372 \\ foo();
1373 \\}
1359 \\#import <Foundation/Foundation.h>;
1360 \\
1361 \\extern void foo();
1362 \\
1363 \\int main() {
1364 \\ NSString *thing = @"aaa";
1365 \\
1366 \\ SEL sel = @selector(lowercaseString);
1367 \\ NSString *lower = (([thing respondsToSelector:sel]) ? @"YES" : @"NO");
1368 \\ NSLog (@"Responds to lowercaseString: %@", lower);
1369 \\ if ([thing respondsToSelector:sel]) //(lower == @"YES")
1370 \\ NSLog(@"lowercaseString is: %@", [thing lowercaseString]);
1371 \\
1372 \\ foo();
1373 \\}
13741374 });
13751375
13761376 const a_o = addObject(b, opts, .{ .name = "a", .objc_source_bytes =
1377 \\#import <Foundation/Foundation.h>;
1378 \\
1379 \\void foo() {
1380 \\ NSString *thing = @"aaa";
1381 \\ SEL sel = @selector(lowercaseString);
1382 \\ NSString *lower = (([thing respondsToSelector:sel]) ? @"YES" : @"NO");
1383 \\ NSLog (@"Responds to lowercaseString in foo(): %@", lower);
1384 \\ if ([thing respondsToSelector:sel]) //(lower == @"YES")
1385 \\ NSLog(@"lowercaseString in foo() is: %@", [thing lowercaseString]);
1386 \\ SEL sel2 = @selector(uppercaseString);
1387 \\ NSString *upper = (([thing respondsToSelector:sel2]) ? @"YES" : @"NO");
1388 \\ NSLog (@"Responds to uppercaseString in foo(): %@", upper);
1389 \\ if ([thing respondsToSelector:sel2]) //(upper == @"YES")
1390 \\ NSLog(@"uppercaseString in foo() is: %@", [thing uppercaseString]);
1391 \\}
1377 \\#import <Foundation/Foundation.h>;
1378 \\
1379 \\void foo() {
1380 \\ NSString *thing = @"aaa";
1381 \\ SEL sel = @selector(lowercaseString);
1382 \\ NSString *lower = (([thing respondsToSelector:sel]) ? @"YES" : @"NO");
1383 \\ NSLog (@"Responds to lowercaseString in foo(): %@", lower);
1384 \\ if ([thing respondsToSelector:sel]) //(lower == @"YES")
1385 \\ NSLog(@"lowercaseString in foo() is: %@", [thing lowercaseString]);
1386 \\ SEL sel2 = @selector(uppercaseString);
1387 \\ NSString *upper = (([thing respondsToSelector:sel2]) ? @"YES" : @"NO");
1388 \\ NSLog (@"Responds to uppercaseString in foo(): %@", upper);
1389 \\ if ([thing respondsToSelector:sel2]) //(upper == @"YES")
1390 \\ NSLog(@"uppercaseString in foo() is: %@", [thing uppercaseString]);
1391 \\}
13921392 });
13931393
13941394 const runWithChecks = struct {
......@@ -1459,12 +1459,12 @@ fn testNoDeadStrip(b: *Build, opts: Options) *Step {
14591459 const test_step = addTestStep(b, "no-dead-strip", opts);
14601460
14611461 const exe = addExecutable(b, opts, .{ .name = "name", .c_source_bytes =
1462 \\__attribute__((used)) int bogus1 = 0;
1463 \\int bogus2 = 0;
1464 \\int foo = 42;
1465 \\int main() {
1466 \\ return foo - 42;
1467 \\}
1462 \\__attribute__((used)) int bogus1 = 0;
1463 \\int bogus2 = 0;
1464 \\int foo = 42;
1465 \\int main() {
1466 \\ return foo - 42;
1467 \\}
14681468 });
14691469 exe.link_gc_sections = true;
14701470
......@@ -1543,11 +1543,11 @@ fn testObjc(b: *Build, opts: Options) *Step {
15431543 const test_step = addTestStep(b, "objc", opts);
15441544
15451545 const lib = addStaticLibrary(b, opts, .{ .name = "a", .objc_source_bytes =
1546 \\#import <Foundation/Foundation.h>
1547 \\@interface Foo : NSObject
1548 \\@end
1549 \\@implementation Foo
1550 \\@end
1546 \\#import <Foundation/Foundation.h>
1547 \\@interface Foo : NSObject
1548 \\@end
1549 \\@implementation Foo
1550 \\@end
15511551 });
15521552
15531553 {
......@@ -1600,32 +1600,32 @@ fn testObjcpp(b: *Build, opts: Options) *Step {
16001600 };
16011601
16021602 const foo_o = addObject(b, opts, .{ .name = "foo", .objcpp_source_bytes =
1603 \\#import "Foo.h"
1604 \\@implementation Foo
1605 \\- (NSString *)name
1606 \\{
1607 \\ NSString *str = [[NSString alloc] initWithFormat:@"Zig"];
1608 \\ return str;
1609 \\}
1610 \\@end
1603 \\#import "Foo.h"
1604 \\@implementation Foo
1605 \\- (NSString *)name
1606 \\{
1607 \\ NSString *str = [[NSString alloc] initWithFormat:@"Zig"];
1608 \\ return str;
1609 \\}
1610 \\@end
16111611 });
16121612 foo_o.root_module.addIncludePath(foo_h.dirname());
16131613 foo_o.linkLibCpp();
16141614
16151615 const exe = addExecutable(b, opts, .{ .name = "main", .objcpp_source_bytes =
1616 \\#import "Foo.h"
1617 \\#import <assert.h>
1618 \\#include <iostream>
1619 \\int main(int argc, char *argv[])
1620 \\{
1621 \\ @autoreleasepool {
1622 \\ Foo *foo = [[Foo alloc] init];
1623 \\ NSString *result = [foo name];
1624 \\ std::cout << "Hello from C++ and " << [result UTF8String];
1625 \\ assert([result isEqualToString:@"Zig"]);
1626 \\ return 0;
1627 \\ }
1628 \\}
1616 \\#import "Foo.h"
1617 \\#import <assert.h>
1618 \\#include <iostream>
1619 \\int main(int argc, char *argv[])
1620 \\{
1621 \\ @autoreleasepool {
1622 \\ Foo *foo = [[Foo alloc] init];
1623 \\ NSString *result = [foo name];
1624 \\ std::cout << "Hello from C++ and " << [result UTF8String];
1625 \\ assert([result isEqualToString:@"Zig"]);
1626 \\ return 0;
1627 \\ }
1628 \\}
16291629 });
16301630 exe.root_module.addIncludePath(foo_h.dirname());
16311631 exe.addObject(foo_o);
......@@ -1677,21 +1677,21 @@ fn testReexportsZig(b: *Build, opts: Options) *Step {
16771677 const test_step = addTestStep(b, "reexports-zig", opts);
16781678
16791679 const lib = addStaticLibrary(b, opts, .{ .name = "a", .zig_source_bytes =
1680 \\const x: i32 = 42;
1681 \\export fn foo() i32 {
1682 \\ return x;
1683 \\}
1684 \\comptime {
1685 \\ @export(&foo, .{ .name = "bar", .linkage = .strong });
1686 \\}
1680 \\const x: i32 = 42;
1681 \\export fn foo() i32 {
1682 \\ return x;
1683 \\}
1684 \\comptime {
1685 \\ @export(&foo, .{ .name = "bar", .linkage = .strong });
1686 \\}
16871687 });
16881688
16891689 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
1690 \\extern int foo();
1691 \\extern int bar();
1692 \\int main() {
1693 \\ return bar() - foo();
1694 \\}
1690 \\extern int foo();
1691 \\extern int bar();
1692 \\int main() {
1693 \\ return bar() - foo();
1694 \\}
16951695 });
16961696 exe.linkLibrary(lib);
16971697
......@@ -1706,32 +1706,32 @@ fn testRelocatable(b: *Build, opts: Options) *Step {
17061706 const test_step = addTestStep(b, "relocatable", opts);
17071707
17081708 const a_o = addObject(b, opts, .{ .name = "a", .cpp_source_bytes =
1709 \\#include <stdexcept>
1710 \\int try_me() {
1711 \\ throw std::runtime_error("Oh no!");
1712 \\}
1709 \\#include <stdexcept>
1710 \\int try_me() {
1711 \\ throw std::runtime_error("Oh no!");
1712 \\}
17131713 });
17141714 a_o.linkLibCpp();
17151715
17161716 const b_o = addObject(b, opts, .{ .name = "b", .cpp_source_bytes =
1717 \\extern int try_me();
1718 \\int try_again() {
1719 \\ return try_me();
1720 \\}
1717 \\extern int try_me();
1718 \\int try_again() {
1719 \\ return try_me();
1720 \\}
17211721 });
17221722
17231723 const main_o = addObject(b, opts, .{ .name = "main", .cpp_source_bytes =
1724 \\#include <iostream>
1725 \\#include <stdexcept>
1726 \\extern int try_again();
1727 \\int main() {
1728 \\ try {
1729 \\ try_again();
1730 \\ } catch (const std::exception &e) {
1731 \\ std::cout << "exception=" << e.what();
1732 \\ }
1733 \\ return 0;
1734 \\}
1724 \\#include <iostream>
1725 \\#include <stdexcept>
1726 \\extern int try_again();
1727 \\int main() {
1728 \\ try {
1729 \\ try_again();
1730 \\ } catch (const std::exception &e) {
1731 \\ std::cout << "exception=" << e.what();
1732 \\ }
1733 \\ return 0;
1734 \\}
17351735 });
17361736 main_o.linkLibCpp();
17371737
......@@ -1774,34 +1774,34 @@ fn testRelocatableZig(b: *Build, opts: Options) *Step {
17741774 const test_step = addTestStep(b, "relocatable-zig", opts);
17751775
17761776 const a_o = addObject(b, opts, .{ .name = "a", .zig_source_bytes =
1777 \\const std = @import("std");
1778 \\export var foo: i32 = 0;
1779 \\export fn incrFoo() void {
1780 \\ foo += 1;
1781 \\ std.debug.print("incrFoo={d}\n", .{foo});
1782 \\}
1777 \\const std = @import("std");
1778 \\export var foo: i32 = 0;
1779 \\export fn incrFoo() void {
1780 \\ foo += 1;
1781 \\ std.debug.print("incrFoo={d}\n", .{foo});
1782 \\}
17831783 });
17841784
17851785 const b_o = addObject(b, opts, .{ .name = "b", .zig_source_bytes =
1786 \\const std = @import("std");
1787 \\extern var foo: i32;
1788 \\export fn decrFoo() void {
1789 \\ foo -= 1;
1790 \\ std.debug.print("decrFoo={d}\n", .{foo});
1791 \\}
1786 \\const std = @import("std");
1787 \\extern var foo: i32;
1788 \\export fn decrFoo() void {
1789 \\ foo -= 1;
1790 \\ std.debug.print("decrFoo={d}\n", .{foo});
1791 \\}
17921792 });
17931793
17941794 const main_o = addObject(b, opts, .{ .name = "main", .zig_source_bytes =
1795 \\const std = @import("std");
1796 \\extern var foo: i32;
1797 \\extern fn incrFoo() void;
1798 \\extern fn decrFoo() void;
1799 \\pub fn main() void {
1800 \\ const init = foo;
1801 \\ incrFoo();
1802 \\ decrFoo();
1803 \\ if (init == foo) @panic("Oh no!");
1804 \\}
1795 \\const std = @import("std");
1796 \\extern var foo: i32;
1797 \\extern fn incrFoo() void;
1798 \\extern fn decrFoo() void;
1799 \\pub fn main() void {
1800 \\ const init = foo;
1801 \\ incrFoo();
1802 \\ decrFoo();
1803 \\ if (init == foo) @panic("Oh no!");
1804 \\}
18051805 });
18061806
18071807 const c_o = addObject(b, opts, .{ .name = "c" });
......@@ -1825,11 +1825,11 @@ fn testSearchStrategy(b: *Build, opts: Options) *Step {
18251825 const test_step = addTestStep(b, "search-strategy", opts);
18261826
18271827 const obj = addObject(b, opts, .{ .name = "a", .c_source_bytes =
1828 \\#include<stdio.h>
1829 \\char world[] = "world";
1830 \\char* hello() {
1831 \\ return "Hello";
1832 \\}
1828 \\#include<stdio.h>
1829 \\char world[] = "world";
1830 \\char* hello() {
1831 \\ return "Hello";
1832 \\}
18331833 });
18341834
18351835 const liba = addStaticLibrary(b, opts, .{ .name = "a" });
......@@ -1839,13 +1839,13 @@ fn testSearchStrategy(b: *Build, opts: Options) *Step {
18391839 dylib.addObject(obj);
18401840
18411841 const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes =
1842 \\#include<stdio.h>
1843 \\char* hello();
1844 \\extern char world[];
1845 \\int main() {
1846 \\ printf("%s %s", hello(), world);
1847 \\ return 0;
1848 \\}
1842 \\#include<stdio.h>
1843 \\char* hello();
1844 \\extern char world[];
1845 \\int main() {
1846 \\ printf("%s %s", hello(), world);
1847 \\ return 0;
1848 \\}
18491849 });
18501850
18511851 {
......@@ -1973,23 +1973,23 @@ fn testSectionBoundarySymbols2(b: *Build, opts: Options) *Step {
19731973 const test_step = addTestStep(b, "section-boundary-symbols-2", opts);
19741974
19751975 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
1976 \\#include <stdio.h>
1977 \\struct pair { int a; int b; };
1978 \\struct pair first __attribute__((section("__DATA,__pairs"))) = { 1, 2 };
1979 \\struct pair second __attribute__((section("__DATA,__pairs"))) = { 3, 4 };
1980 \\extern struct pair pairs_start __asm("section$start$__DATA$__pairs");
1981 \\extern struct pair pairs_end __asm("section$end$__DATA$__pairs");
1982 \\int main() {
1983 \\ printf("%d,%d\n", first.a, first.b);
1984 \\ printf("%d,%d\n", second.a, second.b);
1985 \\ struct pair* p;
1986 \\ for (p = &pairs_start; p < &pairs_end; p++) {
1987 \\ p->a = 0;
1988 \\ }
1989 \\ printf("%d,%d\n", first.a, first.b);
1990 \\ printf("%d,%d\n", second.a, second.b);
1991 \\ return 0;
1992 \\}
1976 \\#include <stdio.h>
1977 \\struct pair { int a; int b; };
1978 \\struct pair first __attribute__((section("__DATA,__pairs"))) = { 1, 2 };
1979 \\struct pair second __attribute__((section("__DATA,__pairs"))) = { 3, 4 };
1980 \\extern struct pair pairs_start __asm("section$start$__DATA$__pairs");
1981 \\extern struct pair pairs_end __asm("section$end$__DATA$__pairs");
1982 \\int main() {
1983 \\ printf("%d,%d\n", first.a, first.b);
1984 \\ printf("%d,%d\n", second.a, second.b);
1985 \\ struct pair* p;
1986 \\ for (p = &pairs_start; p < &pairs_end; p++) {
1987 \\ p->a = 0;
1988 \\ }
1989 \\ printf("%d,%d\n", first.a, first.b);
1990 \\ printf("%d,%d\n", second.a, second.b);
1991 \\ return 0;
1992 \\}
19931993 });
19941994
19951995 const run = b.addRunArtifact(exe);
......@@ -2010,24 +2010,24 @@ fn testSegmentBoundarySymbols(b: *Build, opts: Options) *Step {
20102010 const test_step = addTestStep(b, "segment-boundary-symbols", opts);
20112011
20122012 const obj1 = addObject(b, opts, .{ .name = "a", .cpp_source_bytes =
2013 \\constexpr const char* MESSAGE __attribute__((used, section("__DATA_CONST_1,__message_ptr"))) = "codebase";
2013 \\constexpr const char* MESSAGE __attribute__((used, section("__DATA_CONST_1,__message_ptr"))) = "codebase";
20142014 });
20152015
20162016 const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes =
2017 \\#include <stdio.h>
2018 \\const char* interop();
2019 \\int main() {
2020 \\ printf("All your %s are belong to us.\n", interop());
2021 \\ return 0;
2022 \\}
2017 \\#include <stdio.h>
2018 \\const char* interop();
2019 \\int main() {
2020 \\ printf("All your %s are belong to us.\n", interop());
2021 \\ return 0;
2022 \\}
20232023 });
20242024
20252025 {
20262026 const obj2 = addObject(b, opts, .{ .name = "b", .cpp_source_bytes =
2027 \\extern const char* message_pointer __asm("segment$start$__DATA_CONST_1");
2028 \\extern "C" const char* interop() {
2029 \\ return message_pointer;
2030 \\}
2027 \\extern const char* message_pointer __asm("segment$start$__DATA_CONST_1");
2028 \\extern "C" const char* interop() {
2029 \\ return message_pointer;
2030 \\}
20312031 });
20322032
20332033 const exe = addExecutable(b, opts, .{ .name = "main" });
......@@ -2047,10 +2047,10 @@ fn testSegmentBoundarySymbols(b: *Build, opts: Options) *Step {
20472047
20482048 {
20492049 const obj2 = addObject(b, opts, .{ .name = "c", .cpp_source_bytes =
2050 \\extern const char* message_pointer __asm("segment$start$__DATA_1");
2051 \\extern "C" const char* interop() {
2052 \\ return message_pointer;
2053 \\}
2050 \\extern const char* message_pointer __asm("segment$start$__DATA_1");
2051 \\extern "C" const char* interop() {
2052 \\ return message_pointer;
2053 \\}
20542054 });
20552055
20562056 const exe = addExecutable(b, opts, .{ .name = "main2" });
......@@ -2078,27 +2078,27 @@ fn testSymbolStabs(b: *Build, opts: Options) *Step {
20782078 const test_step = addTestStep(b, "symbol-stabs", opts);
20792079
20802080 const a_o = addObject(b, opts, .{ .name = "a", .c_source_bytes =
2081 \\int foo = 42;
2082 \\int getFoo() {
2083 \\ return foo;
2084 \\}
2081 \\int foo = 42;
2082 \\int getFoo() {
2083 \\ return foo;
2084 \\}
20852085 });
20862086
20872087 const b_o = addObject(b, opts, .{ .name = "b", .c_source_bytes =
2088 \\int bar = 24;
2089 \\int getBar() {
2090 \\ return bar;
2091 \\}
2088 \\int bar = 24;
2089 \\int getBar() {
2090 \\ return bar;
2091 \\}
20922092 });
20932093
20942094 const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes =
2095 \\#include <stdio.h>
2096 \\extern int getFoo();
2097 \\extern int getBar();
2098 \\int main() {
2099 \\ printf("foo=%d,bar=%d", getFoo(), getBar());
2100 \\ return 0;
2101 \\}
2095 \\#include <stdio.h>
2096 \\extern int getFoo();
2097 \\extern int getBar();
2098 \\int main() {
2099 \\ printf("foo=%d,bar=%d", getFoo(), getBar());
2100 \\ return 0;
2101 \\}
21022102 });
21032103
21042104 const exe = addExecutable(b, opts, .{ .name = "main" });
......@@ -2162,11 +2162,11 @@ fn testTbdv3(b: *Build, opts: Options) *Step {
21622162 };
21632163
21642164 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
2165 \\#include <stdio.h>
2166 \\int getFoo();
2167 \\int main() {
2168 \\ return getFoo() - 42;
2169 \\}
2165 \\#include <stdio.h>
2166 \\int getFoo();
2167 \\int main() {
2168 \\ return getFoo() - 42;
2169 \\}
21702170 });
21712171 exe.root_module.linkSystemLibrary("a", .{});
21722172 exe.root_module.addLibraryPath(tbd.dirname());
......@@ -2209,18 +2209,18 @@ fn testThunks(b: *Build, opts: Options) *Step {
22092209 const test_step = addTestStep(b, "thunks", opts);
22102210
22112211 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
2212 \\#include <stdio.h>
2213 \\void bar() {
2214 \\ printf("bar");
2215 \\}
2216 \\void foo() {
2217 \\ fprintf(stdout, "foo");
2218 \\}
2219 \\int main() {
2220 \\ foo();
2221 \\ bar();
2222 \\ return 0;
2223 \\}
2212 \\#include <stdio.h>
2213 \\void bar() {
2214 \\ printf("bar");
2215 \\}
2216 \\void foo() {
2217 \\ fprintf(stdout, "foo");
2218 \\}
2219 \\int main() {
2220 \\ foo();
2221 \\ bar();
2222 \\ return 0;
2223 \\}
22242224 });
22252225
22262226 const check = exe.checkObject();
......@@ -2241,24 +2241,24 @@ fn testTls(b: *Build, opts: Options) *Step {
22412241 const test_step = addTestStep(b, "tls", opts);
22422242
22432243 const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes =
2244 \\_Thread_local int a;
2245 \\int getA() {
2246 \\ return a;
2247 \\}
2244 \\_Thread_local int a;
2245 \\int getA() {
2246 \\ return a;
2247 \\}
22482248 });
22492249
22502250 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
2251 \\#include<stdio.h>
2252 \\extern _Thread_local int a;
2253 \\extern int getA();
2254 \\int getA2() {
2255 \\ return a;
2256 \\}
2257 \\int main() {
2258 \\ a = 2;
2259 \\ printf("%d %d %d", a, getA(), getA2());
2260 \\ return 0;
2261 \\}
2251 \\#include<stdio.h>
2252 \\extern _Thread_local int a;
2253 \\extern int getA();
2254 \\int getA2() {
2255 \\ return a;
2256 \\}
2257 \\int main() {
2258 \\ a = 2;
2259 \\ printf("%d %d %d", a, getA(), getA2());
2260 \\ return 0;
2261 \\}
22622262 });
22632263 exe.root_module.linkSystemLibrary("a", .{});
22642264 exe.root_module.addLibraryPath(dylib.getEmittedBinDirectory());
......@@ -2292,33 +2292,33 @@ fn testTlsPointers(b: *Build, opts: Options) *Step {
22922292 };
22932293
22942294 const bar_o = addObject(b, opts, .{ .name = "bar", .cpp_source_bytes =
2295 \\#include "foo.h"
2296 \\int bar() {
2297 \\ int v1 = Foo<int>::getVar();
2298 \\ return v1;
2299 \\}
2295 \\#include "foo.h"
2296 \\int bar() {
2297 \\ int v1 = Foo<int>::getVar();
2298 \\ return v1;
2299 \\}
23002300 });
23012301 bar_o.root_module.addIncludePath(foo_h.dirname());
23022302 bar_o.linkLibCpp();
23032303
23042304 const baz_o = addObject(b, opts, .{ .name = "baz", .cpp_source_bytes =
2305 \\#include "foo.h"
2306 \\int baz() {
2307 \\ int v1 = Foo<unsigned>::getVar();
2308 \\ return v1;
2309 \\}
2305 \\#include "foo.h"
2306 \\int baz() {
2307 \\ int v1 = Foo<unsigned>::getVar();
2308 \\ return v1;
2309 \\}
23102310 });
23112311 baz_o.root_module.addIncludePath(foo_h.dirname());
23122312 baz_o.linkLibCpp();
23132313
23142314 const main_o = addObject(b, opts, .{ .name = "main", .cpp_source_bytes =
2315 \\extern int bar();
2316 \\extern int baz();
2317 \\int main() {
2318 \\ int v1 = bar();
2319 \\ int v2 = baz();
2320 \\ return v1 != v2;
2321 \\}
2315 \\extern int bar();
2316 \\extern int baz();
2317 \\int main() {
2318 \\ int v1 = bar();
2319 \\ int v2 = baz();
2320 \\ return v1 != v2;
2321 \\}
23222322 });
23232323 main_o.root_module.addIncludePath(foo_h.dirname());
23242324 main_o.linkLibCpp();
......@@ -2340,14 +2340,14 @@ fn testTlsLargeTbss(b: *Build, opts: Options) *Step {
23402340 const test_step = addTestStep(b, "tls-large-tbss", opts);
23412341
23422342 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
2343 \\#include <stdio.h>
2344 \\_Thread_local int x[0x8000];
2345 \\_Thread_local int y[0x8000];
2346 \\int main() {
2347 \\ x[0] = 3;
2348 \\ x[0x7fff] = 5;
2349 \\ printf("%d %d %d %d %d %d\n", x[0], x[1], x[0x7fff], y[0], y[1], y[0x7fff]);
2350 \\}
2343 \\#include <stdio.h>
2344 \\_Thread_local int x[0x8000];
2345 \\_Thread_local int y[0x8000];
2346 \\int main() {
2347 \\ x[0] = 3;
2348 \\ x[0x7fff] = 5;
2349 \\ printf("%d %d %d %d %d %d\n", x[0], x[1], x[0x7fff], y[0], y[1], y[0x7fff]);
2350 \\}
23512351 });
23522352
23532353 const run = addRunArtifact(exe);
......@@ -2361,15 +2361,15 @@ fn testTlsZig(b: *Build, opts: Options) *Step {
23612361 const test_step = addTestStep(b, "tls-zig", opts);
23622362
23632363 const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes =
2364 \\const std = @import("std");
2365 \\threadlocal var x: i32 = 0;
2366 \\threadlocal var y: i32 = -1;
2367 \\pub fn main() void {
2368 \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable;
2369 \\ x -= 1;
2370 \\ y += 1;
2371 \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable;
2372 \\}
2364 \\const std = @import("std");
2365 \\threadlocal var x: i32 = 0;
2366 \\threadlocal var y: i32 = -1;
2367 \\pub fn main() void {
2368 \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable;
2369 \\ x -= 1;
2370 \\ y += 1;
2371 \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable;
2372 \\}
23732373 });
23742374
23752375 const run = addRunArtifact(exe);
......@@ -2387,15 +2387,15 @@ fn testTwoLevelNamespace(b: *Build, opts: Options) *Step {
23872387 const test_step = addTestStep(b, "two-level-namespace", opts);
23882388
23892389 const liba = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes =
2390 \\#include <stdio.h>
2391 \\int foo = 1;
2392 \\int* ptr_to_foo = &foo;
2393 \\int getFoo() {
2394 \\ return foo;
2395 \\}
2396 \\void printInA() {
2397 \\ printf("liba: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo);
2398 \\}
2390 \\#include <stdio.h>
2391 \\int foo = 1;
2392 \\int* ptr_to_foo = &foo;
2393 \\int getFoo() {
2394 \\ return foo;
2395 \\}
2396 \\void printInA() {
2397 \\ printf("liba: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo);
2398 \\}
23992399 });
24002400
24012401 {
......@@ -2408,15 +2408,15 @@ fn testTwoLevelNamespace(b: *Build, opts: Options) *Step {
24082408 }
24092409
24102410 const libb = addSharedLibrary(b, opts, .{ .name = "b", .c_source_bytes =
2411 \\#include <stdio.h>
2412 \\int foo = 2;
2413 \\int* ptr_to_foo = &foo;
2414 \\int getFoo() {
2415 \\ return foo;
2416 \\}
2417 \\void printInB() {
2418 \\ printf("libb: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo);
2419 \\}
2411 \\#include <stdio.h>
2412 \\int foo = 2;
2413 \\int* ptr_to_foo = &foo;
2414 \\int getFoo() {
2415 \\ return foo;
2416 \\}
2417 \\void printInB() {
2418 \\ printf("libb: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo);
2419 \\}
24202420 });
24212421
24222422 {
......@@ -2429,17 +2429,17 @@ fn testTwoLevelNamespace(b: *Build, opts: Options) *Step {
24292429 }
24302430
24312431 const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes =
2432 \\#include <stdio.h>
2433 \\int getFoo();
2434 \\extern int* ptr_to_foo;
2435 \\void printInA();
2436 \\void printInB();
2437 \\int main() {
2438 \\ printf("main: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo);
2439 \\ printInA();
2440 \\ printInB();
2441 \\ return 0;
2442 \\}
2432 \\#include <stdio.h>
2433 \\int getFoo();
2434 \\extern int* ptr_to_foo;
2435 \\void printInA();
2436 \\void printInB();
2437 \\int main() {
2438 \\ printf("main: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo);
2439 \\ printInA();
2440 \\ printInB();
2441 \\ return 0;
2442 \\}
24432443 });
24442444
24452445 {
......@@ -2629,17 +2629,17 @@ fn testUnresolvedError(b: *Build, opts: Options) *Step {
26292629 const test_step = addTestStep(b, "unresolved-error", opts);
26302630
26312631 const obj = addObject(b, opts, .{ .name = "a", .zig_source_bytes =
2632 \\extern fn foo() i32;
2633 \\export fn bar() i32 { return foo() + 1; }
2632 \\extern fn foo() i32;
2633 \\export fn bar() i32 { return foo() + 1; }
26342634 });
26352635
26362636 const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes =
2637 \\const std = @import("std");
2638 \\extern fn foo() i32;
2639 \\extern fn bar() i32;
2640 \\pub fn main() void {
2641 \\ std.debug.print("foo() + bar() = {d}", .{foo() + bar()});
2642 \\}
2637 \\const std = @import("std");
2638 \\extern fn foo() i32;
2639 \\extern fn bar() i32;
2640 \\pub fn main() void {
2641 \\ std.debug.print("foo() + bar() = {d}", .{foo() + bar()});
2642 \\}
26432643 });
26442644 exe.addObject(obj);
26452645
......@@ -2665,17 +2665,17 @@ fn testUnresolvedError2(b: *Build, opts: Options) *Step {
26652665 const test_step = addTestStep(b, "unresolved-error-2", opts);
26662666
26672667 const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes =
2668 \\pub fn main() !void {
2669 \\ const msg_send_fn = @extern(
2670 \\ *const fn () callconv(.C) usize,
2671 \\ .{ .name = "objc_msgSend$initWithContentRect:styleMask:backing:defer:screen:" },
2672 \\ );
2673 \\ _ = @call(
2674 \\ .auto,
2675 \\ msg_send_fn,
2676 \\ .{},
2677 \\ );
2678 \\}
2668 \\pub fn main() !void {
2669 \\ const msg_send_fn = @extern(
2670 \\ *const fn () callconv(.C) usize,
2671 \\ .{ .name = "objc_msgSend$initWithContentRect:styleMask:backing:defer:screen:" },
2672 \\ );
2673 \\ _ = @call(
2674 \\ .auto,
2675 \\ msg_send_fn,
2676 \\ .{},
2677 \\ );
2678 \\}
26792679 });
26802680
26812681 expectLinkErrors(exe, test_step, .{ .exact = &.{
......@@ -2737,82 +2737,82 @@ fn testUnwindInfo(b: *Build, opts: Options) *Step {
27372737 };
27382738
27392739 const main_o = addObject(b, opts, .{ .name = "main", .cpp_source_bytes =
2740 \\#include "all.h"
2741 \\#include <cstdio>
2742 \\
2743 \\void fn_c() {
2744 \\ SimpleStringOwner c{ "cccccccccc" };
2745 \\}
2746 \\
2747 \\void fn_b() {
2748 \\ SimpleStringOwner b{ "b" };
2749 \\ fn_c();
2750 \\}
2751 \\
2752 \\int main() {
2753 \\ try {
2754 \\ SimpleStringOwner a{ "a" };
2755 \\ fn_b();
2756 \\ SimpleStringOwner d{ "d" };
2757 \\ } catch (const Error& e) {
2758 \\ printf("Error: %s\n", e.what());
2759 \\ } catch(const std::exception& e) {
2760 \\ printf("Exception: %s\n", e.what());
2761 \\ }
2762 \\ return 0;
2763 \\}
2740 \\#include "all.h"
2741 \\#include <cstdio>
2742 \\
2743 \\void fn_c() {
2744 \\ SimpleStringOwner c{ "cccccccccc" };
2745 \\}
2746 \\
2747 \\void fn_b() {
2748 \\ SimpleStringOwner b{ "b" };
2749 \\ fn_c();
2750 \\}
2751 \\
2752 \\int main() {
2753 \\ try {
2754 \\ SimpleStringOwner a{ "a" };
2755 \\ fn_b();
2756 \\ SimpleStringOwner d{ "d" };
2757 \\ } catch (const Error& e) {
2758 \\ printf("Error: %s\n", e.what());
2759 \\ } catch(const std::exception& e) {
2760 \\ printf("Exception: %s\n", e.what());
2761 \\ }
2762 \\ return 0;
2763 \\}
27642764 });
27652765 main_o.root_module.addIncludePath(all_h.dirname());
27662766 main_o.linkLibCpp();
27672767
27682768 const simple_string_o = addObject(b, opts, .{ .name = "simple_string", .cpp_source_bytes =
2769 \\#include "all.h"
2770 \\#include <cstdio>
2771 \\#include <cstring>
2772 \\
2773 \\SimpleString::SimpleString(size_t max_size)
2774 \\: max_size{ max_size }, length{} {
2775 \\ if (max_size == 0) {
2776 \\ throw Error{ "Max size must be at least 1." };
2777 \\ }
2778 \\ buffer = new char[max_size];
2779 \\ buffer[0] = 0;
2780 \\}
2781 \\
2782 \\SimpleString::~SimpleString() {
2783 \\ delete[] buffer;
2784 \\}
2785 \\
2786 \\void SimpleString::print(const char* tag) const {
2787 \\ printf("%s: %s", tag, buffer);
2788 \\}
2789 \\
2790 \\bool SimpleString::append_line(const char* x) {
2791 \\ const auto x_len = strlen(x);
2792 \\ if (x_len + length + 2 > max_size) return false;
2793 \\ std::strncpy(buffer + length, x, max_size - length);
2794 \\ length += x_len;
2795 \\ buffer[length++] = '\n';
2796 \\ buffer[length] = 0;
2797 \\ return true;
2798 \\}
2769 \\#include "all.h"
2770 \\#include <cstdio>
2771 \\#include <cstring>
2772 \\
2773 \\SimpleString::SimpleString(size_t max_size)
2774 \\: max_size{ max_size }, length{} {
2775 \\ if (max_size == 0) {
2776 \\ throw Error{ "Max size must be at least 1." };
2777 \\ }
2778 \\ buffer = new char[max_size];
2779 \\ buffer[0] = 0;
2780 \\}
2781 \\
2782 \\SimpleString::~SimpleString() {
2783 \\ delete[] buffer;
2784 \\}
2785 \\
2786 \\void SimpleString::print(const char* tag) const {
2787 \\ printf("%s: %s", tag, buffer);
2788 \\}
2789 \\
2790 \\bool SimpleString::append_line(const char* x) {
2791 \\ const auto x_len = strlen(x);
2792 \\ if (x_len + length + 2 > max_size) return false;
2793 \\ std::strncpy(buffer + length, x, max_size - length);
2794 \\ length += x_len;
2795 \\ buffer[length++] = '\n';
2796 \\ buffer[length] = 0;
2797 \\ return true;
2798 \\}
27992799 });
28002800 simple_string_o.root_module.addIncludePath(all_h.dirname());
28012801 simple_string_o.linkLibCpp();
28022802
28032803 const simple_string_owner_o = addObject(b, opts, .{ .name = "simple_string_owner", .cpp_source_bytes =
2804 \\#include "all.h"
2805 \\
2806 \\SimpleStringOwner::SimpleStringOwner(const char* x) : string{ 10 } {
2807 \\ if (!string.append_line(x)) {
2808 \\ throw Error{ "Not enough memory!" };
2809 \\ }
2810 \\ string.print("Constructed");
2811 \\}
2812 \\
2813 \\SimpleStringOwner::~SimpleStringOwner() {
2814 \\ string.print("About to destroy");
2815 \\}
2804 \\#include "all.h"
2805 \\
2806 \\SimpleStringOwner::SimpleStringOwner(const char* x) : string{ 10 } {
2807 \\ if (!string.append_line(x)) {
2808 \\ throw Error{ "Not enough memory!" };
2809 \\ }
2810 \\ string.print("Constructed");
2811 \\}
2812 \\
2813 \\SimpleStringOwner::~SimpleStringOwner() {
2814 \\ string.print("About to destroy");
2815 \\}
28162816 });
28172817 simple_string_owner_o.root_module.addIncludePath(all_h.dirname());
28182818 simple_string_owner_o.linkLibCpp();
......@@ -2848,52 +2848,52 @@ fn testUnwindInfoNoSubsectionsArm64(b: *Build, opts: Options) *Step {
28482848 const test_step = addTestStep(b, "unwind-info-no-subsections-arm64", opts);
28492849
28502850 const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes =
2851 \\.globl _foo
2852 \\.align 4
2853 \\_foo:
2854 \\ .cfi_startproc
2855 \\ stp x29, x30, [sp, #-32]!
2856 \\ .cfi_def_cfa_offset 32
2857 \\ .cfi_offset w30, -24
2858 \\ .cfi_offset w29, -32
2859 \\ mov x29, sp
2860 \\ .cfi_def_cfa w29, 32
2861 \\ bl _bar
2862 \\ ldp x29, x30, [sp], #32
2863 \\ .cfi_restore w29
2864 \\ .cfi_restore w30
2865 \\ .cfi_def_cfa_offset 0
2866 \\ ret
2867 \\ .cfi_endproc
2868 \\
2869 \\.globl _bar
2870 \\.align 4
2871 \\_bar:
2872 \\ .cfi_startproc
2873 \\ sub sp, sp, #32
2874 \\ .cfi_def_cfa_offset -32
2875 \\ stp x29, x30, [sp, #16]
2876 \\ .cfi_offset w30, -24
2877 \\ .cfi_offset w29, -32
2878 \\ mov x29, sp
2879 \\ .cfi_def_cfa w29, 32
2880 \\ mov w0, #4
2881 \\ ldp x29, x30, [sp, #16]
2882 \\ .cfi_restore w29
2883 \\ .cfi_restore w30
2884 \\ add sp, sp, #32
2885 \\ .cfi_def_cfa_offset 0
2886 \\ ret
2887 \\ .cfi_endproc
2851 \\.globl _foo
2852 \\.align 4
2853 \\_foo:
2854 \\ .cfi_startproc
2855 \\ stp x29, x30, [sp, #-32]!
2856 \\ .cfi_def_cfa_offset 32
2857 \\ .cfi_offset w30, -24
2858 \\ .cfi_offset w29, -32
2859 \\ mov x29, sp
2860 \\ .cfi_def_cfa w29, 32
2861 \\ bl _bar
2862 \\ ldp x29, x30, [sp], #32
2863 \\ .cfi_restore w29
2864 \\ .cfi_restore w30
2865 \\ .cfi_def_cfa_offset 0
2866 \\ ret
2867 \\ .cfi_endproc
2868 \\
2869 \\.globl _bar
2870 \\.align 4
2871 \\_bar:
2872 \\ .cfi_startproc
2873 \\ sub sp, sp, #32
2874 \\ .cfi_def_cfa_offset -32
2875 \\ stp x29, x30, [sp, #16]
2876 \\ .cfi_offset w30, -24
2877 \\ .cfi_offset w29, -32
2878 \\ mov x29, sp
2879 \\ .cfi_def_cfa w29, 32
2880 \\ mov w0, #4
2881 \\ ldp x29, x30, [sp, #16]
2882 \\ .cfi_restore w29
2883 \\ .cfi_restore w30
2884 \\ add sp, sp, #32
2885 \\ .cfi_def_cfa_offset 0
2886 \\ ret
2887 \\ .cfi_endproc
28882888 });
28892889
28902890 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
2891 \\#include <stdio.h>
2892 \\int foo();
2893 \\int main() {
2894 \\ printf("%d\n", foo());
2895 \\ return 0;
2896 \\}
2891 \\#include <stdio.h>
2892 \\int foo();
2893 \\int main() {
2894 \\ printf("%d\n", foo());
2895 \\ return 0;
2896 \\}
28972897 });
28982898 exe.addObject(a_o);
28992899
......@@ -2908,44 +2908,44 @@ fn testUnwindInfoNoSubsectionsX64(b: *Build, opts: Options) *Step {
29082908 const test_step = addTestStep(b, "unwind-info-no-subsections-x64", opts);
29092909
29102910 const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes =
2911 \\.globl _foo
2912 \\_foo:
2913 \\ .cfi_startproc
2914 \\ push %rbp
2915 \\ .cfi_def_cfa_offset 8
2916 \\ .cfi_offset %rbp, -8
2917 \\ mov %rsp, %rbp
2918 \\ .cfi_def_cfa_register %rbp
2919 \\ call _bar
2920 \\ pop %rbp
2921 \\ .cfi_restore %rbp
2922 \\ .cfi_def_cfa_offset 0
2923 \\ ret
2924 \\ .cfi_endproc
2925 \\
2926 \\.globl _bar
2927 \\_bar:
2928 \\ .cfi_startproc
2929 \\ push %rbp
2930 \\ .cfi_def_cfa_offset 8
2931 \\ .cfi_offset %rbp, -8
2932 \\ mov %rsp, %rbp
2933 \\ .cfi_def_cfa_register %rbp
2934 \\ mov $4, %rax
2935 \\ pop %rbp
2936 \\ .cfi_restore %rbp
2937 \\ .cfi_def_cfa_offset 0
2938 \\ ret
2939 \\ .cfi_endproc
2911 \\.globl _foo
2912 \\_foo:
2913 \\ .cfi_startproc
2914 \\ push %rbp
2915 \\ .cfi_def_cfa_offset 8
2916 \\ .cfi_offset %rbp, -8
2917 \\ mov %rsp, %rbp
2918 \\ .cfi_def_cfa_register %rbp
2919 \\ call _bar
2920 \\ pop %rbp
2921 \\ .cfi_restore %rbp
2922 \\ .cfi_def_cfa_offset 0
2923 \\ ret
2924 \\ .cfi_endproc
2925 \\
2926 \\.globl _bar
2927 \\_bar:
2928 \\ .cfi_startproc
2929 \\ push %rbp
2930 \\ .cfi_def_cfa_offset 8
2931 \\ .cfi_offset %rbp, -8
2932 \\ mov %rsp, %rbp
2933 \\ .cfi_def_cfa_register %rbp
2934 \\ mov $4, %rax
2935 \\ pop %rbp
2936 \\ .cfi_restore %rbp
2937 \\ .cfi_def_cfa_offset 0
2938 \\ ret
2939 \\ .cfi_endproc
29402940 });
29412941
29422942 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
2943 \\#include <stdio.h>
2944 \\int foo();
2945 \\int main() {
2946 \\ printf("%d\n", foo());
2947 \\ return 0;
2948 \\}
2943 \\#include <stdio.h>
2944 \\int foo();
2945 \\int main() {
2946 \\ printf("%d\n", foo());
2947 \\ return 0;
2948 \\}
29492949 });
29502950 exe.addObject(a_o);
29512951
......@@ -2961,27 +2961,27 @@ fn testWeakBind(b: *Build, opts: Options) *Step {
29612961 const test_step = addTestStep(b, "weak-bind", opts);
29622962
29632963 const lib = addSharedLibrary(b, opts, .{ .name = "foo", .asm_source_bytes =
2964 \\.globl _weak_dysym
2965 \\.weak_definition _weak_dysym
2966 \\_weak_dysym:
2967 \\ .quad 0x1234
2968 \\
2969 \\.globl _weak_dysym_for_gotpcrel
2970 \\.weak_definition _weak_dysym_for_gotpcrel
2971 \\_weak_dysym_for_gotpcrel:
2972 \\ .quad 0x1234
2973 \\
2974 \\.globl _weak_dysym_fn
2975 \\.weak_definition _weak_dysym_fn
2976 \\_weak_dysym_fn:
2977 \\ ret
2978 \\
2979 \\.section __DATA,__thread_vars,thread_local_variables
2980 \\
2981 \\.globl _weak_dysym_tlv
2982 \\.weak_definition _weak_dysym_tlv
2983 \\_weak_dysym_tlv:
2984 \\ .quad 0x1234
2964 \\.globl _weak_dysym
2965 \\.weak_definition _weak_dysym
2966 \\_weak_dysym:
2967 \\ .quad 0x1234
2968 \\
2969 \\.globl _weak_dysym_for_gotpcrel
2970 \\.weak_definition _weak_dysym_for_gotpcrel
2971 \\_weak_dysym_for_gotpcrel:
2972 \\ .quad 0x1234
2973 \\
2974 \\.globl _weak_dysym_fn
2975 \\.weak_definition _weak_dysym_fn
2976 \\_weak_dysym_fn:
2977 \\ ret
2978 \\
2979 \\.section __DATA,__thread_vars,thread_local_variables
2980 \\
2981 \\.globl _weak_dysym_tlv
2982 \\.weak_definition _weak_dysym_tlv
2983 \\_weak_dysym_tlv:
2984 \\ .quad 0x1234
29852985 });
29862986
29872987 {
......@@ -2995,61 +2995,61 @@ fn testWeakBind(b: *Build, opts: Options) *Step {
29952995 }
29962996
29972997 const exe = addExecutable(b, opts, .{ .name = "main", .asm_source_bytes =
2998 \\.globl _main, _weak_external, _weak_external_for_gotpcrel, _weak_external_fn
2999 \\.weak_definition _weak_external, _weak_external_for_gotpcrel, _weak_external_fn, _weak_internal, _weak_internal_for_gotpcrel, _weak_internal_fn
3000 \\
3001 \\_main:
3002 \\ mov _weak_dysym_for_gotpcrel@GOTPCREL(%rip), %rax
3003 \\ mov _weak_external_for_gotpcrel@GOTPCREL(%rip), %rax
3004 \\ mov _weak_internal_for_gotpcrel@GOTPCREL(%rip), %rax
3005 \\ mov _weak_tlv@TLVP(%rip), %rax
3006 \\ mov _weak_dysym_tlv@TLVP(%rip), %rax
3007 \\ mov _weak_internal_tlv@TLVP(%rip), %rax
3008 \\ callq _weak_dysym_fn
3009 \\ callq _weak_external_fn
3010 \\ callq _weak_internal_fn
3011 \\ mov $0, %rax
3012 \\ ret
3013 \\
3014 \\_weak_external:
3015 \\ .quad 0x1234
3016 \\
3017 \\_weak_external_for_gotpcrel:
3018 \\ .quad 0x1234
3019 \\
3020 \\_weak_external_fn:
3021 \\ ret
3022 \\
3023 \\_weak_internal:
3024 \\ .quad 0x1234
3025 \\
3026 \\_weak_internal_for_gotpcrel:
3027 \\ .quad 0x1234
3028 \\
3029 \\_weak_internal_fn:
3030 \\ ret
3031 \\
3032 \\.data
3033 \\ .quad _weak_dysym
3034 \\ .quad _weak_external + 2
3035 \\ .quad _weak_internal
3036 \\
3037 \\.tbss _weak_tlv$tlv$init, 4, 2
3038 \\.tbss _weak_internal_tlv$tlv$init, 4, 2
3039 \\
3040 \\.section __DATA,__thread_vars,thread_local_variables
3041 \\.globl _weak_tlv
3042 \\.weak_definition _weak_tlv, _weak_internal_tlv
3043 \\
3044 \\_weak_tlv:
3045 \\ .quad __tlv_bootstrap
3046 \\ .quad 0
3047 \\ .quad _weak_tlv$tlv$init
3048 \\
3049 \\_weak_internal_tlv:
3050 \\ .quad __tlv_bootstrap
3051 \\ .quad 0
3052 \\ .quad _weak_internal_tlv$tlv$init
2998 \\.globl _main, _weak_external, _weak_external_for_gotpcrel, _weak_external_fn
2999 \\.weak_definition _weak_external, _weak_external_for_gotpcrel, _weak_external_fn, _weak_internal, _weak_internal_for_gotpcrel, _weak_internal_fn
3000 \\
3001 \\_main:
3002 \\ mov _weak_dysym_for_gotpcrel@GOTPCREL(%rip), %rax
3003 \\ mov _weak_external_for_gotpcrel@GOTPCREL(%rip), %rax
3004 \\ mov _weak_internal_for_gotpcrel@GOTPCREL(%rip), %rax
3005 \\ mov _weak_tlv@TLVP(%rip), %rax
3006 \\ mov _weak_dysym_tlv@TLVP(%rip), %rax
3007 \\ mov _weak_internal_tlv@TLVP(%rip), %rax
3008 \\ callq _weak_dysym_fn
3009 \\ callq _weak_external_fn
3010 \\ callq _weak_internal_fn
3011 \\ mov $0, %rax
3012 \\ ret
3013 \\
3014 \\_weak_external:
3015 \\ .quad 0x1234
3016 \\
3017 \\_weak_external_for_gotpcrel:
3018 \\ .quad 0x1234
3019 \\
3020 \\_weak_external_fn:
3021 \\ ret
3022 \\
3023 \\_weak_internal:
3024 \\ .quad 0x1234
3025 \\
3026 \\_weak_internal_for_gotpcrel:
3027 \\ .quad 0x1234
3028 \\
3029 \\_weak_internal_fn:
3030 \\ ret
3031 \\
3032 \\.data
3033 \\ .quad _weak_dysym
3034 \\ .quad _weak_external + 2
3035 \\ .quad _weak_internal
3036 \\
3037 \\.tbss _weak_tlv$tlv$init, 4, 2
3038 \\.tbss _weak_internal_tlv$tlv$init, 4, 2
3039 \\
3040 \\.section __DATA,__thread_vars,thread_local_variables
3041 \\.globl _weak_tlv
3042 \\.weak_definition _weak_tlv, _weak_internal_tlv
3043 \\
3044 \\_weak_tlv:
3045 \\ .quad __tlv_bootstrap
3046 \\ .quad 0
3047 \\ .quad _weak_tlv$tlv$init
3048 \\
3049 \\_weak_internal_tlv:
3050 \\ .quad __tlv_bootstrap
3051 \\ .quad 0
3052 \\ .quad _weak_internal_tlv$tlv$init
30533053 });
30543054 exe.linkLibrary(lib);
30553055
......@@ -3111,23 +3111,23 @@ fn testWeakLibrary(b: *Build, opts: Options) *Step {
31113111 const test_step = addTestStep(b, "weak-library", opts);
31123112
31133113 const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes =
3114 \\#include<stdio.h>
3115 \\int a = 42;
3116 \\const char* asStr() {
3117 \\ static char str[3];
3118 \\ sprintf(str, "%d", 42);
3119 \\ return str;
3120 \\}
3114 \\#include<stdio.h>
3115 \\int a = 42;
3116 \\const char* asStr() {
3117 \\ static char str[3];
3118 \\ sprintf(str, "%d", 42);
3119 \\ return str;
3120 \\}
31213121 });
31223122
31233123 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
3124 \\#include<stdio.h>
3125 \\extern int a;
3126 \\extern const char* asStr();
3127 \\int main() {
3128 \\ printf("%d %s", a, asStr());
3129 \\ return 0;
3130 \\}
3124 \\#include<stdio.h>
3125 \\extern int a;
3126 \\extern const char* asStr();
3127 \\int main() {
3128 \\ printf("%d %s", a, asStr());
3129 \\ return 0;
3130 \\}
31313131 });
31323132 exe.root_module.linkSystemLibrary("a", .{ .weak = true });
31333133 exe.root_module.addLibraryPath(dylib.getEmittedBinDirectory());
......@@ -3154,11 +3154,11 @@ fn testWeakRef(b: *Build, opts: Options) *Step {
31543154 const test_step = addTestStep(b, "weak-ref", opts);
31553155
31563156 const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
3157 \\#include <stdio.h>
3158 \\#include <sys/_types/_fd_def.h>
3159 \\int main(int argc, char** argv) {
3160 \\ printf("__darwin_check_fd_set_overflow: %p\n", __darwin_check_fd_set_overflow);
3161 \\}
3157 \\#include <stdio.h>
3158 \\#include <sys/_types/_fd_def.h>
3159 \\int main(int argc, char** argv) {
3160 \\ printf("__darwin_check_fd_set_overflow: %p\n", __darwin_check_fd_set_overflow);
3161 \\}
31623162 });
31633163
31643164 const check = exe.checkObject();
tools/doctest.zig+1-1
......@@ -203,7 +203,7 @@ fn printOutput(
203203 if (mem.startsWith(u8, triple, "wasm32") or
204204 mem.startsWith(u8, triple, "riscv64-linux") or
205205 (mem.startsWith(u8, triple, "x86_64-linux") and
206 builtin.os.tag != .linux or builtin.cpu.arch != .x86_64))
206 builtin.os.tag != .linux or builtin.cpu.arch != .x86_64))
207207 {
208208 // skip execution
209209 break :code_block;
tools/fetch_them_macos_headers.zig+2-2
......@@ -99,8 +99,8 @@ pub fn main() anyerror!void {
9999
100100 const version = Version.parse(parsed_json.value.DefaultProperties.MACOSX_DEPLOYMENT_TARGET) orelse
101101 fatal("don't know how to parse SDK version: {s}", .{
102 parsed_json.value.DefaultProperties.MACOSX_DEPLOYMENT_TARGET,
103 });
102 parsed_json.value.DefaultProperties.MACOSX_DEPLOYMENT_TARGET,
103 });
104104 const os_ver: OsVer = switch (version.major) {
105105 10 => .catalina,
106106 11 => .big_sur,
tools/update_clang_options.zig+1-1
......@@ -761,7 +761,7 @@ pub fn main() anyerror!void {
761761 if ((std.mem.startsWith(u8, name, "mno-") and
762762 llvm_to_zig_cpu_features.contains(name["mno-".len..])) or
763763 (std.mem.startsWith(u8, name, "m") and
764 llvm_to_zig_cpu_features.contains(name["m".len..])))
764 llvm_to_zig_cpu_features.contains(name["m".len..])))
765765 {
766766 try stdout.print("m(\"{s}\"),\n", .{name});
767767 } else {