authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-02-18 00:51:59+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-02-18 00:51:59+01:00
logb732070fd36267fb055347e3aa8a1851e4054d50
tree9851eb03564eff472bbb4a605e13e4058baed4c6
parent55c46870b23ac16670beaa3ff1c082b703738307
parentfaccd79ca5debbe22fe168193b8de54393257604
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #22589 from alexrp/target-changes

Some miscellaneous target and calling convention changes

68 files changed, 764 insertions(+), 747 deletions(-)

build.zig+1-1
......@@ -742,7 +742,7 @@ fn addCmakeCfgOptionsToExe(
742742 const mod = exe.root_module;
743743 const target = mod.resolved_target.?.result;
744744
745 if (target.isDarwin()) {
745 if (target.os.tag.isDarwin()) {
746746 // useful for package maintainers
747747 exe.headerpad_max_install_names = true;
748748 }
lib/compiler/aro/aro/Compilation.zig+2-2
......@@ -308,7 +308,7 @@ fn generateSystemDefines(comp: *Compilation, w: anytype) !void {
308308 ),
309309 else => {},
310310 }
311 if (comp.target.isAndroid()) {
311 if (comp.target.abi.isAndroid()) {
312312 try w.writeAll("#define __ANDROID__ 1\n");
313313 }
314314
......@@ -734,7 +734,7 @@ pub fn float80Type(comp: *const Compilation) ?Type {
734734
735735/// Smallest integer type with at least N bits
736736pub fn intLeastN(comp: *const Compilation, bits: usize, signedness: std.builtin.Signedness) Type {
737 if (bits == 64 and (comp.target.isDarwin() or comp.target.isWasm())) {
737 if (bits == 64 and (comp.target.os.tag.isDarwin() or comp.target.cpu.arch.isWasm())) {
738738 // WebAssembly and Darwin use `long long` for `int_least64_t` and `int_fast64_t`.
739739 return .{ .specifier = if (signedness == .signed) .long_long else .ulong_long };
740740 }
lib/compiler/aro/aro/Driver/GCCDetector.zig+1-1
......@@ -183,7 +183,7 @@ fn collectLibDirsAndTriples(
183183 // TODO
184184 return;
185185 }
186 if (target.isAndroid()) {
186 if (target.abi.isAndroid()) {
187187 const AArch64AndroidTriples: [1][]const u8 = .{"aarch64-linux-android"};
188188 const ARMAndroidTriples: [1][]const u8 = .{"arm-linux-androideabi"};
189189 const MIPSELAndroidTriples: [1][]const u8 = .{"mipsel-linux-android"};
lib/compiler/aro/aro/Toolchain.zig+7-7
......@@ -161,7 +161,7 @@ pub fn getLinkerPath(tc: *const Toolchain, buf: []u8) ![]const u8 {
161161 } else {
162162 var linker_name = try std.ArrayList(u8).initCapacity(tc.driver.comp.gpa, 5 + use_linker.len); // "ld64." ++ use_linker
163163 defer linker_name.deinit();
164 if (tc.getTarget().isDarwin()) {
164 if (tc.getTarget().os.tag.isDarwin()) {
165165 linker_name.appendSliceAssumeCapacity("ld64.");
166166 } else {
167167 linker_name.appendSliceAssumeCapacity("ld.");
......@@ -343,7 +343,7 @@ pub fn buildLinkerArgs(tc: *Toolchain, argv: *std.ArrayList([]const u8)) !void {
343343}
344344
345345fn getDefaultRuntimeLibKind(tc: *const Toolchain) RuntimeLibKind {
346 if (tc.getTarget().isAndroid()) {
346 if (tc.getTarget().abi.isAndroid()) {
347347 return .compiler_rt;
348348 }
349349 return .libgcc;
......@@ -369,7 +369,7 @@ pub fn getCompilerRt(tc: *const Toolchain, component: []const u8, file_kind: Fil
369369
370370fn getLibGCCKind(tc: *const Toolchain) LibGCCKind {
371371 const target = tc.getTarget();
372 if (tc.driver.static_libgcc or tc.driver.static or tc.driver.static_pie or target.isAndroid()) {
372 if (tc.driver.static_libgcc or tc.driver.static or tc.driver.static_pie or target.abi.isAndroid()) {
373373 return .static;
374374 }
375375 if (tc.driver.shared_libgcc) {
......@@ -384,7 +384,7 @@ fn getUnwindLibKind(tc: *const Toolchain) !UnwindLibKind {
384384 switch (tc.getRuntimeLibKind()) {
385385 .compiler_rt => {
386386 const target = tc.getTarget();
387 if (target.isAndroid() or target.os.tag == .aix) {
387 if (target.abi.isAndroid() or target.os.tag == .aix) {
388388 return .compiler_rt;
389389 } else {
390390 return .none;
......@@ -417,14 +417,14 @@ fn getAsNeededOption(is_solaris: bool, needed: bool) []const u8 {
417417fn addUnwindLibrary(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !void {
418418 const unw = try tc.getUnwindLibKind();
419419 const target = tc.getTarget();
420 if ((target.isAndroid() and unw == .libgcc) or
420 if ((target.abi.isAndroid() and unw == .libgcc) or
421421 target.os.tag == .elfiamcu or
422422 target.ofmt == .wasm or
423423 target_util.isWindowsMSVCEnvironment(target) or
424424 unw == .none) return;
425425
426426 const lgk = tc.getLibGCCKind();
427 const as_needed = lgk == .unspecified and !target.isAndroid() and !target_util.isCygwinMinGW(target) and target.os.tag != .aix;
427 const as_needed = lgk == .unspecified and !target.abi.isAndroid() and !target_util.isCygwinMinGW(target) and target.os.tag != .aix;
428428 if (as_needed) {
429429 try argv.append(getAsNeededOption(target.os.tag == .solaris, true));
430430 }
......@@ -483,7 +483,7 @@ pub fn addRuntimeLibs(tc: *const Toolchain, argv: *std.ArrayList([]const u8)) !v
483483 },
484484 }
485485
486 if (target.isAndroid() and !tc.driver.static and !tc.driver.static_pie) {
486 if (target.abi.isAndroid() and !tc.driver.static and !tc.driver.static_pie) {
487487 try argv.append("-ldl");
488488 }
489489}
lib/compiler/aro/aro/Type.zig+1-1
......@@ -1102,7 +1102,7 @@ pub fn alignof(ty: Type, comp: *const Compilation) u29 {
11021102 .double => comp.target.cTypeAlignment(.double),
11031103 .long_double => comp.target.cTypeAlignment(.longdouble),
11041104
1105 .int128, .uint128 => if (comp.target.cpu.arch == .s390x and comp.target.os.tag == .linux and comp.target.isGnu()) 8 else 16,
1105 .int128, .uint128 => if (comp.target.cpu.arch == .s390x and comp.target.os.tag == .linux and comp.target.abi.isGnu()) 8 else 16,
11061106 .fp16, .float16 => 2,
11071107
11081108 .float128 => 16,
lib/compiler/aro/aro/target.zig+8-13
......@@ -117,8 +117,8 @@ pub fn int64Type(target: std.Target) Type {
117117
118118 .sparc64 => return intMaxType(target),
119119
120 .x86, .x86_64 => if (!target.isDarwin()) return intMaxType(target),
121 .aarch64, .aarch64_be => if (!target.isDarwin() and target.os.tag != .openbsd and target.os.tag != .windows) return .{ .specifier = .long },
120 .x86, .x86_64 => if (!target.os.tag.isDarwin()) return intMaxType(target),
121 .aarch64, .aarch64_be => if (!target.os.tag.isDarwin() and target.os.tag != .openbsd and target.os.tag != .windows) return .{ .specifier = .long },
122122 else => {},
123123 }
124124 return .{ .specifier = .long_long };
......@@ -144,7 +144,7 @@ pub fn defaultFunctionAlignment(target: std.Target) u8 {
144144}
145145
146146pub fn isTlsSupported(target: std.Target) bool {
147 if (target.isDarwin()) {
147 if (target.os.tag.isDarwin()) {
148148 var supported = false;
149149 switch (target.os.tag) {
150150 .macos => supported = !(target.os.isAtLeast(.macos, .{ .major = 10, .minor = 7, .patch = 0 }) orelse false),
......@@ -199,7 +199,7 @@ pub fn minZeroWidthBitfieldAlignment(target: std.Target) ?u29 {
199199pub fn unnamedFieldAffectsAlignment(target: std.Target) bool {
200200 switch (target.cpu.arch) {
201201 .aarch64 => {
202 if (target.isDarwin() or target.os.tag == .windows) return false;
202 if (target.os.tag.isDarwin() or target.os.tag == .windows) return false;
203203 return true;
204204 },
205205 .armeb => {
......@@ -229,7 +229,7 @@ pub fn packAllEnums(target: std.Target) bool {
229229pub fn defaultAlignment(target: std.Target) u29 {
230230 switch (target.cpu.arch) {
231231 .avr => return 1,
232 .arm => if (target.isAndroid() or target.os.tag == .ios) return 16 else return 8,
232 .arm => if (target.abi.isAndroid() or target.os.tag == .ios) return 16 else return 8,
233233 .sparc => if (std.Target.sparc.featureSetHas(target.cpu.features, .v9)) return 16 else return 8,
234234 .mips, .mipsel => switch (target.abi) {
235235 .none, .gnuabi64 => return 16,
......@@ -242,9 +242,8 @@ pub fn defaultAlignment(target: std.Target) u29 {
242242pub fn systemCompiler(target: std.Target) LangOpts.Compiler {
243243 // Android is linux but not gcc, so these checks go first
244244 // the rest for documentation as fn returns .clang
245 if (target.isDarwin() or
246 target.isAndroid() or
247 target.isBSD() or
245 if (target.abi.isAndroid() or
246 target.os.tag.isBSD() or
248247 target.os.tag == .fuchsia or
249248 target.os.tag == .solaris or
250249 target.os.tag == .haiku or
......@@ -268,7 +267,7 @@ pub fn systemCompiler(target: std.Target) LangOpts.Compiler {
268267
269268pub fn hasFloat128(target: std.Target) bool {
270269 if (target.cpu.arch.isWasm()) return true;
271 if (target.isDarwin()) return false;
270 if (target.os.tag.isDarwin()) return false;
272271 if (target.cpu.arch.isPowerPC()) return std.Target.powerpc.featureSetHas(target.cpu.features, .float128);
273272 return switch (target.os.tag) {
274273 .dragonfly,
......@@ -461,7 +460,6 @@ pub fn get32BitArchVariant(target: std.Target) ?std.Target {
461460 .amdgcn,
462461 .avr,
463462 .msp430,
464 .spu_2,
465463 .ve,
466464 .bpfel,
467465 .bpfeb,
......@@ -522,7 +520,6 @@ pub fn get64BitArchVariant(target: std.Target) ?std.Target {
522520 .lanai,
523521 .m68k,
524522 .msp430,
525 .spu_2,
526523 .xcore,
527524 .xtensa,
528525 => return null,
......@@ -620,8 +617,6 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {
620617 .wasm32 => "wasm32",
621618 .wasm64 => "wasm64",
622619 .ve => "ve",
623 // Note: spu_2 is not supported in LLVM; this is the Zig arch name
624 .spu_2 => "spu_2",
625620 };
626621 writer.writeAll(llvm_arch) catch unreachable;
627622 writer.writeByte('-') catch unreachable;
lib/compiler/aro/aro/toolchains/Linux.zig+7-7
......@@ -27,7 +27,7 @@ pub fn discover(self: *Linux, tc: *Toolchain) !void {
2727fn buildExtraOpts(self: *Linux, tc: *const Toolchain) !void {
2828 const gpa = tc.driver.comp.gpa;
2929 const target = tc.getTarget();
30 const is_android = target.isAndroid();
30 const is_android = target.abi.isAndroid();
3131 if (self.distro.isAlpine() or is_android) {
3232 try self.extra_opts.ensureUnusedCapacity(gpa, 2);
3333 self.extra_opts.appendAssumeCapacity("-z");
......@@ -113,7 +113,7 @@ fn findPaths(self: *Linux, tc: *Toolchain) !void {
113113 try tc.addPathIfExists(&.{ sysroot, "/lib", multiarch_triple }, .file);
114114 try tc.addPathIfExists(&.{ sysroot, "/lib", "..", os_lib_dir }, .file);
115115
116 if (target.isAndroid()) {
116 if (target.abi.isAndroid()) {
117117 // TODO
118118 }
119119 try tc.addPathIfExists(&.{ sysroot, "/usr", "lib", multiarch_triple }, .file);
......@@ -156,7 +156,7 @@ fn getStatic(self: *const Linux, d: *const Driver) bool {
156156
157157pub fn getDefaultLinker(self: *const Linux, target: std.Target) []const u8 {
158158 _ = self;
159 if (target.isAndroid()) {
159 if (target.abi.isAndroid()) {
160160 return "ld.lld";
161161 }
162162 return "ld";
......@@ -169,7 +169,7 @@ pub fn buildLinkerArgs(self: *const Linux, tc: *const Toolchain, argv: *std.Arra
169169 const is_pie = self.getPIE(d);
170170 const is_static_pie = try self.getStaticPIE(d);
171171 const is_static = self.getStatic(d);
172 const is_android = target.isAndroid();
172 const is_android = target.abi.isAndroid();
173173 const is_iamcu = target.os.tag == .elfiamcu;
174174 const is_ve = target.cpu.arch == .ve;
175175 const has_crt_begin_end_files = target.abi != .none; // TODO: clang checks for MIPS vendor
......@@ -326,7 +326,7 @@ pub fn buildLinkerArgs(self: *const Linux, tc: *const Toolchain, argv: *std.Arra
326326}
327327
328328fn getMultiarchTriple(target: std.Target) ?[]const u8 {
329 const is_android = target.isAndroid();
329 const is_android = target.abi.isAndroid();
330330 const is_mips_r6 = std.Target.mips.featureSetHas(target.cpu.features, .mips32r6);
331331 return switch (target.cpu.arch) {
332332 .arm, .thumb => if (is_android) "arm-linux-androideabi" else if (target.abi == .gnueabihf) "arm-linux-gnueabihf" else "arm-linux-gnueabi",
......@@ -380,7 +380,7 @@ pub fn defineSystemIncludes(self: *const Linux, tc: *const Toolchain) !void {
380380
381381 // musl prefers /usr/include before builtin includes, so musl targets will add builtins
382382 // at the end of this function (unless disabled with nostdlibinc)
383 if (!tc.driver.nobuiltininc and (!target.isMusl() or tc.driver.nostdlibinc)) {
383 if (!tc.driver.nobuiltininc and (!target.abi.isMusl() or tc.driver.nostdlibinc)) {
384384 try comp.addBuiltinIncludeDir(tc.driver.aro_name);
385385 }
386386
......@@ -411,7 +411,7 @@ pub fn defineSystemIncludes(self: *const Linux, tc: *const Toolchain) !void {
411411 try comp.addSystemIncludeDir("/usr/include");
412412
413413 std.debug.assert(!tc.driver.nostdlibinc);
414 if (!tc.driver.nobuiltininc and target.isMusl()) {
414 if (!tc.driver.nobuiltininc and target.abi.isMusl()) {
415415 try comp.addBuiltinIncludeDir(tc.driver.aro_name);
416416 }
417417}
lib/compiler_rt/common.zig+3-3
......@@ -14,7 +14,7 @@ else
1414/// For WebAssembly this allows the symbol to be resolved to other modules, but will not
1515/// export it to the host runtime.
1616pub const visibility: std.builtin.SymbolVisibility =
17 if (builtin.target.isWasm() and linkage != .internal) .hidden else .default;
17 if (builtin.target.cpu.arch.isWasm() and linkage != .internal) .hidden else .default;
1818
1919pub const want_aeabi = switch (builtin.abi) {
2020 .eabi,
......@@ -92,7 +92,7 @@ pub const panic = if (builtin.is_test) std.debug.FullPanic(std.debug.defaultPani
9292pub fn F16T(comptime OtherType: type) type {
9393 return switch (builtin.cpu.arch) {
9494 .arm, .armeb, .thumb, .thumbeb => if (std.Target.arm.featureSetHas(builtin.cpu.features, .has_v8))
95 switch (builtin.abi.floatAbi()) {
95 switch (builtin.abi.float()) {
9696 .soft => u16,
9797 .hard => f16,
9898 }
......@@ -100,7 +100,7 @@ pub fn F16T(comptime OtherType: type) type {
100100 u16,
101101 .aarch64, .aarch64_be => f16,
102102 .riscv32, .riscv64 => f16,
103 .x86, .x86_64 => if (builtin.target.isDarwin()) switch (OtherType) {
103 .x86, .x86_64 => if (builtin.target.os.tag.isDarwin()) switch (OtherType) {
104104 // Starting with LLVM 16, Darwin uses different abi for f16
105105 // depending on the type of the other return/argument..???
106106 f32, f64 => u16,
lib/std/Build/Step/Compile.zig+3-3
......@@ -465,7 +465,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
465465 if (compile.linkage != null and compile.linkage.? == .static) {
466466 compile.out_lib_filename = compile.out_filename;
467467 } else if (compile.version) |version| {
468 if (target.isDarwin()) {
468 if (target.os.tag.isDarwin()) {
469469 compile.major_only_filename = owner.fmt("lib{s}.{d}.dylib", .{
470470 compile.name,
471471 version.major,
......@@ -480,7 +480,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
480480 compile.out_lib_filename = compile.out_filename;
481481 }
482482 } else {
483 if (target.isDarwin()) {
483 if (target.os.tag.isDarwin()) {
484484 compile.out_lib_filename = compile.out_filename;
485485 } else if (target.os.tag == .windows) {
486486 compile.out_lib_filename = owner.fmt("{s}.lib", .{compile.name});
......@@ -1524,7 +1524,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
15241524 try zig_args.append(b.fmt("{}", .{version}));
15251525 }
15261526
1527 if (compile.rootModuleTarget().isDarwin()) {
1527 if (compile.rootModuleTarget().os.tag.isDarwin()) {
15281528 const install_name = compile.install_name orelse b.fmt("@rpath/{s}{s}{s}", .{
15291529 compile.rootModuleTarget().libPrefix(),
15301530 compile.name,
lib/std/Target.zig+68-131
......@@ -144,10 +144,6 @@ pub const Os = struct {
144144 };
145145 }
146146
147 pub inline fn isGnuLibC(tag: Os.Tag, abi: Abi) bool {
148 return (tag == .hurd or tag == .linux) and abi.isGnu();
149 }
150
151147 pub fn defaultVersionRange(tag: Tag, arch: Cpu.Arch, abi: Abi) Os {
152148 return .{
153149 .tag = tag,
......@@ -218,23 +214,6 @@ pub const Os = struct {
218214 .windows => .windows,
219215 };
220216 }
221
222 pub fn archName(tag: Tag, arch: Cpu.Arch) [:0]const u8 {
223 return switch (tag) {
224 .linux => switch (arch) {
225 .arm, .armeb, .thumb, .thumbeb => "arm",
226 .aarch64, .aarch64_be => "aarch64",
227 .loongarch32, .loongarch64 => "loongarch",
228 .mips, .mipsel, .mips64, .mips64el => "mips",
229 .powerpc, .powerpcle, .powerpc64, .powerpc64le => "powerpc",
230 .riscv32, .riscv64 => "riscv",
231 .sparc, .sparc64 => "sparc",
232 .x86, .x86_64 => "x86",
233 else => @tagName(arch),
234 },
235 else => @tagName(arch),
236 };
237 }
238217 };
239218
240219 /// Based on NTDDI version constants from
......@@ -763,6 +742,7 @@ pub const mips = @import("Target/mips.zig");
763742pub const msp430 = @import("Target/msp430.zig");
764743pub const nvptx = @import("Target/nvptx.zig");
765744pub const powerpc = @import("Target/powerpc.zig");
745pub const propeller = @import("Target/propeller.zig");
766746pub const riscv = @import("Target/riscv.zig");
767747pub const sparc = @import("Target/sparc.zig");
768748pub const spirv = @import("Target/spirv.zig");
......@@ -772,7 +752,6 @@ pub const wasm = @import("Target/wasm.zig");
772752pub const x86 = @import("Target/x86.zig");
773753pub const xcore = @import("Target/xcore.zig");
774754pub const xtensa = @import("Target/xtensa.zig");
775pub const propeller = @import("Target/propeller.zig");
776755
777756pub const Abi = enum {
778757 none,
......@@ -990,7 +969,12 @@ pub const Abi = enum {
990969 };
991970 }
992971
993 pub inline fn floatAbi(abi: Abi) FloatAbi {
972 pub const Float = enum {
973 hard,
974 soft,
975 };
976
977 pub inline fn float(abi: Abi) Float {
994978 return switch (abi) {
995979 .androideabi,
996980 .eabi,
......@@ -1081,20 +1065,17 @@ pub fn toElfMachine(target: Target) std.elf.EM {
10811065 .msp430 => .MSP430,
10821066 .powerpc, .powerpcle => .PPC,
10831067 .powerpc64, .powerpc64le => .PPC64,
1068 .propeller => .PROPELLER,
10841069 .riscv32, .riscv64 => .RISCV,
10851070 .s390x => .S390,
10861071 .sparc => if (Target.sparc.featureSetHas(target.cpu.features, .v9)) .SPARC32PLUS else .SPARC,
10871072 .sparc64 => .SPARCV9,
1088 .spu_2 => .SPU_2,
10891073 .ve => .VE,
10901074 .x86 => if (target.os.tag == .elfiamcu) .IAMCU else .@"386",
10911075 .x86_64 => .X86_64,
10921076 .xcore => .XCORE,
10931077 .xtensa => .XTENSA,
10941078
1095 .propeller1 => .PROPELLER,
1096 .propeller2 => .PROPELLER2,
1097
10981079 .nvptx,
10991080 .nvptx64,
11001081 .spirv,
......@@ -1148,14 +1129,12 @@ pub fn toCoffMachine(target: Target) std.coff.MachineType {
11481129 .spirv,
11491130 .spirv32,
11501131 .spirv64,
1151 .spu_2,
11521132 .ve,
11531133 .wasm32,
11541134 .wasm64,
11551135 .xcore,
11561136 .xtensa,
1157 .propeller1,
1158 .propeller2,
1137 .propeller,
11591138 => .UNKNOWN,
11601139 };
11611140}
......@@ -1368,8 +1347,7 @@ pub const Cpu = struct {
13681347 powerpcle,
13691348 powerpc64,
13701349 powerpc64le,
1371 propeller1,
1372 propeller2,
1350 propeller,
13731351 riscv32,
13741352 riscv64,
13751353 s390x,
......@@ -1378,7 +1356,6 @@ pub const Cpu = struct {
13781356 spirv,
13791357 spirv32,
13801358 spirv64,
1381 spu_2,
13821359 ve,
13831360 wasm32,
13841361 wasm64,
......@@ -1520,14 +1497,6 @@ pub const Cpu = struct {
15201497 };
15211498 }
15221499
1523 /// Returns if the architecture is a Parallax propeller architecture.
1524 pub inline fn isPropeller(arch: Arch) bool {
1525 return switch (arch) {
1526 .propeller1, .propeller2 => true,
1527 else => false,
1528 };
1529 }
1530
15311500 pub fn parseCpuModel(arch: Arch, cpu_name: []const u8) !*const Cpu.Model {
15321501 for (arch.allCpuModels()) |cpu| {
15331502 if (std.mem.eql(u8, cpu_name, cpu.name)) {
......@@ -1564,7 +1533,6 @@ pub const Cpu = struct {
15641533 .xcore,
15651534 .thumb,
15661535 .ve,
1567 .spu_2,
15681536 // GPU bitness is opaque. For now, assume little endian.
15691537 .spirv,
15701538 .spirv32,
......@@ -1572,8 +1540,7 @@ pub const Cpu = struct {
15721540 .loongarch32,
15731541 .loongarch64,
15741542 .arc,
1575 .propeller1,
1576 .propeller2,
1543 .propeller,
15771544 => .little,
15781545
15791546 .armeb,
......@@ -1593,26 +1560,6 @@ pub const Cpu = struct {
15931560 };
15941561 }
15951562
1596 /// Returns whether this architecture supports the address space
1597 pub fn supportsAddressSpace(arch: Arch, address_space: std.builtin.AddressSpace) bool {
1598 const is_nvptx = arch.isNvptx();
1599 const is_spirv = arch.isSpirV();
1600 const is_gpu = is_nvptx or is_spirv or arch == .amdgcn;
1601 return switch (address_space) {
1602 .generic => true,
1603 .fs, .gs, .ss => arch == .x86_64 or arch == .x86,
1604 .global, .constant, .local, .shared => is_gpu,
1605 .param => is_nvptx,
1606 .input, .output, .uniform, .push_constant, .storage_buffer => is_spirv,
1607 // TODO this should also check how many flash banks the cpu has
1608 .flash, .flash1, .flash2, .flash3, .flash4, .flash5 => arch == .avr,
1609
1610 // Propeller address spaces:
1611 .cog, .hub => arch.isPropeller(),
1612 .lut => (arch == .propeller2),
1613 };
1614 }
1615
16161563 /// Returns a name that matches the lib/std/target/* source file name.
16171564 pub fn genericName(arch: Arch) [:0]const u8 {
16181565 return switch (arch) {
......@@ -1622,6 +1569,7 @@ pub const Cpu = struct {
16221569 .loongarch32, .loongarch64 => "loongarch",
16231570 .mips, .mipsel, .mips64, .mips64el => "mips",
16241571 .powerpc, .powerpcle, .powerpc64, .powerpc64le => "powerpc",
1572 .propeller => "propeller",
16251573 .riscv32, .riscv64 => "riscv",
16261574 .sparc, .sparc64 => "sparc",
16271575 .s390x => "s390x",
......@@ -1629,7 +1577,6 @@ pub const Cpu = struct {
16291577 .nvptx, .nvptx64 => "nvptx",
16301578 .wasm32, .wasm64 => "wasm",
16311579 .spirv, .spirv32, .spirv64 => "spirv",
1632 .propeller1, .propeller2 => "propeller",
16331580 else => @tagName(arch),
16341581 };
16351582 }
......@@ -1770,10 +1717,8 @@ pub const Cpu = struct {
17701717 .aarch64_vfabi_sve,
17711718 => &.{ .aarch64, .aarch64_be },
17721719
1773 .arm_apcs,
17741720 .arm_aapcs,
17751721 .arm_aapcs_vfp,
1776 .arm_aapcs16_vfp,
17771722 .arm_interrupt,
17781723 => &.{ .arm, .armeb, .thumb, .thumbeb },
17791724
......@@ -1813,7 +1758,7 @@ pub const Cpu = struct {
18131758 .powerpc_aix_altivec,
18141759 => &.{ .powerpc, .powerpcle },
18151760
1816 .wasm_watc,
1761 .wasm_mvp,
18171762 => &.{ .wasm64, .wasm32 },
18181763
18191764 .arc_sysv,
......@@ -1854,11 +1799,8 @@ pub const Cpu = struct {
18541799 .msp430_eabi,
18551800 => &.{.msp430},
18561801
1857 .propeller1_sysv,
1858 => &.{.propeller1},
1859
1860 .propeller2_sysv,
1861 => &.{.propeller2},
1802 .propeller_sysv,
1803 => &.{.propeller},
18621804
18631805 .s390x_sysv,
18641806 .s390x_sysv_vx,
......@@ -1937,8 +1879,7 @@ pub const Cpu = struct {
19371879 .msp430 => &msp430.cpu.generic,
19381880 .powerpc, .powerpcle => &powerpc.cpu.ppc,
19391881 .powerpc64, .powerpc64le => &powerpc.cpu.ppc64,
1940 .propeller1 => &propeller.cpu.generic,
1941 .propeller2 => &propeller.cpu.generic,
1882 .propeller => &propeller.cpu.p1,
19421883 .riscv32 => &riscv.cpu.generic_rv32,
19431884 .riscv64 => &riscv.cpu.generic_rv64,
19441885 .spirv, .spirv32, .spirv64 => &spirv.cpu.generic,
......@@ -1954,7 +1895,6 @@ pub const Cpu = struct {
19541895 .xtensa => &xtensa.cpu.generic,
19551896
19561897 .kalimba,
1957 .spu_2,
19581898 => &S.generic_model,
19591899 };
19601900 }
......@@ -2015,6 +1955,35 @@ pub const Cpu = struct {
20151955 pub fn baseline(arch: Arch, os: Os) Cpu {
20161956 return Model.baseline(arch, os).toCpu(arch);
20171957 }
1958
1959 /// Returns whether this architecture supports `address_space`. If `context` is `null`, this
1960 /// function simply answers the general question of whether the architecture has any concept
1961 /// of `address_space`; if non-`null`, the function additionally checks whether
1962 /// `address_space` is valid in that context.
1963 pub fn supportsAddressSpace(
1964 cpu: Cpu,
1965 address_space: std.builtin.AddressSpace,
1966 context: ?std.builtin.AddressSpace.Context,
1967 ) bool {
1968 const arch = cpu.arch;
1969
1970 const is_nvptx = arch.isNvptx();
1971 const is_spirv = arch.isSpirV();
1972 const is_gpu = is_nvptx or is_spirv or arch == .amdgcn;
1973
1974 return switch (address_space) {
1975 .generic => true,
1976 .fs, .gs, .ss => (arch == .x86_64 or arch == .x86) and (context == null or context == .pointer),
1977 .flash, .flash1, .flash2, .flash3, .flash4, .flash5 => arch == .avr, // TODO this should also check how many flash banks the cpu has
1978 .cog, .hub => arch == .propeller,
1979 .lut => arch == .propeller and std.Target.propeller.featureSetHas(cpu.features, .p2),
1980
1981 .global, .local, .shared => is_gpu,
1982 .constant => is_gpu and (context == null or context == .constant),
1983 .param => is_nvptx,
1984 .input, .output, .uniform, .push_constant, .storage_buffer => is_spirv,
1985 };
1986 }
20181987};
20191988
20201989pub fn zigTriple(target: Target, allocator: Allocator) Allocator.Error![]u8 {
......@@ -2054,48 +2023,29 @@ pub fn libPrefix(target: Target) [:0]const u8 {
20542023}
20552024
20562025pub inline fn isMinGW(target: Target) bool {
2057 return target.os.tag == .windows and target.isGnu();
2058}
2059
2060pub inline fn isGnu(target: Target) bool {
2061 return target.abi.isGnu();
2062}
2063
2064pub inline fn isMusl(target: Target) bool {
2065 return target.abi.isMusl();
2066}
2067
2068pub inline fn isAndroid(target: Target) bool {
2069 return target.abi.isAndroid();
2070}
2071
2072pub inline fn isWasm(target: Target) bool {
2073 return target.cpu.arch.isWasm();
2074}
2075
2076pub inline fn isDarwin(target: Target) bool {
2077 return target.os.tag.isDarwin();
2078}
2079
2080pub inline fn isBSD(target: Target) bool {
2081 return target.os.tag.isBSD();
2026 return target.os.tag == .windows and target.abi.isGnu();
20822027}
20832028
20842029pub inline fn isGnuLibC(target: Target) bool {
2085 return target.os.tag.isGnuLibC(target.abi);
2030 return switch (target.os.tag) {
2031 .hurd, .linux => target.abi.isGnu(),
2032 else => false,
2033 };
20862034}
20872035
2088pub inline fn isSpirV(target: Target) bool {
2089 return target.cpu.arch.isSpirV();
2036pub inline fn isMuslLibC(target: Target) bool {
2037 return target.os.tag == .linux and target.abi.isMusl();
20902038}
20912039
2092pub const FloatAbi = enum {
2093 hard,
2094 soft,
2095};
2040pub inline fn isDarwinLibC(target: Target) bool {
2041 return switch (target.abi) {
2042 .none, .macabi, .simulator => target.os.tag.isDarwin(),
2043 else => false,
2044 };
2045}
20962046
2097pub inline fn floatAbi(target: Target) FloatAbi {
2098 return target.abi.floatAbi();
2047pub inline fn isWasiLibC(target: Target) bool {
2048 return target.os.tag == .wasi and target.abi.isMusl();
20992049}
21002050
21012051pub const DynamicLinker = struct {
......@@ -2627,7 +2577,6 @@ pub fn ptrBitWidth_cpu_abi(cpu: Cpu, abi: Abi) u16 {
26272577 return switch (cpu.arch) {
26282578 .avr,
26292579 .msp430,
2630 .spu_2,
26312580 => 16,
26322581
26332582 .arc,
......@@ -2653,8 +2602,7 @@ pub fn ptrBitWidth_cpu_abi(cpu: Cpu, abi: Abi) u16 {
26532602 .spirv32,
26542603 .loongarch32,
26552604 .xtensa,
2656 .propeller1,
2657 .propeller2,
2605 .propeller,
26582606 => 32,
26592607
26602608 .aarch64,
......@@ -2733,7 +2681,7 @@ pub fn stackAlignment(target: Target) u16 {
27332681/// Note that char signedness is implementation-defined and many compilers provide
27342682/// an option to override the default signedness e.g. GCC's -funsigned-char / -fsigned-char
27352683pub fn charSignedness(target: Target) std.builtin.Signedness {
2736 if (target.isDarwin() or target.os.tag == .windows or target.os.tag == .uefi) return .signed;
2684 if (target.os.tag.isDarwin() or target.os.tag == .windows or target.os.tag == .uefi) return .signed;
27372685
27382686 return switch (target.cpu.arch) {
27392687 .arm,
......@@ -3164,10 +3112,8 @@ pub fn cTypeAlignment(target: Target, c_type: CType) u16 {
31643112 .x86,
31653113 .xcore,
31663114 .kalimba,
3167 .spu_2,
31683115 .xtensa,
3169 .propeller1,
3170 .propeller2,
3116 .propeller,
31713117 => 4,
31723118
31733119 .arm,
......@@ -3260,10 +3206,8 @@ pub fn cTypePreferredAlignment(target: Target, c_type: CType) u16 {
32603206 .csky,
32613207 .xcore,
32623208 .kalimba,
3263 .spu_2,
32643209 .xtensa,
3265 .propeller1,
3266 .propeller2,
3210 .propeller,
32673211 => 4,
32683212
32693213 .arc,
......@@ -3330,7 +3274,7 @@ pub fn cCallingConvention(target: Target) ?std.builtin.CallingConvention {
33303274 .windows => .{ .aarch64_aapcs_win = .{} },
33313275 else => .{ .aarch64_aapcs = .{} },
33323276 },
3333 .arm, .armeb, .thumb, .thumbeb => switch (target.abi.floatAbi()) {
3277 .arm, .armeb, .thumb, .thumbeb => switch (target.abi.float()) {
33343278 .soft => .{ .arm_aapcs = .{} },
33353279 .hard => .{ .arm_aapcs_vfp = .{} },
33363280 },
......@@ -3343,7 +3287,7 @@ pub fn cCallingConvention(target: Target) ?std.builtin.CallingConvention {
33433287 .riscv32 => .{ .riscv32_ilp32 = .{} },
33443288 .sparc64 => .{ .sparc64_sysv = .{} },
33453289 .sparc => .{ .sparc_sysv = .{} },
3346 .powerpc64 => if (target.isMusl())
3290 .powerpc64 => if (target.abi.isMusl())
33473291 .{ .powerpc64_elf_v2 = .{} }
33483292 else
33493293 .{ .powerpc64_elf = .{} },
......@@ -3352,8 +3296,7 @@ pub fn cCallingConvention(target: Target) ?std.builtin.CallingConvention {
33523296 .aix => .{ .powerpc_aix = .{} },
33533297 else => .{ .powerpc_sysv = .{} },
33543298 },
3355 .wasm32 => .{ .wasm_watc = .{} },
3356 .wasm64 => .{ .wasm_watc = .{} },
3299 .wasm32, .wasm64 => .{ .wasm_mvp = .{} },
33573300 .arc => .{ .arc_sysv = .{} },
33583301 .avr => .avr_gnu,
33593302 .bpfel, .bpfeb => .{ .bpf_std = .{} },
......@@ -3368,10 +3311,8 @@ pub fn cCallingConvention(target: Target) ?std.builtin.CallingConvention {
33683311 else
33693312 .{ .m68k_sysv = .{} },
33703313 .msp430 => .{ .msp430_eabi = .{} },
3371 .propeller1 => .{ .propeller1_sysv = .{} },
3372 .propeller2 => .{ .propeller2_sysv = .{} },
3314 .propeller => .{ .propeller_sysv = .{} },
33733315 .s390x => .{ .s390x_sysv = .{} },
3374 .spu_2 => null,
33753316 .ve => .{ .ve_sysv = .{} },
33763317 .xcore => .{ .xcore_xs1 = .{} },
33773318 .xtensa => .{ .xtensa_call0 = .{} },
......@@ -3381,10 +3322,6 @@ pub fn cCallingConvention(target: Target) ?std.builtin.CallingConvention {
33813322 };
33823323}
33833324
3384pub fn osArchName(target: std.Target) [:0]const u8 {
3385 return target.os.tag.archName(target.cpu.arch);
3386}
3387
33883325const Target = @This();
33893326const std = @import("std.zig");
33903327const builtin = @import("builtin");
lib/std/Target/Query.zig+2-3
......@@ -26,7 +26,7 @@ os_version_min: ?OsVersion = null,
2626os_version_max: ?OsVersion = null,
2727
2828/// `null` means default when cross compiling, or native when `os_tag` is native.
29/// If `isGnuLibC()` is `false`, this must be `null` and is ignored.
29/// If `isGnu()` is `false`, this must be `null` and is ignored.
3030glibc_version: ?SemanticVersion = null,
3131
3232/// `null` means default when cross compiling, or native when `os_tag` is native.
......@@ -235,8 +235,7 @@ pub fn parse(args: ParseOptions) !Query {
235235
236236 const abi_ver_text = abi_it.rest();
237237 if (abi_it.next() != null) {
238 const tag = result.os_tag orelse builtin.os.tag;
239 if (tag.isGnuLibC(abi)) {
238 if (abi.isGnu()) {
240239 result.glibc_version = parseVersion(abi_ver_text) catch |err| switch (err) {
241240 error.Overflow => return error.InvalidAbiVersion,
242241 error.InvalidVersion => return error.InvalidAbiVersion,
lib/std/Target/propeller.zig+30-4
......@@ -1,20 +1,46 @@
1//! This file is auto-generated by tools/update_cpu_features.zig.
2
13const std = @import("../std.zig");
24const CpuFeature = std.Target.Cpu.Feature;
35const CpuModel = std.Target.Cpu.Model;
46
5pub const Feature = enum {};
7pub const Feature = enum {
8 p2,
9};
610
711pub const featureSet = CpuFeature.FeatureSetFns(Feature).featureSet;
812pub const featureSetHas = CpuFeature.FeatureSetFns(Feature).featureSetHas;
913pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
1014pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1115
12pub const all_features: [0]CpuFeature = .{};
16pub const all_features = blk: {
17 const len = @typeInfo(Feature).@"enum".fields.len;
18 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
19 var result: [len]CpuFeature = undefined;
20 result[@intFromEnum(Feature.p2)] = .{
21 .llvm_name = null,
22 .description = "Enable Propeller 2",
23 .dependencies = featureSet(&[_]Feature{}),
24 };
25 const ti = @typeInfo(Feature);
26 for (&result, 0..) |*elem, i| {
27 elem.index = i;
28 elem.name = ti.@"enum".fields[i].name;
29 }
30 break :blk result;
31};
1332
1433pub const cpu = struct {
15 pub const generic = CpuModel{
16 .name = "generic",
34 pub const p1: CpuModel = .{
35 .name = "p1",
1736 .llvm_name = null,
1837 .features = featureSet(&[_]Feature{}),
1938 };
39 pub const p2: CpuModel = .{
40 .name = "p2",
41 .llvm_name = null,
42 .features = featureSet(&[_]Feature{
43 .p2,
44 }),
45 };
2046};
lib/std/Thread.zig+1-1
......@@ -734,7 +734,7 @@ const PosixThreadImpl = struct {
734734 else => {
735735 var count: c_int = undefined;
736736 var count_len: usize = @sizeOf(c_int);
737 const name = if (comptime target.isDarwin()) "hw.logicalcpu" else "hw.ncpu";
737 const name = if (comptime target.os.tag.isDarwin()) "hw.logicalcpu" else "hw.ncpu";
738738 posix.sysctlbynameZ(name, &count, &count_len, null, 0) catch |err| switch (err) {
739739 error.NameTooLong, error.UnknownName => unreachable,
740740 else => |e| return e,
lib/std/Thread/Futex.zig+1-1
......@@ -80,7 +80,7 @@ else if (builtin.os.tag == .openbsd)
8080 OpenbsdImpl
8181else if (builtin.os.tag == .dragonfly)
8282 DragonflyImpl
83else if (builtin.target.isWasm())
83else if (builtin.target.cpu.arch.isWasm())
8484 WasmImpl
8585else if (std.Thread.use_pthreads)
8686 PosixImpl
lib/std/builtin.zig+19-13
......@@ -220,8 +220,6 @@ pub const CallingConvention = union(enum(u8)) {
220220 };
221221 /// Deprecated; use `.x86_thiscall`.
222222 pub const Thiscall: CallingConvention = .{ .x86_thiscall = .{} };
223 /// Deprecated; do not use.
224 pub const APCS: CallingConvention = .{ .arm_apcs = .{} };
225223 /// Deprecated; use `.arm_aapcs`.
226224 pub const AAPCS: CallingConvention = .{ .arm_aapcs = .{} };
227225 /// Deprecated; use `.arm_aapcs_vfp`.
......@@ -284,14 +282,10 @@ pub const CallingConvention = union(enum(u8)) {
284282 aarch64_vfabi_sve: CommonOptions,
285283
286284 // Calling convetions for the `arm`, `armeb`, `thumb`, and `thumbeb` architectures.
287 /// Deprecated; do not use.
288 arm_apcs: CommonOptions, // Removal of `arm_apcs` is blocked by #21842.
289285 /// ARM Architecture Procedure Call Standard
290286 arm_aapcs: CommonOptions,
291287 /// ARM Architecture Procedure Call Standard Vector Floating-Point
292288 arm_aapcs_vfp: CommonOptions,
293 /// Deprecated; do not use.
294 arm_aapcs16_vfp: CommonOptions, // Removal of `arm_aapcs16_vfp` is blocked by #21842.
295289 arm_interrupt: ArmInterruptOptions,
296290
297291 // Calling conventions for the `mips64` and `mips64el` architectures.
......@@ -331,7 +325,7 @@ pub const CallingConvention = union(enum(u8)) {
331325 powerpc_aix_altivec: CommonOptions,
332326
333327 /// The standard `wasm32` and `wasm64` calling convention, as specified in the WebAssembly Tool Conventions.
334 wasm_watc: CommonOptions,
328 wasm_mvp: CommonOptions,
335329
336330 /// The standard `arc` calling convention.
337331 arc_sysv: CommonOptions,
......@@ -371,11 +365,8 @@ pub const CallingConvention = union(enum(u8)) {
371365 /// The standard `msp430` calling convention.
372366 msp430_eabi: CommonOptions,
373367
374 /// The standard `propeller1` calling convention.
375 propeller1_sysv: CommonOptions,
376
377 /// The standard `propeller2` calling convention.
378 propeller2_sysv: CommonOptions,
368 /// The standard `propeller` calling convention.
369 propeller_sysv: CommonOptions,
379370
380371 // Calling conventions for the `s390x` architecture.
381372 s390x_sysv: CommonOptions,
......@@ -500,6 +491,21 @@ pub const CallingConvention = union(enum(u8)) {
500491/// This data structure is used by the Zig language code generation and
501492/// therefore must be kept in sync with the compiler implementation.
502493pub const AddressSpace = enum(u5) {
494 /// The places where a user can specify an address space attribute
495 pub const Context = enum {
496 /// A function is specified to be placed in a certain address space.
497 function,
498 /// A (global) variable is specified to be placed in a certain address space.
499 /// In contrast to .constant, these values (and thus the address space they will be
500 /// placed in) are required to be mutable.
501 variable,
502 /// A (global) constant value is specified to be placed in a certain address space.
503 /// In contrast to .variable, values placed in this address space are not required to be mutable.
504 constant,
505 /// A pointer is ascripted to point into a certain address space.
506 pointer,
507 };
508
503509 // CPU address spaces.
504510 generic,
505511 gs,
......@@ -951,7 +957,7 @@ pub const VaList = switch (builtin.cpu.arch) {
951957 .amdgcn => *u8,
952958 .avr => *anyopaque,
953959 .bpfel, .bpfeb => *anyopaque,
954 .hexagon => if (builtin.target.isMusl()) VaListHexagon else *u8,
960 .hexagon => if (builtin.target.abi.isMusl()) VaListHexagon else *u8,
955961 .loongarch32, .loongarch64 => *anyopaque,
956962 .mips, .mipsel, .mips64, .mips64el => *anyopaque,
957963 .riscv32, .riscv64 => *anyopaque,
lib/std/c.zig+6-6
......@@ -2808,7 +2808,7 @@ pub const Sigaction = switch (native_os) {
28082808 .mipsel,
28092809 .mips64,
28102810 .mips64el,
2811 => if (builtin.target.isMusl())
2811 => if (builtin.target.abi.isMusl())
28122812 linux.Sigaction
28132813 else if (builtin.target.ptrBitWidth() == 64) extern struct {
28142814 pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
......@@ -6701,7 +6701,7 @@ pub const Stat = switch (native_os) {
67016701 return self.ctim;
67026702 }
67036703 },
6704 .mips, .mipsel => if (builtin.target.isMusl()) extern struct {
6704 .mips, .mipsel => if (builtin.target.abi.isMusl()) extern struct {
67056705 dev: dev_t,
67066706 __pad0: [2]i32,
67076707 ino: ino_t,
......@@ -6762,7 +6762,7 @@ pub const Stat = switch (native_os) {
67626762 return self.ctim;
67636763 }
67646764 },
6765 .mips64, .mips64el => if (builtin.target.isMusl()) extern struct {
6765 .mips64, .mips64el => if (builtin.target.abi.isMusl()) extern struct {
67666766 dev: dev_t,
67676767 __pad0: [3]i32,
67686768 ino: ino_t,
......@@ -9863,16 +9863,16 @@ pub const LC = enum(c_int) {
98639863
98649864pub extern "c" fn setlocale(category: LC, locale: ?[*:0]const u8) ?[*:0]const u8;
98659865
9866pub const getcontext = if (builtin.target.isAndroid() or builtin.target.os.tag == .openbsd)
9866pub const getcontext = if (builtin.target.abi.isAndroid() or builtin.target.os.tag == .openbsd)
98679867{} // android bionic and openbsd libc does not implement getcontext
9868else if (native_os == .linux and builtin.target.isMusl())
9868else if (native_os == .linux and builtin.target.abi.isMusl())
98699869 linux.getcontext
98709870else
98719871 private.getcontext;
98729872
98739873pub const max_align_t = if (native_abi == .msvc or native_abi == .itanium)
98749874 f64
9875else if (builtin.target.isDarwin())
9875else if (native_os.isDarwin())
98769876 c_longdouble
98779877else
98789878 extern struct {
lib/std/c/darwin.zig+1-1
......@@ -979,7 +979,7 @@ pub const kevent64_s = extern struct {
979979// to make sure the struct is laid out the same. These values were
980980// produced from C code using the offsetof macro.
981981comptime {
982 if (builtin.target.isDarwin()) {
982 if (builtin.target.os.tag.isDarwin()) {
983983 assert(@offsetOf(kevent64_s, "ident") == 0);
984984 assert(@offsetOf(kevent64_s, "filter") == 8);
985985 assert(@offsetOf(kevent64_s, "flags") == 10);
lib/std/debug.zig+4-4
......@@ -292,7 +292,7 @@ pub fn dumpHexFallible(bytes: []const u8) !void {
292292/// TODO multithreaded awareness
293293pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
294294 nosuspend {
295 if (builtin.target.isWasm()) {
295 if (builtin.target.cpu.arch.isWasm()) {
296296 if (native_os == .wasi) {
297297 const stderr = io.getStdErr().writer();
298298 stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return;
......@@ -380,7 +380,7 @@ pub inline fn getContext(context: *ThreadContext) bool {
380380/// TODO multithreaded awareness
381381pub fn dumpStackTraceFromBase(context: *ThreadContext) void {
382382 nosuspend {
383 if (builtin.target.isWasm()) {
383 if (builtin.target.cpu.arch.isWasm()) {
384384 if (native_os == .wasi) {
385385 const stderr = io.getStdErr().writer();
386386 stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return;
......@@ -478,7 +478,7 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *std.builtin.StackT
478478/// TODO multithreaded awareness
479479pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void {
480480 nosuspend {
481 if (builtin.target.isWasm()) {
481 if (builtin.target.cpu.arch.isWasm()) {
482482 if (native_os == .wasi) {
483483 const stderr = io.getStdErr().writer();
484484 stderr.print("Unable to dump stack trace: not implemented for Wasm\n", .{}) catch return;
......@@ -759,7 +759,7 @@ pub const StackIterator = struct {
759759 pub fn initWithContext(first_address: ?usize, debug_info: *SelfInfo, context: *posix.ucontext_t) !StackIterator {
760760 // The implementation of DWARF unwinding on aarch64-macos is not complete. However, Apple mandates that
761761 // the frame pointer register is always used, so on this platform we can safely use the FP-based unwinder.
762 if (builtin.target.isDarwin() and native_arch == .aarch64)
762 if (builtin.target.os.tag.isDarwin() and native_arch == .aarch64)
763763 return init(first_address, @truncate(context.mcontext.ss.fp));
764764
765765 if (SelfInfo.supports_unwinding) {
lib/std/debug/Dwarf/abi.zig-1
......@@ -17,7 +17,6 @@ pub fn supportsUnwinding(target: std.Target) bool {
1717 .spirv,
1818 .spirv32,
1919 .spirv64,
20 .spu_2,
2120 => false,
2221
2322 // Enabling this causes relocation errors such as:
lib/std/debug/SelfInfo.zig+4-4
......@@ -121,13 +121,13 @@ pub fn deinit(self: *SelfInfo) void {
121121}
122122
123123pub fn getModuleForAddress(self: *SelfInfo, address: usize) !*Module {
124 if (builtin.target.isDarwin()) {
124 if (builtin.target.os.tag.isDarwin()) {
125125 return self.lookupModuleDyld(address);
126126 } else if (native_os == .windows) {
127127 return self.lookupModuleWin32(address);
128128 } else if (native_os == .haiku) {
129129 return self.lookupModuleHaiku(address);
130 } else if (builtin.target.isWasm()) {
130 } else if (builtin.target.cpu.arch.isWasm()) {
131131 return self.lookupModuleWasm(address);
132132 } else {
133133 return self.lookupModuleDl(address);
......@@ -138,13 +138,13 @@ pub fn getModuleForAddress(self: *SelfInfo, address: usize) !*Module {
138138// This can be called when getModuleForAddress fails, so implementations should provide
139139// a path that doesn't rely on any side-effects of a prior successful module lookup.
140140pub fn getModuleNameForAddress(self: *SelfInfo, address: usize) ?[]const u8 {
141 if (builtin.target.isDarwin()) {
141 if (builtin.target.os.tag.isDarwin()) {
142142 return self.lookupModuleNameDyld(address);
143143 } else if (native_os == .windows) {
144144 return self.lookupModuleNameWin32(address);
145145 } else if (native_os == .haiku) {
146146 return null;
147 } else if (builtin.target.isWasm()) {
147 } else if (builtin.target.cpu.arch.isWasm()) {
148148 return null;
149149 } else {
150150 return self.lookupModuleNameDl(address);
lib/std/elf.zig-2
......@@ -1178,8 +1178,6 @@ pub const EM = enum(u16) {
11781178 MIPS_RS3_LE = 10,
11791179 /// Old version of Sparc v9, from before the ABI (deprecated)
11801180 OLD_SPARCV9 = 11,
1181 /// SPU Mark II
1182 SPU_2 = 13,
11831181 /// HPPA
11841182 PARISC = 15,
11851183 /// Fujitsu VPP500 (also old version of PowerPC; deprecated)
lib/std/fs/Dir.zig+1-1
......@@ -2587,7 +2587,7 @@ const CopyFileRawError = error{SystemResources} || posix.CopyFileRangeError || p
25872587// The copy starts at offset 0, the initial offsets are preserved.
25882588// No metadata is transferred over.
25892589fn copy_file(fd_in: posix.fd_t, fd_out: posix.fd_t, maybe_size: ?u64) CopyFileRawError!void {
2590 if (builtin.target.isDarwin()) {
2590 if (builtin.target.os.tag.isDarwin()) {
25912591 const rc = posix.system.fcopyfile(fd_in, fd_out, null, .{ .DATA = true });
25922592 switch (posix.errno(rc)) {
25932593 .SUCCESS => return,
lib/std/heap.zig+3-3
......@@ -348,7 +348,7 @@ pub const page_allocator: Allocator = if (@hasDecl(root, "os") and
348348 @hasDecl(root.os, "heap") and
349349 @hasDecl(root.os.heap, "page_allocator"))
350350 root.os.heap.page_allocator
351else if (builtin.target.isWasm()) .{
351else if (builtin.target.cpu.arch.isWasm()) .{
352352 .ptr = undefined,
353353 .vtable = &WasmAllocator.vtable,
354354} else if (builtin.target.os.tag == .plan9) .{
......@@ -508,7 +508,7 @@ test PageAllocator {
508508 const allocator = page_allocator;
509509 try testAllocator(allocator);
510510 try testAllocatorAligned(allocator);
511 if (!builtin.target.isWasm()) {
511 if (!builtin.target.cpu.arch.isWasm()) {
512512 try testAllocatorLargeAlignment(allocator);
513513 try testAllocatorAlignedShrink(allocator);
514514 }
......@@ -990,7 +990,7 @@ test {
990990 _ = FixedBufferAllocator;
991991 _ = ThreadSafeAllocator;
992992 _ = SbrkAllocator;
993 if (builtin.target.isWasm()) {
993 if (builtin.target.cpu.arch.isWasm()) {
994994 _ = WasmAllocator;
995995 }
996996 if (!builtin.single_threaded) _ = smp_allocator;
lib/std/heap/WasmAllocator.zig+1-1
......@@ -7,7 +7,7 @@ const wasm = std.wasm;
77const math = std.math;
88
99comptime {
10 if (!builtin.target.isWasm()) {
10 if (!builtin.target.cpu.arch.isWasm()) {
1111 @compileError("only available for wasm32 arch");
1212 }
1313 if (!builtin.single_threaded) {
lib/std/heap/debug_allocator.zig+2-2
......@@ -1140,7 +1140,7 @@ test "shrink" {
11401140}
11411141
11421142test "large object - grow" {
1143 if (builtin.target.isWasm()) {
1143 if (builtin.target.cpu.arch.isWasm()) {
11441144 // Not expected to pass on targets that do not have memory mapping.
11451145 return error.SkipZigTest;
11461146 }
......@@ -1319,7 +1319,7 @@ test "realloc large object to larger alignment" {
13191319}
13201320
13211321test "large object rejects shrinking to small" {
1322 if (builtin.target.isWasm()) {
1322 if (builtin.target.cpu.arch.isWasm()) {
13231323 // Not expected to pass on targets that do not have memory mapping.
13241324 return error.SkipZigTest;
13251325 }
lib/std/math/big/int_test.zig+1-1
......@@ -2262,7 +2262,7 @@ test "bitNotWrap more than two limbs" {
22622262 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
22632263 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
22642264 // LLVM: unexpected runtime library name: __umodei4
2265 if (builtin.zig_backend == .stage2_llvm and comptime builtin.target.isWasm()) return error.SkipZigTest; // TODO
2265 if (builtin.zig_backend == .stage2_llvm and comptime builtin.target.cpu.arch.isWasm()) return error.SkipZigTest; // TODO
22662266
22672267 var a = try Managed.initSet(testing.allocator, maxInt(Limb));
22682268 defer a.deinit();
lib/std/math/gamma.zig+1-1
......@@ -263,7 +263,7 @@ test gamma {
263263}
264264
265265test "gamma.special" {
266 if (builtin.cpu.arch.isArm() and builtin.target.floatAbi() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
266 if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
267267
268268 inline for (&.{ f32, f64 }) |T| {
269269 try expect(std.math.isNan(gamma(T, -std.math.nan(T))));
lib/std/math/log10.zig+1-1
......@@ -135,7 +135,7 @@ test log10_int {
135135 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
136136 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
137137 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
138 if (builtin.zig_backend == .stage2_llvm and comptime builtin.target.isWasm()) return error.SkipZigTest; // TODO
138 if (builtin.zig_backend == .stage2_llvm and comptime builtin.target.cpu.arch.isWasm()) return error.SkipZigTest; // TODO
139139
140140 inline for (
141141 .{ u8, u16, u32, u64, u128, u256, u512 },
lib/std/posix.zig+2-2
......@@ -3583,7 +3583,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
35833583 return rc;
35843584 }
35853585
3586 const have_sock_flags = !builtin.target.isDarwin() and native_os != .haiku;
3586 const have_sock_flags = !builtin.target.os.tag.isDarwin() and native_os != .haiku;
35873587 const filtered_sock_type = if (!have_sock_flags)
35883588 socket_type & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC)
35893589 else
......@@ -3879,7 +3879,7 @@ pub fn accept(
38793879 /// description of the `CLOEXEC` flag in `open` for reasons why this may be useful.
38803880 flags: u32,
38813881) AcceptError!socket_t {
3882 const have_accept4 = !(builtin.target.isDarwin() or native_os == .windows or native_os == .haiku);
3882 const have_accept4 = !(builtin.target.os.tag.isDarwin() or native_os == .windows or native_os == .haiku);
38833883 assert(0 == (flags & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC))); // Unsupported flag(s)
38843884
38853885 const accepted_sock: socket_t = while (true) {
lib/std/zig/LibCDirs.zig+3-3
......@@ -127,7 +127,7 @@ fn detectFromInstallation(arena: Allocator, target: std.Target, lci: *const LibC
127127
128128 var sysroot: ?[]const u8 = null;
129129
130 if (target.isDarwin()) d: {
130 if (target.os.tag.isDarwin()) d: {
131131 const down1 = std.fs.path.dirname(lci.sys_include_dir.?) orelse break :d;
132132 const down2 = std.fs.path.dirname(down1) orelse break :d;
133133 try framework_list.append(try std.fs.path.join(arena, &.{ down2, "System", "Library", "Frameworks" }));
......@@ -150,7 +150,7 @@ pub fn detectFromBuilding(
150150) !LibCDirs {
151151 const s = std.fs.path.sep_str;
152152
153 if (target.isDarwin()) {
153 if (target.os.tag.isDarwin()) {
154154 const list = try arena.alloc([]const u8, 1);
155155 list[0] = try std.fmt.allocPrint(
156156 arena,
......@@ -187,7 +187,7 @@ pub fn detectFromBuilding(
187187 "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "generic-{s}",
188188 .{ zig_lib_dir, generic_name },
189189 );
190 const generic_arch_name = target.osArchName();
190 const generic_arch_name = std.zig.target.osArchName(target);
191191 const arch_os_include_dir = try std.fmt.allocPrint(
192192 arena,
193193 "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-{s}-any",
lib/std/zig/LibCInstallation.zig+5-5
......@@ -81,7 +81,7 @@ pub fn parse(
8181 }
8282
8383 const os_tag = target.os.tag;
84 if (self.crt_dir == null and !target.isDarwin()) {
84 if (self.crt_dir == null and !target.os.tag.isDarwin()) {
8585 log.err("crt_dir may not be empty for {s}", .{@tagName(os_tag)});
8686 return error.ParseError;
8787 }
......@@ -167,7 +167,7 @@ pub const FindNativeOptions = struct {
167167pub fn findNative(args: FindNativeOptions) FindError!LibCInstallation {
168168 var self: LibCInstallation = .{};
169169
170 if (is_darwin and args.target.isDarwin()) {
170 if (is_darwin and args.target.os.tag.isDarwin()) {
171171 if (!std.zig.system.darwin.isSdkInstalled(args.allocator))
172172 return error.DarwinSdkNotFound;
173173 const sdk = std.zig.system.darwin.getSdk(args.allocator, args.target) orelse
......@@ -444,7 +444,7 @@ fn findNativeCrtDirPosix(self: *LibCInstallation, args: FindNativeOptions) FindE
444444 self.crt_dir = try ccPrintFileName(.{
445445 .allocator = args.allocator,
446446 .search_basename = switch (args.target.os.tag) {
447 .linux => if (args.target.isAndroid()) "crtbegin_dynamic.o" else "crt1.o",
447 .linux => if (args.target.abi.isAndroid()) "crtbegin_dynamic.o" else "crt1.o",
448448 else => "crt1.o",
449449 },
450450 .want_dirname = .only_dir,
......@@ -734,7 +734,7 @@ pub const CrtBasenames = struct {
734734
735735 const target = args.target;
736736
737 if (target.isAndroid()) return switch (mode) {
737 if (target.abi.isAndroid()) return switch (mode) {
738738 .dynamic_lib => .{
739739 .crtbegin = "crtbegin_so.o",
740740 .crtend = "crtend_so.o",
......@@ -1025,7 +1025,7 @@ const fs = std.fs;
10251025const Allocator = std.mem.Allocator;
10261026const Path = std.Build.Cache.Path;
10271027
1028const is_darwin = builtin.target.isDarwin();
1028const is_darwin = builtin.target.os.tag.isDarwin();
10291029const is_windows = builtin.target.os.tag == .windows;
10301030const is_haiku = builtin.target.os.tag == .haiku;
10311031
lib/std/zig/system.zig+1-1
......@@ -415,7 +415,7 @@ pub fn resolveTargetQuery(query: Target.Query) DetectError!Target {
415415 }
416416
417417 // https://github.com/llvm/llvm-project/issues/105978
418 if (result.cpu.arch.isArm() and result.abi.floatAbi() == .soft) {
418 if (result.cpu.arch.isArm() and result.abi.float() == .soft) {
419419 result.cpu.features.removeFeature(@intFromEnum(Target.arm.Feature.vfp2));
420420 }
421421 }
lib/std/zig/system/NativePaths.zig+1-1
......@@ -83,7 +83,7 @@ pub fn detect(arena: Allocator, native_target: std.Target) !NativePaths {
8383
8484 // TODO: consider also adding homebrew paths
8585 // TODO: consider also adding macports paths
86 if (builtin.target.isDarwin()) {
86 if (builtin.target.os.tag.isDarwin()) {
8787 if (std.zig.system.darwin.isSdkInstalled(arena)) sdk: {
8888 const sdk = std.zig.system.darwin.getSdk(arena, native_target) orelse break :sdk;
8989 try self.addLibDir(try std.fs.path.join(arena, &.{ sdk, "usr/lib" }));
lib/std/zig/target.zig+17
......@@ -129,6 +129,23 @@ pub fn glibcRuntimeTriple(
129129 };
130130}
131131
132pub fn osArchName(target: std.Target) [:0]const u8 {
133 return switch (target.os.tag) {
134 .linux => switch (target.cpu.arch) {
135 .arm, .armeb, .thumb, .thumbeb => "arm",
136 .aarch64, .aarch64_be => "aarch64",
137 .loongarch32, .loongarch64 => "loongarch",
138 .mips, .mipsel, .mips64, .mips64el => "mips",
139 .powerpc, .powerpcle, .powerpc64, .powerpc64le => "powerpc",
140 .riscv32, .riscv64 => "riscv",
141 .sparc, .sparc64 => "sparc",
142 .x86, .x86_64 => "x86",
143 else => @tagName(target.cpu.arch),
144 },
145 else => @tagName(target.cpu.arch),
146 };
147}
148
132149pub fn muslArchName(arch: std.Target.Cpu.Arch, abi: std.Target.Abi) [:0]const u8 {
133150 return switch (abi) {
134151 .muslabin32 => "mipsn32",
src/Compilation.zig+6-15
......@@ -1766,11 +1766,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
17661766 if (comp.config.link_libc and is_exe_or_dyn_lib) {
17671767 // If the "is darwin" check is moved below the libc_installation check below,
17681768 // error.LibCInstallationMissingCrtDir is returned from lci.resolveCrtPaths().
1769 if (target.isDarwin()) {
1770 switch (target.abi) {
1771 .none, .simulator, .macabi => {},
1772 else => return error.LibCUnavailable,
1773 }
1769 if (target.isDarwinLibC()) {
17741770 // TODO delete logic from MachO flush() and queue up tasks here instead.
17751771 } else if (comp.libc_installation) |lci| {
17761772 const basenames = LibCInstallation.CrtBasenames.get(.{
......@@ -1793,7 +1789,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
17931789 // Loads the libraries provided by `target_util.libcFullLinkFlags(target)`.
17941790 comp.link_task_queue.shared.appendAssumeCapacity(.load_host_libc);
17951791 comp.remaining_prelink_tasks += 1;
1796 } else if (target.isMusl() and !target.isWasm()) {
1792 } else if (target.isMuslLibC()) {
17971793 if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable;
17981794
17991795 if (musl.needsCrt0(comp.config.output_mode, comp.config.link_mode, comp.config.pie)) |f| {
......@@ -1817,7 +1813,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18171813
18181814 comp.queued_jobs.glibc_crt_file[@intFromEnum(glibc.CrtFile.libc_nonshared_a)] = true;
18191815 comp.remaining_prelink_tasks += 1;
1820 } else if (target.isWasm() and target.os.tag == .wasi) {
1816 } else if (target.isWasiLibC()) {
18211817 if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable;
18221818
18231819 for (comp.wasi_emulated_libs) |crt_file| {
......@@ -1839,11 +1835,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18391835 // When linking mingw-w64 there are some import libs we always need.
18401836 try comp.windows_libs.ensureUnusedCapacity(gpa, mingw.always_link_libs.len);
18411837 for (mingw.always_link_libs) |name| comp.windows_libs.putAssumeCapacity(name, {});
1842 } else if (target.isDarwin()) {
1843 switch (target.abi) {
1844 .none, .simulator, .macabi => {},
1845 else => return error.LibCUnavailable,
1846 }
18471838 } else if (target.os.tag == .freestanding and capable_of_building_zig_libc) {
18481839 comp.queued_jobs.zig_libc = true;
18491840 comp.remaining_prelink_tasks += 1;
......@@ -5545,7 +5536,7 @@ pub fn addCCArgs(
55455536
55465537 // We might want to support -mfloat-abi=softfp for Arm and CSKY here in the future.
55475538 if (target_util.clangSupportsFloatAbiArg(target)) {
5548 const fabi = @tagName(target.floatAbi());
5539 const fabi = @tagName(target.abi.float());
55495540
55505541 try argv.append(switch (target.cpu.arch) {
55515542 // For whatever reason, Clang doesn't support `-mfloat-abi` for s390x.
......@@ -5598,7 +5589,7 @@ pub fn addCCArgs(
55985589 if (ext != .assembly) {
55995590 try argv.append(if (target.os.tag == .freestanding) "-ffreestanding" else "-fhosted");
56005591
5601 if (target_util.clangSupportsNoImplicitFloatArg(target) and target.floatAbi() == .soft) {
5592 if (target_util.clangSupportsNoImplicitFloatArg(target) and target.abi.float() == .soft) {
56025593 try argv.append("-mno-implicit-float");
56035594 }
56045595
......@@ -5646,7 +5637,7 @@ pub fn addCCArgs(
56465637 // LLVM IR files don't support these flags.
56475638 if (ext != .ll and ext != .bc) {
56485639 // https://github.com/llvm/llvm-project/issues/105972
5649 if (target.cpu.arch.isPowerPC() and target.floatAbi() == .soft) {
5640 if (target.cpu.arch.isPowerPC() and target.abi.float() == .soft) {
56505641 try argv.append("-D__NO_FPRS__");
56515642 try argv.append("-D_SOFT_FLOAT");
56525643 try argv.append("-D_SOFT_DOUBLE");
src/Sema.zig+10-52
......@@ -9378,7 +9378,7 @@ pub fn handleExternLibName(
93789378 );
93799379 break :blk;
93809380 }
9381 if (!target.isWasm() and !block.ownerModule().pic) {
9381 if (!target.cpu.arch.isWasm() and !block.ownerModule().pic) {
93829382 return sema.fail(
93839383 block,
93849384 src_loc,
......@@ -9407,10 +9407,8 @@ const calling_conventions_supporting_var_args = [_]std.builtin.CallingConvention
94079407 .aarch64_aapcs_win,
94089408 .aarch64_vfabi,
94099409 .aarch64_vfabi_sve,
9410 .arm_apcs,
94119410 .arm_aapcs,
94129411 .arm_aapcs_vfp,
9413 .arm_aapcs16_vfp,
94149412 .mips64_n64,
94159413 .mips64_n32,
94169414 .mips_o32,
......@@ -9427,7 +9425,7 @@ const calling_conventions_supporting_var_args = [_]std.builtin.CallingConvention
94279425 .powerpc_sysv_altivec,
94289426 .powerpc_aix,
94299427 .powerpc_aix_altivec,
9430 .wasm_watc,
9428 .wasm_mvp,
94319429 .arc_sysv,
94329430 .avr_gnu,
94339431 .bpf_std,
......@@ -26513,7 +26511,7 @@ fn zirWasmMemorySize(
2651326511 const index_src = block.builtinCallArgSrc(extra.node, 0);
2651426512 const builtin_src = block.nodeOffset(extra.node);
2651526513 const target = sema.pt.zcu.getTarget();
26516 if (!target.isWasm()) {
26514 if (!target.cpu.arch.isWasm()) {
2651726515 return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
2651826516 }
2651926517
......@@ -26538,7 +26536,7 @@ fn zirWasmMemoryGrow(
2653826536 const index_src = block.builtinCallArgSrc(extra.node, 0);
2653926537 const delta_src = block.builtinCallArgSrc(extra.node, 1);
2654026538 const target = sema.pt.zcu.getTarget();
26541 if (!target.isWasm()) {
26539 if (!target.cpu.arch.isWasm()) {
2654226540 return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
2654326541 }
2654426542
......@@ -37222,30 +37220,12 @@ fn analyzeComptimeAlloc(
3722237220 } })));
3722337221}
3722437222
37225/// The places where a user can specify an address space attribute
37226pub const AddressSpaceContext = enum {
37227 /// A function is specified to be placed in a certain address space.
37228 function,
37229
37230 /// A (global) variable is specified to be placed in a certain address space.
37231 /// In contrast to .constant, these values (and thus the address space they will be
37232 /// placed in) are required to be mutable.
37233 variable,
37234
37235 /// A (global) constant value is specified to be placed in a certain address space.
37236 /// In contrast to .variable, values placed in this address space are not required to be mutable.
37237 constant,
37238
37239 /// A pointer is ascripted to point into a certain address space.
37240 pointer,
37241};
37242
3724337223fn resolveAddressSpace(
3724437224 sema: *Sema,
3724537225 block: *Block,
3724637226 src: LazySrcLoc,
3724737227 zir_ref: Zir.Inst.Ref,
37248 ctx: AddressSpaceContext,
37228 ctx: std.builtin.AddressSpace.Context,
3724937229) !std.builtin.AddressSpace {
3725037230 const air_ref = try sema.resolveInst(zir_ref);
3725137231 return sema.analyzeAsAddressSpace(block, src, air_ref, ctx);
......@@ -37256,7 +37236,7 @@ pub fn analyzeAsAddressSpace(
3725637236 block: *Block,
3725737237 src: LazySrcLoc,
3725837238 air_ref: Air.Inst.Ref,
37259 ctx: AddressSpaceContext,
37239 ctx: std.builtin.AddressSpace.Context,
3726037240) !std.builtin.AddressSpace {
3726137241 const pt = sema.pt;
3726237242 const addrspace_ty = try sema.getBuiltinType(src, .AddressSpace);
......@@ -37264,30 +37244,8 @@ pub fn analyzeAsAddressSpace(
3726437244 const addrspace_val = try sema.resolveConstDefinedValue(block, src, coerced, .{ .simple = .@"addrspace" });
3726537245 const address_space = try sema.interpretBuiltinType(block, src, addrspace_val, std.builtin.AddressSpace);
3726637246 const target = pt.zcu.getTarget();
37267 const arch = target.cpu.arch;
37268
37269 const is_nv = arch.isNvptx();
37270 const is_amd = arch == .amdgcn;
37271 const is_spirv = arch.isSpirV();
37272 const is_gpu = is_nv or is_amd or is_spirv;
37273
37274 const supported = switch (address_space) {
37275 // TODO: on spir-v only when os is opencl.
37276 .generic => true,
37277 .gs, .fs, .ss => (arch == .x86 or arch == .x86_64) and ctx == .pointer,
37278 // TODO: check that .shared and .local are left uninitialized
37279 .param => is_nv,
37280 .input, .output, .uniform, .push_constant, .storage_buffer => is_spirv,
37281 .global, .shared, .local => is_gpu,
37282 .constant => is_gpu and (ctx == .constant),
37283 // TODO this should also check how many flash banks the cpu has
37284 .flash, .flash1, .flash2, .flash3, .flash4, .flash5 => arch == .avr,
37285
37286 .cog, .hub => arch.isPropeller(),
37287 .lut => (arch == .propeller2),
37288 };
37289
37290 if (!supported) {
37247
37248 if (!target.cpu.supportsAddressSpace(address_space, ctx)) {
3729137249 // TODO error messages could be made more elaborate here
3729237250 const entity = switch (ctx) {
3729337251 .function => "functions",
......@@ -37299,7 +37257,7 @@ pub fn analyzeAsAddressSpace(
3729937257 block,
3730037258 src,
3730137259 "{s} with address space '{s}' are not supported on {s}",
37302 .{ entity, @tagName(address_space), arch.genericName() },
37260 .{ entity, @tagName(address_space), target.cpu.arch.genericName() },
3730337261 );
3730437262 }
3730537263
......@@ -38729,7 +38687,7 @@ pub fn resolveNavPtrModifiers(
3872938687 };
3873038688
3873138689 const @"addrspace": std.builtin.AddressSpace = as: {
38732 const addrspace_ctx: Sema.AddressSpaceContext = switch (zir_decl.kind) {
38690 const addrspace_ctx: std.builtin.AddressSpace.Context = switch (zir_decl.kind) {
3873338691 .@"var" => .variable,
3873438692 else => switch (nav_ty.zigTypeTag(zcu)) {
3873538693 .@"fn" => .function,
src/Type.zig+1-2
......@@ -1647,7 +1647,7 @@ pub fn maxIntAlignment(target: std.Target) u16 {
16471647 .avr => 1,
16481648 .msp430 => 2,
16491649 .xcore => 4,
1650 .propeller1, .propeller2 => 4,
1650 .propeller => 4,
16511651
16521652 .arm,
16531653 .armeb,
......@@ -1698,7 +1698,6 @@ pub fn maxIntAlignment(target: std.Target) u16 {
16981698
16991699 // Below this comment are unverified but based on the fact that C requires
17001700 // int128_t to be 16 bytes aligned, it's a safe default.
1701 .spu_2,
17021701 .csky,
17031702 .arc,
17041703 .m68k,
src/Zcu.zig+3-7
......@@ -3594,7 +3594,6 @@ pub fn atomicPtrAlignment(
35943594 const max_atomic_bits: u16 = switch (target.cpu.arch) {
35953595 .avr,
35963596 .msp430,
3597 .spu_2,
35983597 => 16,
35993598
36003599 .arc,
......@@ -3620,8 +3619,7 @@ pub fn atomicPtrAlignment(
36203619 .spirv32,
36213620 .loongarch32,
36223621 .xtensa,
3623 .propeller1,
3624 .propeller2,
3622 .propeller,
36253623 => 32,
36263624
36273625 .amdgcn,
......@@ -4211,9 +4209,7 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu
42114209 => |opts| opts.incoming_stack_alignment == null,
42124210
42134211 .arm_aapcs_vfp,
4214 => |opts| opts.incoming_stack_alignment == null and target.os.tag != .watchos,
4215 .arm_aapcs16_vfp,
4216 => |opts| opts.incoming_stack_alignment == null and target.os.tag == .watchos,
4212 => |opts| opts.incoming_stack_alignment == null,
42174213
42184214 .arm_interrupt,
42194215 => |opts| opts.incoming_stack_alignment == null,
......@@ -4241,7 +4237,7 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu
42414237 };
42424238 },
42434239 .stage2_wasm => switch (cc) {
4244 .wasm_watc => |opts| opts.incoming_stack_alignment == null,
4240 .wasm_mvp => |opts| opts.incoming_stack_alignment == null,
42454241 else => false,
42464242 },
42474243 .stage2_arm => switch (cc) {
src/arch/wasm/CodeGen.zig+8-8
......@@ -1396,7 +1396,7 @@ fn resolveCallingConventionValues(
13961396 result.local_index += 1;
13971397 }
13981398 },
1399 .wasm_watc => {
1399 .wasm_mvp => {
14001400 for (fn_info.param_types.get(ip)) |ty| {
14011401 const ty_classes = abi.classifyType(Type.fromInterned(ty), zcu);
14021402 for (ty_classes) |class| {
......@@ -1421,7 +1421,7 @@ pub fn firstParamSRet(
14211421 switch (cc) {
14221422 .@"inline" => unreachable,
14231423 .auto => return isByRef(return_type, zcu, target),
1424 .wasm_watc => {
1424 .wasm_mvp => {
14251425 const ty_classes = abi.classifyType(return_type, zcu);
14261426 if (ty_classes[0] == .indirect) return true;
14271427 if (ty_classes[0] == .direct and ty_classes[1] == .direct) return true;
......@@ -1434,7 +1434,7 @@ pub fn firstParamSRet(
14341434/// Lowers a Zig type and its value based on a given calling convention to ensure
14351435/// it matches the ABI.
14361436fn lowerArg(cg: *CodeGen, cc: std.builtin.CallingConvention, ty: Type, value: WValue) !void {
1437 if (cc != .wasm_watc) {
1437 if (cc != .wasm_mvp) {
14381438 return cg.lowerToStack(value);
14391439 }
14401440
......@@ -2124,7 +2124,7 @@ fn airRet(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21242124 // to the stack instead
21252125 if (cg.return_value != .none) {
21262126 try cg.store(cg.return_value, operand, ret_ty, 0);
2127 } else if (fn_info.cc == .wasm_watc and ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2127 } else if (fn_info.cc == .wasm_mvp and ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
21282128 switch (ret_ty.zigTypeTag(zcu)) {
21292129 // Aggregate types can be lowered as a singular value
21302130 .@"struct", .@"union" => {
......@@ -2268,7 +2268,7 @@ fn airCall(cg: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModifie
22682268 } else if (first_param_sret) {
22692269 break :result_value sret;
22702270 // TODO: Make this less fragile and optimize
2271 } else if (zcu.typeToFunc(fn_ty).?.cc == .wasm_watc and ret_ty.zigTypeTag(zcu) == .@"struct" or ret_ty.zigTypeTag(zcu) == .@"union") {
2271 } else if (zcu.typeToFunc(fn_ty).?.cc == .wasm_mvp and ret_ty.zigTypeTag(zcu) == .@"struct" or ret_ty.zigTypeTag(zcu) == .@"union") {
22722272 const result_local = try cg.allocLocal(ret_ty);
22732273 try cg.addLocal(.local_set, result_local.local.value);
22742274 const scalar_type = abi.scalarType(ret_ty, zcu);
......@@ -2546,7 +2546,7 @@ fn airArg(cg: *CodeGen, inst: Air.Inst.Index) InnerError!void {
25462546 const arg = cg.args[arg_index];
25472547 const cc = zcu.typeToFunc(zcu.navValue(cg.owner_nav).typeOf(zcu)).?.cc;
25482548 const arg_ty = cg.typeOfIndex(inst);
2549 if (cc == .wasm_watc) {
2549 if (cc == .wasm_mvp) {
25502550 const arg_classes = abi.classifyType(arg_ty, zcu);
25512551 for (arg_classes) |class| {
25522552 if (class != .none) {
......@@ -7047,7 +7047,7 @@ fn callIntrinsic(
70477047
70487048 // Always pass over C-ABI
70497049
7050 const want_sret_param = firstParamSRet(.{ .wasm_watc = .{} }, return_type, zcu, cg.target);
7050 const want_sret_param = firstParamSRet(.{ .wasm_mvp = .{} }, return_type, zcu, cg.target);
70517051 // if we want return as first param, we allocate a pointer to stack,
70527052 // and emit it as our first argument
70537053 const sret = if (want_sret_param) blk: {
......@@ -7060,7 +7060,7 @@ fn callIntrinsic(
70607060 for (args, 0..) |arg, arg_i| {
70617061 assert(!(want_sret_param and arg == .stack));
70627062 assert(Type.fromInterned(param_types[arg_i]).hasRuntimeBitsIgnoreComptime(zcu));
7063 try cg.lowerArg(.{ .wasm_watc = .{} }, Type.fromInterned(param_types[arg_i]), arg);
7063 try cg.lowerArg(.{ .wasm_mvp = .{} }, Type.fromInterned(param_types[arg_i]), arg);
70647064 }
70657065
70667066 try cg.addInst(.{ .tag = .call_intrinsic, .data = .{ .intrinsic = intrinsic } });
src/arch/x86_64/CodeGen.zig+1-1
......@@ -90078,7 +90078,7 @@ fn floatCompilerRtAbiName(float_bits: u32) u8 {
9007890078fn floatCompilerRtAbiType(self: *CodeGen, ty: Type, other_ty: Type) Type {
9007990079 if (ty.toIntern() == .f16_type and
9008090080 (other_ty.toIntern() == .f32_type or other_ty.toIntern() == .f64_type) and
90081 self.target.isDarwin()) return .u16;
90081 self.target.os.tag.isDarwin()) return .u16;
9008290082 return ty;
9008390083}
9008490084
src/codegen/c.zig+1-1
......@@ -7725,7 +7725,7 @@ fn toCallingConvention(cc: std.builtin.CallingConvention, zcu: *Zcu) ?[]const u8
77257725 .aarch64_vfabi_sve => "aarch64_sve_pcs",
77267726
77277727 .arm_aapcs => "pcs(\"aapcs\")",
7728 .arm_aapcs_vfp, .arm_aapcs16_vfp => "pcs(\"aapcs-vfp\")",
7728 .arm_aapcs_vfp => "pcs(\"aapcs-vfp\")",
77297729
77307730 .arm_interrupt => |opts| switch (opts.type) {
77317731 .generic => "interrupt",
src/codegen/llvm.zig+20-33
......@@ -98,9 +98,7 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 {
9898 .ve => "ve",
9999
100100 .kalimba,
101 .spu_2,
102 .propeller1,
103 .propeller2,
101 .propeller,
104102 => unreachable, // Gated by hasLlvmSupport().
105103
106104 };
......@@ -1303,7 +1301,7 @@ pub const Object = struct {
13031301 .large => .Large,
13041302 };
13051303
1306 const float_abi: llvm.TargetMachine.FloatABI = if (comp.root_mod.resolved_target.result.floatAbi() == .hard)
1304 const float_abi: llvm.TargetMachine.FloatABI = if (comp.root_mod.resolved_target.result.abi.float() == .hard)
13071305 .Hard
13081306 else
13091307 .Soft;
......@@ -2941,7 +2939,7 @@ pub const Object = struct {
29412939 function_index.setLinkage(.internal, &o.builder);
29422940 function_index.setUnnamedAddr(.unnamed_addr, &o.builder);
29432941 } else {
2944 if (target.isWasm()) {
2942 if (target.cpu.arch.isWasm()) {
29452943 try attributes.addFnAttr(.{ .string = .{
29462944 .kind = try o.builder.string("wasm-import-name"),
29472945 .value = try o.builder.string(nav.name.toSlice(ip)),
......@@ -3158,7 +3156,7 @@ pub const Object = struct {
31583156 .value = try o.builder.string(std.mem.span(s)),
31593157 } }, &o.builder);
31603158 }
3161 if (target.floatAbi() == .soft) {
3159 if (target.abi.float() == .soft) {
31623160 // `use-soft-float` means "use software routines for floating point computations". In
31633161 // other words, it configures how LLVM lowers basic float instructions like `fcmp`,
31643162 // `fadd`, etc. The float calling convention is configured on `TargetMachine` and is
......@@ -4832,7 +4830,7 @@ pub const NavGen = struct {
48324830 const global_index = o.nav_map.get(nav_index).?;
48334831
48344832 const decl_name = decl_name: {
4835 if (zcu.getTarget().isWasm() and ty.zigTypeTag(zcu) == .@"fn") {
4833 if (zcu.getTarget().cpu.arch.isWasm() and ty.zigTypeTag(zcu) == .@"fn") {
48364834 if (lib_name.toSlice(ip)) |lib_name_slice| {
48374835 if (!std.mem.eql(u8, lib_name_slice, "c")) {
48384836 break :decl_name try o.builder.strtabStringFmt("{}|{s}", .{ nav.name.fmt(ip), lib_name_slice });
......@@ -6569,7 +6567,7 @@ pub const FuncGen = struct {
65696567 // Workaround for:
65706568 // * https://github.com/llvm/llvm-project/blob/56905dab7da50bccfcceaeb496b206ff476127e1/llvm/lib/MC/WasmObjectWriter.cpp#L560
65716569 // * https://github.com/llvm/llvm-project/blob/56905dab7da50bccfcceaeb496b206ff476127e1/llvm/test/MC/WebAssembly/blockaddress.ll
6572 if (zcu.comp.getTarget().isWasm()) break :jmp_table null;
6570 if (zcu.comp.getTarget().cpu.arch.isWasm()) break :jmp_table null;
65736571
65746572 // On a 64-bit target, 1024 pointers in our jump table is about 8K of pointers. This seems just
65756573 // about acceptable - it won't fill L1d cache on most CPUs.
......@@ -10026,7 +10024,7 @@ pub const FuncGen = struct {
1002610024 // of the length. This means we need to emit a check where we skip the memset when the length
1002710025 // is 0 as we allow for undefined pointers in 0-sized slices.
1002810026 // This logic can be removed once https://github.com/ziglang/zig/issues/16360 is done.
10029 const intrinsic_len0_traps = o.target.isWasm() and
10027 const intrinsic_len0_traps = o.target.cpu.arch.isWasm() and
1003010028 ptr_ty.isSlice(zcu) and
1003110029 std.Target.wasm.featureSetHas(o.target.cpu.features, .bulk_memory);
1003210030
......@@ -10183,7 +10181,7 @@ pub const FuncGen = struct {
1018310181 // For this reason we must add a check for 0-sized slices as its pointer field can be undefined.
1018410182 // We only have to do this for slices as arrays will have a valid pointer.
1018510183 // This logic can be removed once https://github.com/ziglang/zig/issues/16360 is done.
10186 if (o.target.isWasm() and
10184 if (o.target.cpu.arch.isWasm() and
1018710185 std.Target.wasm.featureSetHas(o.target.cpu.features, .bulk_memory) and
1018810186 dest_ptr_ty.isSlice(zcu))
1018910187 {
......@@ -11768,16 +11766,8 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: std.Targ
1176811766 .x86_interrupt => .x86_intrcc,
1176911767 .aarch64_vfabi => .aarch64_vector_pcs,
1177011768 .aarch64_vfabi_sve => .aarch64_sve_vector_pcs,
11771 .arm_apcs => .arm_apcscc,
1177211769 .arm_aapcs => .arm_aapcscc,
11773 .arm_aapcs_vfp => if (target.os.tag != .watchos)
11774 .arm_aapcs_vfpcc
11775 else
11776 null,
11777 .arm_aapcs16_vfp => if (target.os.tag == .watchos)
11778 .arm_aapcs_vfpcc
11779 else
11780 null,
11770 .arm_aapcs_vfp => .arm_aapcs_vfpcc,
1178111771 .riscv64_lp64_v => .riscv_vectorcallcc,
1178211772 .riscv32_ilp32_v => .riscv_vectorcallcc,
1178311773 .avr_builtin => .avr_builtincc,
......@@ -11821,7 +11811,7 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: std.Targ
1182111811 .powerpc_sysv_altivec,
1182211812 .powerpc_aix,
1182311813 .powerpc_aix_altivec,
11824 .wasm_watc,
11814 .wasm_mvp,
1182511815 .arc_sysv,
1182611816 .avr_gnu,
1182711817 .bpf_std,
......@@ -11834,8 +11824,7 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: std.Targ
1183411824 .m68k_sysv,
1183511825 .m68k_gnu,
1183611826 .msp430_eabi,
11837 .propeller1_sysv,
11838 .propeller2_sysv,
11827 .propeller_sysv,
1183911828 .s390x_sysv,
1184011829 .s390x_sysv_vx,
1184111830 .ve_sysv,
......@@ -11999,12 +11988,12 @@ fn firstParamSRet(fn_info: InternPool.Key.FuncType, zcu: *Zcu, target: std.Targe
1199911988 .x86_64_win => x86_64_abi.classifyWindows(return_type, zcu) == .memory,
1200011989 .x86_sysv, .x86_win => isByRef(return_type, zcu),
1200111990 .x86_stdcall => !isScalar(zcu, return_type),
12002 .wasm_watc => wasm_c_abi.classifyType(return_type, zcu)[0] == .indirect,
11991 .wasm_mvp => wasm_c_abi.classifyType(return_type, zcu)[0] == .indirect,
1200311992 .aarch64_aapcs,
1200411993 .aarch64_aapcs_darwin,
1200511994 .aarch64_aapcs_win,
1200611995 => aarch64_c_abi.classifyType(return_type, zcu) == .memory,
12007 .arm_aapcs, .arm_aapcs_vfp, .arm_aapcs16_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) {
11996 .arm_aapcs, .arm_aapcs_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) {
1200811997 .memory, .i64_array => true,
1200911998 .i32_array => |size| size != 1,
1201011999 .byval => false,
......@@ -12054,7 +12043,7 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu
1205412043 .integer => return o.builder.intType(@intCast(return_type.bitSize(zcu))),
1205512044 .double_integer => return o.builder.arrayType(2, .i64),
1205612045 },
12057 .arm_aapcs, .arm_aapcs_vfp, .arm_aapcs16_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) {
12046 .arm_aapcs, .arm_aapcs_vfp => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) {
1205812047 .memory, .i64_array => return .void,
1205912048 .i32_array => |len| return if (len == 1) .i32 else .void,
1206012049 .byval => return o.lowerType(return_type),
......@@ -12084,7 +12073,7 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu
1208412073 return o.builder.structType(.normal, types[0..types_len]);
1208512074 },
1208612075 },
12087 .wasm_watc => {
12076 .wasm_mvp => {
1208812077 if (isScalar(zcu, return_type)) {
1208912078 return o.lowerType(return_type);
1209012079 }
......@@ -12303,7 +12292,7 @@ const ParamTypeIterator = struct {
1230312292 .double_integer => return Lowering{ .i64_array = 2 },
1230412293 }
1230512294 },
12306 .arm_aapcs, .arm_aapcs_vfp, .arm_aapcs16_vfp => {
12295 .arm_aapcs, .arm_aapcs_vfp => {
1230712296 it.zig_index += 1;
1230812297 it.llvm_index += 1;
1230912298 switch (arm_c_abi.classifyType(ty, zcu, .arg)) {
......@@ -12349,7 +12338,7 @@ const ParamTypeIterator = struct {
1234912338 },
1235012339 }
1235112340 },
12352 .wasm_watc => {
12341 .wasm_mvp => {
1235312342 it.zig_index += 1;
1235412343 it.llvm_index += 1;
1235512344 if (isScalar(zcu, ty)) {
......@@ -12707,7 +12696,7 @@ fn backendSupportsF16(target: std.Target) bool {
1270712696 .armeb,
1270812697 .thumb,
1270912698 .thumbeb,
12710 => target.floatAbi() == .soft or std.Target.arm.featureSetHas(target.cpu.features, .fp_armv8),
12699 => target.abi.float() == .soft or std.Target.arm.featureSetHas(target.cpu.features, .fp_armv8),
1271112700 .aarch64,
1271212701 .aarch64_be,
1271312702 => std.Target.aarch64.featureSetHas(target.cpu.features, .fp_armv8),
......@@ -12734,7 +12723,7 @@ fn backendSupportsF128(target: std.Target) bool {
1273412723 .armeb,
1273512724 .thumb,
1273612725 .thumbeb,
12737 => target.floatAbi() == .soft or std.Target.arm.featureSetHas(target.cpu.features, .fp_armv8),
12726 => target.abi.float() == .soft or std.Target.arm.featureSetHas(target.cpu.features, .fp_armv8),
1273812727 .aarch64,
1273912728 .aarch64_be,
1274012729 => std.Target.aarch64.featureSetHas(target.cpu.features, .fp_armv8),
......@@ -13024,9 +13013,7 @@ pub fn initializeLLVMTarget(arch: std.Target.Cpu.Arch) void {
1302413013
1302513014 // LLVM does does not have a backend for these.
1302613015 .kalimba,
13027 .spu_2,
13028 .propeller1,
13029 .propeller2,
13016 .propeller,
1303013017 => unreachable,
1303113018 }
1303213019}
src/glibc.zig+1-1
......@@ -469,7 +469,7 @@ fn add_include_dirs(comp: *Compilation, arena: Allocator, args: *std.ArrayList([
469469 try args.append("-I");
470470 try args.append(try lib_path(comp, arena, lib_libc ++ "include" ++ s ++ "generic-glibc"));
471471
472 const arch_name = target.osArchName();
472 const arch_name = std.zig.target.osArchName(target);
473473 try args.append("-I");
474474 try args.append(try std.fmt.allocPrint(arena, "{s}" ++ s ++ "libc" ++ s ++ "include" ++ s ++ "{s}-linux-any", .{
475475 comp.zig_lib_directory.path.?, arch_name,
src/libtsan.zig+6-6
......@@ -36,7 +36,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
3636 .watchos => if (target.abi == .simulator) "clang_rt.tsan_watchossim_dynamic" else "clang_rt.tsan_watchos_dynamic",
3737 else => "tsan",
3838 };
39 const link_mode: std.builtin.LinkMode = if (target.isDarwin()) .dynamic else .static;
39 const link_mode: std.builtin.LinkMode = if (target.os.tag.isDarwin()) .dynamic else .static;
4040 const output_mode = .Lib;
4141 const basename = try std.zig.binNameAlloc(arena, .{
4242 .root_name = root_name,
......@@ -52,9 +52,9 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
5252
5353 const optimize_mode = comp.compilerRtOptMode();
5454 const strip = comp.compilerRtStrip();
55 const link_libcpp = target.isDarwin();
5655 const unwind_tables: std.builtin.UnwindTables =
5756 if (target.cpu.arch == .x86 and target.os.tag == .windows) .none else .@"async";
57 const link_libcpp = target.os.tag.isDarwin();
5858
5959 const config = Compilation.Config.resolve(.{
6060 .output_mode = output_mode,
......@@ -276,14 +276,14 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
276276 });
277277 }
278278
279 const skip_linker_dependencies = !target.isDarwin();
280 const linker_allow_shlib_undefined = target.isDarwin();
281 const install_name = if (target.isDarwin())
279 const skip_linker_dependencies = !target.os.tag.isDarwin();
280 const linker_allow_shlib_undefined = target.os.tag.isDarwin();
281 const install_name = if (target.os.tag.isDarwin())
282282 try std.fmt.allocPrintZ(arena, "@rpath/{s}", .{basename})
283283 else
284284 null;
285285 // Workaround for https://github.com/llvm/llvm-project/issues/97627
286 const headerpad_size: ?u32 = if (target.isDarwin()) 32 else null;
286 const headerpad_size: ?u32 = if (target.os.tag.isDarwin()) 32 else null;
287287 const sub_compilation = Compilation.create(comp.gpa, arena, .{
288288 .local_cache_directory = comp.global_cache_directory,
289289 .global_cache_directory = comp.global_cache_directory,
src/libunwind.zig+1-1
......@@ -136,7 +136,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
136136 if (!comp.config.any_non_single_threaded) {
137137 try cflags.append("-D_LIBUNWIND_HAS_NO_THREADS");
138138 }
139 if (target.cpu.arch.isArm() and target.abi.floatAbi() == .hard) {
139 if (target.cpu.arch.isArm() and target.abi.float() == .hard) {
140140 try cflags.append("-DCOMPILER_RT_ARMHF_TARGET");
141141 }
142142 try cflags.append("-Wno-bitwise-conditional-parentheses");
src/link.zig+2-2
......@@ -2067,7 +2067,7 @@ fn resolveLibInput(
20672067
20682068 const lib_name = name_query.name;
20692069
2070 if (target.isDarwin() and link_mode == .dynamic) tbd: {
2070 if (target.os.tag.isDarwin() and link_mode == .dynamic) tbd: {
20712071 // Prefer .tbd over .dylib.
20722072 const test_path: Path = .{
20732073 .root_dir = lib_directory,
......@@ -2104,7 +2104,7 @@ fn resolveLibInput(
21042104
21052105 // In the case of Darwin, the main check will be .dylib, so here we
21062106 // additionally check for .so files.
2107 if (target.isDarwin() and link_mode == .dynamic) so: {
2107 if (target.os.tag.isDarwin() and link_mode == .dynamic) so: {
21082108 const test_path: Path = .{
21092109 .root_dir = lib_directory,
21102110 .sub_path = try std.fmt.allocPrint(arena, "lib{s}.so", .{lib_name}),
src/link/Coff.zig+1-1
......@@ -1881,7 +1881,7 @@ fn linkWithLLD(coff: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
18811881 try argv.append(try allocPrint(arena, "-MLLVM:-target-abi={s}", .{mabi}));
18821882 }
18831883
1884 try argv.append(try allocPrint(arena, "-MLLVM:-float-abi={s}", .{if (target.abi.floatAbi() == .hard) "hard" else "soft"}));
1884 try argv.append(try allocPrint(arena, "-MLLVM:-float-abi={s}", .{if (target.abi.float() == .hard) "hard" else "soft"}));
18851885
18861886 if (comp.config.lto != .none) {
18871887 switch (optimize_mode) {
src/link/Dwarf.zig+1-4
......@@ -3538,11 +3538,8 @@ fn updateLazyType(
35383538 .aarch64_vfabi => .LLVM_AAPCS,
35393539 .aarch64_vfabi_sve => .LLVM_AAPCS,
35403540
3541 .arm_apcs => .normal,
35423541 .arm_aapcs => .LLVM_AAPCS,
3543 .arm_aapcs_vfp,
3544 .arm_aapcs16_vfp,
3545 => .LLVM_AAPCS_VFP,
3542 .arm_aapcs_vfp => .LLVM_AAPCS_VFP,
35463543
35473544 .riscv64_lp64_v,
35483545 .riscv32_ilp32_v,
src/link/Elf.zig+2-2
......@@ -1709,7 +1709,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
17091709
17101710 try argv.appendSlice(&.{
17111711 "-mllvm",
1712 try std.fmt.allocPrint(arena, "-float-abi={s}", .{if (target.abi.floatAbi() == .hard) "hard" else "soft"}),
1712 try std.fmt.allocPrint(arena, "-float-abi={s}", .{if (target.abi.float() == .hard) "hard" else "soft"}),
17131713 });
17141714
17151715 if (comp.config.lto != .none) {
......@@ -2053,7 +2053,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
20532053 try argv.append(lib_path);
20542054 }
20552055 try argv.append(try comp.crtFileAsString(arena, "libc_nonshared.a"));
2056 } else if (target.isMusl()) {
2056 } else if (target.abi.isMusl()) {
20572057 try argv.append(try comp.crtFileAsString(arena, switch (link_mode) {
20582058 .static => "libc.a",
20592059 .dynamic => "libc.so",
src/link/MachO.zig+1-1
......@@ -3548,7 +3548,7 @@ pub fn getTarget(self: MachO) std.Target {
35483548pub fn invalidateKernelCache(dir: fs.Dir, sub_path: []const u8) !void {
35493549 const tracy = trace(@src());
35503550 defer tracy.end();
3551 if (builtin.target.isDarwin() and builtin.target.cpu.arch == .aarch64) {
3551 if (builtin.target.os.tag.isDarwin() and builtin.target.cpu.arch == .aarch64) {
35523552 try dir.copyFile(sub_path, dir, sub_path, .{});
35533553 }
35543554}
src/link/Wasm.zig+2-2
......@@ -4600,7 +4600,7 @@ fn convertZcuFnType(
46004600 if (CodeGen.firstParamSRet(cc, return_type, zcu, target)) {
46014601 try params_buffer.append(gpa, .i32); // memory address is always a 32-bit handle
46024602 } else if (return_type.hasRuntimeBitsIgnoreComptime(zcu)) {
4603 if (cc == .wasm_watc) {
4603 if (cc == .wasm_mvp) {
46044604 const res_classes = abi.classifyType(return_type, zcu);
46054605 assert(res_classes[0] == .direct and res_classes[1] == .none);
46064606 const scalar_type = abi.scalarType(return_type, zcu);
......@@ -4618,7 +4618,7 @@ fn convertZcuFnType(
46184618 if (!param_type.hasRuntimeBitsIgnoreComptime(zcu)) continue;
46194619
46204620 switch (cc) {
4621 .wasm_watc => {
4621 .wasm_mvp => {
46224622 const param_classes = abi.classifyType(param_type, zcu);
46234623 if (param_classes[1] == .none) {
46244624 if (param_classes[0] == .direct) {
src/main.zig+1-1
......@@ -3983,7 +3983,7 @@ fn createModule(
39833983 }
39843984 create_module.lib_dir_args = undefined; // From here we use lib_directories instead.
39853985
3986 if (resolved_target.is_native_os and target.isDarwin()) {
3986 if (resolved_target.is_native_os and target.os.tag.isDarwin()) {
39873987 // If we want to link against frameworks, we need system headers.
39883988 if (create_module.frameworks.count() > 0)
39893989 create_module.want_native_include_dirs = true;
src/target.zig+9-12
......@@ -12,7 +12,7 @@ pub const default_stack_protector_buffer_size = 4;
1212pub fn cannotDynamicLink(target: std.Target) bool {
1313 return switch (target.os.tag) {
1414 .freestanding => true,
15 else => target.isSpirV(),
15 else => target.cpu.arch.isSpirV(),
1616 };
1717}
1818
......@@ -40,12 +40,12 @@ pub fn libcNeedsLibUnwind(target: std.Target) bool {
4040}
4141
4242pub fn requiresPIE(target: std.Target) bool {
43 return target.isAndroid() or target.isDarwin() or target.os.tag == .openbsd;
43 return target.abi.isAndroid() or target.os.tag.isDarwin() or target.os.tag == .openbsd;
4444}
4545
4646/// This function returns whether non-pic code is completely invalid on the given target.
4747pub fn requiresPIC(target: std.Target, linking_libc: bool) bool {
48 return target.isAndroid() or
48 return target.abi.isAndroid() or
4949 target.os.tag == .windows or target.os.tag == .uefi or
5050 osRequiresLibC(target) or
5151 (linking_libc and target.isGnuLibC());
......@@ -195,9 +195,7 @@ pub fn hasLlvmSupport(target: std.Target, ofmt: std.Target.ObjectFormat) bool {
195195
196196 // No LLVM backend exists.
197197 .kalimba,
198 .spu_2,
199 .propeller1,
200 .propeller2,
198 .propeller,
201199 => false,
202200 };
203201}
......@@ -247,7 +245,7 @@ pub fn clangSupportsStackProtector(target: std.Target) bool {
247245}
248246
249247pub fn libcProvidesStackProtector(target: std.Target) bool {
250 return !target.isMinGW() and target.os.tag != .wasi and !target.isSpirV();
248 return !target.isMinGW() and target.os.tag != .wasi and !target.cpu.arch.isSpirV();
251249}
252250
253251pub fn supportsReturnAddress(target: std.Target) bool {
......@@ -444,12 +442,11 @@ pub fn addrSpaceCastIsValid(
444442 from: AddressSpace,
445443 to: AddressSpace,
446444) bool {
447 const arch = target.cpu.arch;
448 switch (arch) {
449 .x86_64, .x86 => return arch.supportsAddressSpace(from) and arch.supportsAddressSpace(to),
445 switch (target.cpu.arch) {
446 .x86_64, .x86 => return target.cpu.supportsAddressSpace(from, null) and target.cpu.supportsAddressSpace(to, null),
450447 .nvptx64, .nvptx, .amdgcn => {
451 const to_generic = arch.supportsAddressSpace(from) and to == .generic;
452 const from_generic = arch.supportsAddressSpace(to) and from == .generic;
448 const to_generic = target.cpu.supportsAddressSpace(from, null) and to == .generic;
449 const from_generic = target.cpu.supportsAddressSpace(to, null) and from == .generic;
453450 return to_generic or from_generic;
454451 },
455452 else => return from == .generic and to == .generic,
stage1/zig.h+94-57
......@@ -9,6 +9,7 @@
99#define zig_clang
1010#define zig_gnuc
1111#elif defined(__GNUC__)
12#define zig_gcc
1213#define zig_gnuc
1314#elif defined(__IBMC__)
1415#define zig_xlc
......@@ -171,7 +172,7 @@
171172#define zig_callconv(c) __attribute__((c))
172173#endif
173174
174#if zig_has_attribute(naked) || defined(zig_gnuc)
175#if zig_has_attribute(naked) || defined(zig_gcc)
175176#define zig_naked_decl __attribute__((naked))
176177#define zig_naked __attribute__((naked))
177178#elif defined(zig_msvc)
......@@ -265,7 +266,7 @@
265266#define zig_linksection_fn zig_linksection
266267#endif
267268
268#if zig_has_builtin(unreachable) || defined(zig_gnuc) || defined(zig_tinyc)
269#if zig_has_builtin(unreachable) || defined(zig_gcc) || defined(zig_tinyc)
269270#define zig_unreachable() __builtin_unreachable()
270271#elif defined(zig_msvc)
271272#define zig_unreachable() __assume(0)
......@@ -293,11 +294,11 @@
293294#endif /* zig_macho */
294295#endif /* zig_msvc */
295296
296#if (zig_has_attribute(alias) || defined(zig_tinyc)) && !defined(zig_macho)
297#define zig_export(symbol, name) __attribute__((alias(symbol)))
298#elif defined(zig_msvc)
297#if defined(zig_msvc)
299298#define zig_export(symbol, name) ; \
300299 __pragma(comment(linker, "/alternatename:" zig_mangle_c(name) "=" zig_mangle_c(symbol)))
300#elif (zig_has_attribute(alias) || defined(zig_tinyc)) && !defined(zig_macho)
301#define zig_export(symbol, name) __attribute__((alias(symbol)))
301302#else
302303#define zig_export(symbol, name) ; \
303304 __asm(zig_mangle_c(name) " = " zig_mangle_c(symbol))
......@@ -321,7 +322,7 @@
321322#if defined(zig_msvc)
322323#define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args;\
323324 __pragma(comment(linker, "/alternatename:" zig_mangle_c(#fn_name) "=" zig_mangle_c(#libc_name)));
324#define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, sig_args, call_args)
325#define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, libc_name, sig_args, call_args)
325326#else /* zig_msvc */
326327#define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args __asm(zig_mangle_c(#libc_name));
327328#define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type libc_name sig_args; \
......@@ -331,7 +332,7 @@
331332#define zig_expand_import_0(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, libc_name, sig_args, call_args)
332333#define zig_expand_import_1(Type, fn_name, libc_name, sig_args, call_args) zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args)
333334
334#if zig_has_attribute(weak) || defined(zig_gnuc) || defined(zig_tinyc)
335#if zig_has_attribute(weak) || defined(zig_gcc) || defined(zig_tinyc)
335336#define zig_weak_linkage __attribute__((weak))
336337#define zig_weak_linkage_fn __attribute__((weak))
337338#elif defined(zig_msvc)
......@@ -418,7 +419,7 @@
418419#define zig_breakpoint() zig_breakpoint_unavailable
419420#endif
420421
421#if zig_has_builtin(return_address) || defined(zig_gnuc) || defined(zig_tinyc)
422#if zig_has_builtin(return_address) || defined(zig_gcc) || defined(zig_tinyc)
422423#define zig_return_address() __builtin_extract_return_addr(__builtin_return_address(0))
423424#elif defined(zig_msvc)
424425#define zig_return_address() _ReturnAddress()
......@@ -426,7 +427,7 @@
426427#define zig_return_address() 0
427428#endif
428429
429#if zig_has_builtin(frame_address) || defined(zig_gnuc) || defined(zig_tinyc)
430#if zig_has_builtin(frame_address) || defined(zig_gcc) || defined(zig_tinyc)
430431#define zig_frame_address() __builtin_frame_address(0)
431432#elif defined(zig_msvc)
432433#define zig_frame_address() _AddressOfReturnAddress()
......@@ -434,7 +435,7 @@
434435#define zig_frame_address() 0
435436#endif
436437
437#if zig_has_builtin(prefetch) || defined(zig_gnuc)
438#if zig_has_builtin(prefetch) || defined(zig_gcc)
438439#define zig_prefetch(addr, rw, locality) __builtin_prefetch(addr, rw, locality)
439440#else
440441#define zig_prefetch(addr, rw, locality)
......@@ -452,7 +453,7 @@
452453#define zig_noreturn [[noreturn]]
453454#elif __STDC_VERSION__ >= 201112L
454455#define zig_noreturn _Noreturn
455#elif zig_has_attribute(noreturn) || defined(zig_gnuc) || defined(zig_tinyc)
456#elif zig_has_attribute(noreturn) || defined(zig_gcc) || defined(zig_tinyc)
456457#define zig_noreturn __attribute__((noreturn))
457458#elif defined(zig_msvc)
458459#define zig_noreturn __declspec(noreturn)
......@@ -650,7 +651,7 @@ typedef ptrdiff_t intptr_t;
650651 zig_operator(Type, Type, operation, operator)
651652#define zig_shift_operator(Type, operation, operator) \
652653 zig_operator(Type, uint8_t, operation, operator)
653#define zig_int_helpers(w) \
654#define zig_int_helpers(w, PromotedUnsigned) \
654655 zig_basic_operator(uint##w##_t, and_u##w, &) \
655656 zig_basic_operator( int##w##_t, and_i##w, &) \
656657 zig_basic_operator(uint##w##_t, or_u##w, |) \
......@@ -726,19 +727,51 @@ typedef ptrdiff_t intptr_t;
726727 } \
727728\
728729 static inline uint##w##_t zig_mulw_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \
729 return zig_wrap_u##w(lhs * rhs, bits); \
730 return zig_wrap_u##w((PromotedUnsigned)lhs * rhs, bits); \
730731 } \
731732\
732733 static inline int##w##_t zig_mulw_i##w(int##w##_t lhs, int##w##_t rhs, uint8_t bits) { \
733734 return zig_wrap_i##w((int##w##_t)((uint##w##_t)lhs * (uint##w##_t)rhs), bits); \
734735 }
735zig_int_helpers(8)
736zig_int_helpers(16)
737zig_int_helpers(32)
738zig_int_helpers(64)
736#if UINT8_MAX <= UINT_MAX
737zig_int_helpers(8, unsigned int)
738#elif UINT8_MAX <= ULONG_MAX
739zig_int_helpers(8, unsigned long)
740#elif UINT8_MAX <= ULLONG_MAX
741zig_int_helpers(8, unsigned long long)
742#else
743zig_int_helpers(8, uint8_t)
744#endif
745#if UINT16_MAX <= UINT_MAX
746zig_int_helpers(16, unsigned int)
747#elif UINT16_MAX <= ULONG_MAX
748zig_int_helpers(16, unsigned long)
749#elif UINT16_MAX <= ULLONG_MAX
750zig_int_helpers(16, unsigned long long)
751#else
752zig_int_helpers(16, uint16_t)
753#endif
754#if UINT32_MAX <= UINT_MAX
755zig_int_helpers(32, unsigned int)
756#elif UINT32_MAX <= ULONG_MAX
757zig_int_helpers(32, unsigned long)
758#elif UINT32_MAX <= ULLONG_MAX
759zig_int_helpers(32, unsigned long long)
760#else
761zig_int_helpers(32, uint32_t)
762#endif
763#if UINT64_MAX <= UINT_MAX
764zig_int_helpers(64, unsigned int)
765#elif UINT64_MAX <= ULONG_MAX
766zig_int_helpers(64, unsigned long)
767#elif UINT64_MAX <= ULLONG_MAX
768zig_int_helpers(64, unsigned long long)
769#else
770zig_int_helpers(64, uint64_t)
771#endif
739772
740773static inline bool zig_addo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) {
741#if zig_has_builtin(add_overflow) || defined(zig_gnuc)
774#if zig_has_builtin(add_overflow) || defined(zig_gcc)
742775 uint32_t full_res;
743776 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
744777 *res = zig_wrap_u32(full_res, bits);
......@@ -751,7 +784,7 @@ static inline bool zig_addo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8
751784
752785zig_extern int32_t __addosi4(int32_t lhs, int32_t rhs, int *overflow);
753786static inline bool zig_addo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) {
754#if zig_has_builtin(add_overflow) || defined(zig_gnuc)
787#if zig_has_builtin(add_overflow) || defined(zig_gcc)
755788 int32_t full_res;
756789 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
757790#else
......@@ -764,7 +797,7 @@ static inline bool zig_addo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t
764797}
765798
766799static inline bool zig_addo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) {
767#if zig_has_builtin(add_overflow) || defined(zig_gnuc)
800#if zig_has_builtin(add_overflow) || defined(zig_gcc)
768801 uint64_t full_res;
769802 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
770803 *res = zig_wrap_u64(full_res, bits);
......@@ -777,7 +810,7 @@ static inline bool zig_addo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8
777810
778811zig_extern int64_t __addodi4(int64_t lhs, int64_t rhs, int *overflow);
779812static inline bool zig_addo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) {
780#if zig_has_builtin(add_overflow) || defined(zig_gnuc)
813#if zig_has_builtin(add_overflow) || defined(zig_gcc)
781814 int64_t full_res;
782815 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
783816#else
......@@ -790,7 +823,7 @@ static inline bool zig_addo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t
790823}
791824
792825static inline bool zig_addo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t bits) {
793#if zig_has_builtin(add_overflow) || defined(zig_gnuc)
826#if zig_has_builtin(add_overflow) || defined(zig_gcc)
794827 uint8_t full_res;
795828 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
796829 *res = zig_wrap_u8(full_res, bits);
......@@ -804,7 +837,7 @@ static inline bool zig_addo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t b
804837}
805838
806839static inline bool zig_addo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits) {
807#if zig_has_builtin(add_overflow) || defined(zig_gnuc)
840#if zig_has_builtin(add_overflow) || defined(zig_gcc)
808841 int8_t full_res;
809842 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
810843 *res = zig_wrap_i8(full_res, bits);
......@@ -818,7 +851,7 @@ static inline bool zig_addo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits
818851}
819852
820853static inline bool zig_addo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8_t bits) {
821#if zig_has_builtin(add_overflow) || defined(zig_gnuc)
854#if zig_has_builtin(add_overflow) || defined(zig_gcc)
822855 uint16_t full_res;
823856 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
824857 *res = zig_wrap_u16(full_res, bits);
......@@ -832,7 +865,7 @@ static inline bool zig_addo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8
832865}
833866
834867static inline bool zig_addo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t bits) {
835#if zig_has_builtin(add_overflow) || defined(zig_gnuc)
868#if zig_has_builtin(add_overflow) || defined(zig_gcc)
836869 int16_t full_res;
837870 bool overflow = __builtin_add_overflow(lhs, rhs, &full_res);
838871 *res = zig_wrap_i16(full_res, bits);
......@@ -846,7 +879,7 @@ static inline bool zig_addo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t
846879}
847880
848881static inline bool zig_subo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) {
849#if zig_has_builtin(sub_overflow) || defined(zig_gnuc)
882#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
850883 uint32_t full_res;
851884 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
852885 *res = zig_wrap_u32(full_res, bits);
......@@ -859,7 +892,7 @@ static inline bool zig_subo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8
859892
860893zig_extern int32_t __subosi4(int32_t lhs, int32_t rhs, int *overflow);
861894static inline bool zig_subo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) {
862#if zig_has_builtin(sub_overflow) || defined(zig_gnuc)
895#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
863896 int32_t full_res;
864897 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
865898#else
......@@ -872,7 +905,7 @@ static inline bool zig_subo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t
872905}
873906
874907static inline bool zig_subo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) {
875#if zig_has_builtin(sub_overflow) || defined(zig_gnuc)
908#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
876909 uint64_t full_res;
877910 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
878911 *res = zig_wrap_u64(full_res, bits);
......@@ -885,7 +918,7 @@ static inline bool zig_subo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8
885918
886919zig_extern int64_t __subodi4(int64_t lhs, int64_t rhs, int *overflow);
887920static inline bool zig_subo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) {
888#if zig_has_builtin(sub_overflow) || defined(zig_gnuc)
921#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
889922 int64_t full_res;
890923 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
891924#else
......@@ -898,7 +931,7 @@ static inline bool zig_subo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t
898931}
899932
900933static inline bool zig_subo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t bits) {
901#if zig_has_builtin(sub_overflow) || defined(zig_gnuc)
934#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
902935 uint8_t full_res;
903936 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
904937 *res = zig_wrap_u8(full_res, bits);
......@@ -912,7 +945,7 @@ static inline bool zig_subo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t b
912945}
913946
914947static inline bool zig_subo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits) {
915#if zig_has_builtin(sub_overflow) || defined(zig_gnuc)
948#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
916949 int8_t full_res;
917950 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
918951 *res = zig_wrap_i8(full_res, bits);
......@@ -926,7 +959,7 @@ static inline bool zig_subo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits
926959}
927960
928961static inline bool zig_subo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8_t bits) {
929#if zig_has_builtin(sub_overflow) || defined(zig_gnuc)
962#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
930963 uint16_t full_res;
931964 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
932965 *res = zig_wrap_u16(full_res, bits);
......@@ -940,7 +973,7 @@ static inline bool zig_subo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8
940973}
941974
942975static inline bool zig_subo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t bits) {
943#if zig_has_builtin(sub_overflow) || defined(zig_gnuc)
976#if zig_has_builtin(sub_overflow) || defined(zig_gcc)
944977 int16_t full_res;
945978 bool overflow = __builtin_sub_overflow(lhs, rhs, &full_res);
946979 *res = zig_wrap_i16(full_res, bits);
......@@ -954,7 +987,7 @@ static inline bool zig_subo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t
954987}
955988
956989static inline bool zig_mulo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8_t bits) {
957#if zig_has_builtin(mul_overflow) || defined(zig_gnuc)
990#if zig_has_builtin(mul_overflow) || defined(zig_gcc)
958991 uint32_t full_res;
959992 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res);
960993 *res = zig_wrap_u32(full_res, bits);
......@@ -967,7 +1000,7 @@ static inline bool zig_mulo_u32(uint32_t *res, uint32_t lhs, uint32_t rhs, uint8
9671000
9681001zig_extern int32_t __mulosi4(int32_t lhs, int32_t rhs, int *overflow);
9691002static inline bool zig_mulo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t bits) {
970#if zig_has_builtin(mul_overflow) || defined(zig_gnuc)
1003#if zig_has_builtin(mul_overflow) || defined(zig_gcc)
9711004 int32_t full_res;
9721005 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res);
9731006#else
......@@ -980,7 +1013,7 @@ static inline bool zig_mulo_i32(int32_t *res, int32_t lhs, int32_t rhs, uint8_t
9801013}
9811014
9821015static inline bool zig_mulo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8_t bits) {
983#if zig_has_builtin(mul_overflow) || defined(zig_gnuc)
1016#if zig_has_builtin(mul_overflow) || defined(zig_gcc)
9841017 uint64_t full_res;
9851018 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res);
9861019 *res = zig_wrap_u64(full_res, bits);
......@@ -993,7 +1026,7 @@ static inline bool zig_mulo_u64(uint64_t *res, uint64_t lhs, uint64_t rhs, uint8
9931026
9941027zig_extern int64_t __mulodi4(int64_t lhs, int64_t rhs, int *overflow);
9951028static inline bool zig_mulo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t bits) {
996#if zig_has_builtin(mul_overflow) || defined(zig_gnuc)
1029#if zig_has_builtin(mul_overflow) || defined(zig_gcc)
9971030 int64_t full_res;
9981031 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res);
9991032#else
......@@ -1006,7 +1039,7 @@ static inline bool zig_mulo_i64(int64_t *res, int64_t lhs, int64_t rhs, uint8_t
10061039}
10071040
10081041static inline bool zig_mulo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t bits) {
1009#if zig_has_builtin(mul_overflow) || defined(zig_gnuc)
1042#if zig_has_builtin(mul_overflow) || defined(zig_gcc)
10101043 uint8_t full_res;
10111044 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res);
10121045 *res = zig_wrap_u8(full_res, bits);
......@@ -1020,7 +1053,7 @@ static inline bool zig_mulo_u8(uint8_t *res, uint8_t lhs, uint8_t rhs, uint8_t b
10201053}
10211054
10221055static inline bool zig_mulo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits) {
1023#if zig_has_builtin(mul_overflow) || defined(zig_gnuc)
1056#if zig_has_builtin(mul_overflow) || defined(zig_gcc)
10241057 int8_t full_res;
10251058 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res);
10261059 *res = zig_wrap_i8(full_res, bits);
......@@ -1034,7 +1067,7 @@ static inline bool zig_mulo_i8(int8_t *res, int8_t lhs, int8_t rhs, uint8_t bits
10341067}
10351068
10361069static inline bool zig_mulo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8_t bits) {
1037#if zig_has_builtin(mul_overflow) || defined(zig_gnuc)
1070#if zig_has_builtin(mul_overflow) || defined(zig_gcc)
10381071 uint16_t full_res;
10391072 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res);
10401073 *res = zig_wrap_u16(full_res, bits);
......@@ -1048,7 +1081,7 @@ static inline bool zig_mulo_u16(uint16_t *res, uint16_t lhs, uint16_t rhs, uint8
10481081}
10491082
10501083static inline bool zig_mulo_i16(int16_t *res, int16_t lhs, int16_t rhs, uint8_t bits) {
1051#if zig_has_builtin(mul_overflow) || defined(zig_gnuc)
1084#if zig_has_builtin(mul_overflow) || defined(zig_gcc)
10521085 int16_t full_res;
10531086 bool overflow = __builtin_mul_overflow(lhs, rhs, &full_res);
10541087 *res = zig_wrap_i16(full_res, bits);
......@@ -1157,7 +1190,7 @@ static inline int8_t zig_byte_swap_i8(int8_t val, uint8_t bits) {
11571190
11581191static inline uint16_t zig_byte_swap_u16(uint16_t val, uint8_t bits) {
11591192 uint16_t full_res;
1160#if zig_has_builtin(bswap16) || defined(zig_gnuc)
1193#if zig_has_builtin(bswap16) || defined(zig_gcc)
11611194 full_res = __builtin_bswap16(val);
11621195#else
11631196 full_res = (uint16_t)zig_byte_swap_u8((uint8_t)(val >> 0), 8) << 8 |
......@@ -1172,7 +1205,7 @@ static inline int16_t zig_byte_swap_i16(int16_t val, uint8_t bits) {
11721205
11731206static inline uint32_t zig_byte_swap_u32(uint32_t val, uint8_t bits) {
11741207 uint32_t full_res;
1175#if zig_has_builtin(bswap32) || defined(zig_gnuc)
1208#if zig_has_builtin(bswap32) || defined(zig_gcc)
11761209 full_res = __builtin_bswap32(val);
11771210#else
11781211 full_res = (uint32_t)zig_byte_swap_u16((uint16_t)(val >> 0), 16) << 16 |
......@@ -1187,7 +1220,7 @@ static inline int32_t zig_byte_swap_i32(int32_t val, uint8_t bits) {
11871220
11881221static inline uint64_t zig_byte_swap_u64(uint64_t val, uint8_t bits) {
11891222 uint64_t full_res;
1190#if zig_has_builtin(bswap64) || defined(zig_gnuc)
1223#if zig_has_builtin(bswap64) || defined(zig_gcc)
11911224 full_res = __builtin_bswap64(val);
11921225#else
11931226 full_res = (uint64_t)zig_byte_swap_u32((uint32_t)(val >> 0), 32) << 32 |
......@@ -1267,7 +1300,7 @@ static inline int64_t zig_bit_reverse_i64(int64_t val, uint8_t bits) {
12671300 static inline uint8_t zig_popcount_i##w(int##w##_t val, uint8_t bits) { \
12681301 return zig_popcount_u##w((uint##w##_t)val, bits); \
12691302 }
1270#if zig_has_builtin(popcount) || defined(zig_gnuc) || defined(zig_tinyc)
1303#if zig_has_builtin(popcount) || defined(zig_gcc) || defined(zig_tinyc)
12711304#define zig_builtin_popcount(w) \
12721305 static inline uint8_t zig_popcount_u##w(uint##w##_t val, uint8_t bits) { \
12731306 (void)bits; \
......@@ -1296,7 +1329,7 @@ zig_builtin_popcount(64)
12961329 static inline uint8_t zig_ctz_i##w(int##w##_t val, uint8_t bits) { \
12971330 return zig_ctz_u##w((uint##w##_t)val, bits); \
12981331 }
1299#if zig_has_builtin(ctz) || defined(zig_gnuc) || defined(zig_tinyc)
1332#if zig_has_builtin(ctz) || defined(zig_gcc) || defined(zig_tinyc)
13001333#define zig_builtin_ctz(w) \
13011334 static inline uint8_t zig_ctz_u##w(uint##w##_t val, uint8_t bits) { \
13021335 if (val == 0) return bits; \
......@@ -1321,7 +1354,7 @@ zig_builtin_ctz(64)
13211354 static inline uint8_t zig_clz_i##w(int##w##_t val, uint8_t bits) { \
13221355 return zig_clz_u##w((uint##w##_t)val, bits); \
13231356 }
1324#if zig_has_builtin(clz) || defined(zig_gnuc) || defined(zig_tinyc)
1357#if zig_has_builtin(clz) || defined(zig_gcc) || defined(zig_tinyc)
13251358#define zig_builtin_clz(w) \
13261359 static inline uint8_t zig_clz_u##w(uint##w##_t val, uint8_t bits) { \
13271360 if (val == 0) return bits; \
......@@ -3176,7 +3209,7 @@ long double __cdecl nanl(char const* input);
31763209#define __builtin_infl() zig_msvc_flt_infl
31773210#endif
31783211
3179#if (zig_has_builtin(nan) && zig_has_builtin(nans) && zig_has_builtin(inf)) || defined(zig_gnuc)
3212#if (zig_has_builtin(nan) && zig_has_builtin(nans) && zig_has_builtin(inf)) || defined(zig_gcc)
31803213#define zig_make_special_f16(sign, name, arg, repr) sign zig_make_f16 (__builtin_##name, )(arg)
31813214#define zig_make_special_f32(sign, name, arg, repr) sign zig_make_f32 (__builtin_##name, )(arg)
31823215#define zig_make_special_f64(sign, name, arg, repr) sign zig_make_f64 (__builtin_##name, )(arg)
......@@ -3202,7 +3235,7 @@ typedef double zig_f16;
32023235#elif LDBL_MANT_DIG == 11
32033236typedef long double zig_f16;
32043237#define zig_make_f16(fp, repr) fp##l
3205#elif FLT16_MANT_DIG == 11 && (zig_has_builtin(inff16) || defined(zig_gnuc))
3238#elif FLT16_MANT_DIG == 11 && (zig_has_builtin(inff16) || defined(zig_gcc))
32063239typedef _Float16 zig_f16;
32073240#define zig_make_f16(fp, repr) fp##f16
32083241#elif defined(__SIZEOF_FP16__)
......@@ -3324,7 +3357,7 @@ typedef zig_u128 zig_f80;
33243357#define zig_init_special_f80(sign, name, arg, repr) repr
33253358#endif
33263359
3327#if !defined(zig_clang) && defined(zig_gnuc) && defined(zig_x86)
3360#if defined(zig_gcc) && defined(zig_x86)
33283361#define zig_f128_has_miscompilations 1
33293362#else
33303363#define zig_f128_has_miscompilations 0
......@@ -3729,7 +3762,11 @@ zig_float_builtins(64)
37293762 res = zig_atomicrmw_expected; \
37303763} while (0)
37313764
3732#if (__STDC_VERSION__ >= 201112L || (zig_has_include(<stdatomic.h>) && !defined(zig_msvc))) && !defined(__STDC_NO_ATOMICS__)
3765#if (__STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)) || (zig_has_include(<stdatomic.h>) && !defined(zig_msvc))
3766#define zig_c11_atomics
3767#endif
3768
3769#if defined(zig_c11_atomics)
37333770#include <stdatomic.h>
37343771typedef enum memory_order zig_memory_order;
37353772#define zig_memory_order_relaxed memory_order_relaxed
......@@ -3765,9 +3802,9 @@ typedef int zig_memory_order;
37653802#define zig_memory_order_acq_rel __ATOMIC_ACQ_REL
37663803#define zig_memory_order_seq_cst __ATOMIC_SEQ_CST
37673804#define zig_atomic(Type) Type
3768#define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, &(expected), &(desired), false, succ, fail)
3769#define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, &(expected), &(desired), true, succ, fail)
3770#define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) __atomic_exchange(obj, &(arg), &(res), order)
3805#define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, (ReprType *)&(expected), (ReprType *)&(desired), false, succ, fail)
3806#define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, (ReprType *)&(expected), (ReprType *)&(desired), true, succ, fail)
3807#define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) __atomic_exchange(obj, (ReprType *)&(arg), &(res), order)
37713808#define zig_atomicrmw_add(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_add (obj, arg, order)
37723809#define zig_atomicrmw_sub(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_sub (obj, arg, order)
37733810#define zig_atomicrmw_or(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_or (obj, arg, order)
......@@ -3776,7 +3813,7 @@ typedef int zig_memory_order;
37763813#define zig_atomicrmw_nand(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_nand(obj, arg, order)
37773814#define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_min (obj, arg, order)
37783815#define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_max (obj, arg, order)
3779#define zig_atomic_store( obj, arg, order, Type, ReprType) __atomic_store (obj, &(arg), order)
3816#define zig_atomic_store( obj, arg, order, Type, ReprType) __atomic_store (obj, (ReprType *)&(arg), order)
37803817#define zig_atomic_load(res, obj, order, Type, ReprType) __atomic_load (obj, &(res), order)
37813818#undef zig_atomicrmw_xchg_float
37823819#define zig_atomicrmw_xchg_float zig_atomicrmw_xchg
......@@ -3823,7 +3860,7 @@ typedef int zig_memory_order;
38233860#define zig_atomic_load(res, obj, order, Type, ReprType) zig_atomics_unavailable
38243861#endif
38253862
3826#if defined(zig_msvc) && defined(zig_x86)
3863#if !defined(zig_c11_atomics) && defined(zig_msvc) && defined(zig_x86)
38273864
38283865/* TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 */
38293866
......@@ -4069,7 +4106,7 @@ static inline void zig_msvc_atomic_store_i128(zig_i128 volatile* obj, zig_i128 a
40694106
40704107#endif /* zig_x86_32 */
40714108
4072#endif /* zig_msvc && zig_x86 */
4109#endif /* !zig_c11_atomics && zig_msvc && zig_x86 */
40734110
40744111/* ======================== Special Case Intrinsics ========================= */
40754112
stage1/zig1.wasm
Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ
test/behavior/floatop.zig+2-2
......@@ -126,7 +126,7 @@ test "cmp f16" {
126126 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
127127 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
128128 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
129 if (builtin.cpu.arch.isArm() and builtin.target.floatAbi() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
129 if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
130130
131131 try testCmp(f16);
132132 try comptime testCmp(f16);
......@@ -135,7 +135,7 @@ test "cmp f16" {
135135test "cmp f32/f64" {
136136 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
137137 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
138 if (builtin.cpu.arch.isArm() and builtin.target.floatAbi() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
138 if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
139139
140140 try testCmp(f32);
141141 try comptime testCmp(f32);
test/behavior/math.zig+3-3
......@@ -1639,7 +1639,7 @@ test "NaN comparison" {
16391639 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
16401640 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
16411641 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1642 if (builtin.cpu.arch.isArm() and builtin.target.floatAbi() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
1642 if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
16431643
16441644 try testNanEqNan(f16);
16451645 try testNanEqNan(f32);
......@@ -1795,7 +1795,7 @@ test "runtime comparison to NaN is comptime-known" {
17951795 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
17961796 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
17971797 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1798 if (builtin.cpu.arch.isArm() and builtin.target.floatAbi() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
1798 if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
17991799
18001800 const S = struct {
18011801 fn doTheTest(comptime F: type, x: F) void {
......@@ -1826,7 +1826,7 @@ test "runtime int comparison to inf is comptime-known" {
18261826 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
18271827 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
18281828 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1829 if (builtin.cpu.arch.isArm() and builtin.target.floatAbi() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
1829 if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234
18301830
18311831 const S = struct {
18321832 fn doTheTest(comptime F: type, x: u32) void {
test/c_abi/main.zig+4-4
......@@ -135,7 +135,7 @@ export fn zig_f64(x: f64) void {
135135 expect(x == 56.78) catch @panic("test failure: zig_f64");
136136}
137137export fn zig_longdouble(x: c_longdouble) void {
138 if (!builtin.target.isWasm()) return; // waiting for #1481
138 if (!builtin.target.cpu.arch.isWasm()) return; // waiting for #1481
139139 expect(x == 12.34) catch @panic("test failure: zig_longdouble");
140140}
141141
......@@ -1661,7 +1661,7 @@ test "bool simd vector" {
16611661 }
16621662
16631663 {
1664 if (!builtin.target.isWasm()) c_vector_256_bool(.{
1664 if (!builtin.target.cpu.arch.isWasm()) c_vector_256_bool(.{
16651665 false,
16661666 true,
16671667 true,
......@@ -2179,7 +2179,7 @@ test "bool simd vector" {
21792179 try expect(vec[255] == false);
21802180 }
21812181 {
2182 if (!builtin.target.isWasm()) c_vector_512_bool(.{
2182 if (!builtin.target.cpu.arch.isWasm()) c_vector_512_bool(.{
21832183 true,
21842184 true,
21852185 true,
......@@ -5593,7 +5593,7 @@ test "f80 extra struct" {
55935593
55945594comptime {
55955595 skip: {
5596 if (builtin.target.isWasm()) break :skip;
5596 if (builtin.target.cpu.arch.isWasm()) break :skip;
55975597
55985598 _ = struct {
55995599 export fn zig_f128(x: f128) f128 {
test/cases/compile_errors/@import_zon_bad_type.zig+3-3
......@@ -117,9 +117,9 @@ export fn testMutablePointer() void {
117117// tmp.zig:37:38: note: imported here
118118// neg_inf.zon:1:1: error: expected type '?u8'
119119// tmp.zig:57:28: note: imported here
120// neg_inf.zon:1:1: error: expected type 'tmp.testNonExhaustiveEnum__enum_490'
120// neg_inf.zon:1:1: error: expected type 'tmp.testNonExhaustiveEnum__enum_487'
121121// tmp.zig:62:39: note: imported here
122// neg_inf.zon:1:1: error: expected type 'tmp.testUntaggedUnion__union_492'
122// neg_inf.zon:1:1: error: expected type 'tmp.testUntaggedUnion__union_489'
123123// tmp.zig:67:44: note: imported here
124// neg_inf.zon:1:1: error: expected type 'tmp.testTaggedUnionVoid__union_495'
124// neg_inf.zon:1:1: error: expected type 'tmp.testTaggedUnionVoid__union_492'
125125// tmp.zig:72:50: note: imported here
test/cases/compile_errors/anytype_param_requires_comptime.zig+1-1
......@@ -15,6 +15,6 @@ pub export fn entry() void {
1515// error
1616//
1717// :7:25: error: unable to resolve comptime value
18// :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_464.C' must be comptime-known
18// :7:25: note: initializer of comptime-only struct 'tmp.S.foo__anon_461.C' must be comptime-known
1919// :4:16: note: struct requires comptime because of this field
2020// :4:16: note: types are not available at runtime
test/cases/compile_errors/bogus_method_call_on_slice.zig+1-1
......@@ -16,5 +16,5 @@ pub export fn entry2() void {
1616//
1717// :3:6: error: no field or member function named 'copy' in '[]const u8'
1818// :9:8: error: no field or member function named 'bar' in '@TypeOf(.{})'
19// :12:18: error: no field or member function named 'bar' in 'tmp.entry2__struct_468'
19// :12:18: error: no field or member function named 'bar' in 'tmp.entry2__struct_465'
2020// :12:6: note: struct declared here
test/cases/compile_errors/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig+2-4
......@@ -1,10 +1,8 @@
1export fn entry1() callconv(.APCS) void {}
21export fn entry2() callconv(.AAPCS) void {}
32export fn entry3() callconv(.AAPCSVFP) void {}
43
54// error
65// target=x86_64-linux-none
76//
8// :1:30: error: calling convention 'arm_apcs' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'
9// :2:30: error: calling convention 'arm_aapcs' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'
10// :3:30: error: calling convention 'arm_aapcs_vfp' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'
7// :1:30: error: calling convention 'arm_aapcs' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'
8// :2:30: error: calling convention 'arm_aapcs_vfp' only available on architectures 'arm', 'armeb', 'thumb', 'thumbeb'
test/cases/compile_errors/coerce_anon_struct.zig+1-1
......@@ -6,6 +6,6 @@ export fn foo() void {
66
77// error
88//
9// :4:16: error: expected type 'tmp.T', found 'tmp.foo__struct_457'
9// :4:16: error: expected type 'tmp.T', found 'tmp.foo__struct_454'
1010// :3:16: note: struct declared here
1111// :1:11: note: struct declared here
test/cases/compile_errors/redundant_try.zig+2-2
......@@ -44,9 +44,9 @@ comptime {
4444//
4545// :5:23: error: expected error union type, found 'comptime_int'
4646// :10:23: error: expected error union type, found '@TypeOf(.{})'
47// :15:23: error: expected error union type, found 'tmp.test2__struct_494'
47// :15:23: error: expected error union type, found 'tmp.test2__struct_491'
4848// :15:23: note: struct declared here
49// :20:27: error: expected error union type, found 'tmp.test3__struct_496'
49// :20:27: error: expected error union type, found 'tmp.test3__struct_493'
5050// :20:27: note: struct declared here
5151// :25:23: error: expected error union type, found 'struct { comptime *const [5:0]u8 = "hello" }'
5252// :31:13: error: expected error union type, found 'u32'
test/standalone/stack_iterator/build.zig+2-2
......@@ -24,7 +24,7 @@ pub fn build(b: *std.Build) void {
2424 .root_source_file = b.path("unwind.zig"),
2525 .target = target,
2626 .optimize = optimize,
27 .unwind_tables = if (target.result.isDarwin()) .@"async" else null,
27 .unwind_tables = if (target.result.os.tag.isDarwin()) .@"async" else null,
2828 .omit_frame_pointer = false,
2929 }),
3030 });
......@@ -94,7 +94,7 @@ pub fn build(b: *std.Build) void {
9494 .root_source_file = b.path("shared_lib_unwind.zig"),
9595 .target = target,
9696 .optimize = optimize,
97 .unwind_tables = if (target.result.isDarwin()) .@"async" else null,
97 .unwind_tables = if (target.result.os.tag.isDarwin()) .@"async" else null,
9898 .omit_frame_pointer = true,
9999 }),
100100 });
test/standalone/stack_iterator/shared_lib_unwind.zig+2-2
......@@ -36,8 +36,8 @@ extern fn frame0(
3636
3737pub fn main() !void {
3838 // Disabled until the DWARF unwinder bugs on .aarch64 are solved
39 if (builtin.omit_frame_pointer and comptime builtin.target.isDarwin() and builtin.cpu.arch == .aarch64) return;
40 if (builtin.target.isDarwin() and builtin.cpu.arch == .x86_64) return; // https://github.com/ziglang/zig/issues/21337
39 if (builtin.omit_frame_pointer and comptime builtin.target.os.tag.isDarwin() and builtin.cpu.arch == .aarch64) return;
40 if (builtin.target.os.tag.isDarwin() and builtin.cpu.arch == .x86_64) return; // https://github.com/ziglang/zig/issues/21337
4141
4242 if (!std.debug.have_ucontext or !std.debug.have_getcontext) return;
4343
test/standalone/stack_iterator/unwind.zig+1-1
......@@ -88,7 +88,7 @@ noinline fn frame0(expected: *[4]usize, unwound: *[4]usize) void {
8888
8989pub fn main() !void {
9090 // Disabled until the DWARF unwinder bugs on .aarch64 are solved
91 if (builtin.omit_frame_pointer and comptime builtin.target.isDarwin() and builtin.cpu.arch == .aarch64) return;
91 if (builtin.omit_frame_pointer and comptime builtin.target.os.tag.isDarwin() and builtin.cpu.arch == .aarch64) return;
9292
9393 if (!std.debug.have_ucontext or !std.debug.have_getcontext) return;
9494
tools/update_cpu_features.zig+361-281
......@@ -34,10 +34,12 @@ const Feature = struct {
3434 flatten: bool = false,
3535};
3636
37const LlvmTarget = struct {
37const ArchTarget = struct {
3838 zig_name: []const u8,
39 llvm_name: []const u8,
40 td_name: []const u8,
39 llvm: ?struct {
40 name: []const u8,
41 td_name: []const u8,
42 },
4143 feature_overrides: []const FeatureOverride = &.{},
4244 extra_cpus: []const Cpu = &.{},
4345 extra_features: []const Feature = &.{},
......@@ -45,11 +47,13 @@ const LlvmTarget = struct {
4547 branch_quota: ?usize = null,
4648};
4749
48const llvm_targets = [_]LlvmTarget{
50const targets = [_]ArchTarget{
4951 .{
5052 .zig_name = "aarch64",
51 .llvm_name = "AArch64",
52 .td_name = "AArch64.td",
53 .llvm = .{
54 .name = "AArch64",
55 .td_name = "AArch64",
56 },
5357 .branch_quota = 2000,
5458 .feature_overrides = &.{
5559 .{
......@@ -391,8 +395,10 @@ const llvm_targets = [_]LlvmTarget{
391395 },
392396 .{
393397 .zig_name = "amdgcn",
394 .llvm_name = "AMDGPU",
395 .td_name = "AMDGPU.td",
398 .llvm = .{
399 .name = "AMDGPU",
400 .td_name = "AMDGPU",
401 },
396402 .feature_overrides = &.{
397403 .{
398404 .llvm_name = "DumpCode",
......@@ -418,13 +424,17 @@ const llvm_targets = [_]LlvmTarget{
418424 },
419425 .{
420426 .zig_name = "arc",
421 .llvm_name = "ARC",
422 .td_name = "ARC.td",
427 .llvm = .{
428 .name = "ARC",
429 .td_name = "ARC",
430 },
423431 },
424432 .{
425433 .zig_name = "arm",
426 .llvm_name = "ARM",
427 .td_name = "ARM.td",
434 .llvm = .{
435 .name = "ARM",
436 .td_name = "ARM",
437 },
428438 .branch_quota = 10000,
429439 .feature_overrides = &.{
430440 .{
......@@ -928,66 +938,113 @@ const llvm_targets = [_]LlvmTarget{
928938 },
929939 .{
930940 .zig_name = "avr",
931 .llvm_name = "AVR",
932 .td_name = "AVR.td",
941 .llvm = .{
942 .name = "AVR",
943 .td_name = "AVR",
944 },
933945 },
934946 .{
935947 .zig_name = "bpf",
936 .llvm_name = "BPF",
937 .td_name = "BPF.td",
948 .llvm = .{
949 .name = "BPF",
950 .td_name = "BPF",
951 },
938952 },
939953 .{
940954 .zig_name = "csky",
941 .llvm_name = "CSKY",
942 .td_name = "CSKY.td",
955 .llvm = .{
956 .name = "CSKY",
957 .td_name = "CSKY",
958 },
943959 },
944960 .{
945961 .zig_name = "hexagon",
946 .llvm_name = "Hexagon",
947 .td_name = "Hexagon.td",
962 .llvm = .{
963 .name = "Hexagon",
964 .td_name = "Hexagon",
965 },
948966 },
949967 .{
950968 .zig_name = "lanai",
951 .llvm_name = "Lanai",
952 .td_name = "Lanai.td",
969 .llvm = .{
970 .name = "Lanai",
971 .td_name = "Lanai",
972 },
953973 },
954974 .{
955975 .zig_name = "loongarch",
956 .llvm_name = "LoongArch",
957 .td_name = "LoongArch.td",
976 .llvm = .{
977 .name = "LoongArch",
978 .td_name = "LoongArch",
979 },
958980 },
959981 .{
960982 .zig_name = "m68k",
961 .llvm_name = "M68k",
962 .td_name = "M68k.td",
983 .llvm = .{
984 .name = "M68k",
985 .td_name = "M68k",
986 },
963987 },
964988 .{
965989 .zig_name = "msp430",
966 .llvm_name = "MSP430",
967 .td_name = "MSP430.td",
990 .llvm = .{
991 .name = "MSP430",
992 .td_name = "MSP430",
993 },
968994 },
969995 .{
970996 .zig_name = "mips",
971 .llvm_name = "Mips",
972 .td_name = "Mips.td",
997 .llvm = .{
998 .name = "Mips",
999 .td_name = "Mips",
1000 },
9731001 },
9741002 .{
9751003 .zig_name = "nvptx",
976 .llvm_name = "NVPTX",
977 .td_name = "NVPTX.td",
1004 .llvm = .{
1005 .name = "NVPTX",
1006 .td_name = "NVPTX",
1007 },
9781008 },
9791009 .{
9801010 .zig_name = "powerpc",
981 .llvm_name = "PowerPC",
982 .td_name = "PPC.td",
1011 .llvm = .{
1012 .name = "PowerPC",
1013 .td_name = "PPC",
1014 },
9831015 .omit_cpus = &.{
9841016 "ppc32",
9851017 },
9861018 },
1019 .{
1020 .zig_name = "propeller",
1021 .llvm = null,
1022 .extra_features = &.{
1023 .{
1024 .zig_name = "p2",
1025 .desc = "Enable Propeller 2",
1026 .deps = &.{},
1027 },
1028 },
1029 .extra_cpus = &.{
1030 .{
1031 .llvm_name = null,
1032 .zig_name = "p1",
1033 .features = &.{},
1034 },
1035 .{
1036 .llvm_name = null,
1037 .zig_name = "p2",
1038 .features = &.{"p2"},
1039 },
1040 },
1041 },
9871042 .{
9881043 .zig_name = "riscv",
989 .llvm_name = "RISCV",
990 .td_name = "RISCV.td",
1044 .llvm = .{
1045 .name = "RISCV",
1046 .td_name = "RISCV",
1047 },
9911048 .branch_quota = 2000,
9921049 .feature_overrides = &.{
9931050 .{
......@@ -1010,29 +1067,38 @@ const llvm_targets = [_]LlvmTarget{
10101067 },
10111068 .{
10121069 .zig_name = "sparc",
1013 .llvm_name = "Sparc",
1014 .td_name = "Sparc.td",
1070 .llvm = .{
1071 .name = "Sparc",
1072 .td_name = "Sparc",
1073 },
10151074 },
10161075 // TODO: merge tools/update_spirv_features.zig into this script
10171076 //.{
10181077 // .zig_name = "spirv",
1019 // .llvm_name = "SPIRV",
1020 // .td_name = "SPIRV.td",
1078 // .llvm = .{
1079 // .name = "SPIRV",
1080 // },
10211081 //},
10221082 .{
10231083 .zig_name = "s390x",
1024 .llvm_name = "SystemZ",
1025 .td_name = "SystemZ.td",
1084 .llvm = .{
1085 .name = "SystemZ",
1086 .td_name = "SystemZ",
1087 },
10261088 },
10271089 .{
10281090 .zig_name = "ve",
1029 .llvm_name = "VE",
1030 .td_name = "VE.td",
1091 .llvm = .{
1092 .name = "VE",
1093 .td_name = "VE",
1094 },
10311095 },
10321096 .{
10331097 .zig_name = "wasm",
1034 .llvm_name = "WebAssembly",
1035 .td_name = "WebAssembly.td",
1098 .llvm = .{
1099 .name = "WebAssembly",
1100 .td_name = "WebAssembly",
1101 },
10361102 .extra_features = &.{
10371103 .{
10381104 .zig_name = "nontrapping_bulk_memory_len0",
......@@ -1057,8 +1123,10 @@ const llvm_targets = [_]LlvmTarget{
10571123 },
10581124 .{
10591125 .zig_name = "x86",
1060 .llvm_name = "X86",
1061 .td_name = "X86.td",
1126 .llvm = .{
1127 .name = "X86",
1128 .td_name = "X86",
1129 },
10621130 .feature_overrides = &.{
10631131 .{
10641132 .llvm_name = "64bit-mode",
......@@ -1362,13 +1430,17 @@ const llvm_targets = [_]LlvmTarget{
13621430 },
13631431 .{
13641432 .zig_name = "xcore",
1365 .llvm_name = "XCore",
1366 .td_name = "XCore.td",
1433 .llvm = .{
1434 .name = "XCore",
1435 .td_name = "XCore",
1436 },
13671437 },
13681438 .{
13691439 .zig_name = "xtensa",
1370 .llvm_name = "Xtensa",
1371 .td_name = "Xtensa.td",
1440 .llvm = .{
1441 .name = "Xtensa",
1442 .td_name = "Xtensa",
1443 },
13721444 },
13731445};
13741446
......@@ -1413,33 +1485,33 @@ pub fn main() anyerror!void {
14131485 var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{});
14141486 defer zig_src_dir.close();
14151487
1416 const root_progress = std.Progress.start(.{ .estimated_total_items = llvm_targets.len });
1488 const root_progress = std.Progress.start(.{ .estimated_total_items = targets.len });
14171489 defer root_progress.end();
14181490
14191491 if (builtin.single_threaded) {
1420 for (llvm_targets) |llvm_target| {
1421 if (filter) |zig_name| if (!std.mem.eql(u8, llvm_target.zig_name, zig_name)) continue;
1492 for (targets) |target| {
1493 if (filter) |zig_name| if (!std.mem.eql(u8, target.zig_name, zig_name)) continue;
14221494 try processOneTarget(.{
14231495 .llvm_tblgen_exe = llvm_tblgen_exe,
14241496 .llvm_src_root = llvm_src_root,
14251497 .zig_src_dir = zig_src_dir,
14261498 .root_progress = root_progress,
1427 .llvm_target = llvm_target,
1499 .target = target,
14281500 });
14291501 }
14301502 } else {
14311503 var pool: std.Thread.Pool = undefined;
1432 try pool.init(.{ .allocator = arena, .n_jobs = llvm_targets.len });
1504 try pool.init(.{ .allocator = arena, .n_jobs = targets.len });
14331505 defer pool.deinit();
14341506
1435 for (llvm_targets) |llvm_target| {
1436 if (filter) |zig_name| if (!std.mem.eql(u8, llvm_target.zig_name, zig_name)) continue;
1507 for (targets) |target| {
1508 if (filter) |zig_name| if (!std.mem.eql(u8, target.zig_name, zig_name)) continue;
14371509 const job = Job{
14381510 .llvm_tblgen_exe = llvm_tblgen_exe,
14391511 .llvm_src_root = llvm_src_root,
14401512 .zig_src_dir = zig_src_dir,
14411513 .root_progress = root_progress,
1442 .llvm_target = llvm_target,
1514 .target = target,
14431515 };
14441516 try pool.spawn(processOneTarget, .{job});
14451517 }
......@@ -1451,162 +1523,147 @@ const Job = struct {
14511523 llvm_src_root: []const u8,
14521524 zig_src_dir: std.fs.Dir,
14531525 root_progress: std.Progress.Node,
1454 llvm_target: LlvmTarget,
1526 target: ArchTarget,
14551527};
14561528
14571529fn processOneTarget(job: Job) void {
14581530 errdefer |err| std.debug.panic("panic: {s}", .{@errorName(err)});
1459 const llvm_target = job.llvm_target;
1531 const target = job.target;
14601532
14611533 var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator);
14621534 defer arena_state.deinit();
14631535 const arena = arena_state.allocator();
14641536
1465 const progress_node = job.root_progress.start(llvm_target.zig_name, 3);
1537 const progress_node = job.root_progress.start(target.zig_name, 3);
14661538 defer progress_node.end();
14671539
1468 const tblgen_progress = progress_node.start("running llvm-tblgen", 0);
1469
1470 const child_args = [_][]const u8{
1471 job.llvm_tblgen_exe,
1472 "--dump-json",
1473 try std.fmt.allocPrint(arena, "{s}/llvm/lib/Target/{s}/{s}", .{
1474 job.llvm_src_root,
1475 llvm_target.llvm_name,
1476 llvm_target.td_name,
1477 }),
1478 try std.fmt.allocPrint(arena, "-I={s}/llvm/include", .{job.llvm_src_root}),
1479 try std.fmt.allocPrint(arena, "-I={s}/llvm/lib/Target/{s}", .{
1480 job.llvm_src_root, llvm_target.llvm_name,
1481 }),
1482 };
1540 var features_table = std.StringHashMap(Feature).init(arena);
1541 var all_features = std.ArrayList(Feature).init(arena);
1542 var all_cpus = std.ArrayList(Cpu).init(arena);
14831543
1484 const child_result = try std.process.Child.run(.{
1485 .allocator = arena,
1486 .argv = &child_args,
1487 .max_output_bytes = 500 * 1024 * 1024,
1488 });
1489 tblgen_progress.end();
1490 if (child_result.stderr.len != 0) {
1491 std.debug.print("{s}\n", .{child_result.stderr});
1492 }
1544 if (target.llvm) |llvm| {
1545 const tblgen_progress = progress_node.start("running llvm-tblgen", 0);
14931546
1494 const json_text = switch (child_result.term) {
1495 .Exited => |code| if (code == 0) child_result.stdout else {
1496 std.debug.print("llvm-tblgen exited with code {d}\n", .{code});
1497 std.process.exit(1);
1498 },
1499 else => {
1500 std.debug.print("llvm-tblgen crashed\n", .{});
1501 std.process.exit(1);
1502 },
1503 };
1547 const child_args = [_][]const u8{
1548 job.llvm_tblgen_exe,
1549 "--dump-json",
1550 try std.fmt.allocPrint(arena, "{s}/llvm/lib/Target/{s}/{s}.td", .{
1551 job.llvm_src_root,
1552 llvm.name,
1553 llvm.td_name,
1554 }),
1555 try std.fmt.allocPrint(arena, "-I={s}/llvm/include", .{job.llvm_src_root}),
1556 try std.fmt.allocPrint(arena, "-I={s}/llvm/lib/Target/{s}", .{
1557 job.llvm_src_root, llvm.name,
1558 }),
1559 };
15041560
1505 const json_parse_progress = progress_node.start("parsing JSON", 0);
1561 const child_result = try std.process.Child.run(.{
1562 .allocator = arena,
1563 .argv = &child_args,
1564 .max_output_bytes = 500 * 1024 * 1024,
1565 });
1566 tblgen_progress.end();
1567 if (child_result.stderr.len != 0) {
1568 std.debug.print("{s}\n", .{child_result.stderr});
1569 }
15061570
1507 const parsed = try json.parseFromSlice(json.Value, arena, json_text, .{});
1508 defer parsed.deinit();
1509 const root_map = &parsed.value.object;
1510 json_parse_progress.end();
1571 const json_text = switch (child_result.term) {
1572 .Exited => |code| if (code == 0) child_result.stdout else {
1573 std.debug.print("llvm-tblgen exited with code {d}\n", .{code});
1574 std.process.exit(1);
1575 },
1576 else => {
1577 std.debug.print("llvm-tblgen crashed\n", .{});
1578 std.process.exit(1);
1579 },
1580 };
15111581
1512 const render_progress = progress_node.start("rendering Zig code", 0);
1582 const json_parse_progress = progress_node.start("parsing JSON", 0);
15131583
1514 // So far, LLVM only has a few aliases for the same CPU.
1515 var cpu_aliases = std.StringHashMap(std.SegmentedList(struct {
1516 llvm: []const u8,
1517 zig: []const u8,
1518 }, 4)).init(arena);
1584 const parsed = try json.parseFromSlice(json.Value, arena, json_text, .{});
1585 defer parsed.deinit();
1586 const root_map = &parsed.value.object;
1587 json_parse_progress.end();
15191588
1520 {
1521 var it = root_map.iterator();
1522 while (it.next()) |kv| {
1523 if (kv.key_ptr.len == 0) continue;
1524 if (kv.key_ptr.*[0] == '!') continue;
1525 if (kv.value_ptr.* != .object) continue;
1526 if (hasSuperclass(&kv.value_ptr.object, "ProcessorAlias")) {
1527 // Note that `Name` is actually the alias, while `Alias` is the name that will have
1528 // a full `Processor` object defined.
1529 const llvm_alias = kv.value_ptr.object.get("Name").?.string;
1530 const llvm_name = kv.value_ptr.object.get("Alias").?.string;
1531
1532 const gop = try cpu_aliases.getOrPut(try llvmNameToZigName(arena, llvm_name));
1533
1534 if (!gop.found_existing) gop.value_ptr.* = .{};
1535
1536 try gop.value_ptr.append(arena, .{
1537 .llvm = llvm_alias,
1538 .zig = try llvmNameToZigName(arena, llvm_alias),
1539 });
1589 const collate_progress = progress_node.start("collating LLVM data", 0);
1590
1591 // So far, LLVM only has a few aliases for the same CPU.
1592 var cpu_aliases = std.StringHashMap(std.SegmentedList(struct {
1593 llvm: []const u8,
1594 zig: []const u8,
1595 }, 4)).init(arena);
1596
1597 {
1598 var it = root_map.iterator();
1599 while (it.next()) |kv| {
1600 if (kv.key_ptr.len == 0) continue;
1601 if (kv.key_ptr.*[0] == '!') continue;
1602 if (kv.value_ptr.* != .object) continue;
1603 if (hasSuperclass(&kv.value_ptr.object, "ProcessorAlias")) {
1604 // Note that `Name` is actually the alias, while `Alias` is the name that will have
1605 // a full `Processor` object defined.
1606 const llvm_alias = kv.value_ptr.object.get("Name").?.string;
1607 const llvm_name = kv.value_ptr.object.get("Alias").?.string;
1608
1609 const gop = try cpu_aliases.getOrPut(try llvmNameToZigName(arena, llvm_name));
1610
1611 if (!gop.found_existing) gop.value_ptr.* = .{};
1612
1613 try gop.value_ptr.append(arena, .{
1614 .llvm = llvm_alias,
1615 .zig = try llvmNameToZigName(arena, llvm_alias),
1616 });
1617 }
15401618 }
15411619 }
1542 }
15431620
1544 var features_table = std.StringHashMap(Feature).init(arena);
1545 var all_features = std.ArrayList(Feature).init(arena);
1546 var all_cpus = std.ArrayList(Cpu).init(arena);
1547 {
1548 var it = root_map.iterator();
1549 while (it.next()) |kv| {
1550 if (kv.key_ptr.len == 0) continue;
1551 if (kv.key_ptr.*[0] == '!') continue;
1552 if (kv.value_ptr.* != .object) continue;
1553 if (hasSuperclass(&kv.value_ptr.object, "SubtargetFeature")) {
1554 const llvm_name = kv.value_ptr.object.get("Name").?.string;
1555 if (llvm_name.len == 0) continue;
1556
1557 var zig_name = try llvmNameToZigName(arena, llvm_name);
1558 var desc = kv.value_ptr.object.get("Desc").?.string;
1559 var deps = std.ArrayList([]const u8).init(arena);
1560 var omit = false;
1561 var flatten = false;
1562 var omit_deps: []const []const u8 = &.{};
1563 var extra_deps: []const []const u8 = &.{};
1564 for (llvm_target.feature_overrides) |feature_override| {
1565 if (mem.eql(u8, llvm_name, feature_override.llvm_name)) {
1566 if (feature_override.omit) {
1567 // Still put the feature into the table so that we can
1568 // expand dependencies for the feature overrides marked `flatten`.
1569 omit = true;
1570 }
1571 if (feature_override.flatten) {
1572 flatten = true;
1573 }
1574 if (feature_override.zig_name) |override_name| {
1575 zig_name = override_name;
1576 }
1577 if (feature_override.desc) |override_desc| {
1578 desc = override_desc;
1621 {
1622 var it = root_map.iterator();
1623 while (it.next()) |kv| {
1624 if (kv.key_ptr.len == 0) continue;
1625 if (kv.key_ptr.*[0] == '!') continue;
1626 if (kv.value_ptr.* != .object) continue;
1627 if (hasSuperclass(&kv.value_ptr.object, "SubtargetFeature")) {
1628 const llvm_name = kv.value_ptr.object.get("Name").?.string;
1629 if (llvm_name.len == 0) continue;
1630
1631 var zig_name = try llvmNameToZigName(arena, llvm_name);
1632 var desc = kv.value_ptr.object.get("Desc").?.string;
1633 var deps = std.ArrayList([]const u8).init(arena);
1634 var omit = false;
1635 var flatten = false;
1636 var omit_deps: []const []const u8 = &.{};
1637 var extra_deps: []const []const u8 = &.{};
1638 for (target.feature_overrides) |feature_override| {
1639 if (mem.eql(u8, llvm_name, feature_override.llvm_name)) {
1640 if (feature_override.omit) {
1641 // Still put the feature into the table so that we can
1642 // expand dependencies for the feature overrides marked `flatten`.
1643 omit = true;
1644 }
1645 if (feature_override.flatten) {
1646 flatten = true;
1647 }
1648 if (feature_override.zig_name) |override_name| {
1649 zig_name = override_name;
1650 }
1651 if (feature_override.desc) |override_desc| {
1652 desc = override_desc;
1653 }
1654 omit_deps = feature_override.omit_deps;
1655 extra_deps = feature_override.extra_deps;
1656 break;
15791657 }
1580 omit_deps = feature_override.omit_deps;
1581 extra_deps = feature_override.extra_deps;
1582 break;
15831658 }
1584 }
1585 const implies = kv.value_ptr.object.get("Implies").?.array;
1586 for (implies.items) |imply| {
1587 const other_key = imply.object.get("def").?.string;
1588 const other_obj = root_map.get(other_key).?.object;
1589 const other_llvm_name = other_obj.get("Name").?.string;
1590 const other_zig_name = (try llvmFeatureNameToZigNameOmit(
1591 arena,
1592 llvm_target,
1593 other_llvm_name,
1594 )) orelse continue;
1595 for (omit_deps) |omit_dep| {
1596 if (mem.eql(u8, other_zig_name, omit_dep)) break;
1597 } else {
1598 try deps.append(other_zig_name);
1599 }
1600 }
1601 // This is used by AArch64.
1602 if (kv.value_ptr.object.get("DefaultExts")) |exts_val| {
1603 for (exts_val.array.items) |ext| {
1604 const other_key = ext.object.get("def").?.string;
1659 const implies = kv.value_ptr.object.get("Implies").?.array;
1660 for (implies.items) |imply| {
1661 const other_key = imply.object.get("def").?.string;
16051662 const other_obj = root_map.get(other_key).?.object;
16061663 const other_llvm_name = other_obj.get("Name").?.string;
16071664 const other_zig_name = (try llvmFeatureNameToZigNameOmit(
16081665 arena,
1609 llvm_target,
1666 target,
16101667 other_llvm_name,
16111668 )) orelse continue;
16121669 for (omit_deps) |omit_dep| {
......@@ -1615,118 +1672,141 @@ fn processOneTarget(job: Job) void {
16151672 try deps.append(other_zig_name);
16161673 }
16171674 }
1675 // This is used by AArch64.
1676 if (kv.value_ptr.object.get("DefaultExts")) |exts_val| {
1677 for (exts_val.array.items) |ext| {
1678 const other_key = ext.object.get("def").?.string;
1679 const other_obj = root_map.get(other_key).?.object;
1680 const other_llvm_name = other_obj.get("Name").?.string;
1681 const other_zig_name = (try llvmFeatureNameToZigNameOmit(
1682 arena,
1683 target,
1684 other_llvm_name,
1685 )) orelse continue;
1686 for (omit_deps) |omit_dep| {
1687 if (mem.eql(u8, other_zig_name, omit_dep)) break;
1688 } else {
1689 try deps.append(other_zig_name);
1690 }
1691 }
1692 }
1693 for (extra_deps) |extra_dep| {
1694 try deps.append(extra_dep);
1695 }
1696 const feature: Feature = .{
1697 .llvm_name = llvm_name,
1698 .zig_name = zig_name,
1699 .desc = desc,
1700 .deps = deps.items,
1701 .flatten = flatten,
1702 };
1703 try features_table.put(zig_name, feature);
1704 if (!omit and !flatten) {
1705 try all_features.append(feature);
1706 }
16181707 }
1619 for (extra_deps) |extra_dep| {
1620 try deps.append(extra_dep);
1621 }
1622 const feature: Feature = .{
1623 .llvm_name = llvm_name,
1624 .zig_name = zig_name,
1625 .desc = desc,
1626 .deps = deps.items,
1627 .flatten = flatten,
1628 };
1629 try features_table.put(zig_name, feature);
1630 if (!omit and !flatten) {
1631 try all_features.append(feature);
1632 }
1633 }
1634 if (hasSuperclass(&kv.value_ptr.object, "Processor")) {
1635 const llvm_name = kv.value_ptr.object.get("Name").?.string;
1636 if (llvm_name.len == 0) continue;
1637 const omitted = for (llvm_target.omit_cpus) |omit_cpu_name| {
1638 if (mem.eql(u8, omit_cpu_name, llvm_name)) break true;
1639 } else false;
1640 if (omitted) continue;
1641
1642 var zig_name = try llvmNameToZigName(arena, llvm_name);
1643 var deps = std.ArrayList([]const u8).init(arena);
1644 var omit_deps: []const []const u8 = &.{};
1645 var extra_deps: []const []const u8 = &.{};
1646 for (llvm_target.feature_overrides) |feature_override| {
1647 if (mem.eql(u8, llvm_name, feature_override.llvm_name)) {
1648 if (feature_override.omit) {
1649 continue;
1708 if (hasSuperclass(&kv.value_ptr.object, "Processor")) {
1709 const llvm_name = kv.value_ptr.object.get("Name").?.string;
1710 if (llvm_name.len == 0) continue;
1711 const omitted = for (target.omit_cpus) |omit_cpu_name| {
1712 if (mem.eql(u8, omit_cpu_name, llvm_name)) break true;
1713 } else false;
1714 if (omitted) continue;
1715
1716 var zig_name = try llvmNameToZigName(arena, llvm_name);
1717 var deps = std.ArrayList([]const u8).init(arena);
1718 var omit_deps: []const []const u8 = &.{};
1719 var extra_deps: []const []const u8 = &.{};
1720 for (target.feature_overrides) |feature_override| {
1721 if (mem.eql(u8, llvm_name, feature_override.llvm_name)) {
1722 if (feature_override.omit) {
1723 continue;
1724 }
1725 if (feature_override.zig_name) |override_name| {
1726 zig_name = override_name;
1727 }
1728 omit_deps = feature_override.omit_deps;
1729 extra_deps = feature_override.extra_deps;
1730 break;
16501731 }
1651 if (feature_override.zig_name) |override_name| {
1652 zig_name = override_name;
1732 }
1733 const features = kv.value_ptr.object.get("Features").?.array;
1734 for (features.items) |feature| {
1735 const feature_key = feature.object.get("def").?.string;
1736 const feature_obj = root_map.get(feature_key).?.object;
1737 const feature_llvm_name = feature_obj.get("Name").?.string;
1738 if (feature_llvm_name.len == 0) continue;
1739 const feature_zig_name = (try llvmFeatureNameToZigNameOmit(
1740 arena,
1741 target,
1742 feature_llvm_name,
1743 )) orelse continue;
1744 for (omit_deps) |omit_dep| {
1745 if (mem.eql(u8, feature_zig_name, omit_dep)) break;
1746 } else {
1747 try deps.append(feature_zig_name);
16531748 }
1654 omit_deps = feature_override.omit_deps;
1655 extra_deps = feature_override.extra_deps;
1656 break;
16571749 }
1658 }
1659 const features = kv.value_ptr.object.get("Features").?.array;
1660 for (features.items) |feature| {
1661 const feature_key = feature.object.get("def").?.string;
1662 const feature_obj = root_map.get(feature_key).?.object;
1663 const feature_llvm_name = feature_obj.get("Name").?.string;
1664 if (feature_llvm_name.len == 0) continue;
1665 const feature_zig_name = (try llvmFeatureNameToZigNameOmit(
1666 arena,
1667 llvm_target,
1668 feature_llvm_name,
1669 )) orelse continue;
1670 for (omit_deps) |omit_dep| {
1671 if (mem.eql(u8, feature_zig_name, omit_dep)) break;
1672 } else {
1750 for (extra_deps) |extra_dep| {
1751 try deps.append(extra_dep);
1752 }
1753 const tune_features = kv.value_ptr.object.get("TuneFeatures").?.array;
1754 for (tune_features.items) |feature| {
1755 const feature_key = feature.object.get("def").?.string;
1756 const feature_obj = root_map.get(feature_key).?.object;
1757 const feature_llvm_name = feature_obj.get("Name").?.string;
1758 if (feature_llvm_name.len == 0) continue;
1759 const feature_zig_name = (try llvmFeatureNameToZigNameOmit(
1760 arena,
1761 target,
1762 feature_llvm_name,
1763 )) orelse continue;
16731764 try deps.append(feature_zig_name);
16741765 }
1675 }
1676 for (extra_deps) |extra_dep| {
1677 try deps.append(extra_dep);
1678 }
1679 const tune_features = kv.value_ptr.object.get("TuneFeatures").?.array;
1680 for (tune_features.items) |feature| {
1681 const feature_key = feature.object.get("def").?.string;
1682 const feature_obj = root_map.get(feature_key).?.object;
1683 const feature_llvm_name = feature_obj.get("Name").?.string;
1684 if (feature_llvm_name.len == 0) continue;
1685 const feature_zig_name = (try llvmFeatureNameToZigNameOmit(
1686 arena,
1687 llvm_target,
1688 feature_llvm_name,
1689 )) orelse continue;
1690 try deps.append(feature_zig_name);
1691 }
1692 try all_cpus.append(.{
1693 .llvm_name = llvm_name,
1694 .zig_name = zig_name,
1695 .features = deps.items,
1696 });
1697
1698 if (cpu_aliases.get(zig_name)) |aliases| {
1699 var alias_it = aliases.constIterator(0);
1700
1701 alias_it: while (alias_it.next()) |alias| {
1702 for (llvm_target.omit_cpus) |omit_cpu_name| {
1703 if (mem.eql(u8, omit_cpu_name, alias.llvm)) continue :alias_it;
1704 }
1766 try all_cpus.append(.{
1767 .llvm_name = llvm_name,
1768 .zig_name = zig_name,
1769 .features = deps.items,
1770 });
1771
1772 if (cpu_aliases.get(zig_name)) |aliases| {
1773 var alias_it = aliases.constIterator(0);
17051774
1706 try all_cpus.append(.{
1707 .llvm_name = alias.llvm,
1708 .zig_name = alias.zig,
1709 .features = deps.items,
1710 });
1775 alias_it: while (alias_it.next()) |alias| {
1776 for (target.omit_cpus) |omit_cpu_name| {
1777 if (mem.eql(u8, omit_cpu_name, alias.llvm)) continue :alias_it;
1778 }
1779
1780 try all_cpus.append(.{
1781 .llvm_name = alias.llvm,
1782 .zig_name = alias.zig,
1783 .features = deps.items,
1784 });
1785 }
17111786 }
17121787 }
17131788 }
17141789 }
1790
1791 collate_progress.end();
17151792 }
1716 for (llvm_target.extra_features) |extra_feature| {
1793
1794 for (target.extra_features) |extra_feature| {
17171795 try features_table.put(extra_feature.zig_name, extra_feature);
17181796 try all_features.append(extra_feature);
17191797 }
1720 for (llvm_target.extra_cpus) |extra_cpu| {
1798 for (target.extra_cpus) |extra_cpu| {
17211799 try all_cpus.append(extra_cpu);
17221800 }
17231801 mem.sort(Feature, all_features.items, {}, featureLessThan);
17241802 mem.sort(Cpu, all_cpus.items, {}, cpuLessThan);
17251803
1804 const render_progress = progress_node.start("rendering Zig code", 0);
1805
17261806 var target_dir = try job.zig_src_dir.openDir("lib/std/Target", .{});
17271807 defer target_dir.close();
17281808
1729 const zig_code_basename = try std.fmt.allocPrint(arena, "{s}.zig", .{llvm_target.zig_name});
1809 const zig_code_basename = try std.fmt.allocPrint(arena, "{s}.zig", .{target.zig_name});
17301810 var zig_code_file = try target_dir.createFile(zig_code_basename, .{});
17311811 defer zig_code_file.close();
17321812
......@@ -1760,7 +1840,7 @@ fn processOneTarget(job: Job) void {
17601840 \\pub const all_features = blk: {
17611841 \\
17621842 );
1763 if (llvm_target.branch_quota) |branch_quota| {
1843 if (target.branch_quota) |branch_quota| {
17641844 try w.print(" @setEvalBranchQuota({d});\n", .{branch_quota});
17651845 }
17661846 try w.writeAll(
......@@ -1941,10 +2021,10 @@ fn llvmNameToZigName(arena: mem.Allocator, llvm_name: []const u8) ![]const u8 {
19412021
19422022fn llvmFeatureNameToZigNameOmit(
19432023 arena: mem.Allocator,
1944 llvm_target: LlvmTarget,
2024 target: ArchTarget,
19452025 llvm_name: []const u8,
19462026) !?[]const u8 {
1947 for (llvm_target.feature_overrides) |feature_override| {
2027 for (target.feature_overrides) |feature_override| {
19482028 if (mem.eql(u8, feature_override.llvm_name, llvm_name)) {
19492029 if (feature_override.omit) return null;
19502030 return feature_override.zig_name orelse break;