diff --git a/lib/compiler/aro/aro/Parser.zig b/lib/compiler/aro/aro/Parser.zig index 85053b7e48..8327469853 100644 --- a/lib/compiler/aro/aro/Parser.zig +++ b/lib/compiler/aro/aro/Parser.zig @@ -979,7 +979,7 @@ fn decl(p: *Parser) Error!bool { _ = try p.expectToken(.semicolon); if (decl_spec.ty.is(.@"enum") or (decl_spec.ty.isRecord() and !decl_spec.ty.isAnonymousRecord(p.comp) and - !decl_spec.ty.isTypeof())) // we follow GCC and clang's behavior here + !decl_spec.ty.isTypeof())) // we follow GCC and clang's behavior here { const specifier = decl_spec.ty.canonicalize(.standard).specifier; const attrs = p.attr_buf.items(.attr)[attr_buf_top..]; diff --git a/lib/compiler/aro/aro/pragmas/gcc.zig b/lib/compiler/aro/aro/pragmas/gcc.zig index bf5daf95be..ce67698b88 100644 --- a/lib/compiler/aro/aro/pragmas/gcc.zig +++ b/lib/compiler/aro/aro/pragmas/gcc.zig @@ -114,9 +114,9 @@ fn preprocessorHandler(pragma: *Pragma, pp: *Preprocessor, start_idx: TokenIndex const gcc_pragma = std.meta.stringToEnum(Directive, pp.expandedSlice(directive_tok)) orelse return pp.comp.addDiagnostic(.{ - .tag = .unknown_gcc_pragma, - .loc = directive_tok.loc, - }, pp.expansionSlice(start_idx + 1)); + .tag = .unknown_gcc_pragma, + .loc = directive_tok.loc, + }, pp.expansionSlice(start_idx + 1)); switch (gcc_pragma) { .warning, .@"error" => { diff --git a/lib/compiler/resinator/lang.zig b/lib/compiler/resinator/lang.zig index 7cc69f1cf1..769733ceba 100644 --- a/lib/compiler/resinator/lang.zig +++ b/lib/compiler/resinator/lang.zig @@ -255,7 +255,7 @@ pub fn parse(lang_tag: []const u8) error{InvalidLanguageTag}!Parsed { // Special case for qps-ploca and qps-plocm else if (std.ascii.eqlIgnoreCase(lang_code, "qps") and (std.ascii.eqlIgnoreCase(part_str, "ploca") or - std.ascii.eqlIgnoreCase(part_str, "plocm"))) + std.ascii.eqlIgnoreCase(part_str, "plocm"))) { parsed.suffix = part_str; } else { diff --git a/lib/compiler_rt/count0bits.zig b/lib/compiler_rt/count0bits.zig index 874cbacdc7..c2fba8ba1e 100644 --- a/lib/compiler_rt/count0bits.zig +++ b/lib/compiler_rt/count0bits.zig @@ -143,7 +143,7 @@ pub const __clzsi2 = switch (builtin.cpu.arch) { .arm, .armeb, .thumb, .thumbeb => impl: { const use_thumb1 = (builtin.cpu.arch.isThumb() or - std.Target.arm.featureSetHas(builtin.cpu.features, .noarm)) and + std.Target.arm.featureSetHas(builtin.cpu.features, .noarm)) and !std.Target.arm.featureSetHas(builtin.cpu.features, .thumb2); if (use_thumb1) { diff --git a/lib/compiler_rt/int.zig b/lib/compiler_rt/int.zig index e71a0c0990..758ca74781 100644 --- a/lib/compiler_rt/int.zig +++ b/lib/compiler_rt/int.zig @@ -81,19 +81,19 @@ fn test_one_divmoddi4(a: i64, b: i64, expected_q: i64, expected_r: i64) !void { const cases__divmoddi4 = [_][4]i64{ - [_]i64{ 0, 1, 0, 0 }, - [_]i64{ 0, -1, 0, 0 }, - [_]i64{ 2, 1, 2, 0 }, - [_]i64{ 2, -1, -2, 0 }, - [_]i64{ -2, 1, -2, 0 }, - [_]i64{ -2, -1, 2, 0 }, - [_]i64{ 7, 5, 1, 2 }, - [_]i64{ -7, 5, -1, -2 }, - [_]i64{ 19, 5, 3, 4 }, - [_]i64{ 19, -5, -3, 4 }, - [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000000))), 0 }, - [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000007))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000001))), -1 }, -}; + [_]i64{ 0, 1, 0, 0 }, + [_]i64{ 0, -1, 0, 0 }, + [_]i64{ 2, 1, 2, 0 }, + [_]i64{ 2, -1, -2, 0 }, + [_]i64{ -2, 1, -2, 0 }, + [_]i64{ -2, -1, 2, 0 }, + [_]i64{ 7, 5, 1, 2 }, + [_]i64{ -7, 5, -1, -2 }, + [_]i64{ 19, 5, 3, 4 }, + [_]i64{ 19, -5, -3, 4 }, + [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000000))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000000))), 0 }, + [_]i64{ @as(i64, @bitCast(@as(u64, 0x8000000000000007))), 8, @as(i64, @bitCast(@as(u64, 0xf000000000000001))), -1 }, + }; test "test_divmoddi4" { for (cases__divmoddi4) |case| { @@ -215,19 +215,19 @@ pub fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 { const cases__divmodsi4 = [_][4]i32{ - [_]i32{ 0, 1, 0, 0 }, - [_]i32{ 0, -1, 0, 0 }, - [_]i32{ 2, 1, 2, 0 }, - [_]i32{ 2, -1, -2, 0 }, - [_]i32{ -2, 1, -2, 0 }, - [_]i32{ -2, -1, 2, 0 }, - [_]i32{ 7, 5, 1, 2 }, - [_]i32{ -7, 5, -1, -2 }, - [_]i32{ 19, 5, 3, 4 }, - [_]i32{ 19, -5, -3, 4 }, - [_]i32{ @bitCast(@as(u32, 0x80000000)), 8, @bitCast(@as(u32, 0xf0000000)), 0 }, - [_]i32{ @bitCast(@as(u32, 0x80000007)), 8, @bitCast(@as(u32, 0xf0000001)), -1 }, -}; + [_]i32{ 0, 1, 0, 0 }, + [_]i32{ 0, -1, 0, 0 }, + [_]i32{ 2, 1, 2, 0 }, + [_]i32{ 2, -1, -2, 0 }, + [_]i32{ -2, 1, -2, 0 }, + [_]i32{ -2, -1, 2, 0 }, + [_]i32{ 7, 5, 1, 2 }, + [_]i32{ -7, 5, -1, -2 }, + [_]i32{ 19, 5, 3, 4 }, + [_]i32{ 19, -5, -3, 4 }, + [_]i32{ @bitCast(@as(u32, 0x80000000)), 8, @bitCast(@as(u32, 0xf0000000)), 0 }, + [_]i32{ @bitCast(@as(u32, 0x80000007)), 8, @bitCast(@as(u32, 0xf0000001)), -1 }, + }; fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) !void { var r: i32 = undefined; diff --git a/lib/compiler_rt/popcount.zig b/lib/compiler_rt/popcount.zig index d54a4aab42..492423dda5 100644 --- a/lib/compiler_rt/popcount.zig +++ b/lib/compiler_rt/popcount.zig @@ -40,7 +40,7 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 { var x: UT = @bitCast(a); x -= (x >> 1) & (~@as(UT, 0) / 3); // 0x55...55, aggregate duos x = ((x >> 2) & (~@as(UT, 0) / 5)) // 0x33...33, aggregate nibbles - + (x & (~@as(UT, 0) / 5)); + + (x & (~@as(UT, 0) / 5)); x += x >> 4; x &= ~@as(UT, 0) / 17; // 0x0F...0F, aggregate bytes // 8 most significant bits of x + (x<<8) + (x<<16) + .. diff --git a/lib/docs/wasm/markdown/Parser.zig b/lib/docs/wasm/markdown/Parser.zig index 1b5f40792e..fab43afa84 100644 --- a/lib/docs/wasm/markdown/Parser.zig +++ b/lib/docs/wasm/markdown/Parser.zig @@ -374,7 +374,7 @@ fn appendBlockStart(p: *Parser, block_start: BlockStart) !void { // or not of the same marker type. const should_close_list = last_pending_block.tag == .list and (block_start.tag != .list_item or - block_start.data.list_item.marker != last_pending_block.data.list.marker); + block_start.data.list_item.marker != last_pending_block.data.list.marker); // The last block should also be closed if the new block is not a table // row, which is the only allowed child of a table. const should_close_table = last_pending_block.tag == .table and diff --git a/lib/std/Target.zig b/lib/std/Target.zig index 740949858f..2f1d2d599d 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -299,7 +299,7 @@ pub const Os = struct { pub fn parse(str: []const u8) !WindowsVersion { return std.meta.stringToEnum(WindowsVersion, str) orelse @enumFromInt(std.fmt.parseInt(u32, str, 0) catch - return error.InvalidOperatingSystemVersion); + return error.InvalidOperatingSystemVersion); } /// This function is defined to serialize a Zig source code representation of this diff --git a/lib/std/c.zig b/lib/std/c.zig index 498e7d14ca..9b7d36cb32 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -9879,10 +9879,10 @@ pub extern "c" fn setlocale(category: LC, locale: ?[*:0]const u8) ?[*:0]const u8 pub const getcontext = if (builtin.target.abi.isAndroid() or builtin.target.os.tag == .openbsd) {} // android bionic and openbsd libc does not implement getcontext -else if (native_os == .linux and builtin.target.abi.isMusl()) - linux.getcontext -else - private.getcontext; + else if (native_os == .linux and builtin.target.abi.isMusl()) + linux.getcontext + else + private.getcontext; pub const max_align_t = if (native_abi == .msvc or native_abi == .itanium) f64 diff --git a/lib/std/crypto/tls/Client.zig b/lib/std/crypto/tls/Client.zig index 09e5e0fdd5..738fe122dd 100644 --- a/lib/std/crypto/tls/Client.zig +++ b/lib/std/crypto/tls/Client.zig @@ -692,7 +692,7 @@ pub fn init(stream: anytype, options: Options) InitError(@TypeOf(stream))!Client const client_key_exchange_msg = .{@intFromEnum(tls.ContentType.handshake)} ++ int(u16, @intFromEnum(tls.ProtocolVersion.tls_1_2)) ++ array(u16, u8, .{@intFromEnum(tls.HandshakeType.client_key_exchange)} ++ - array(u24, u8, array(u8, u8, key_share.secp256r1_kp.public_key.toUncompressedSec1()))); + array(u24, u8, array(u8, u8, key_share.secp256r1_kp.public_key.toUncompressedSec1()))); const client_change_cipher_spec_msg = .{@intFromEnum(tls.ContentType.change_cipher_spec)} ++ int(u16, @intFromEnum(tls.ProtocolVersion.tls_1_2)) ++ array(u16, tls.ChangeCipherSpecType, .{.change_cipher_spec}); @@ -720,11 +720,11 @@ pub fn init(stream: anytype, options: Options) InitError(@TypeOf(stream))!Client ); const client_verify_cleartext = .{@intFromEnum(tls.HandshakeType.finished)} ++ array(u24, u8, hmacExpandLabel( - P.Hmac, - &master_secret, - &.{ "client finished", &p.transcript_hash.peek() }, - P.verify_data_length, - )); + P.Hmac, + &master_secret, + &.{ "client finished", &p.transcript_hash.peek() }, + P.verify_data_length, + )); p.transcript_hash.update(&client_verify_cleartext); p.version = .{ .tls_1_2 = .{ .expected_server_verify_data = hmacExpandLabel( @@ -745,7 +745,7 @@ pub fn init(stream: anytype, options: Options) InitError(@TypeOf(stream))!Client var client_verify_msg = .{@intFromEnum(tls.ContentType.handshake)} ++ int(u16, @intFromEnum(tls.ProtocolVersion.tls_1_2)) ++ array(u16, u8, nonce[P.fixed_iv_length..].* ++ - @as([client_verify_cleartext.len + P.mac_length]u8, undefined)); + @as([client_verify_cleartext.len + P.mac_length]u8, undefined)); P.AEAD.encrypt( client_verify_msg[client_verify_msg.len - P.mac_length - client_verify_cleartext.len ..][0..client_verify_cleartext.len], diff --git a/lib/std/debug/SelfInfo.zig b/lib/std/debug/SelfInfo.zig index 0bd3f2d41b..ea7ecac4ed 100644 --- a/lib/std/debug/SelfInfo.zig +++ b/lib/std/debug/SelfInfo.zig @@ -689,15 +689,15 @@ pub const Module = switch (native_os) { const o_file_path = mem.sliceTo(self.strings[symbol.ofile..], 0); const o_file_info = self.ofiles.getPtr(o_file_path) orelse (self.loadOFile(allocator, o_file_path) catch |err| switch (err) { - error.FileNotFound, - error.MissingDebugInfo, - error.InvalidDebugInfo, - => return .{ - .relocated_address = relocated_address, - .symbol = symbol, - }, - else => return err, - }); + error.FileNotFound, + error.MissingDebugInfo, + error.InvalidDebugInfo, + => return .{ + .relocated_address = relocated_address, + .symbol = symbol, + }, + else => return err, + }); return .{ .relocated_address = relocated_address, diff --git a/lib/std/http/Client.zig b/lib/std/http/Client.zig index 3560e69b58..86f29b4a08 100644 --- a/lib/std/http/Client.zig +++ b/lib/std/http/Client.zig @@ -960,13 +960,13 @@ pub const Request = struct { pub const WaitError = RequestError || SendError || TransferReadError || proto.HeadersParser.CheckCompleteHeadError || Response.ParseError || error{ - TooManyHttpRedirects, - RedirectRequiresResend, - HttpRedirectLocationMissing, - HttpRedirectLocationInvalid, - CompressionInitializationFailed, - CompressionUnsupported, - }; + TooManyHttpRedirects, + RedirectRequiresResend, + HttpRedirectLocationMissing, + HttpRedirectLocationInvalid, + CompressionInitializationFailed, + CompressionUnsupported, + }; /// Waits for a response from the server and parses any headers that are sent. /// This function will block until the final response is received. @@ -1540,12 +1540,12 @@ pub fn connect( pub const RequestError = ConnectTcpError || ConnectErrorPartial || Request.SendError || std.fmt.ParseIntError || Connection.WriteError || error{ - UnsupportedUriScheme, - UriMissingHost, + UnsupportedUriScheme, + UriMissingHost, - CertificateBundleLoadFailure, - UnsupportedTransferEncoding, -}; + CertificateBundleLoadFailure, + UnsupportedTransferEncoding, + }; pub const RequestOptions = struct { version: http.Version = .@"HTTP/1.1", diff --git a/lib/std/posix.zig b/lib/std/posix.zig index 4dd93f719f..30cbcab6e9 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -2851,12 +2851,12 @@ pub fn renameatW( rc = windows.ntdll.NtSetInformationFile( - src_fd, - &io_status_block, - rename_info, - @intCast(struct_len), // already checked for error.NameTooLong - .FileRenameInformation, - ); + src_fd, + &io_status_block, + rename_info, + @intCast(struct_len), // already checked for error.NameTooLong + .FileRenameInformation, + ); } switch (rc) { diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index a24b5f5401..264a262a04 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -372,7 +372,7 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { if (!ais.indentStackEmpty() and token_tags[i] != .colon and ((token_tags[i] != .semicolon and token_tags[i] != .comma) or - ais.lastSpaceModeIndent() < ais.currentIndent())) + ais.lastSpaceModeIndent() < ais.currentIndent())) { ais.popIndent(); try ais.pushIndent(.normal); @@ -1185,9 +1185,9 @@ fn renderVarDeclWithoutFixups( { const name_space = if (var_decl.ast.type_node == 0 and (var_decl.ast.align_node != 0 or - var_decl.ast.addrspace_node != 0 or - var_decl.ast.section_node != 0 or - var_decl.ast.init_node != 0)) + var_decl.ast.addrspace_node != 0 or + var_decl.ast.section_node != 0 or + var_decl.ast.init_node != 0)) Space.space else Space.none; diff --git a/src/Sema.zig b/src/Sema.zig index 7e3ab51a29..ea51589911 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -23443,7 +23443,7 @@ fn ptrCastFull( errdefer msg.destroy(sema.gpa); if (dest_info.flags.size == .many and (src_info.flags.size == .slice or - (src_info.flags.size == .one and Type.fromInterned(src_info.child).zigTypeTag(zcu) == .array))) + (src_info.flags.size == .one and Type.fromInterned(src_info.child).zigTypeTag(zcu) == .array))) { try sema.errNote(src, msg, "use 'ptr' field to convert slice to many pointer", .{}); } else { @@ -28136,9 +28136,9 @@ fn fieldCallBind( const first_param_type = Type.fromInterned(func_type.param_types.get(ip)[0]); if (first_param_type.isGenericPoison() or (first_param_type.zigTypeTag(zcu) == .pointer and - (first_param_type.ptrSize(zcu) == .one or - first_param_type.ptrSize(zcu) == .c) and - first_param_type.childType(zcu).eql(concrete_ty, zcu))) + (first_param_type.ptrSize(zcu) == .one or + first_param_type.ptrSize(zcu) == .c) and + first_param_type.childType(zcu).eql(concrete_ty, zcu))) { // Note that if the param type is generic poison, we know that it must // specifically be `anytype` since it's the first parameter, meaning we @@ -29652,7 +29652,7 @@ fn coerceExtra( if (dest_info.sentinel == .none or inst_info.sentinel == .none or Air.internedToRef(dest_info.sentinel) != - try sema.coerceInMemory(Value.fromInterned(inst_info.sentinel), Type.fromInterned(dest_info.child))) + try sema.coerceInMemory(Value.fromInterned(inst_info.sentinel), Type.fromInterned(dest_info.child))) break :p; const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty); @@ -30492,12 +30492,12 @@ pub fn coerceInMemoryAllowed( } const ok_sent = (dest_info.sentinel == null and src_info.sentinel == null) or (src_info.sentinel != null and - dest_info.sentinel != null and - dest_info.sentinel.?.eql( - try pt.getCoerced(src_info.sentinel.?, dest_info.elem_type), - dest_info.elem_type, - zcu, - )); + dest_info.sentinel != null and + dest_info.sentinel.?.eql( + try pt.getCoerced(src_info.sentinel.?, dest_info.elem_type), + dest_info.elem_type, + zcu, + )); if (!ok_sent) { return .{ .array_sentinel = .{ .actual = src_info.sentinel orelse Value.@"unreachable", diff --git a/src/Type.zig b/src/Type.zig index 883c752ef1..106aa3d2d8 100644 --- a/src/Type.zig +++ b/src/Type.zig @@ -610,11 +610,12 @@ pub fn hasRuntimeBitsInner( // in which case we want control flow to continue down below. if (tag_ty != .none and try Type.fromInterned(tag_ty).hasRuntimeBitsInner( - ignore_comptime_only, - strat, - zcu, - tid, - )) { + ignore_comptime_only, + strat, + zcu, + tid, + )) + { return true; } }, diff --git a/src/Zcu.zig b/src/Zcu.zig index bac2713240..483b507bb4 100644 --- a/src/Zcu.zig +++ b/src/Zcu.zig @@ -1496,8 +1496,8 @@ pub const SrcLoc = struct { const case = tree.fullSwitchCase(case_node).?; const is_special = (case.ast.values.len == 0) or (case.ast.values.len == 1 and - node_tags[case.ast.values[0]] == .identifier and - mem.eql(u8, tree.tokenSlice(main_tokens[case.ast.values[0]]), "_")); + node_tags[case.ast.values[0]] == .identifier and + mem.eql(u8, tree.tokenSlice(main_tokens[case.ast.values[0]]), "_")); if (!is_special) continue; return tree.nodeToSpan(case_node); @@ -1516,8 +1516,8 @@ pub const SrcLoc = struct { const case = tree.fullSwitchCase(case_node).?; const is_special = (case.ast.values.len == 0) or (case.ast.values.len == 1 and - node_tags[case.ast.values[0]] == .identifier and - mem.eql(u8, tree.tokenSlice(main_tokens[case.ast.values[0]]), "_")); + node_tags[case.ast.values[0]] == .identifier and + mem.eql(u8, tree.tokenSlice(main_tokens[case.ast.values[0]]), "_")); if (is_special) continue; for (case.ast.values) |item_node| { diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig index 2db96edd6d..c66de9dd30 100644 --- a/src/arch/riscv64/CodeGen.zig +++ b/src/arch/riscv64/CodeGen.zig @@ -685,8 +685,7 @@ fn restoreState(func: *Func, state: State, deaths: []const Air.Inst.Index, compt const ExpectedContents = [@typeInfo(RegisterManager.TrackedRegisters).array.len]RegisterLock; var stack align(@max(@alignOf(ExpectedContents), @alignOf(std.heap.StackFallbackAllocator(0)))) = - if (opts.update_tracking) - {} else std.heap.stackFallback(@sizeOf(ExpectedContents), func.gpa); + if (opts.update_tracking) {} else std.heap.stackFallback(@sizeOf(ExpectedContents), func.gpa); var reg_locks = if (opts.update_tracking) {} else try std.ArrayList(RegisterLock).initCapacity( stack.get(), @@ -2260,7 +2259,7 @@ fn airIntCast(func: *Func, inst: Air.Inst.Index) !void { const dst_mcv = if (dst_int_info.bits <= src_storage_bits and math.divCeil(u16, dst_int_info.bits, 64) catch unreachable == - math.divCeil(u32, src_storage_bits, 64) catch unreachable and + math.divCeil(u32, src_storage_bits, 64) catch unreachable and func.reuseOperand(inst, ty_op.operand, 0, src_mcv)) src_mcv else dst: { const dst_mcv = try func.allocRegOrMem(dst_ty, inst, true); try func.genCopy(min_ty, dst_mcv, src_mcv); @@ -2311,9 +2310,9 @@ fn airNot(func: *Func, inst: Air.Inst.Index) !void { const dst_reg: Register = if (func.reuseOperand(inst, ty_op.operand, 0, operand) and operand == .register) - operand.register - else - (try func.allocRegOrMem(func.typeOfIndex(inst), inst, true)).register; + operand.register + else + (try func.allocRegOrMem(func.typeOfIndex(inst), inst, true)).register; switch (ty.zigTypeTag(zcu)) { .bool => { @@ -6222,11 +6221,11 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void { const instruction: union(enum) { mnem: Mnemonic, pseudo: Pseudo } = if (std.meta.stringToEnum(Mnemonic, mnem_str)) |mnem| - .{ .mnem = mnem } - else if (std.meta.stringToEnum(Pseudo, mnem_str)) |pseudo| - .{ .pseudo = pseudo } - else - return func.fail("invalid mnem str '{s}'", .{mnem_str}); + .{ .mnem = mnem } + else if (std.meta.stringToEnum(Pseudo, mnem_str)) |pseudo| + .{ .pseudo = pseudo } + else + return func.fail("invalid mnem str '{s}'", .{mnem_str}); const Operand = union(enum) { none, diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index 91a9270fd5..7b734994f4 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -82655,8 +82655,7 @@ fn restoreState(self: *CodeGen, state: State, deaths: []const Air.Inst.Index, co const ExpectedContents = [@typeInfo(RegisterManager.TrackedRegisters).array.len]RegisterLock; var stack align(@max(@alignOf(ExpectedContents), @alignOf(std.heap.StackFallbackAllocator(0)))) = - if (opts.update_tracking) - {} else std.heap.stackFallback(@sizeOf(ExpectedContents), self.gpa); + if (opts.update_tracking) {} else std.heap.stackFallback(@sizeOf(ExpectedContents), self.gpa); var reg_locks = if (opts.update_tracking) {} else try std.ArrayList(RegisterLock).initCapacity( stack.get(), @@ -83216,7 +83215,7 @@ fn airIntCast(self: *CodeGen, inst: Air.Inst.Index) !void { const dst_mcv = if ((if (src_mcv.getReg()) |src_reg| src_reg.class() == .general_purpose else src_abi_size > 8) and dst_int_info.bits <= src_storage_bits and std.math.divCeil(u16, dst_int_info.bits, 64) catch unreachable == - std.math.divCeil(u32, src_storage_bits, 64) catch unreachable and + std.math.divCeil(u32, src_storage_bits, 64) catch unreachable and self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) src_mcv else dst: { const dst_mcv = try self.allocRegOrMem(inst, true); 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 ._ => { const hi_reg: Register = switch (bit_size) { - 8 => .ah, - 16, 32, 64 => .edx, - else => unreachable, - }; + 8 => .ah, + 16, 32, 64 => .edx, + else => unreachable, + }; try self.asmRegisterRegister(.{ ._, .xor }, hi_reg, hi_reg); }, .i_ => try self.asmOpOnly(.{ ._, switch (bit_size) { @@ -89019,9 +89018,9 @@ fn genShiftBinOpMir( .size = .fromSize(abi_size), .disp = std.math.cast(i32, @as(i64, @bitCast(addr))) orelse return self.fail("TODO genShiftBinOpMir between {s} and {s}", .{ - @tagName(lhs_mcv), - @tagName(shift_mcv), - }), + @tagName(lhs_mcv), + @tagName(shift_mcv), + }), } }, }, .indirect => |reg_off| .{ @@ -89761,17 +89760,17 @@ fn genBinOp( const ordered_air: [2]Air.Inst.Ref = if (lhs_ty.isVector(zcu) and switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) { - .bool => false, - .int => switch (air_tag) { - .cmp_lt, .cmp_gte => true, - else => false, - }, - .float => switch (air_tag) { - .cmp_gte, .cmp_gt => true, - else => false, - }, - else => unreachable, - }) .{ rhs_air, lhs_air } else .{ lhs_air, rhs_air }; + .bool => false, + .int => switch (air_tag) { + .cmp_lt, .cmp_gte => true, + else => false, + }, + .float => switch (air_tag) { + .cmp_gte, .cmp_gt => true, + else => false, + }, + else => unreachable, + }) .{ rhs_air, lhs_air } else .{ lhs_air, rhs_air }; if (lhs_ty.isAbiInt(zcu)) for (ordered_air) |op_air| { switch (try self.resolveInst(op_air)) { @@ -91776,13 +91775,13 @@ fn genIntMulComplexOpMir(self: *CodeGen, dst_ty: Type, dst_mcv: MCValue, src_mcv .size = .fromSize(abi_size), .disp = std.math.cast(i32, @as(i64, @bitCast(addr))) orelse return self.asmRegisterRegister( - .{ .i_, .mul }, - dst_alias, - registerAlias( - try self.copyToTmpRegister(dst_ty, resolved_src_mcv), - abi_size, + .{ .i_, .mul }, + dst_alias, + registerAlias( + try self.copyToTmpRegister(dst_ty, resolved_src_mcv), + abi_size, + ), ), - ), } }, }, .indirect => |reg_off| .{ @@ -94101,9 +94100,9 @@ fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void { std.mem.eql(u8, rest, "r,m") or std.mem.eql(u8, rest, "m,r")) self.register_manager.tryAllocReg(maybe_inst, abi.RegisterClass.gp) orelse if (output != .none) - null - else - return self.fail("ran out of registers lowering inline asm", .{}) + null + else + return self.fail("ran out of registers lowering inline asm", .{}) else if (std.mem.startsWith(u8, rest, "{") and std.mem.endsWith(u8, rest, "}")) parseRegName(rest["{".len .. rest.len - "}".len]) orelse return self.fail("invalid register constraint: '{s}'", .{constraint}) @@ -96965,9 +96964,9 @@ fn airAtomicLoad(self: *CodeGen, inst: Air.Inst.Index) !void { const dst_mcv = if (self.reuseOperand(inst, atomic_load.ptr, 0, ptr_mcv)) - ptr_mcv - else - try self.allocRegOrMem(inst, true); + ptr_mcv + else + try self.allocRegOrMem(inst, true); try self.load(dst_mcv, ptr_ty, ptr_mcv); return self.finishAir(inst, dst_mcv, .{ atomic_load.ptr, .none, .none }); @@ -103712,9 +103711,9 @@ const Select = struct { if (cg.intInfo(ty.childType(zcu))) |int_info| int_info.signedness == .signed else false, .signed_int_or_full_vec => |size| ty.isVector(zcu) and @divExact(size.bitSize(cg.target), 8) >= ty.abiSize(zcu) and if (cg.intInfo(ty.childType(zcu))) |int_info| switch (int_info.signedness) { - .signed => true, - .unsigned => int_info.bits >= 8 and std.math.isPowerOfTwo(int_info.bits), - } else false, + .signed => true, + .unsigned => int_info.bits >= 8 and std.math.isPowerOfTwo(int_info.bits), + } else false, .unsigned_int_vec => |size| ty.isVector(zcu) and @divExact(size.bitSize(cg.target), 8) >= ty.abiSize(zcu) and if (cg.intInfo(ty.childType(zcu))) |int_info| int_info.signedness == .unsigned else false, .size => |size| @divExact(size.bitSize(cg.target), 8) >= ty.abiSize(zcu), @@ -103736,26 +103735,26 @@ const Select = struct { if (cg.intInfo(ty.scalarType(zcu))) |int_info| of_is.is.bitSize(cg.target) >= int_info.bits else false, .scalar_signed_int => |of_is| @divExact(of_is.of.bitSize(cg.target), 8) >= cg.unalignedSize(ty) and if (cg.intInfo(ty.scalarType(zcu))) |int_info| int_info.signedness == .signed and - of_is.is.bitSize(cg.target) >= int_info.bits else false, + of_is.is.bitSize(cg.target) >= int_info.bits else false, .scalar_unsigned_int => |of_is| @divExact(of_is.of.bitSize(cg.target), 8) >= cg.unalignedSize(ty) and if (cg.intInfo(ty.scalarType(zcu))) |int_info| int_info.signedness == .unsigned and - of_is.is.bitSize(cg.target) >= int_info.bits else false, + of_is.is.bitSize(cg.target) >= int_info.bits else false, .multiple_scalar_int => |of_is| ty.abiSize(zcu) % @divExact(of_is.of.bitSize(cg.target), 8) == 0 and if (cg.intInfo(ty.scalarType(zcu))) |int_info| of_is.is.bitSize(cg.target) >= int_info.bits else false, .multiple_scalar_signed_int => |of_is| ty.abiSize(zcu) % @divExact(of_is.of.bitSize(cg.target), 8) == 0 and if (cg.intInfo(ty.scalarType(zcu))) |int_info| int_info.signedness == .signed and - of_is.is.bitSize(cg.target) >= int_info.bits else false, + of_is.is.bitSize(cg.target) >= int_info.bits else false, .multiple_scalar_unsigned_int => |of_is| ty.abiSize(zcu) % @divExact(of_is.of.bitSize(cg.target), 8) == 0 and if (cg.intInfo(ty.scalarType(zcu))) |int_info| int_info.signedness == .unsigned and - of_is.is.bitSize(cg.target) >= int_info.bits else false, + of_is.is.bitSize(cg.target) >= int_info.bits else false, .multiple_scalar_exact_int => |of_is| ty.abiSize(zcu) % @divExact(of_is.of.bitSize(cg.target), 8) == 0 and if (cg.intInfo(ty.scalarType(zcu))) |int_info| of_is.is == int_info.bits else false, .multiple_scalar_exact_signed_int => |of_is| ty.abiSize(zcu) % @divExact(of_is.of.bitSize(cg.target), 8) == 0 and if (cg.intInfo(ty.scalarType(zcu))) |int_info| int_info.signedness == .signed and - of_is.is == int_info.bits else false, + of_is.is == int_info.bits else false, .multiple_scalar_exact_unsigned_int => |of_is| ty.abiSize(zcu) % @divExact(of_is.of.bitSize(cg.target), 8) == 0 and if (cg.intInfo(ty.scalarType(zcu))) |int_info| int_info.signedness == .unsigned and - of_is.is == int_info.bits else false, + of_is.is == int_info.bits else false, .scalar_remainder_int => |of_is| if (cg.intInfo(ty.scalarType(zcu))) |int_info| of_is.is.bitSize(cg.target) >= (int_info.bits - 1) % of_is.of.bitSize(cg.target) + 1 else diff --git a/src/codegen.zig b/src/codegen.zig index 7726af8387..ad241d047d 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -423,7 +423,7 @@ pub fn generateSymbol( const padding = abi_size - (math.cast(usize, Type.fromInterned(vector_type.child).abiSize(zcu) * vector_type.len) orelse - return error.Overflow); + return error.Overflow); if (padding > 0) try code.appendNTimes(gpa, 0, padding); } }, diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 7dd2895911..5012f7e0e8 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -1990,7 +1990,7 @@ pub const DeclGen = struct { if (dest_bits <= 64 and src_bits <= 64) { const needs_cast = src_int_info == null or (toCIntBits(dest_int_info.bits) != toCIntBits(src_int_info.?.bits) or - dest_int_info.signedness != src_int_info.?.signedness); + dest_int_info.signedness != src_int_info.?.signedness); return !needs_cast and !src_is_ptr; } else return false; } @@ -2031,7 +2031,7 @@ pub const DeclGen = struct { if (dest_bits <= 64 and src_bits <= 64) { const needs_cast = src_int_info == null or (toCIntBits(dest_int_info.bits) != toCIntBits(src_int_info.?.bits) or - dest_int_info.signedness != src_int_info.?.signedness); + dest_int_info.signedness != src_int_info.?.signedness); if (needs_cast) { try w.writeByte('('); @@ -4348,7 +4348,7 @@ fn airEquality( .aligned, .array, .vector, .fwd_decl, .function => unreachable, .aggregate => |aggregate| if (aggregate.fields.len == 2 and (aggregate.fields.at(0, ctype_pool).name.index == .is_null or - aggregate.fields.at(1, ctype_pool).name.index == .is_null)) + aggregate.fields.at(1, ctype_pool).name.index == .is_null)) { try f.writeCValueMember(writer, lhs, .{ .identifier = "is_null" }); try writer.writeAll(" || "); diff --git a/src/codegen/c/Type.zig b/src/codegen/c/Type.zig index 54f012e8ef..ec1bf40e0c 100644 --- a/src/codegen/c/Type.zig +++ b/src/codegen/c/Type.zig @@ -758,12 +758,12 @@ pub const Info = union(enum) { fn tag(pointer_info: Pointer) Pool.Tag { return @enumFromInt(@intFromEnum(Pool.Tag.pointer) + @as(u2, @bitCast(packed struct(u2) { - @"const": bool, - @"volatile": bool, - }{ - .@"const" = pointer_info.@"const", - .@"volatile" = pointer_info.@"volatile", - }))); + @"const": bool, + @"volatile": bool, + }{ + .@"const" = pointer_info.@"const", + .@"volatile" = pointer_info.@"volatile", + }))); } }; @@ -887,24 +887,24 @@ pub const Info = union(enum) { pool_adapter.eql(lhs_vector_info.elem_ctype, rhs_info.vector.elem_ctype), .fwd_decl => |lhs_fwd_decl_info| lhs_fwd_decl_info.tag == rhs_info.fwd_decl.tag and switch (lhs_fwd_decl_info.name) { - .anon => |lhs_anon| rhs_info.fwd_decl.name == .anon and lhs_anon.eqlAdapted( - lhs_pool, - rhs_info.fwd_decl.name.anon, - rhs_pool, - pool_adapter, - ), - .index => |lhs_index| rhs_info.fwd_decl.name == .index and - lhs_index == rhs_info.fwd_decl.name.index, - }, + .anon => |lhs_anon| rhs_info.fwd_decl.name == .anon and lhs_anon.eqlAdapted( + lhs_pool, + rhs_info.fwd_decl.name.anon, + rhs_pool, + pool_adapter, + ), + .index => |lhs_index| rhs_info.fwd_decl.name == .index and + lhs_index == rhs_info.fwd_decl.name.index, + }, .aggregate => |lhs_aggregate_info| lhs_aggregate_info.tag == rhs_info.aggregate.tag and lhs_aggregate_info.@"packed" == rhs_info.aggregate.@"packed" and switch (lhs_aggregate_info.name) { - .anon => |lhs_anon| rhs_info.aggregate.name == .anon and - lhs_anon.index == rhs_info.aggregate.name.anon.index and - lhs_anon.id == rhs_info.aggregate.name.anon.id, - .fwd_decl => |lhs_fwd_decl| rhs_info.aggregate.name == .fwd_decl and - pool_adapter.eql(lhs_fwd_decl, rhs_info.aggregate.name.fwd_decl), - } and lhs_aggregate_info.fields.eqlAdapted( + .anon => |lhs_anon| rhs_info.aggregate.name == .anon and + lhs_anon.index == rhs_info.aggregate.name.anon.index and + lhs_anon.id == rhs_info.aggregate.name.anon.id, + .fwd_decl => |lhs_fwd_decl| rhs_info.aggregate.name == .fwd_decl and + pool_adapter.eql(lhs_fwd_decl, rhs_info.aggregate.name.fwd_decl), + } and lhs_aggregate_info.fields.eqlAdapted( lhs_pool, rhs_info.aggregate.fields, rhs_pool, @@ -913,13 +913,12 @@ pub const Info = union(enum) { .function => |lhs_function_info| lhs_function_info.param_ctypes.len == rhs_info.function.param_ctypes.len and pool_adapter.eql(lhs_function_info.return_ctype, rhs_info.function.return_ctype) and - for (0..lhs_function_info.param_ctypes.len) |param_index| - { - if (!pool_adapter.eql( - lhs_function_info.param_ctypes.at(param_index, lhs_pool), - rhs_info.function.param_ctypes.at(param_index, rhs_pool), - )) break false; - } else true, + for (0..lhs_function_info.param_ctypes.len) |param_index| { + if (!pool_adapter.eql( + lhs_function_info.param_ctypes.at(param_index, lhs_pool), + rhs_info.function.param_ctypes.at(param_index, rhs_pool), + )) break false; + } else true, }; } }; @@ -2301,13 +2300,13 @@ pub const Pool = struct { const return_type = Type.fromInterned(func_info.return_type); const return_ctype: CType = if (!ip.isNoReturn(func_info.return_type)) try pool.fromType( - allocator, - scratch, - return_type, - pt, - mod, - kind.asParameter(), - ) else .void; + allocator, + scratch, + return_type, + pt, + mod, + kind.asParameter(), + ) else .void; for (0..func_info.param_types.len) |param_index| { const param_type = Type.fromInterned( func_info.param_types.get(ip)[param_index], diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 2767c320d1..a6dbb08a42 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -388,7 +388,7 @@ const DataLayoutBuilder = struct { self.target.cpu.arch != .riscv64 and self.target.cpu.arch != .loongarch64 and !(self.target.cpu.arch == .aarch64 and - (self.target.os.tag == .uefi or self.target.os.tag == .windows)) and + (self.target.os.tag == .uefi or self.target.os.tag == .windows)) and self.target.cpu.arch != .bpfeb and self.target.cpu.arch != .bpfel) continue; try writer.writeAll("-p"); if (info.llvm != .default) try writer.print("{d}", .{@intFromEnum(info.llvm)}); @@ -859,55 +859,54 @@ pub const Object = struct { builder.data_layout = try builder.fmt("{}", .{DataLayoutBuilder{ .target = target }}); const debug_compile_unit, const debug_enums_fwd_ref, const debug_globals_fwd_ref = - if (!builder.strip) - debug_info: { - // We fully resolve all paths at this point to avoid lack of - // source line info in stack traces or lack of debugging - // information which, if relative paths were used, would be - // very location dependent. - // TODO: the only concern I have with this is WASI as either host or target, should - // we leave the paths as relative then? - // TODO: This is totally wrong. In dwarf, paths are encoded as relative to - // a particular directory, and then the directory path is specified elsewhere. - // In the compiler frontend we have it stored correctly in this - // way already, but here we throw all that sweet information - // into the garbage can by converting into absolute paths. What - // a terrible tragedy. - const compile_unit_dir = blk: { - if (comp.zcu) |zcu| m: { - const d = try zcu.main_mod.root.joinString(arena, ""); - if (d.len == 0) break :m; - if (std.fs.path.isAbsolute(d)) break :blk d; - break :blk std.fs.realpathAlloc(arena, d) catch break :blk d; - } - break :blk try std.process.getCwdAlloc(arena); - }; + if (!builder.strip) debug_info: { + // We fully resolve all paths at this point to avoid lack of + // source line info in stack traces or lack of debugging + // information which, if relative paths were used, would be + // very location dependent. + // TODO: the only concern I have with this is WASI as either host or target, should + // we leave the paths as relative then? + // TODO: This is totally wrong. In dwarf, paths are encoded as relative to + // a particular directory, and then the directory path is specified elsewhere. + // In the compiler frontend we have it stored correctly in this + // way already, but here we throw all that sweet information + // into the garbage can by converting into absolute paths. What + // a terrible tragedy. + const compile_unit_dir = blk: { + if (comp.zcu) |zcu| m: { + const d = try zcu.main_mod.root.joinString(arena, ""); + if (d.len == 0) break :m; + if (std.fs.path.isAbsolute(d)) break :blk d; + break :blk std.fs.realpathAlloc(arena, d) catch break :blk d; + } + break :blk try std.process.getCwdAlloc(arena); + }; - const debug_file = try builder.debugFile( - try builder.metadataString(comp.root_name), - try builder.metadataString(compile_unit_dir), - ); + const debug_file = try builder.debugFile( + try builder.metadataString(comp.root_name), + try builder.metadataString(compile_unit_dir), + ); - const debug_enums_fwd_ref = try builder.debugForwardReference(); - const debug_globals_fwd_ref = try builder.debugForwardReference(); + const debug_enums_fwd_ref = try builder.debugForwardReference(); + const debug_globals_fwd_ref = try builder.debugForwardReference(); - const debug_compile_unit = try builder.debugCompileUnit( - debug_file, - // Don't use the version string here; LLVM misparses it when it - // includes the git revision. - try builder.metadataStringFmt("zig {d}.{d}.{d}", .{ - build_options.semver.major, - build_options.semver.minor, - build_options.semver.patch, - }), - debug_enums_fwd_ref, - debug_globals_fwd_ref, - .{ .optimized = comp.root_mod.optimize_mode != .Debug }, - ); + const debug_compile_unit = try builder.debugCompileUnit( + debug_file, + // Don't use the version string here; LLVM misparses it when it + // includes the git revision. + try builder.metadataStringFmt("zig {d}.{d}.{d}", .{ + build_options.semver.major, + build_options.semver.minor, + build_options.semver.patch, + }), + debug_enums_fwd_ref, + debug_globals_fwd_ref, + .{ .optimized = comp.root_mod.optimize_mode != .Debug }, + ); - try builder.metadataNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit}); - break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref }; - } else .{.none} ** 3; + try builder.metadataNamed(try builder.metadataString("llvm.dbg.cu"), &.{debug_compile_unit}); + break :debug_info .{ debug_compile_unit, debug_enums_fwd_ref, debug_globals_fwd_ref }; + } else .{.none} ** 3; const obj = try arena.create(Object); obj.* = .{ @@ -2759,9 +2758,9 @@ pub const Object = struct { const full_fields: [2]Builder.Metadata = if (layout.tag_align.compare(.gte, layout.payload_align)) - .{ debug_tag_type, debug_payload_type } - else - .{ debug_payload_type, debug_tag_type }; + .{ debug_tag_type, debug_payload_type } + else + .{ debug_payload_type, debug_tag_type }; const debug_tagged_union_type = try o.builder.debugStructType( try o.builder.metadataString(name), @@ -4551,11 +4550,11 @@ pub const Object = struct { // instruction is followed by a `wrap_optional`, it will return this value // verbatim, and the result should test as non-null. switch (zcu.getTarget().ptrBitWidth()) { - 16 => 0xaaaa, - 32 => 0xaaaaaaaa, - 64 => 0xaaaaaaaa_aaaaaaaa, - else => unreachable, - }; + 16 => 0xaaaa, + 32 => 0xaaaaaaaa, + 64 => 0xaaaaaaaa_aaaaaaaa, + else => unreachable, + }; const llvm_usize = try o.lowerType(Type.usize); const llvm_ptr_ty = try o.lowerType(ptr_ty); return o.builder.castConst(.inttoptr, try o.builder.intConst(llvm_usize, int), llvm_ptr_ty); @@ -9544,7 +9543,7 @@ pub const FuncGen = struct { if (llvm_dest_ty.isStruct(&o.builder) or ((operand_ty.zigTypeTag(zcu) == .vector or inst_ty.zigTypeTag(zcu) == .vector) and - operand_ty.bitSize(zcu) != inst_ty.bitSize(zcu))) + operand_ty.bitSize(zcu) != inst_ty.bitSize(zcu))) { // Both our operand and our result are values, not pointers, // but LLVM won't let us bitcast struct values or vectors with padding bits. diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 3a9ba1e149..44f0795969 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -3821,38 +3821,38 @@ const msdos_stub: [120]u8 = .{ 0x40, 0x00, // Absolute offset to relocation table. 64 matches the header size (all bytes before the MS-DOS stub program). 0x00, 0x00, // Overlay number. Zero means this is the main executable. } -// Reserved words. -++ .{ 0x00, 0x00 } ** 4 -// OEM-related fields. -++ .{ - 0x00, 0x00, // OEM identifier. - 0x00, 0x00, // OEM information. -} -// Reserved words. -++ .{ 0x00, 0x00 } ** 10 -// 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. -++ .{ 0x78, 0x00, 0x00, 0x00 } -// What follows is a 16-bit x86 MS-DOS program of 7 instructions that prints the bytes after these instructions and then exits. -++ .{ - // Set the value of the data segment to the same value as the code segment. - 0x0e, // push cs - 0x1f, // pop ds - // Set the DX register to the address of the message. - // If you count all bytes of these 7 instructions you get 14, so that's the address of what's after these instructions. - 0xba, 14, 0x00, // mov dx, 14 - // Set AH to the system call code for printing a message. - 0xb4, 0x09, // mov ah, 0x09 - // Perform the system call to print the message. - 0xcd, 0x21, // int 0x21 - // Set AH to 0x4c which is the system call code for exiting, and set AL to 0x01 which is the exit code. - 0xb8, 0x01, 0x4c, // mov ax, 0x4c01 - // Peform the system call to exit the program with exit code 1. - 0xcd, 0x21, // int 0x21 -} -// Message to print. -++ "This program cannot be run in DOS mode.".* -// Message terminators. -++ .{ - '$', // We do not pass a length to the print system call; the string is terminated by this character. - 0x00, 0x00, // Terminating zero bytes. -}; + // Reserved words. + ++ .{ 0x00, 0x00 } ** 4 + // OEM-related fields. + ++ .{ + 0x00, 0x00, // OEM identifier. + 0x00, 0x00, // OEM information. + } + // Reserved words. + ++ .{ 0x00, 0x00 } ** 10 + // 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. + ++ .{ 0x78, 0x00, 0x00, 0x00 } + // What follows is a 16-bit x86 MS-DOS program of 7 instructions that prints the bytes after these instructions and then exits. + ++ .{ + // Set the value of the data segment to the same value as the code segment. + 0x0e, // push cs + 0x1f, // pop ds + // Set the DX register to the address of the message. + // If you count all bytes of these 7 instructions you get 14, so that's the address of what's after these instructions. + 0xba, 14, 0x00, // mov dx, 14 + // Set AH to the system call code for printing a message. + 0xb4, 0x09, // mov ah, 0x09 + // Perform the system call to print the message. + 0xcd, 0x21, // int 0x21 + // Set AH to 0x4c which is the system call code for exiting, and set AL to 0x01 which is the exit code. + 0xb8, 0x01, 0x4c, // mov ax, 0x4c01 + // Peform the system call to exit the program with exit code 1. + 0xcd, 0x21, // int 0x21 + } + // Message to print. + ++ "This program cannot be run in DOS mode.".* + // Message terminators. + ++ .{ + '$', // We do not pass a length to the print system call; the string is terminated by this character. + 0x00, 0x00, // Terminating zero bytes. + }; diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index e2a189e8e7..61bcf24a76 100644 --- a/src/link/Dwarf.zig +++ b/src/link/Dwarf.zig @@ -1995,30 +1995,30 @@ pub const WipNav = struct { errdefer _ = if (!decl_gop.found_existing) dwarf.decls.pop(); const was_generic_decl = decl_gop.found_existing and switch (try dwarf.debug_info.declAbbrevCode(wip_nav.unit, decl_gop.value_ptr.*)) { - .null, - .decl_alias, - .decl_empty_enum, - .decl_enum, - .decl_namespace_struct, - .decl_struct, - .decl_packed_struct, - .decl_union, - .decl_var, - .decl_const, - .decl_const_runtime_bits, - .decl_const_comptime_state, - .decl_const_runtime_bits_comptime_state, - .decl_empty_func, - .decl_func, - .decl_empty_func_generic, - .decl_func_generic, - => false, - .generic_decl_var, - .generic_decl_const, - .generic_decl_func, - => true, - else => unreachable, - }; + .null, + .decl_alias, + .decl_empty_enum, + .decl_enum, + .decl_namespace_struct, + .decl_struct, + .decl_packed_struct, + .decl_union, + .decl_var, + .decl_const, + .decl_const_runtime_bits, + .decl_const_comptime_state, + .decl_const_runtime_bits_comptime_state, + .decl_empty_func, + .decl_func, + .decl_empty_func_generic, + .decl_func_generic, + => false, + .generic_decl_var, + .generic_decl_const, + .generic_decl_func, + => true, + else => unreachable, + }; if (parent_type.getCaptures(zcu).len == 0) { if (was_generic_decl) try dwarf.freeCommonEntry(wip_nav.unit, decl_gop.value_ptr.*); decl_gop.value_ptr.* = orig_entry; diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig index d6076a5558..f489294aa0 100644 --- a/src/link/Elf/Object.zig +++ b/src/link/Elf/Object.zig @@ -236,11 +236,11 @@ pub fn validateEFlags( const fabi: riscv.Eflags.FloatAbi = if (std.Target.riscv.featureSetHas(features, .d)) - .double - else if (std.Target.riscv.featureSetHas(features, .f)) - .single - else - .soft; + .double + else if (std.Target.riscv.featureSetHas(features, .f)) + .single + else + .soft; if (flags.fabi != fabi) { any_errors = true; diff --git a/src/link/Elf/relocatable.zig b/src/link/Elf/relocatable.zig index e8f9414da6..a33717d2d1 100644 --- a/src/link/Elf/relocatable.zig +++ b/src/link/Elf/relocatable.zig @@ -217,20 +217,20 @@ fn initSections(elf_file: *Elf) !void { if (elf_file.section_indexes.eh_frame == null) { elf_file.section_indexes.eh_frame = elf_file.sectionByName(".eh_frame") orelse try elf_file.addSection(.{ - .name = try elf_file.insertShString(".eh_frame"), - .type = if (elf_file.getTarget().cpu.arch == .x86_64) - elf.SHT_X86_64_UNWIND - else - elf.SHT_PROGBITS, - .flags = elf.SHF_ALLOC, - .addralign = elf_file.ptrWidthBytes(), - }); + .name = try elf_file.insertShString(".eh_frame"), + .type = if (elf_file.getTarget().cpu.arch == .x86_64) + elf.SHT_X86_64_UNWIND + else + elf.SHT_PROGBITS, + .flags = elf.SHF_ALLOC, + .addralign = elf_file.ptrWidthBytes(), + }); } elf_file.section_indexes.eh_frame_rela = elf_file.sectionByName(".rela.eh_frame") orelse try elf_file.addRelaShdr( - try elf_file.insertShString(".rela.eh_frame"), - elf_file.section_indexes.eh_frame.?, - ); + try elf_file.insertShString(".rela.eh_frame"), + elf_file.section_indexes.eh_frame.?, + ); } try initComdatGroups(elf_file); diff --git a/src/link/Elf/synthetic_sections.zig b/src/link/Elf/synthetic_sections.zig index 6d26ec5d1f..8364846019 100644 --- a/src/link/Elf/synthetic_sections.zig +++ b/src/link/Elf/synthetic_sections.zig @@ -551,7 +551,7 @@ pub const GotSection = struct { switch (entry.tag) { .got => if (symbol.?.flags.import or symbol.?.isIFunc(elf_file) or ((elf_file.isEffectivelyDynLib() or (elf_file.base.isExe() and comp.config.pie)) and - !symbol.?.isAbs(elf_file))) + !symbol.?.isAbs(elf_file))) { num += 1; }, diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 97a84809d7..486bca1857 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -1617,14 +1617,14 @@ fn initOutputSections(self: *MachO) !void { } self.text_sect_index = self.getSectionByName("__TEXT", "__text") orelse try self.addSection("__TEXT", "__text", .{ - .alignment = switch (self.getTarget().cpu.arch) { - .x86_64 => 0, - .aarch64 => 2, - else => unreachable, - }, - .flags = macho.S_REGULAR | - macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS, - }); + .alignment = switch (self.getTarget().cpu.arch) { + .x86_64 => 0, + .aarch64 => 2, + else => unreachable, + }, + .flags = macho.S_REGULAR | + macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS, + }); self.data_sect_index = self.getSectionByName("__DATA", "__data") orelse try self.addSection("__DATA", "__data", .{}); } diff --git a/src/link/MachO/Atom.zig b/src/link/MachO/Atom.zig index 4270ff0306..ab3b54bf1b 100644 --- a/src/link/MachO/Atom.zig +++ b/src/link/MachO/Atom.zig @@ -149,10 +149,10 @@ pub fn initOutputSection(sect: macho.section_64, macho_file: *MachO) !u8 { if (macho_file.base.isRelocatable()) { const osec = macho_file.getSectionByName(sect.segName(), sect.sectName()) orelse try macho_file.addSection( - sect.segName(), - sect.sectName(), - .{ .flags = sect.flags }, - ); + sect.segName(), + sect.sectName(), + .{ .flags = sect.flags }, + ); return osec; } diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig index 76fa43bc65..8e186d400a 100644 --- a/src/link/MachO/ZigObject.zig +++ b/src/link/MachO/ZigObject.zig @@ -1104,8 +1104,8 @@ fn createTlvDescriptor( const sect_index = macho_file.getSectionByName("__DATA", "__thread_vars") orelse try macho_file.addSection("__DATA", "__thread_vars", .{ - .flags = macho.S_THREAD_LOCAL_VARIABLES, - }); + .flags = macho.S_THREAD_LOCAL_VARIABLES, + }); sym.out_n_sect = sect_index; atom.out_n_sect = sect_index; diff --git a/src/link/MachO/dead_strip.zig b/src/link/MachO/dead_strip.zig index 30f53d3744..24d7e18d1a 100644 --- a/src/link/MachO/dead_strip.zig +++ b/src/link/MachO/dead_strip.zig @@ -102,8 +102,8 @@ fn mark(roots: []*Atom, objects: []const File.Index, macho_file: *MachO) void { const isec = atom.getInputSection(macho_file); if (isec.isDontDeadStripIfReferencesLive() and !(mem.eql(u8, isec.sectName(), "__eh_frame") or - mem.eql(u8, isec.sectName(), "__compact_unwind") or - isec.attrs() & macho.S_ATTR_DEBUG != 0) and + mem.eql(u8, isec.sectName(), "__compact_unwind") or + isec.attrs() & macho.S_ATTR_DEBUG != 0) and !atom.isAlive() and refersLive(atom, macho_file)) { markLive(atom, macho_file); diff --git a/src/main.zig b/src/main.zig index a5b0f23014..97a25a39fa 100644 --- a/src/main.zig +++ b/src/main.zig @@ -5919,8 +5919,8 @@ pub const ClangArgIterator = struct { self.arg_iterator_response_file = initArgIteratorResponseFile(arena, resp_file_path) catch |err| { - fatal("unable to read response file '{s}': {s}", .{ resp_file_path, @errorName(err) }); - }; + fatal("unable to read response file '{s}': {s}", .{ resp_file_path, @errorName(err) }); + }; // NOTE: The ArgIteratorResponseFile returns tokens from next() that are slices of an // internal buffer. This internal buffer is arena allocated, so it is not cleaned up here. @@ -6233,8 +6233,8 @@ fn cmdAstCheck( file.tree.?.tokens.len * (@sizeOf(std.zig.Token.Tag) + @sizeOf(Ast.ByteOffset)); const tree_bytes = @sizeOf(Ast) + file.tree.?.nodes.len * (@sizeOf(Ast.Node.Tag) + - @sizeOf(Ast.Node.Data) + - @sizeOf(Ast.TokenIndex)); + @sizeOf(Ast.Node.Data) + + @sizeOf(Ast.TokenIndex)); const instruction_bytes = file.zir.?.instructions.len * // Here we don't use @sizeOf(Zir.Inst.Data) because it would include // the debug safety tag but we want to measure release size. diff --git a/src/translate_c.zig b/src/translate_c.zig index 410791d3dc..19a2fde13c 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -2570,9 +2570,9 @@ fn transInitListExprRecord( // Unions and Structs are both represented as RecordDecl const record_ty = ty.getAsRecordType() orelse blk: { - is_union_type = true; - break :blk ty.getAsUnionType(); - } orelse unreachable; + is_union_type = true; + break :blk ty.getAsUnionType(); + } orelse unreachable; const record_decl = record_ty.getDecl(); const record_def = record_decl.getDefinition() orelse unreachable; @@ -4006,7 +4006,7 @@ fn transCPtrCast( if (!src_ty.isArrayType() and ((src_child_type.isConstQualified() and !child_type.isConstQualified()) or (src_child_type.isVolatileQualified() and - !child_type.isVolatileQualified()))) + !child_type.isVolatileQualified()))) { return removeCVQualifiers(c, dst_type_node, expr); } else { @@ -4092,8 +4092,8 @@ fn transFloatingLiteralQuad(c: *Context, expr: *const clang.FloatingLiteral, use false; break :fmt_decimal if (could_roundtrip) try c.arena.dupe(u8, temp_str) else null; } - // otherwise, fall back to the hexadecimal format - orelse try std.fmt.allocPrint(c.arena, "{x}", .{quad}); + // otherwise, fall back to the hexadecimal format + orelse try std.fmt.allocPrint(c.arena, "{x}", .{quad}); var node = try Tag.float_literal.create(c.arena, str); if (is_negative) node = try Tag.negate.create(c.arena, node); @@ -5080,15 +5080,14 @@ fn finishTransFnProto( const is_noalias = param_qt.isRestrictQualified(); const param_name: ?[]const u8 = - if (fn_decl) |decl| - blk: { - const param = decl.getParamDecl(@as(c_uint, @intCast(i))); - const param_name: []const u8 = try c.str(@as(*const clang.NamedDecl, @ptrCast(param)).getName_bytes_begin()); - if (param_name.len < 1) - break :blk null; + if (fn_decl) |decl| blk: { + const param = decl.getParamDecl(@as(c_uint, @intCast(i))); + const param_name: []const u8 = try c.str(@as(*const clang.NamedDecl, @ptrCast(param)).getName_bytes_begin()); + if (param_name.len < 1) + break :blk null; - break :blk param_name; - } else null; + break :blk param_name; + } else null; const type_node = try transQualType(c, scope, param_qt, source_loc); fn_params.addOneAssumeCapacity().* = .{ diff --git a/test/behavior/export_builtin.zig b/test/behavior/export_builtin.zig index 2b9a64b2ab..1d2f184acb 100644 --- a/test/behavior/export_builtin.zig +++ b/test/behavior/export_builtin.zig @@ -59,8 +59,8 @@ test "exporting comptime-known value" { if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_x86_64 and (builtin.target.ofmt != .elf and - builtin.target.ofmt != .macho and - builtin.target.ofmt != .coff)) return error.SkipZigTest; + builtin.target.ofmt != .macho and + builtin.target.ofmt != .coff)) return error.SkipZigTest; if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; diff --git a/test/link/elf.zig b/test/link/elf.zig index dfa5954032..dc48db9836 100644 --- a/test/link/elf.zig +++ b/test/link/elf.zig @@ -475,7 +475,7 @@ fn testCommentString(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "comment-string", opts); const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = - \\pub fn main() void {} + \\pub fn main() void {} }); const check = exe.checkObject(); @@ -490,7 +490,7 @@ fn testCommentStringStaticLib(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "comment-string-static-lib", opts); const lib = addStaticLibrary(b, opts, .{ .name = "lib", .zig_source_bytes = - \\export fn foo() void {} + \\export fn foo() void {} }); const check = lib.checkObject(); @@ -861,23 +861,23 @@ fn testEmitRelocatable(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "emit-relocatable", opts); const a_o = addObject(b, opts, .{ .name = "a", .zig_source_bytes = - \\const std = @import("std"); - \\extern var bar: i32; - \\export fn foo() i32 { - \\ return bar; - \\} - \\export fn printFoo() void { - \\ std.debug.print("foo={d}\n", .{foo()}); - \\} + \\const std = @import("std"); + \\extern var bar: i32; + \\export fn foo() i32 { + \\ return bar; + \\} + \\export fn printFoo() void { + \\ std.debug.print("foo={d}\n", .{foo()}); + \\} }); a_o.linkLibC(); const b_o = addObject(b, opts, .{ .name = "b", .c_source_bytes = - \\#include - \\int bar = 42; - \\void printBar() { - \\ fprintf(stderr, "bar=%d\n", bar); - \\} + \\#include + \\int bar = 42; + \\void printBar() { + \\ fprintf(stderr, "bar=%d\n", bar); + \\} }); b_o.linkLibC(); @@ -886,13 +886,13 @@ fn testEmitRelocatable(b: *Build, opts: Options) *Step { c_o.addObject(b_o); const exe = addExecutable(b, opts, .{ .name = "test", .zig_source_bytes = - \\const std = @import("std"); - \\extern fn printFoo() void; - \\extern fn printBar() void; - \\pub fn main() void { - \\ printFoo(); - \\ printBar(); - \\} + \\const std = @import("std"); + \\extern fn printFoo() void; + \\extern fn printBar() void; + \\pub fn main() void { + \\ printFoo(); + \\ printBar(); + \\} }); exe.addObject(c_o); exe.linkLibC(); @@ -1920,8 +1920,8 @@ fn testInitArrayOrder(b: *Build, opts: Options) *Step { g_o.linkLibC(); const h_o = addObject(b, opts, .{ .name = "h", .c_source_bytes = - \\#include - \\__attribute__((destructor)) void fini2() { printf("8"); } + \\#include + \\__attribute__((destructor)) void fini2() { printf("8"); } }); h_o.linkLibC(); @@ -2495,23 +2495,23 @@ fn testMergeStrings2(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "merge-strings2", opts); const obj1 = addObject(b, opts, .{ .name = "a", .zig_source_bytes = - \\const std = @import("std"); - \\export fn foo() void { - \\ var arr: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 }; - \\ const slice = std.mem.sliceTo(&arr, 3); - \\ std.testing.expectEqualSlices(u16, arr[0..2], slice) catch unreachable; - \\} + \\const std = @import("std"); + \\export fn foo() void { + \\ var arr: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 }; + \\ const slice = std.mem.sliceTo(&arr, 3); + \\ std.testing.expectEqualSlices(u16, arr[0..2], slice) catch unreachable; + \\} }); const obj2 = addObject(b, opts, .{ .name = "b", .zig_source_bytes = - \\const std = @import("std"); - \\extern fn foo() void; - \\pub fn main() void { - \\ foo(); - \\ var arr: [5:0]u16 = [_:0]u16{ 5, 4, 3, 2, 1 }; - \\ const slice = std.mem.sliceTo(&arr, 3); - \\ std.testing.expectEqualSlices(u16, arr[0..2], slice) catch unreachable; - \\} + \\const std = @import("std"); + \\extern fn foo() void; + \\pub fn main() void { + \\ foo(); + \\ var arr: [5:0]u16 = [_:0]u16{ 5, 4, 3, 2, 1 }; + \\ const slice = std.mem.sliceTo(&arr, 3); + \\ std.testing.expectEqualSlices(u16, arr[0..2], slice) catch unreachable; + \\} }); { @@ -2752,17 +2752,17 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step { }); obj2.linkLibCpp(); const obj3 = addObject(b, opts, .{ .name = "obj3", .cpp_source_bytes = - \\#include - \\#include - \\extern int try_again(); - \\int main() { - \\ try { - \\ try_again(); - \\ } catch (const std::exception &e) { - \\ std::cout << "exception=" << e.what(); - \\ } - \\ return 0; - \\} + \\#include + \\#include + \\extern int try_again(); + \\int main() { + \\ try { + \\ try_again(); + \\ } catch (const std::exception &e) { + \\ std::cout << "exception=" << e.what(); + \\ } + \\ return 0; + \\} }); obj3.linkLibCpp(); @@ -2864,15 +2864,15 @@ fn testRelocatableMergeStrings(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "relocatable-merge-strings", opts); const obj1 = addObject(b, opts, .{ .name = "a", .asm_source_bytes = - \\.section .rodata.str1.1,"aMS",@progbits,1 - \\val1: - \\.ascii "Hello \0" - \\.section .rodata.str1.1,"aMS",@progbits,1 - \\val5: - \\.ascii "World \0" - \\.section .rodata.str1.1,"aMS",@progbits,1 - \\val7: - \\.ascii "Hello \0" + \\.section .rodata.str1.1,"aMS",@progbits,1 + \\val1: + \\.ascii "Hello \0" + \\.section .rodata.str1.1,"aMS",@progbits,1 + \\val5: + \\.ascii "World \0" + \\.section .rodata.str1.1,"aMS",@progbits,1 + \\val7: + \\.ascii "Hello \0" }); const obj2 = addObject(b, opts, .{ .name = "b" }); @@ -3030,18 +3030,18 @@ fn testThunks(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "thunks", opts); const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\void foo(); - \\__attribute__((section(".bar"))) void bar() { - \\ return foo(); - \\} - \\__attribute__((section(".foo"))) void foo() { - \\ return bar(); - \\} - \\int main() { - \\ foo(); - \\ bar(); - \\ return 0; - \\} + \\void foo(); + \\__attribute__((section(".bar"))) void bar() { + \\ return foo(); + \\} + \\__attribute__((section(".foo"))) void foo() { + \\ return bar(); + \\} + \\int main() { + \\ foo(); + \\ bar(); + \\ return 0; + \\} }); const check = exe.checkObject(); diff --git a/test/link/macho.zig b/test/link/macho.zig index 289d0201f7..e12096bee0 100644 --- a/test/link/macho.zig +++ b/test/link/macho.zig @@ -109,20 +109,20 @@ fn testDeadStrip(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "dead-strip", opts); const obj = addObject(b, opts, .{ .name = "a", .cpp_source_bytes = - \\#include - \\int two() { return 2; } - \\int live_var1 = 1; - \\int live_var2 = two(); - \\int dead_var1 = 3; - \\int dead_var2 = 4; - \\void live_fn1() {} - \\void live_fn2() { live_fn1(); } - \\void dead_fn1() {} - \\void dead_fn2() { dead_fn1(); } - \\int main() { - \\ printf("%d %d\n", live_var1, live_var2); - \\ live_fn2(); - \\} + \\#include + \\int two() { return 2; } + \\int live_var1 = 1; + \\int live_var2 = two(); + \\int dead_var1 = 3; + \\int dead_var2 = 4; + \\void live_fn1() {} + \\void live_fn2() { live_fn1(); } + \\void dead_fn1() {} + \\void dead_fn2() { dead_fn1(); } + \\int main() { + \\ printf("%d %d\n", live_var1, live_var2); + \\ live_fn2(); + \\} }); { @@ -190,21 +190,21 @@ fn testDuplicateDefinitions(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "duplicate-definitions", opts); const obj = addObject(b, opts, .{ .name = "a", .zig_source_bytes = - \\var x: usize = 1; - \\export fn strong() void { x += 1; } - \\export fn weak() void { x += 1; } + \\var x: usize = 1; + \\export fn strong() void { x += 1; } + \\export fn weak() void { x += 1; } }); const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = - \\var x: usize = 1; - \\export fn strong() void { x += 1; } - \\comptime { @export(&weakImpl, .{ .name = "weak", .linkage = .weak }); } - \\fn weakImpl() callconv(.C) void { x += 1; } - \\extern fn weak() void; - \\pub fn main() void { - \\ weak(); - \\ strong(); - \\} + \\var x: usize = 1; + \\export fn strong() void { x += 1; } + \\comptime { @export(&weakImpl, .{ .name = "weak", .linkage = .weak }); } + \\fn weakImpl() callconv(.C) void { x += 1; } + \\extern fn weak() void; + \\pub fn main() void { + \\ weak(); + \\ strong(); + \\} }); exe.addObject(obj); @@ -221,16 +221,16 @@ fn testDeadStripDylibs(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "dead-strip-dylibs", opts); const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\int main() { - \\ if (objc_getClass("NSObject") == 0) { - \\ return -1; - \\ } - \\ if (objc_getClass("NSApplication") == 0) { - \\ return -2; - \\ } - \\ return 0; - \\} + \\#include + \\int main() { + \\ if (objc_getClass("NSObject") == 0) { + \\ return -1; + \\ } + \\ if (objc_getClass("NSApplication") == 0) { + \\ return -2; + \\ } + \\ return 0; + \\} }); { @@ -270,11 +270,11 @@ fn testDylib(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "dylib", opts); const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = - \\#include - \\char world[] = "world"; - \\char* hello() { - \\ return "Hello"; - \\} + \\#include + \\char world[] = "world"; + \\char* hello() { + \\ return "Hello"; + \\} }); const check = dylib.checkObject(); @@ -284,13 +284,13 @@ fn testDylib(b: *Build, opts: Options) *Step { test_step.dependOn(&check.step); const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\char* hello(); - \\extern char world[]; - \\int main() { - \\ printf("%s %s", hello(), world); - \\ return 0; - \\} + \\#include + \\char* hello(); + \\extern char world[]; + \\int main() { + \\ printf("%s %s", hello(), world); + \\ return 0; + \\} }); exe.root_module.linkSystemLibrary("a", .{}); exe.root_module.addLibraryPath(dylib.getEmittedBinDirectory()); @@ -345,10 +345,10 @@ fn testEmptyObject(b: *Build, opts: Options) *Step { const empty = addObject(b, opts, .{ .name = "empty", .c_source_bytes = "" }); const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\int main() { - \\ printf("Hello world!"); - \\} + \\#include + \\int main() { + \\ printf("Hello world!"); + \\} }); exe.addObject(empty); @@ -375,11 +375,11 @@ fn testEntryPoint(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "entry-point", opts); const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\int non_main() { - \\ printf("%d", 42); - \\ return 0; - \\} + \\#include + \\int non_main() { + \\ printf("%d", 42); + \\ return 0; + \\} }); exe.entry = .{ .symbol_name = "_non_main" }; @@ -597,10 +597,10 @@ fn testHeaderWeakFlags(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "header-weak-flags", opts); const obj1 = addObject(b, opts, .{ .name = "a", .asm_source_bytes = - \\.globl _x - \\.weak_definition _x - \\_x: - \\ ret + \\.globl _x + \\.weak_definition _x + \\_x: + \\ ret }); const lib = addSharedLibrary(b, opts, .{ .name = "a" }); @@ -659,11 +659,11 @@ fn testHeaderWeakFlags(b: *Build, opts: Options) *Step { { const exe = addExecutable(b, opts, .{ .name = "main3", .asm_source_bytes = - \\.globl _main, _x - \\_x: - \\ - \\_main: - \\ ret + \\.globl _main, _x + \\_x: + \\ + \\_main: + \\ ret }); exe.linkLibrary(lib); @@ -684,11 +684,11 @@ fn testHelloC(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "hello-c", opts); const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\int main() { - \\ printf("Hello world!\n"); - \\ return 0; - \\} + \\#include + \\int main() { + \\ printf("Hello world!\n"); + \\ return 0; + \\} }); const run = addRunArtifact(exe); @@ -708,10 +708,10 @@ fn testHelloZig(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "hello-zig", opts); const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = - \\const std = @import("std"); - \\pub fn main() void { - \\ std.io.getStdOut().writer().print("Hello world!\n", .{}) catch unreachable; - \\} + \\const std = @import("std"); + \\pub fn main() void { + \\ std.io.getStdOut().writer().print("Hello world!\n", .{}) catch unreachable; + \\} }); const run = addRunArtifact(exe); @@ -729,10 +729,10 @@ fn testLargeBss(b: *Build, opts: Options) *Step { // maybe S_GB_ZEROFILL section is an answer to this but it doesn't seem supported by dyld // anymore. When I get some free time I will re-investigate this. const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\char arr[0x1000000]; - \\int main() { - \\ return arr[2000]; - \\} + \\char arr[0x1000000]; + \\int main() { + \\ return arr[2000]; + \\} }); const run = addRunArtifact(exe); @@ -746,11 +746,11 @@ fn testLayout(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "layout", opts); const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\int main() { - \\ printf("Hello world!"); - \\ return 0; - \\} + \\#include + \\int main() { + \\ printf("Hello world!"); + \\ return 0; + \\} }); const check = exe.checkObject(); @@ -936,15 +936,15 @@ fn testLinksection(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "linksection", opts); const obj = addObject(b, opts, .{ .name = "main", .zig_source_bytes = - \\export var test_global: u32 linksection("__DATA,__TestGlobal") = undefined; - \\export fn testFn() linksection("__TEXT,__TestFn") callconv(.C) void { - \\ TestGenericFn("A").f(); - \\} - \\fn TestGenericFn(comptime suffix: []const u8) type { - \\ return struct { - \\ fn f() linksection("__TEXT,__TestGenFn" ++ suffix) void {} - \\ }; - \\} + \\export var test_global: u32 linksection("__DATA,__TestGlobal") = undefined; + \\export fn testFn() linksection("__TEXT,__TestFn") callconv(.C) void { + \\ TestGenericFn("A").f(); + \\} + \\fn TestGenericFn(comptime suffix: []const u8) type { + \\ return struct { + \\ fn f() linksection("__TEXT,__TestGenFn" ++ suffix) void {} + \\ }; + \\} }); const check = obj.checkObject(); @@ -967,71 +967,71 @@ fn testMergeLiteralsX64(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "merge-literals-x64", opts); const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = - \\.globl _q1 - \\.globl _s1 - \\ - \\.align 4 - \\_q1: - \\ lea L._q1(%rip), %rax - \\ mov (%rax), %xmm0 - \\ ret - \\ - \\.section __TEXT,__cstring,cstring_literals - \\l._s1: - \\ .asciz "hello" - \\ - \\.section __TEXT,__literal8,8byte_literals - \\.align 8 - \\L._q1: - \\ .double 1.2345 - \\ - \\.section __DATA,__data - \\.align 8 - \\_s1: - \\ .quad l._s1 + \\.globl _q1 + \\.globl _s1 + \\ + \\.align 4 + \\_q1: + \\ lea L._q1(%rip), %rax + \\ mov (%rax), %xmm0 + \\ ret + \\ + \\.section __TEXT,__cstring,cstring_literals + \\l._s1: + \\ .asciz "hello" + \\ + \\.section __TEXT,__literal8,8byte_literals + \\.align 8 + \\L._q1: + \\ .double 1.2345 + \\ + \\.section __DATA,__data + \\.align 8 + \\_s1: + \\ .quad l._s1 }); const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes = - \\.globl _q2 - \\.globl _s2 - \\.globl _s3 - \\ - \\.align 4 - \\_q2: - \\ lea L._q2(%rip), %rax - \\ mov (%rax), %xmm0 - \\ ret - \\ - \\.section __TEXT,__cstring,cstring_literals - \\l._s2: - \\ .asciz "hello" - \\l._s3: - \\ .asciz "world" - \\ - \\.section __TEXT,__literal8,8byte_literals - \\.align 8 - \\L._q2: - \\ .double 1.2345 - \\ - \\.section __DATA,__data - \\.align 8 - \\_s2: - \\ .quad l._s2 - \\_s3: - \\ .quad l._s3 + \\.globl _q2 + \\.globl _s2 + \\.globl _s3 + \\ + \\.align 4 + \\_q2: + \\ lea L._q2(%rip), %rax + \\ mov (%rax), %xmm0 + \\ ret + \\ + \\.section __TEXT,__cstring,cstring_literals + \\l._s2: + \\ .asciz "hello" + \\l._s3: + \\ .asciz "world" + \\ + \\.section __TEXT,__literal8,8byte_literals + \\.align 8 + \\L._q2: + \\ .double 1.2345 + \\ + \\.section __DATA,__data + \\.align 8 + \\_s2: + \\ .quad l._s2 + \\_s3: + \\ .quad l._s3 }); const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\extern double q1(); - \\extern double q2(); - \\extern const char* s1; - \\extern const char* s2; - \\extern const char* s3; - \\int main() { - \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2()); - \\ return 0; - \\} + \\#include + \\extern double q1(); + \\extern double q2(); + \\extern const char* s1; + \\extern const char* s2; + \\extern const char* s3; + \\int main() { + \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2()); + \\ return 0; + \\} }); const runWithChecks = struct { @@ -1083,71 +1083,71 @@ fn testMergeLiteralsArm64(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "merge-literals-arm64", opts); const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = - \\.globl _q1 - \\.globl _s1 - \\ - \\.align 4 - \\_q1: - \\ adrp x8, L._q1@PAGE - \\ ldr d0, [x8, L._q1@PAGEOFF] - \\ ret - \\ - \\.section __TEXT,__cstring,cstring_literals - \\l._s1: - \\ .asciz "hello" - \\ - \\.section __TEXT,__literal8,8byte_literals - \\.align 8 - \\L._q1: - \\ .double 1.2345 - \\ - \\.section __DATA,__data - \\.align 8 - \\_s1: - \\ .quad l._s1 + \\.globl _q1 + \\.globl _s1 + \\ + \\.align 4 + \\_q1: + \\ adrp x8, L._q1@PAGE + \\ ldr d0, [x8, L._q1@PAGEOFF] + \\ ret + \\ + \\.section __TEXT,__cstring,cstring_literals + \\l._s1: + \\ .asciz "hello" + \\ + \\.section __TEXT,__literal8,8byte_literals + \\.align 8 + \\L._q1: + \\ .double 1.2345 + \\ + \\.section __DATA,__data + \\.align 8 + \\_s1: + \\ .quad l._s1 }); const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes = - \\.globl _q2 - \\.globl _s2 - \\.globl _s3 - \\ - \\.align 4 - \\_q2: - \\ adrp x8, L._q2@PAGE - \\ ldr d0, [x8, L._q2@PAGEOFF] - \\ ret - \\ - \\.section __TEXT,__cstring,cstring_literals - \\l._s2: - \\ .asciz "hello" - \\l._s3: - \\ .asciz "world" - \\ - \\.section __TEXT,__literal8,8byte_literals - \\.align 8 - \\L._q2: - \\ .double 1.2345 - \\ - \\.section __DATA,__data - \\.align 8 - \\_s2: - \\ .quad l._s2 - \\_s3: - \\ .quad l._s3 + \\.globl _q2 + \\.globl _s2 + \\.globl _s3 + \\ + \\.align 4 + \\_q2: + \\ adrp x8, L._q2@PAGE + \\ ldr d0, [x8, L._q2@PAGEOFF] + \\ ret + \\ + \\.section __TEXT,__cstring,cstring_literals + \\l._s2: + \\ .asciz "hello" + \\l._s3: + \\ .asciz "world" + \\ + \\.section __TEXT,__literal8,8byte_literals + \\.align 8 + \\L._q2: + \\ .double 1.2345 + \\ + \\.section __DATA,__data + \\.align 8 + \\_s2: + \\ .quad l._s2 + \\_s3: + \\ .quad l._s3 }); const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\extern double q1(); - \\extern double q2(); - \\extern const char* s1; - \\extern const char* s2; - \\extern const char* s3; - \\int main() { - \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2()); - \\ return 0; - \\} + \\#include + \\extern double q1(); + \\extern double q2(); + \\extern const char* s1; + \\extern const char* s2; + \\extern const char* s3; + \\int main() { + \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2()); + \\ return 0; + \\} }); const runWithChecks = struct { @@ -1203,59 +1203,59 @@ fn testMergeLiteralsArm642(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "merge-literals-arm64-2", opts); const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = - \\.globl _q1 - \\.globl _s1 - \\ - \\.align 4 - \\_q1: - \\ adrp x0, L._q1@PAGE - \\ ldr x0, [x0, L._q1@PAGEOFF] - \\ ret - \\ - \\.section __TEXT,__cstring,cstring_literals - \\_s1: - \\ .asciz "hello" - \\ - \\.section __TEXT,__literal8,8byte_literals - \\.align 8 - \\L._q1: - \\ .double 1.2345 + \\.globl _q1 + \\.globl _s1 + \\ + \\.align 4 + \\_q1: + \\ adrp x0, L._q1@PAGE + \\ ldr x0, [x0, L._q1@PAGEOFF] + \\ ret + \\ + \\.section __TEXT,__cstring,cstring_literals + \\_s1: + \\ .asciz "hello" + \\ + \\.section __TEXT,__literal8,8byte_literals + \\.align 8 + \\L._q1: + \\ .double 1.2345 }); const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes = - \\.globl _q2 - \\.globl _s2 - \\.globl _s3 - \\ - \\.align 4 - \\_q2: - \\ adrp x0, L._q2@PAGE - \\ ldr x0, [x0, L._q2@PAGEOFF] - \\ ret - \\ - \\.section __TEXT,__cstring,cstring_literals - \\_s2: - \\ .asciz "hello" - \\_s3: - \\ .asciz "world" - \\ - \\.section __TEXT,__literal8,8byte_literals - \\.align 8 - \\L._q2: - \\ .double 1.2345 + \\.globl _q2 + \\.globl _s2 + \\.globl _s3 + \\ + \\.align 4 + \\_q2: + \\ adrp x0, L._q2@PAGE + \\ ldr x0, [x0, L._q2@PAGEOFF] + \\ ret + \\ + \\.section __TEXT,__cstring,cstring_literals + \\_s2: + \\ .asciz "hello" + \\_s3: + \\ .asciz "world" + \\ + \\.section __TEXT,__literal8,8byte_literals + \\.align 8 + \\L._q2: + \\ .double 1.2345 }); const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\extern double q1(); - \\extern double q2(); - \\extern const char* s1; - \\extern const char* s2; - \\extern const char* s3; - \\int main() { - \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2()); - \\ return 0; - \\} + \\#include + \\extern double q1(); + \\extern double q2(); + \\extern const char* s1; + \\extern const char* s2; + \\extern const char* s3; + \\int main() { + \\ printf("%s, %s, %s, %f, %f", s1, s2, s3, q1(), q2()); + \\ return 0; + \\} }); const exe = addExecutable(b, opts, .{ .name = "main1" }); @@ -1277,43 +1277,43 @@ fn testMergeLiteralsAlignment(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "merge-literals-alignment", opts); const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = - \\.globl _s1 - \\.globl _s2 - \\ - \\.section __TEXT,__cstring,cstring_literals - \\.align 3 - \\_s1: - \\ .asciz "str1" - \\_s2: - \\ .asciz "str2" + \\.globl _s1 + \\.globl _s2 + \\ + \\.section __TEXT,__cstring,cstring_literals + \\.align 3 + \\_s1: + \\ .asciz "str1" + \\_s2: + \\ .asciz "str2" }); const b_o = addObject(b, opts, .{ .name = "b", .asm_source_bytes = - \\.globl _s3 - \\.globl _s4 - \\ - \\.section __TEXT,__cstring,cstring_literals - \\.align 2 - \\_s3: - \\ .asciz "str1" - \\_s4: - \\ .asciz "str2" + \\.globl _s3 + \\.globl _s4 + \\ + \\.section __TEXT,__cstring,cstring_literals + \\.align 2 + \\_s3: + \\ .asciz "str1" + \\_s4: + \\ .asciz "str2" }); const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\#include - \\#include - \\extern const char* s1; - \\extern const char* s2; - \\extern const char* s3; - \\extern const char* s4; - \\int main() { - \\ assert((uintptr_t)(&s1) % 8 == 0 && s1 == s3); - \\ assert((uintptr_t)(&s2) % 8 == 0 && s2 == s4); - \\ printf("%s%s%s%s", &s1, &s2, &s3, &s4); - \\ return 0; - \\} + \\#include + \\#include + \\#include + \\extern const char* s1; + \\extern const char* s2; + \\extern const char* s3; + \\extern const char* s4; + \\int main() { + \\ assert((uintptr_t)(&s1) % 8 == 0 && s1 == s3); + \\ assert((uintptr_t)(&s2) % 8 == 0 && s2 == s4); + \\ printf("%s%s%s%s", &s1, &s2, &s3, &s4); + \\ return 0; + \\} , .c_source_flags = &.{"-Wno-format"} }); const runWithChecks = struct { @@ -1356,39 +1356,39 @@ fn testMergeLiteralsObjc(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "merge-literals-objc", opts); const main_o = addObject(b, opts, .{ .name = "main", .objc_source_bytes = - \\#import ; - \\ - \\extern void foo(); - \\ - \\int main() { - \\ NSString *thing = @"aaa"; - \\ - \\ SEL sel = @selector(lowercaseString); - \\ NSString *lower = (([thing respondsToSelector:sel]) ? @"YES" : @"NO"); - \\ NSLog (@"Responds to lowercaseString: %@", lower); - \\ if ([thing respondsToSelector:sel]) //(lower == @"YES") - \\ NSLog(@"lowercaseString is: %@", [thing lowercaseString]); - \\ - \\ foo(); - \\} + \\#import ; + \\ + \\extern void foo(); + \\ + \\int main() { + \\ NSString *thing = @"aaa"; + \\ + \\ SEL sel = @selector(lowercaseString); + \\ NSString *lower = (([thing respondsToSelector:sel]) ? @"YES" : @"NO"); + \\ NSLog (@"Responds to lowercaseString: %@", lower); + \\ if ([thing respondsToSelector:sel]) //(lower == @"YES") + \\ NSLog(@"lowercaseString is: %@", [thing lowercaseString]); + \\ + \\ foo(); + \\} }); const a_o = addObject(b, opts, .{ .name = "a", .objc_source_bytes = - \\#import ; - \\ - \\void foo() { - \\ NSString *thing = @"aaa"; - \\ SEL sel = @selector(lowercaseString); - \\ NSString *lower = (([thing respondsToSelector:sel]) ? @"YES" : @"NO"); - \\ NSLog (@"Responds to lowercaseString in foo(): %@", lower); - \\ if ([thing respondsToSelector:sel]) //(lower == @"YES") - \\ NSLog(@"lowercaseString in foo() is: %@", [thing lowercaseString]); - \\ SEL sel2 = @selector(uppercaseString); - \\ NSString *upper = (([thing respondsToSelector:sel2]) ? @"YES" : @"NO"); - \\ NSLog (@"Responds to uppercaseString in foo(): %@", upper); - \\ if ([thing respondsToSelector:sel2]) //(upper == @"YES") - \\ NSLog(@"uppercaseString in foo() is: %@", [thing uppercaseString]); - \\} + \\#import ; + \\ + \\void foo() { + \\ NSString *thing = @"aaa"; + \\ SEL sel = @selector(lowercaseString); + \\ NSString *lower = (([thing respondsToSelector:sel]) ? @"YES" : @"NO"); + \\ NSLog (@"Responds to lowercaseString in foo(): %@", lower); + \\ if ([thing respondsToSelector:sel]) //(lower == @"YES") + \\ NSLog(@"lowercaseString in foo() is: %@", [thing lowercaseString]); + \\ SEL sel2 = @selector(uppercaseString); + \\ NSString *upper = (([thing respondsToSelector:sel2]) ? @"YES" : @"NO"); + \\ NSLog (@"Responds to uppercaseString in foo(): %@", upper); + \\ if ([thing respondsToSelector:sel2]) //(upper == @"YES") + \\ NSLog(@"uppercaseString in foo() is: %@", [thing uppercaseString]); + \\} }); const runWithChecks = struct { @@ -1459,12 +1459,12 @@ fn testNoDeadStrip(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "no-dead-strip", opts); const exe = addExecutable(b, opts, .{ .name = "name", .c_source_bytes = - \\__attribute__((used)) int bogus1 = 0; - \\int bogus2 = 0; - \\int foo = 42; - \\int main() { - \\ return foo - 42; - \\} + \\__attribute__((used)) int bogus1 = 0; + \\int bogus2 = 0; + \\int foo = 42; + \\int main() { + \\ return foo - 42; + \\} }); exe.link_gc_sections = true; @@ -1543,11 +1543,11 @@ fn testObjc(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "objc", opts); const lib = addStaticLibrary(b, opts, .{ .name = "a", .objc_source_bytes = - \\#import - \\@interface Foo : NSObject - \\@end - \\@implementation Foo - \\@end + \\#import + \\@interface Foo : NSObject + \\@end + \\@implementation Foo + \\@end }); { @@ -1600,32 +1600,32 @@ fn testObjcpp(b: *Build, opts: Options) *Step { }; const foo_o = addObject(b, opts, .{ .name = "foo", .objcpp_source_bytes = - \\#import "Foo.h" - \\@implementation Foo - \\- (NSString *)name - \\{ - \\ NSString *str = [[NSString alloc] initWithFormat:@"Zig"]; - \\ return str; - \\} - \\@end + \\#import "Foo.h" + \\@implementation Foo + \\- (NSString *)name + \\{ + \\ NSString *str = [[NSString alloc] initWithFormat:@"Zig"]; + \\ return str; + \\} + \\@end }); foo_o.root_module.addIncludePath(foo_h.dirname()); foo_o.linkLibCpp(); const exe = addExecutable(b, opts, .{ .name = "main", .objcpp_source_bytes = - \\#import "Foo.h" - \\#import - \\#include - \\int main(int argc, char *argv[]) - \\{ - \\ @autoreleasepool { - \\ Foo *foo = [[Foo alloc] init]; - \\ NSString *result = [foo name]; - \\ std::cout << "Hello from C++ and " << [result UTF8String]; - \\ assert([result isEqualToString:@"Zig"]); - \\ return 0; - \\ } - \\} + \\#import "Foo.h" + \\#import + \\#include + \\int main(int argc, char *argv[]) + \\{ + \\ @autoreleasepool { + \\ Foo *foo = [[Foo alloc] init]; + \\ NSString *result = [foo name]; + \\ std::cout << "Hello from C++ and " << [result UTF8String]; + \\ assert([result isEqualToString:@"Zig"]); + \\ return 0; + \\ } + \\} }); exe.root_module.addIncludePath(foo_h.dirname()); exe.addObject(foo_o); @@ -1677,21 +1677,21 @@ fn testReexportsZig(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "reexports-zig", opts); const lib = addStaticLibrary(b, opts, .{ .name = "a", .zig_source_bytes = - \\const x: i32 = 42; - \\export fn foo() i32 { - \\ return x; - \\} - \\comptime { - \\ @export(&foo, .{ .name = "bar", .linkage = .strong }); - \\} + \\const x: i32 = 42; + \\export fn foo() i32 { + \\ return x; + \\} + \\comptime { + \\ @export(&foo, .{ .name = "bar", .linkage = .strong }); + \\} }); const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\extern int foo(); - \\extern int bar(); - \\int main() { - \\ return bar() - foo(); - \\} + \\extern int foo(); + \\extern int bar(); + \\int main() { + \\ return bar() - foo(); + \\} }); exe.linkLibrary(lib); @@ -1706,32 +1706,32 @@ fn testRelocatable(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "relocatable", opts); const a_o = addObject(b, opts, .{ .name = "a", .cpp_source_bytes = - \\#include - \\int try_me() { - \\ throw std::runtime_error("Oh no!"); - \\} + \\#include + \\int try_me() { + \\ throw std::runtime_error("Oh no!"); + \\} }); a_o.linkLibCpp(); const b_o = addObject(b, opts, .{ .name = "b", .cpp_source_bytes = - \\extern int try_me(); - \\int try_again() { - \\ return try_me(); - \\} + \\extern int try_me(); + \\int try_again() { + \\ return try_me(); + \\} }); const main_o = addObject(b, opts, .{ .name = "main", .cpp_source_bytes = - \\#include - \\#include - \\extern int try_again(); - \\int main() { - \\ try { - \\ try_again(); - \\ } catch (const std::exception &e) { - \\ std::cout << "exception=" << e.what(); - \\ } - \\ return 0; - \\} + \\#include + \\#include + \\extern int try_again(); + \\int main() { + \\ try { + \\ try_again(); + \\ } catch (const std::exception &e) { + \\ std::cout << "exception=" << e.what(); + \\ } + \\ return 0; + \\} }); main_o.linkLibCpp(); @@ -1774,34 +1774,34 @@ fn testRelocatableZig(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "relocatable-zig", opts); const a_o = addObject(b, opts, .{ .name = "a", .zig_source_bytes = - \\const std = @import("std"); - \\export var foo: i32 = 0; - \\export fn incrFoo() void { - \\ foo += 1; - \\ std.debug.print("incrFoo={d}\n", .{foo}); - \\} + \\const std = @import("std"); + \\export var foo: i32 = 0; + \\export fn incrFoo() void { + \\ foo += 1; + \\ std.debug.print("incrFoo={d}\n", .{foo}); + \\} }); const b_o = addObject(b, opts, .{ .name = "b", .zig_source_bytes = - \\const std = @import("std"); - \\extern var foo: i32; - \\export fn decrFoo() void { - \\ foo -= 1; - \\ std.debug.print("decrFoo={d}\n", .{foo}); - \\} + \\const std = @import("std"); + \\extern var foo: i32; + \\export fn decrFoo() void { + \\ foo -= 1; + \\ std.debug.print("decrFoo={d}\n", .{foo}); + \\} }); const main_o = addObject(b, opts, .{ .name = "main", .zig_source_bytes = - \\const std = @import("std"); - \\extern var foo: i32; - \\extern fn incrFoo() void; - \\extern fn decrFoo() void; - \\pub fn main() void { - \\ const init = foo; - \\ incrFoo(); - \\ decrFoo(); - \\ if (init == foo) @panic("Oh no!"); - \\} + \\const std = @import("std"); + \\extern var foo: i32; + \\extern fn incrFoo() void; + \\extern fn decrFoo() void; + \\pub fn main() void { + \\ const init = foo; + \\ incrFoo(); + \\ decrFoo(); + \\ if (init == foo) @panic("Oh no!"); + \\} }); const c_o = addObject(b, opts, .{ .name = "c" }); @@ -1825,11 +1825,11 @@ fn testSearchStrategy(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "search-strategy", opts); const obj = addObject(b, opts, .{ .name = "a", .c_source_bytes = - \\#include - \\char world[] = "world"; - \\char* hello() { - \\ return "Hello"; - \\} + \\#include + \\char world[] = "world"; + \\char* hello() { + \\ return "Hello"; + \\} }); const liba = addStaticLibrary(b, opts, .{ .name = "a" }); @@ -1839,13 +1839,13 @@ fn testSearchStrategy(b: *Build, opts: Options) *Step { dylib.addObject(obj); const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\char* hello(); - \\extern char world[]; - \\int main() { - \\ printf("%s %s", hello(), world); - \\ return 0; - \\} + \\#include + \\char* hello(); + \\extern char world[]; + \\int main() { + \\ printf("%s %s", hello(), world); + \\ return 0; + \\} }); { @@ -1973,23 +1973,23 @@ fn testSectionBoundarySymbols2(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "section-boundary-symbols-2", opts); const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\struct pair { int a; int b; }; - \\struct pair first __attribute__((section("__DATA,__pairs"))) = { 1, 2 }; - \\struct pair second __attribute__((section("__DATA,__pairs"))) = { 3, 4 }; - \\extern struct pair pairs_start __asm("section$start$__DATA$__pairs"); - \\extern struct pair pairs_end __asm("section$end$__DATA$__pairs"); - \\int main() { - \\ printf("%d,%d\n", first.a, first.b); - \\ printf("%d,%d\n", second.a, second.b); - \\ struct pair* p; - \\ for (p = &pairs_start; p < &pairs_end; p++) { - \\ p->a = 0; - \\ } - \\ printf("%d,%d\n", first.a, first.b); - \\ printf("%d,%d\n", second.a, second.b); - \\ return 0; - \\} + \\#include + \\struct pair { int a; int b; }; + \\struct pair first __attribute__((section("__DATA,__pairs"))) = { 1, 2 }; + \\struct pair second __attribute__((section("__DATA,__pairs"))) = { 3, 4 }; + \\extern struct pair pairs_start __asm("section$start$__DATA$__pairs"); + \\extern struct pair pairs_end __asm("section$end$__DATA$__pairs"); + \\int main() { + \\ printf("%d,%d\n", first.a, first.b); + \\ printf("%d,%d\n", second.a, second.b); + \\ struct pair* p; + \\ for (p = &pairs_start; p < &pairs_end; p++) { + \\ p->a = 0; + \\ } + \\ printf("%d,%d\n", first.a, first.b); + \\ printf("%d,%d\n", second.a, second.b); + \\ return 0; + \\} }); const run = b.addRunArtifact(exe); @@ -2010,24 +2010,24 @@ fn testSegmentBoundarySymbols(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "segment-boundary-symbols", opts); const obj1 = addObject(b, opts, .{ .name = "a", .cpp_source_bytes = - \\constexpr const char* MESSAGE __attribute__((used, section("__DATA_CONST_1,__message_ptr"))) = "codebase"; + \\constexpr const char* MESSAGE __attribute__((used, section("__DATA_CONST_1,__message_ptr"))) = "codebase"; }); const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\const char* interop(); - \\int main() { - \\ printf("All your %s are belong to us.\n", interop()); - \\ return 0; - \\} + \\#include + \\const char* interop(); + \\int main() { + \\ printf("All your %s are belong to us.\n", interop()); + \\ return 0; + \\} }); { const obj2 = addObject(b, opts, .{ .name = "b", .cpp_source_bytes = - \\extern const char* message_pointer __asm("segment$start$__DATA_CONST_1"); - \\extern "C" const char* interop() { - \\ return message_pointer; - \\} + \\extern const char* message_pointer __asm("segment$start$__DATA_CONST_1"); + \\extern "C" const char* interop() { + \\ return message_pointer; + \\} }); const exe = addExecutable(b, opts, .{ .name = "main" }); @@ -2047,10 +2047,10 @@ fn testSegmentBoundarySymbols(b: *Build, opts: Options) *Step { { const obj2 = addObject(b, opts, .{ .name = "c", .cpp_source_bytes = - \\extern const char* message_pointer __asm("segment$start$__DATA_1"); - \\extern "C" const char* interop() { - \\ return message_pointer; - \\} + \\extern const char* message_pointer __asm("segment$start$__DATA_1"); + \\extern "C" const char* interop() { + \\ return message_pointer; + \\} }); const exe = addExecutable(b, opts, .{ .name = "main2" }); @@ -2078,27 +2078,27 @@ fn testSymbolStabs(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "symbol-stabs", opts); const a_o = addObject(b, opts, .{ .name = "a", .c_source_bytes = - \\int foo = 42; - \\int getFoo() { - \\ return foo; - \\} + \\int foo = 42; + \\int getFoo() { + \\ return foo; + \\} }); const b_o = addObject(b, opts, .{ .name = "b", .c_source_bytes = - \\int bar = 24; - \\int getBar() { - \\ return bar; - \\} + \\int bar = 24; + \\int getBar() { + \\ return bar; + \\} }); const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\extern int getFoo(); - \\extern int getBar(); - \\int main() { - \\ printf("foo=%d,bar=%d", getFoo(), getBar()); - \\ return 0; - \\} + \\#include + \\extern int getFoo(); + \\extern int getBar(); + \\int main() { + \\ printf("foo=%d,bar=%d", getFoo(), getBar()); + \\ return 0; + \\} }); const exe = addExecutable(b, opts, .{ .name = "main" }); @@ -2162,11 +2162,11 @@ fn testTbdv3(b: *Build, opts: Options) *Step { }; const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\int getFoo(); - \\int main() { - \\ return getFoo() - 42; - \\} + \\#include + \\int getFoo(); + \\int main() { + \\ return getFoo() - 42; + \\} }); exe.root_module.linkSystemLibrary("a", .{}); exe.root_module.addLibraryPath(tbd.dirname()); @@ -2209,18 +2209,18 @@ fn testThunks(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "thunks", opts); const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\void bar() { - \\ printf("bar"); - \\} - \\void foo() { - \\ fprintf(stdout, "foo"); - \\} - \\int main() { - \\ foo(); - \\ bar(); - \\ return 0; - \\} + \\#include + \\void bar() { + \\ printf("bar"); + \\} + \\void foo() { + \\ fprintf(stdout, "foo"); + \\} + \\int main() { + \\ foo(); + \\ bar(); + \\ return 0; + \\} }); const check = exe.checkObject(); @@ -2241,24 +2241,24 @@ fn testTls(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "tls", opts); const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = - \\_Thread_local int a; - \\int getA() { - \\ return a; - \\} + \\_Thread_local int a; + \\int getA() { + \\ return a; + \\} }); const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\extern _Thread_local int a; - \\extern int getA(); - \\int getA2() { - \\ return a; - \\} - \\int main() { - \\ a = 2; - \\ printf("%d %d %d", a, getA(), getA2()); - \\ return 0; - \\} + \\#include + \\extern _Thread_local int a; + \\extern int getA(); + \\int getA2() { + \\ return a; + \\} + \\int main() { + \\ a = 2; + \\ printf("%d %d %d", a, getA(), getA2()); + \\ return 0; + \\} }); exe.root_module.linkSystemLibrary("a", .{}); exe.root_module.addLibraryPath(dylib.getEmittedBinDirectory()); @@ -2292,33 +2292,33 @@ fn testTlsPointers(b: *Build, opts: Options) *Step { }; const bar_o = addObject(b, opts, .{ .name = "bar", .cpp_source_bytes = - \\#include "foo.h" - \\int bar() { - \\ int v1 = Foo::getVar(); - \\ return v1; - \\} + \\#include "foo.h" + \\int bar() { + \\ int v1 = Foo::getVar(); + \\ return v1; + \\} }); bar_o.root_module.addIncludePath(foo_h.dirname()); bar_o.linkLibCpp(); const baz_o = addObject(b, opts, .{ .name = "baz", .cpp_source_bytes = - \\#include "foo.h" - \\int baz() { - \\ int v1 = Foo::getVar(); - \\ return v1; - \\} + \\#include "foo.h" + \\int baz() { + \\ int v1 = Foo::getVar(); + \\ return v1; + \\} }); baz_o.root_module.addIncludePath(foo_h.dirname()); baz_o.linkLibCpp(); const main_o = addObject(b, opts, .{ .name = "main", .cpp_source_bytes = - \\extern int bar(); - \\extern int baz(); - \\int main() { - \\ int v1 = bar(); - \\ int v2 = baz(); - \\ return v1 != v2; - \\} + \\extern int bar(); + \\extern int baz(); + \\int main() { + \\ int v1 = bar(); + \\ int v2 = baz(); + \\ return v1 != v2; + \\} }); main_o.root_module.addIncludePath(foo_h.dirname()); main_o.linkLibCpp(); @@ -2340,14 +2340,14 @@ fn testTlsLargeTbss(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "tls-large-tbss", opts); const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\_Thread_local int x[0x8000]; - \\_Thread_local int y[0x8000]; - \\int main() { - \\ x[0] = 3; - \\ x[0x7fff] = 5; - \\ printf("%d %d %d %d %d %d\n", x[0], x[1], x[0x7fff], y[0], y[1], y[0x7fff]); - \\} + \\#include + \\_Thread_local int x[0x8000]; + \\_Thread_local int y[0x8000]; + \\int main() { + \\ x[0] = 3; + \\ x[0x7fff] = 5; + \\ printf("%d %d %d %d %d %d\n", x[0], x[1], x[0x7fff], y[0], y[1], y[0x7fff]); + \\} }); const run = addRunArtifact(exe); @@ -2361,15 +2361,15 @@ fn testTlsZig(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "tls-zig", opts); const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = - \\const std = @import("std"); - \\threadlocal var x: i32 = 0; - \\threadlocal var y: i32 = -1; - \\pub fn main() void { - \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable; - \\ x -= 1; - \\ y += 1; - \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable; - \\} + \\const std = @import("std"); + \\threadlocal var x: i32 = 0; + \\threadlocal var y: i32 = -1; + \\pub fn main() void { + \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable; + \\ x -= 1; + \\ y += 1; + \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable; + \\} }); const run = addRunArtifact(exe); @@ -2387,15 +2387,15 @@ fn testTwoLevelNamespace(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "two-level-namespace", opts); const liba = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = - \\#include - \\int foo = 1; - \\int* ptr_to_foo = &foo; - \\int getFoo() { - \\ return foo; - \\} - \\void printInA() { - \\ printf("liba: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo); - \\} + \\#include + \\int foo = 1; + \\int* ptr_to_foo = &foo; + \\int getFoo() { + \\ return foo; + \\} + \\void printInA() { + \\ printf("liba: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo); + \\} }); { @@ -2408,15 +2408,15 @@ fn testTwoLevelNamespace(b: *Build, opts: Options) *Step { } const libb = addSharedLibrary(b, opts, .{ .name = "b", .c_source_bytes = - \\#include - \\int foo = 2; - \\int* ptr_to_foo = &foo; - \\int getFoo() { - \\ return foo; - \\} - \\void printInB() { - \\ printf("libb: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo); - \\} + \\#include + \\int foo = 2; + \\int* ptr_to_foo = &foo; + \\int getFoo() { + \\ return foo; + \\} + \\void printInB() { + \\ printf("libb: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo); + \\} }); { @@ -2429,17 +2429,17 @@ fn testTwoLevelNamespace(b: *Build, opts: Options) *Step { } const main_o = addObject(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\int getFoo(); - \\extern int* ptr_to_foo; - \\void printInA(); - \\void printInB(); - \\int main() { - \\ printf("main: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo); - \\ printInA(); - \\ printInB(); - \\ return 0; - \\} + \\#include + \\int getFoo(); + \\extern int* ptr_to_foo; + \\void printInA(); + \\void printInB(); + \\int main() { + \\ printf("main: getFoo()=%d, ptr_to_foo=%d\n", getFoo(), *ptr_to_foo); + \\ printInA(); + \\ printInB(); + \\ return 0; + \\} }); { @@ -2629,17 +2629,17 @@ fn testUnresolvedError(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "unresolved-error", opts); const obj = addObject(b, opts, .{ .name = "a", .zig_source_bytes = - \\extern fn foo() i32; - \\export fn bar() i32 { return foo() + 1; } + \\extern fn foo() i32; + \\export fn bar() i32 { return foo() + 1; } }); const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = - \\const std = @import("std"); - \\extern fn foo() i32; - \\extern fn bar() i32; - \\pub fn main() void { - \\ std.debug.print("foo() + bar() = {d}", .{foo() + bar()}); - \\} + \\const std = @import("std"); + \\extern fn foo() i32; + \\extern fn bar() i32; + \\pub fn main() void { + \\ std.debug.print("foo() + bar() = {d}", .{foo() + bar()}); + \\} }); exe.addObject(obj); @@ -2665,17 +2665,17 @@ fn testUnresolvedError2(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "unresolved-error-2", opts); const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = - \\pub fn main() !void { - \\ const msg_send_fn = @extern( - \\ *const fn () callconv(.C) usize, - \\ .{ .name = "objc_msgSend$initWithContentRect:styleMask:backing:defer:screen:" }, - \\ ); - \\ _ = @call( - \\ .auto, - \\ msg_send_fn, - \\ .{}, - \\ ); - \\} + \\pub fn main() !void { + \\ const msg_send_fn = @extern( + \\ *const fn () callconv(.C) usize, + \\ .{ .name = "objc_msgSend$initWithContentRect:styleMask:backing:defer:screen:" }, + \\ ); + \\ _ = @call( + \\ .auto, + \\ msg_send_fn, + \\ .{}, + \\ ); + \\} }); expectLinkErrors(exe, test_step, .{ .exact = &.{ @@ -2737,82 +2737,82 @@ fn testUnwindInfo(b: *Build, opts: Options) *Step { }; const main_o = addObject(b, opts, .{ .name = "main", .cpp_source_bytes = - \\#include "all.h" - \\#include - \\ - \\void fn_c() { - \\ SimpleStringOwner c{ "cccccccccc" }; - \\} - \\ - \\void fn_b() { - \\ SimpleStringOwner b{ "b" }; - \\ fn_c(); - \\} - \\ - \\int main() { - \\ try { - \\ SimpleStringOwner a{ "a" }; - \\ fn_b(); - \\ SimpleStringOwner d{ "d" }; - \\ } catch (const Error& e) { - \\ printf("Error: %s\n", e.what()); - \\ } catch(const std::exception& e) { - \\ printf("Exception: %s\n", e.what()); - \\ } - \\ return 0; - \\} + \\#include "all.h" + \\#include + \\ + \\void fn_c() { + \\ SimpleStringOwner c{ "cccccccccc" }; + \\} + \\ + \\void fn_b() { + \\ SimpleStringOwner b{ "b" }; + \\ fn_c(); + \\} + \\ + \\int main() { + \\ try { + \\ SimpleStringOwner a{ "a" }; + \\ fn_b(); + \\ SimpleStringOwner d{ "d" }; + \\ } catch (const Error& e) { + \\ printf("Error: %s\n", e.what()); + \\ } catch(const std::exception& e) { + \\ printf("Exception: %s\n", e.what()); + \\ } + \\ return 0; + \\} }); main_o.root_module.addIncludePath(all_h.dirname()); main_o.linkLibCpp(); const simple_string_o = addObject(b, opts, .{ .name = "simple_string", .cpp_source_bytes = - \\#include "all.h" - \\#include - \\#include - \\ - \\SimpleString::SimpleString(size_t max_size) - \\: max_size{ max_size }, length{} { - \\ if (max_size == 0) { - \\ throw Error{ "Max size must be at least 1." }; - \\ } - \\ buffer = new char[max_size]; - \\ buffer[0] = 0; - \\} - \\ - \\SimpleString::~SimpleString() { - \\ delete[] buffer; - \\} - \\ - \\void SimpleString::print(const char* tag) const { - \\ printf("%s: %s", tag, buffer); - \\} - \\ - \\bool SimpleString::append_line(const char* x) { - \\ const auto x_len = strlen(x); - \\ if (x_len + length + 2 > max_size) return false; - \\ std::strncpy(buffer + length, x, max_size - length); - \\ length += x_len; - \\ buffer[length++] = '\n'; - \\ buffer[length] = 0; - \\ return true; - \\} + \\#include "all.h" + \\#include + \\#include + \\ + \\SimpleString::SimpleString(size_t max_size) + \\: max_size{ max_size }, length{} { + \\ if (max_size == 0) { + \\ throw Error{ "Max size must be at least 1." }; + \\ } + \\ buffer = new char[max_size]; + \\ buffer[0] = 0; + \\} + \\ + \\SimpleString::~SimpleString() { + \\ delete[] buffer; + \\} + \\ + \\void SimpleString::print(const char* tag) const { + \\ printf("%s: %s", tag, buffer); + \\} + \\ + \\bool SimpleString::append_line(const char* x) { + \\ const auto x_len = strlen(x); + \\ if (x_len + length + 2 > max_size) return false; + \\ std::strncpy(buffer + length, x, max_size - length); + \\ length += x_len; + \\ buffer[length++] = '\n'; + \\ buffer[length] = 0; + \\ return true; + \\} }); simple_string_o.root_module.addIncludePath(all_h.dirname()); simple_string_o.linkLibCpp(); const simple_string_owner_o = addObject(b, opts, .{ .name = "simple_string_owner", .cpp_source_bytes = - \\#include "all.h" - \\ - \\SimpleStringOwner::SimpleStringOwner(const char* x) : string{ 10 } { - \\ if (!string.append_line(x)) { - \\ throw Error{ "Not enough memory!" }; - \\ } - \\ string.print("Constructed"); - \\} - \\ - \\SimpleStringOwner::~SimpleStringOwner() { - \\ string.print("About to destroy"); - \\} + \\#include "all.h" + \\ + \\SimpleStringOwner::SimpleStringOwner(const char* x) : string{ 10 } { + \\ if (!string.append_line(x)) { + \\ throw Error{ "Not enough memory!" }; + \\ } + \\ string.print("Constructed"); + \\} + \\ + \\SimpleStringOwner::~SimpleStringOwner() { + \\ string.print("About to destroy"); + \\} }); simple_string_owner_o.root_module.addIncludePath(all_h.dirname()); simple_string_owner_o.linkLibCpp(); @@ -2848,52 +2848,52 @@ fn testUnwindInfoNoSubsectionsArm64(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "unwind-info-no-subsections-arm64", opts); const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = - \\.globl _foo - \\.align 4 - \\_foo: - \\ .cfi_startproc - \\ stp x29, x30, [sp, #-32]! - \\ .cfi_def_cfa_offset 32 - \\ .cfi_offset w30, -24 - \\ .cfi_offset w29, -32 - \\ mov x29, sp - \\ .cfi_def_cfa w29, 32 - \\ bl _bar - \\ ldp x29, x30, [sp], #32 - \\ .cfi_restore w29 - \\ .cfi_restore w30 - \\ .cfi_def_cfa_offset 0 - \\ ret - \\ .cfi_endproc - \\ - \\.globl _bar - \\.align 4 - \\_bar: - \\ .cfi_startproc - \\ sub sp, sp, #32 - \\ .cfi_def_cfa_offset -32 - \\ stp x29, x30, [sp, #16] - \\ .cfi_offset w30, -24 - \\ .cfi_offset w29, -32 - \\ mov x29, sp - \\ .cfi_def_cfa w29, 32 - \\ mov w0, #4 - \\ ldp x29, x30, [sp, #16] - \\ .cfi_restore w29 - \\ .cfi_restore w30 - \\ add sp, sp, #32 - \\ .cfi_def_cfa_offset 0 - \\ ret - \\ .cfi_endproc + \\.globl _foo + \\.align 4 + \\_foo: + \\ .cfi_startproc + \\ stp x29, x30, [sp, #-32]! + \\ .cfi_def_cfa_offset 32 + \\ .cfi_offset w30, -24 + \\ .cfi_offset w29, -32 + \\ mov x29, sp + \\ .cfi_def_cfa w29, 32 + \\ bl _bar + \\ ldp x29, x30, [sp], #32 + \\ .cfi_restore w29 + \\ .cfi_restore w30 + \\ .cfi_def_cfa_offset 0 + \\ ret + \\ .cfi_endproc + \\ + \\.globl _bar + \\.align 4 + \\_bar: + \\ .cfi_startproc + \\ sub sp, sp, #32 + \\ .cfi_def_cfa_offset -32 + \\ stp x29, x30, [sp, #16] + \\ .cfi_offset w30, -24 + \\ .cfi_offset w29, -32 + \\ mov x29, sp + \\ .cfi_def_cfa w29, 32 + \\ mov w0, #4 + \\ ldp x29, x30, [sp, #16] + \\ .cfi_restore w29 + \\ .cfi_restore w30 + \\ add sp, sp, #32 + \\ .cfi_def_cfa_offset 0 + \\ ret + \\ .cfi_endproc }); const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\int foo(); - \\int main() { - \\ printf("%d\n", foo()); - \\ return 0; - \\} + \\#include + \\int foo(); + \\int main() { + \\ printf("%d\n", foo()); + \\ return 0; + \\} }); exe.addObject(a_o); @@ -2908,44 +2908,44 @@ fn testUnwindInfoNoSubsectionsX64(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "unwind-info-no-subsections-x64", opts); const a_o = addObject(b, opts, .{ .name = "a", .asm_source_bytes = - \\.globl _foo - \\_foo: - \\ .cfi_startproc - \\ push %rbp - \\ .cfi_def_cfa_offset 8 - \\ .cfi_offset %rbp, -8 - \\ mov %rsp, %rbp - \\ .cfi_def_cfa_register %rbp - \\ call _bar - \\ pop %rbp - \\ .cfi_restore %rbp - \\ .cfi_def_cfa_offset 0 - \\ ret - \\ .cfi_endproc - \\ - \\.globl _bar - \\_bar: - \\ .cfi_startproc - \\ push %rbp - \\ .cfi_def_cfa_offset 8 - \\ .cfi_offset %rbp, -8 - \\ mov %rsp, %rbp - \\ .cfi_def_cfa_register %rbp - \\ mov $4, %rax - \\ pop %rbp - \\ .cfi_restore %rbp - \\ .cfi_def_cfa_offset 0 - \\ ret - \\ .cfi_endproc + \\.globl _foo + \\_foo: + \\ .cfi_startproc + \\ push %rbp + \\ .cfi_def_cfa_offset 8 + \\ .cfi_offset %rbp, -8 + \\ mov %rsp, %rbp + \\ .cfi_def_cfa_register %rbp + \\ call _bar + \\ pop %rbp + \\ .cfi_restore %rbp + \\ .cfi_def_cfa_offset 0 + \\ ret + \\ .cfi_endproc + \\ + \\.globl _bar + \\_bar: + \\ .cfi_startproc + \\ push %rbp + \\ .cfi_def_cfa_offset 8 + \\ .cfi_offset %rbp, -8 + \\ mov %rsp, %rbp + \\ .cfi_def_cfa_register %rbp + \\ mov $4, %rax + \\ pop %rbp + \\ .cfi_restore %rbp + \\ .cfi_def_cfa_offset 0 + \\ ret + \\ .cfi_endproc }); const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\int foo(); - \\int main() { - \\ printf("%d\n", foo()); - \\ return 0; - \\} + \\#include + \\int foo(); + \\int main() { + \\ printf("%d\n", foo()); + \\ return 0; + \\} }); exe.addObject(a_o); @@ -2961,27 +2961,27 @@ fn testWeakBind(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "weak-bind", opts); const lib = addSharedLibrary(b, opts, .{ .name = "foo", .asm_source_bytes = - \\.globl _weak_dysym - \\.weak_definition _weak_dysym - \\_weak_dysym: - \\ .quad 0x1234 - \\ - \\.globl _weak_dysym_for_gotpcrel - \\.weak_definition _weak_dysym_for_gotpcrel - \\_weak_dysym_for_gotpcrel: - \\ .quad 0x1234 - \\ - \\.globl _weak_dysym_fn - \\.weak_definition _weak_dysym_fn - \\_weak_dysym_fn: - \\ ret - \\ - \\.section __DATA,__thread_vars,thread_local_variables - \\ - \\.globl _weak_dysym_tlv - \\.weak_definition _weak_dysym_tlv - \\_weak_dysym_tlv: - \\ .quad 0x1234 + \\.globl _weak_dysym + \\.weak_definition _weak_dysym + \\_weak_dysym: + \\ .quad 0x1234 + \\ + \\.globl _weak_dysym_for_gotpcrel + \\.weak_definition _weak_dysym_for_gotpcrel + \\_weak_dysym_for_gotpcrel: + \\ .quad 0x1234 + \\ + \\.globl _weak_dysym_fn + \\.weak_definition _weak_dysym_fn + \\_weak_dysym_fn: + \\ ret + \\ + \\.section __DATA,__thread_vars,thread_local_variables + \\ + \\.globl _weak_dysym_tlv + \\.weak_definition _weak_dysym_tlv + \\_weak_dysym_tlv: + \\ .quad 0x1234 }); { @@ -2995,61 +2995,61 @@ fn testWeakBind(b: *Build, opts: Options) *Step { } const exe = addExecutable(b, opts, .{ .name = "main", .asm_source_bytes = - \\.globl _main, _weak_external, _weak_external_for_gotpcrel, _weak_external_fn - \\.weak_definition _weak_external, _weak_external_for_gotpcrel, _weak_external_fn, _weak_internal, _weak_internal_for_gotpcrel, _weak_internal_fn - \\ - \\_main: - \\ mov _weak_dysym_for_gotpcrel@GOTPCREL(%rip), %rax - \\ mov _weak_external_for_gotpcrel@GOTPCREL(%rip), %rax - \\ mov _weak_internal_for_gotpcrel@GOTPCREL(%rip), %rax - \\ mov _weak_tlv@TLVP(%rip), %rax - \\ mov _weak_dysym_tlv@TLVP(%rip), %rax - \\ mov _weak_internal_tlv@TLVP(%rip), %rax - \\ callq _weak_dysym_fn - \\ callq _weak_external_fn - \\ callq _weak_internal_fn - \\ mov $0, %rax - \\ ret - \\ - \\_weak_external: - \\ .quad 0x1234 - \\ - \\_weak_external_for_gotpcrel: - \\ .quad 0x1234 - \\ - \\_weak_external_fn: - \\ ret - \\ - \\_weak_internal: - \\ .quad 0x1234 - \\ - \\_weak_internal_for_gotpcrel: - \\ .quad 0x1234 - \\ - \\_weak_internal_fn: - \\ ret - \\ - \\.data - \\ .quad _weak_dysym - \\ .quad _weak_external + 2 - \\ .quad _weak_internal - \\ - \\.tbss _weak_tlv$tlv$init, 4, 2 - \\.tbss _weak_internal_tlv$tlv$init, 4, 2 - \\ - \\.section __DATA,__thread_vars,thread_local_variables - \\.globl _weak_tlv - \\.weak_definition _weak_tlv, _weak_internal_tlv - \\ - \\_weak_tlv: - \\ .quad __tlv_bootstrap - \\ .quad 0 - \\ .quad _weak_tlv$tlv$init - \\ - \\_weak_internal_tlv: - \\ .quad __tlv_bootstrap - \\ .quad 0 - \\ .quad _weak_internal_tlv$tlv$init + \\.globl _main, _weak_external, _weak_external_for_gotpcrel, _weak_external_fn + \\.weak_definition _weak_external, _weak_external_for_gotpcrel, _weak_external_fn, _weak_internal, _weak_internal_for_gotpcrel, _weak_internal_fn + \\ + \\_main: + \\ mov _weak_dysym_for_gotpcrel@GOTPCREL(%rip), %rax + \\ mov _weak_external_for_gotpcrel@GOTPCREL(%rip), %rax + \\ mov _weak_internal_for_gotpcrel@GOTPCREL(%rip), %rax + \\ mov _weak_tlv@TLVP(%rip), %rax + \\ mov _weak_dysym_tlv@TLVP(%rip), %rax + \\ mov _weak_internal_tlv@TLVP(%rip), %rax + \\ callq _weak_dysym_fn + \\ callq _weak_external_fn + \\ callq _weak_internal_fn + \\ mov $0, %rax + \\ ret + \\ + \\_weak_external: + \\ .quad 0x1234 + \\ + \\_weak_external_for_gotpcrel: + \\ .quad 0x1234 + \\ + \\_weak_external_fn: + \\ ret + \\ + \\_weak_internal: + \\ .quad 0x1234 + \\ + \\_weak_internal_for_gotpcrel: + \\ .quad 0x1234 + \\ + \\_weak_internal_fn: + \\ ret + \\ + \\.data + \\ .quad _weak_dysym + \\ .quad _weak_external + 2 + \\ .quad _weak_internal + \\ + \\.tbss _weak_tlv$tlv$init, 4, 2 + \\.tbss _weak_internal_tlv$tlv$init, 4, 2 + \\ + \\.section __DATA,__thread_vars,thread_local_variables + \\.globl _weak_tlv + \\.weak_definition _weak_tlv, _weak_internal_tlv + \\ + \\_weak_tlv: + \\ .quad __tlv_bootstrap + \\ .quad 0 + \\ .quad _weak_tlv$tlv$init + \\ + \\_weak_internal_tlv: + \\ .quad __tlv_bootstrap + \\ .quad 0 + \\ .quad _weak_internal_tlv$tlv$init }); exe.linkLibrary(lib); @@ -3111,23 +3111,23 @@ fn testWeakLibrary(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "weak-library", opts); const dylib = addSharedLibrary(b, opts, .{ .name = "a", .c_source_bytes = - \\#include - \\int a = 42; - \\const char* asStr() { - \\ static char str[3]; - \\ sprintf(str, "%d", 42); - \\ return str; - \\} + \\#include + \\int a = 42; + \\const char* asStr() { + \\ static char str[3]; + \\ sprintf(str, "%d", 42); + \\ return str; + \\} }); const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\extern int a; - \\extern const char* asStr(); - \\int main() { - \\ printf("%d %s", a, asStr()); - \\ return 0; - \\} + \\#include + \\extern int a; + \\extern const char* asStr(); + \\int main() { + \\ printf("%d %s", a, asStr()); + \\ return 0; + \\} }); exe.root_module.linkSystemLibrary("a", .{ .weak = true }); exe.root_module.addLibraryPath(dylib.getEmittedBinDirectory()); @@ -3154,11 +3154,11 @@ fn testWeakRef(b: *Build, opts: Options) *Step { const test_step = addTestStep(b, "weak-ref", opts); const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes = - \\#include - \\#include - \\int main(int argc, char** argv) { - \\ printf("__darwin_check_fd_set_overflow: %p\n", __darwin_check_fd_set_overflow); - \\} + \\#include + \\#include + \\int main(int argc, char** argv) { + \\ printf("__darwin_check_fd_set_overflow: %p\n", __darwin_check_fd_set_overflow); + \\} }); const check = exe.checkObject(); diff --git a/tools/doctest.zig b/tools/doctest.zig index 070a59ee37..025d59517f 100644 --- a/tools/doctest.zig +++ b/tools/doctest.zig @@ -203,7 +203,7 @@ fn printOutput( if (mem.startsWith(u8, triple, "wasm32") or mem.startsWith(u8, triple, "riscv64-linux") or (mem.startsWith(u8, triple, "x86_64-linux") and - builtin.os.tag != .linux or builtin.cpu.arch != .x86_64)) + builtin.os.tag != .linux or builtin.cpu.arch != .x86_64)) { // skip execution break :code_block; diff --git a/tools/fetch_them_macos_headers.zig b/tools/fetch_them_macos_headers.zig index 3d17681ee0..4b6bb87ae0 100644 --- a/tools/fetch_them_macos_headers.zig +++ b/tools/fetch_them_macos_headers.zig @@ -99,8 +99,8 @@ pub fn main() anyerror!void { const version = Version.parse(parsed_json.value.DefaultProperties.MACOSX_DEPLOYMENT_TARGET) orelse fatal("don't know how to parse SDK version: {s}", .{ - parsed_json.value.DefaultProperties.MACOSX_DEPLOYMENT_TARGET, - }); + parsed_json.value.DefaultProperties.MACOSX_DEPLOYMENT_TARGET, + }); const os_ver: OsVer = switch (version.major) { 10 => .catalina, 11 => .big_sur, diff --git a/tools/update_clang_options.zig b/tools/update_clang_options.zig index 9cc0ad90cd..2573d173a9 100644 --- a/tools/update_clang_options.zig +++ b/tools/update_clang_options.zig @@ -761,7 +761,7 @@ pub fn main() anyerror!void { if ((std.mem.startsWith(u8, name, "mno-") and llvm_to_zig_cpu_features.contains(name["mno-".len..])) or (std.mem.startsWith(u8, name, "m") and - llvm_to_zig_cpu_features.contains(name["m".len..]))) + llvm_to_zig_cpu_features.contains(name["m".len..]))) { try stdout.print("m(\"{s}\"),\n", .{name}); } else {