authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-06 22:51:55-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-05-06 22:51:55-04:00
log0df28f9d45105c44fa28a86a880272acb9ccf630
tree1387a31e3717e802d103dbff4a3302942f9bd9d0
parentac1aaec9c38eb44b93099ff18579a9401f107100
parentefeb031b7917f552ea73ee59c086e3d75c87cbaf
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #11492 from ziglang/ci-stage3-behavior

CI: add non-LLVM backends to the test matrix

10 files changed, 348 insertions(+), 91 deletions(-)

build.zig+12
...@@ -445,6 +445,9 @@ pub fn build(b: *Builder) !void {...@@ -445,6 +445,9 @@ pub fn build(b: *Builder) !void {
445 false, // skip_single_threaded445 false, // skip_single_threaded
446 skip_non_native,446 skip_non_native,
447 skip_libc,447 skip_libc,
448 skip_stage1,
449 omit_stage2,
450 is_stage1,
448 ));451 ));
449452
450 toolchain_step.dependOn(tests.addPkgTests(453 toolchain_step.dependOn(tests.addPkgTests(
...@@ -457,6 +460,9 @@ pub fn build(b: *Builder) !void {...@@ -457,6 +460,9 @@ pub fn build(b: *Builder) !void {
457 true, // skip_single_threaded460 true, // skip_single_threaded
458 skip_non_native,461 skip_non_native,
459 true, // skip_libc462 true, // skip_libc
463 skip_stage1,
464 omit_stage2 or true, // TODO get these all passing
465 is_stage1,
460 ));466 ));
461467
462 toolchain_step.dependOn(tests.addPkgTests(468 toolchain_step.dependOn(tests.addPkgTests(
...@@ -469,6 +475,9 @@ pub fn build(b: *Builder) !void {...@@ -469,6 +475,9 @@ pub fn build(b: *Builder) !void {
469 true, // skip_single_threaded475 true, // skip_single_threaded
470 skip_non_native,476 skip_non_native,
471 true, // skip_libc477 true, // skip_libc
478 skip_stage1,
479 omit_stage2 or true, // TODO get these all passing
480 is_stage1,
472 ));481 ));
473482
474 toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));483 toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
...@@ -494,6 +503,9 @@ pub fn build(b: *Builder) !void {...@@ -494,6 +503,9 @@ pub fn build(b: *Builder) !void {
494 false,503 false,
495 skip_non_native,504 skip_non_native,
496 skip_libc,505 skip_libc,
506 skip_stage1,
507 omit_stage2 or true, // TODO get these all passing
508 is_stage1,
497 );509 );
498510
499 const test_step = b.step("test", "Run all the tests");511 const test_step = b.step("test", "Run all the tests");
ci/azure/macos_script+19-6
...@@ -58,12 +58,25 @@ make $JOBS install...@@ -58,12 +58,25 @@ make $JOBS install
58# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.58# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.
59release/bin/zig build -p stage2 -Denable-llvm59release/bin/zig build -p stage2 -Denable-llvm
6060
61stage2/bin/zig test ../test/behavior.zig -I../test -fLLVM61stage2/bin/zig build test-behavior
62stage2/bin/zig test ../test/behavior.zig -I../test -fno-LLVM62
6363# TODO: upgrade these to test stage2 instead of stage1
64release/bin/zig build test-toolchain -Denable-macos-sdk64# TODO: upgrade these to test stage3 instead of stage2
65release/bin/zig build test-std65release/bin/zig build test-behavior -Denable-macos-sdk -Domit-stage2
66release/bin/zig build docs66release/bin/zig build test-compiler-rt -Denable-macos-sdk
67release/bin/zig build test-std -Denable-macos-sdk
68release/bin/zig build test-minilibc -Denable-macos-sdk
69release/bin/zig build test-compare-output -Denable-macos-sdk
70release/bin/zig build test-standalone -Denable-macos-sdk
71release/bin/zig build test-stack-traces -Denable-macos-sdk
72release/bin/zig build test-cli -Denable-macos-sdk
73release/bin/zig build test-asm-link -Denable-macos-sdk
74release/bin/zig build test-runtime-safety -Denable-macos-sdk
75release/bin/zig build test-translate-c -Denable-macos-sdk
76release/bin/zig build test-run-translated-c -Denable-macos-sdk
77release/bin/zig build docs -Denable-macos-sdk
78release/bin/zig build test-fmt -Denable-macos-sdk
79release/bin/zig build test-stage2 -Denable-macos-sdk
6780
68if [ "${BUILD_REASON}" != "PullRequest" ]; then81if [ "${BUILD_REASON}" != "PullRequest" ]; then
69 mv ../LICENSE release/82 mv ../LICENSE release/
ci/zinc/linux_test.sh+11-19
...@@ -48,25 +48,19 @@ cd $WORKSPACE...@@ -48,25 +48,19 @@ cd $WORKSPACE
48$ZIG fmt --check . --exclude test/cases/48$ZIG fmt --check . --exclude test/cases/
4949
50# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.50# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.
51$ZIG build -p stage2 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"51$ZIG build -p stage2 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
5252
53# Ensure that stage2 can build itself.53# Ensure that stage2 can build itself.
54./stage2/bin/zig build -p stage3 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"54stage2/bin/zig build -p stage3 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
5555stage2/bin/zig build # test building self-hosted without LLVM
56stage2/bin/zig test test/behavior.zig -I test -fLLVM56stage2/bin/zig build -Dtarget=arm-linux-musleabihf # test building self-hosted for 32-bit arm
57stage2/bin/zig test test/behavior.zig -I test -fno-LLVM57
58stage2/bin/zig test test/behavior.zig -I test -fLLVM -target aarch64-linux --test-cmd qemu-aarch64 --test-cmd-bin58# Here we use stage2 instead of stage3 because of two bugs remaining:
59stage2/bin/zig test test/behavior.zig -I test -fno-LLVM -target aarch64-linux --test-cmd qemu-aarch64 --test-cmd-bin59# * https://github.com/ziglang/zig/issues/11367 (and corresponding workaround in compiler source)
60stage2/bin/zig test test/behavior.zig -I test -ofmt=c60# * https://github.com/ziglang/zig/pull/11492#issuecomment-1112871321
61stage2/bin/zig test test/behavior.zig -I test -fno-LLVM -target wasm32-wasi --test-cmd wasmtime --test-cmd-bin61stage2/bin/zig build test-behavior -fqemu -fwasmtime
62stage2/bin/zig test test/behavior.zig -I test -fLLVM -target wasm32-wasi --test-cmd wasmtime --test-cmd-bin62
63stage2/bin/zig test test/behavior.zig -I test -fno-LLVM -target arm-linux --test-cmd qemu-arm --test-cmd-bin63$ZIG build test-behavior -fqemu -fwasmtime -Domit-stage2
64stage2/bin/zig test test/behavior.zig -I test -fLLVM -target aarch64-macos --test-no-exec
65stage2/bin/zig test test/behavior.zig -I test -fno-LLVM -target aarch64-macos --test-no-exec
66stage2/bin/zig test test/behavior.zig -I test -fLLVM -target x86_64-macos --test-no-exec
67stage2/bin/zig test test/behavior.zig -I test -fno-LLVM -target x86_64-macos --test-no-exec
68
69$ZIG build test-behavior -fqemu -fwasmtime
70$ZIG build test-compiler-rt -fqemu -fwasmtime64$ZIG build test-compiler-rt -fqemu -fwasmtime
71$ZIG build test-std -fqemu -fwasmtime65$ZIG build test-std -fqemu -fwasmtime
72$ZIG build test-minilibc -fqemu -fwasmtime66$ZIG build test-minilibc -fqemu -fwasmtime
...@@ -79,8 +73,6 @@ $ZIG build test-runtime-safety -fqemu -fwasmtime...@@ -79,8 +73,6 @@ $ZIG build test-runtime-safety -fqemu -fwasmtime
79$ZIG build test-translate-c -fqemu -fwasmtime73$ZIG build test-translate-c -fqemu -fwasmtime
80$ZIG build test-run-translated-c -fqemu -fwasmtime74$ZIG build test-run-translated-c -fqemu -fwasmtime
81$ZIG build docs -fqemu -fwasmtime75$ZIG build docs -fqemu -fwasmtime
82$ZIG build # test building self-hosted without LLVM
83$ZIG build -Dtarget=arm-linux-musleabihf # test building self-hosted for 32-bit arm
84$ZIG build test-fmt -fqemu -fwasmtime76$ZIG build test-fmt -fqemu -fwasmtime
85$ZIG build test-stage2 -fqemu -fwasmtime77$ZIG build test-stage2 -fqemu -fwasmtime
8678
lib/std/build.zig+14
...@@ -1590,6 +1590,8 @@ pub const LibExeObjStep = struct {...@@ -1590,6 +1590,8 @@ pub const LibExeObjStep = struct {
15901590
1591 want_lto: ?bool = null,1591 want_lto: ?bool = null,
1592 use_stage1: ?bool = null,1592 use_stage1: ?bool = null,
1593 use_llvm: ?bool = null,
1594 ofmt: ?std.Target.ObjectFormat = null,
15931595
1594 output_path_source: GeneratedFile,1596 output_path_source: GeneratedFile,
1595 output_lib_path_source: GeneratedFile,1597 output_lib_path_source: GeneratedFile,
...@@ -2351,6 +2353,18 @@ pub const LibExeObjStep = struct {...@@ -2351,6 +2353,18 @@ pub const LibExeObjStep = struct {
2351 }2353 }
2352 }2354 }
23532355
2356 if (self.use_llvm) |use_llvm| {
2357 if (use_llvm) {
2358 try zig_args.append("-fLLVM");
2359 } else {
2360 try zig_args.append("-fno-LLVM");
2361 }
2362 }
2363
2364 if (self.ofmt) |ofmt| {
2365 try zig_args.append(try std.fmt.allocPrint(builder.allocator, "-ofmt={s}", .{@tagName(ofmt)}));
2366 }
2367
2354 if (self.entry_symbol_name) |entry| {2368 if (self.entry_symbol_name) |entry| {
2355 try zig_args.append("--entry");2369 try zig_args.append("--entry");
2356 try zig_args.append(entry);2370 try zig_args.append(entry);
lib/std/os/linux/arm-eabi.zig+4-1
...@@ -99,7 +99,10 @@ pub fn syscall6(...@@ -99,7 +99,10 @@ pub fn syscall6(
9999
100/// This matches the libc clone function.100/// This matches the libc clone function.
101pub extern fn clone(101pub extern fn clone(
102 func: fn (arg: usize) callconv(.C) u8,102 func: switch (@import("builtin").zig_backend) {
103 .stage1 => fn (arg: usize) callconv(.C) u8,
104 else => *const fn (arg: usize) callconv(.C) u8,
105 },
103 stack: usize,106 stack: usize,
104 flags: u32,107 flags: u32,
105 arg: usize,108 arg: usize,
src/codegen/llvm.zig+95-9
...@@ -4234,36 +4234,103 @@ pub const FuncGen = struct {...@@ -4234,36 +4234,103 @@ pub const FuncGen = struct {
4234 return null;4234 return null;
42354235
4236 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4236 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
4237
4237 const operand = try self.resolveInst(ty_op.operand);4238 const operand = try self.resolveInst(ty_op.operand);
4238 const operand_ty = self.air.typeOf(ty_op.operand);4239 const operand_ty = self.air.typeOf(ty_op.operand);
4239 const operand_scalar_ty = operand_ty.scalarType();4240 const operand_scalar_ty = operand_ty.scalarType();
4241
4240 const dest_ty = self.air.typeOfIndex(inst);4242 const dest_ty = self.air.typeOfIndex(inst);
4243 const dest_scalar_ty = dest_ty.scalarType();
4241 const dest_llvm_ty = try self.dg.llvmType(dest_ty);4244 const dest_llvm_ty = try self.dg.llvmType(dest_ty);
4245 const target = self.dg.module.getTarget();
42424246
4243 if (operand_scalar_ty.isSignedInt()) {4247 if (intrinsicsAllowed(dest_scalar_ty, target)) {
4244 return self.builder.buildSIToFP(operand, dest_llvm_ty, "");4248 if (operand_scalar_ty.isSignedInt()) {
4245 } else {4249 return self.builder.buildSIToFP(operand, dest_llvm_ty, "");
4246 return self.builder.buildUIToFP(operand, dest_llvm_ty, "");4250 } else {
4251 return self.builder.buildUIToFP(operand, dest_llvm_ty, "");
4252 }
4247 }4253 }
4254
4255 const operand_bits = @intCast(u16, operand_scalar_ty.bitSize(target));
4256 const rt_int_bits = compilerRtIntBits(operand_bits);
4257 const rt_int_ty = self.context.intType(rt_int_bits);
4258 const extended = e: {
4259 if (operand_scalar_ty.isSignedInt()) {
4260 break :e self.builder.buildSExtOrBitCast(operand, rt_int_ty, "");
4261 } else {
4262 break :e self.builder.buildZExtOrBitCast(operand, rt_int_ty, "");
4263 }
4264 };
4265 const dest_bits = dest_scalar_ty.floatBits(target);
4266 const compiler_rt_operand_abbrev = compilerRtIntAbbrev(rt_int_bits);
4267 const compiler_rt_dest_abbrev = compilerRtFloatAbbrev(dest_bits);
4268 const sign_prefix = if (operand_scalar_ty.isSignedInt()) "" else "un";
4269 var fn_name_buf: [64]u8 = undefined;
4270 const fn_name = std.fmt.bufPrintZ(&fn_name_buf, "__float{s}{s}i{s}f", .{
4271 sign_prefix,
4272 compiler_rt_operand_abbrev,
4273 compiler_rt_dest_abbrev,
4274 }) catch unreachable;
4275 const param_types = [1]*const llvm.Type{rt_int_ty};
4276 const libc_fn = self.getLibcFunction(fn_name, &param_types, dest_llvm_ty);
4277 const params = [1]*const llvm.Value{extended};
4278
4279 return self.builder.buildCall(libc_fn, &params, params.len, .C, .Auto, "");
4248 }4280 }
42494281
4250 fn airFloatToInt(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {4282 fn airFloatToInt(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value {
4251 if (self.liveness.isUnused(inst))4283 if (self.liveness.isUnused(inst))
4252 return null;4284 return null;
42534285
4286 const target = self.dg.module.getTarget();
4254 const ty_op = self.air.instructions.items(.data)[inst].ty_op;4287 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
4288
4255 const operand = try self.resolveInst(ty_op.operand);4289 const operand = try self.resolveInst(ty_op.operand);
4290 const operand_ty = self.air.typeOf(ty_op.operand);
4291 const operand_scalar_ty = operand_ty.scalarType();
4292
4256 const dest_ty = self.air.typeOfIndex(inst);4293 const dest_ty = self.air.typeOfIndex(inst);
4257 const dest_scalar_ty = dest_ty.scalarType();4294 const dest_scalar_ty = dest_ty.scalarType();
4258 const dest_llvm_ty = try self.dg.llvmType(dest_ty);4295 const dest_llvm_ty = try self.dg.llvmType(dest_ty);
42594296
4260 // TODO set fast math flag4297 if (intrinsicsAllowed(operand_scalar_ty, target)) {
4298 // TODO set fast math flag
4299 if (dest_scalar_ty.isSignedInt()) {
4300 return self.builder.buildFPToSI(operand, dest_llvm_ty, "");
4301 } else {
4302 return self.builder.buildFPToUI(operand, dest_llvm_ty, "");
4303 }
4304 }
42614305
4262 if (dest_scalar_ty.isSignedInt()) {4306 const rt_int_bits = compilerRtIntBits(@intCast(u16, dest_scalar_ty.bitSize(target)));
4263 return self.builder.buildFPToSI(operand, dest_llvm_ty, "");4307 const libc_ret_ty = self.context.intType(rt_int_bits);
4264 } else {4308
4265 return self.builder.buildFPToUI(operand, dest_llvm_ty, "");4309 const operand_bits = operand_scalar_ty.floatBits(target);
4310 const compiler_rt_operand_abbrev = compilerRtFloatAbbrev(operand_bits);
4311
4312 const compiler_rt_dest_abbrev = compilerRtIntAbbrev(rt_int_bits);
4313 const sign_prefix = if (dest_scalar_ty.isSignedInt()) "" else "un";
4314
4315 var fn_name_buf: [64]u8 = undefined;
4316 const fn_name = std.fmt.bufPrintZ(&fn_name_buf, "__fix{s}{s}f{s}i", .{
4317 sign_prefix,
4318 compiler_rt_operand_abbrev,
4319 compiler_rt_dest_abbrev,
4320 }) catch unreachable;
4321
4322 const operand_llvm_ty = try self.dg.llvmType(operand_ty);
4323 const param_types = [1]*const llvm.Type{operand_llvm_ty};
4324 const libc_fn = self.getLibcFunction(fn_name, &param_types, libc_ret_ty);
4325 const params = [1]*const llvm.Value{operand};
4326
4327 const result = self.builder.buildCall(libc_fn, &params, params.len, .C, .Auto, "");
4328
4329 if (libc_ret_ty == dest_llvm_ty) {
4330 return result;
4266 }4331 }
4332
4333 return self.builder.buildTrunc(result, dest_llvm_ty, "");
4267 }4334 }
42684335
4269 fn airSliceField(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !?*const llvm.Value {4336 fn airSliceField(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !?*const llvm.Value {
...@@ -5615,6 +5682,16 @@ pub const FuncGen = struct {...@@ -5615,6 +5682,16 @@ pub const FuncGen = struct {
5615 };5682 };
5616 }5683 }
56175684
5685 fn compilerRtIntAbbrev(bits: u16) []const u8 {
5686 return switch (bits) {
5687 16 => "h",
5688 32 => "s",
5689 64 => "d",
5690 128 => "t",
5691 else => "o", // Non-standard
5692 };
5693 }
5694
5618 /// Creates a floating point comparison by lowering to the appropriate5695 /// Creates a floating point comparison by lowering to the appropriate
5619 /// hardware instruction or softfloat routine for the target5696 /// hardware instruction or softfloat routine for the target
5620 fn buildFloatCmp(5697 fn buildFloatCmp(
...@@ -8313,3 +8390,12 @@ fn needDbgVarWorkaround(dg: *DeclGen, ty: Type) bool {...@@ -8313,3 +8390,12 @@ fn needDbgVarWorkaround(dg: *DeclGen, ty: Type) bool {
8313 }8390 }
8314 return false;8391 return false;
8315}8392}
8393
8394fn compilerRtIntBits(bits: u16) u16 {
8395 inline for (.{ 8, 16, 32, 64, 128 }) |b| {
8396 if (bits <= b) {
8397 return b;
8398 }
8399 }
8400 return bits;
8401}
src/codegen/llvm/bindings.zig+8
...@@ -476,6 +476,14 @@ pub const Builder = opaque {...@@ -476,6 +476,14 @@ pub const Builder = opaque {
476 Name: [*:0]const u8,476 Name: [*:0]const u8,
477 ) *const Value;477 ) *const Value;
478478
479 pub const buildSExtOrBitCast = LLVMBuildSExtOrBitCast;
480 extern fn LLVMBuildSExtOrBitCast(
481 *const Builder,
482 Val: *const Value,
483 DestTy: *const Type,
484 Name: [*:0]const u8,
485 ) *const Value;
486
479 pub const buildCall = ZigLLVMBuildCall;487 pub const buildCall = ZigLLVMBuildCall;
480 extern fn ZigLLVMBuildCall(488 extern fn ZigLLVMBuildCall(
481 *const Builder,489 *const Builder,
src/link/MachO.zig+16-10
...@@ -392,8 +392,9 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {...@@ -392,8 +392,9 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {
392 // Adhoc code signature is required when targeting aarch64-macos either directly or indirectly via the simulator392 // Adhoc code signature is required when targeting aarch64-macos either directly or indirectly via the simulator
393 // ABI such as aarch64-ios-simulator, etc.393 // ABI such as aarch64-ios-simulator, etc.
394 const requires_adhoc_codesig = cpu_arch == .aarch64 and (os_tag == .macos or abi == .simulator);394 const requires_adhoc_codesig = cpu_arch == .aarch64 and (os_tag == .macos or abi == .simulator);
395 const use_llvm = build_options.have_llvm and options.use_llvm;
395 const use_stage1 = build_options.is_stage1 and options.use_stage1;396 const use_stage1 = build_options.is_stage1 and options.use_stage1;
396 const needs_prealloc = !(use_stage1 or options.cache_mode == .whole);397 const needs_prealloc = !(use_stage1 or use_llvm or options.cache_mode == .whole);
397398
398 const self = try gpa.create(MachO);399 const self = try gpa.create(MachO);
399 errdefer gpa.destroy(self);400 errdefer gpa.destroy(self);
...@@ -410,7 +411,6 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {...@@ -410,7 +411,6 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO {
410 .needs_prealloc = needs_prealloc,411 .needs_prealloc = needs_prealloc,
411 };412 };
412413
413 const use_llvm = build_options.have_llvm and options.use_llvm;
414 if (use_llvm and !use_stage1) {414 if (use_llvm and !use_stage1) {
415 self.llvm_object = try LlvmObject.create(gpa, options);415 self.llvm_object = try LlvmObject.create(gpa, options);
416 }416 }
...@@ -519,7 +519,8 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -519,7 +519,8 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
519 var needs_full_relink = true;519 var needs_full_relink = true;
520520
521 cache: {521 cache: {
522 if (use_stage1 and self.base.options.disable_lld_caching) break :cache;522 if ((use_stage1 and self.base.options.disable_lld_caching) or self.base.options.cache_mode == .whole)
523 break :cache;
523524
524 man = comp.cache_parent.obtain();525 man = comp.cache_parent.obtain();
525526
...@@ -571,7 +572,8 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -571,7 +572,8 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
571 if (mem.eql(u8, prev_digest, &digest)) {572 if (mem.eql(u8, prev_digest, &digest)) {
572 // Hot diggity dog! The output binary is already there.573 // Hot diggity dog! The output binary is already there.
573574
574 if (use_stage1) {575 const use_llvm = build_options.have_llvm and self.base.options.use_llvm;
576 if (use_llvm or use_stage1) {
575 log.debug("MachO Zld digest={s} match - skipping invocation", .{std.fmt.fmtSliceHexLower(&digest)});577 log.debug("MachO Zld digest={s} match - skipping invocation", .{std.fmt.fmtSliceHexLower(&digest)});
576 self.base.lock = man.toOwnedLock();578 self.base.lock = man.toOwnedLock();
577 return;579 return;
...@@ -1025,7 +1027,8 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -1025,7 +1027,8 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
1025 try self.createTentativeDefAtoms();1027 try self.createTentativeDefAtoms();
1026 try self.parseObjectsIntoAtoms();1028 try self.parseObjectsIntoAtoms();
10271029
1028 if (use_stage1) {1030 const use_llvm = build_options.have_llvm and self.base.options.use_llvm;
1031 if (use_llvm or use_stage1) {
1029 try self.sortSections();1032 try self.sortSections();
1030 try self.allocateTextSegment();1033 try self.allocateTextSegment();
1031 try self.allocateDataConstSegment();1034 try self.allocateDataConstSegment();
...@@ -1041,7 +1044,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -1041,7 +1044,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
1041 self.logSectionOrdinals();1044 self.logSectionOrdinals();
1042 }1045 }
10431046
1044 if (use_stage1) {1047 if (use_llvm or use_stage1) {
1045 try self.writeAllAtoms();1048 try self.writeAllAtoms();
1046 } else {1049 } else {
1047 try self.writeAtoms();1050 try self.writeAtoms();
...@@ -1097,7 +1100,8 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -1097,7 +1100,8 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
1097 }1100 }
10981101
1099 cache: {1102 cache: {
1100 if (use_stage1 and self.base.options.disable_lld_caching) break :cache;1103 if ((use_stage1 and self.base.options.disable_lld_caching) or self.base.options.cache_mode == .whole)
1104 break :cache;
1101 // Update the file with the digest. If it fails we can continue; it only1105 // Update the file with the digest. If it fails we can continue; it only
1102 // means that the next invocation will have an unnecessary cache miss.1106 // means that the next invocation will have an unnecessary cache miss.
1103 Cache.writeSmallFile(cache_dir_handle, id_symlink_basename, &digest) catch |err| {1107 Cache.writeSmallFile(cache_dir_handle, id_symlink_basename, &digest) catch |err| {
...@@ -4930,12 +4934,13 @@ fn allocateSegment(self: *MachO, index: u16, offset: u64) !void {...@@ -4930,12 +4934,13 @@ fn allocateSegment(self: *MachO, index: u16, offset: u64) !void {
4930 var start: u64 = offset;4934 var start: u64 = offset;
4931 for (seg.sections.items) |*sect, sect_id| {4935 for (seg.sections.items) |*sect, sect_id| {
4932 const is_zerofill = sect.flags == macho.S_ZEROFILL or sect.flags == macho.S_THREAD_LOCAL_ZEROFILL;4936 const is_zerofill = sect.flags == macho.S_ZEROFILL or sect.flags == macho.S_THREAD_LOCAL_ZEROFILL;
4937 const use_llvm = build_options.have_llvm and self.base.options.use_llvm;
4933 const use_stage1 = build_options.is_stage1 and self.base.options.use_stage1;4938 const use_stage1 = build_options.is_stage1 and self.base.options.use_stage1;
4934 const alignment = try math.powi(u32, 2, sect.@"align");4939 const alignment = try math.powi(u32, 2, sect.@"align");
4935 const start_aligned = mem.alignForwardGeneric(u64, start, alignment);4940 const start_aligned = mem.alignForwardGeneric(u64, start, alignment);
49364941
4937 // TODO handle zerofill sections in stage24942 // TODO handle zerofill sections in stage2
4938 sect.offset = if (is_zerofill and use_stage1) 0 else @intCast(u32, seg.inner.fileoff + start_aligned);4943 sect.offset = if (is_zerofill and (use_stage1 or use_llvm)) 0 else @intCast(u32, seg.inner.fileoff + start_aligned);
4939 sect.addr = seg.inner.vmaddr + start_aligned;4944 sect.addr = seg.inner.vmaddr + start_aligned;
49404945
4941 // Recalculate section size given the allocated start address4946 // Recalculate section size given the allocated start address
...@@ -4963,7 +4968,7 @@ fn allocateSegment(self: *MachO, index: u16, offset: u64) !void {...@@ -4963,7 +4968,7 @@ fn allocateSegment(self: *MachO, index: u16, offset: u64) !void {
49634968
4964 start = start_aligned + sect.size;4969 start = start_aligned + sect.size;
49654970
4966 if (!(is_zerofill and use_stage1)) {4971 if (!(is_zerofill and (use_stage1 or use_llvm))) {
4967 seg.inner.filesize = start;4972 seg.inner.filesize = start;
4968 }4973 }
4969 seg.inner.vmsize = start;4974 seg.inner.vmsize = start;
...@@ -5012,10 +5017,11 @@ fn initSection(...@@ -5012,10 +5017,11 @@ fn initSection(
5012 sect.addr = seg.inner.vmaddr + off - seg.inner.fileoff;5017 sect.addr = seg.inner.vmaddr + off - seg.inner.fileoff;
50135018
5014 const is_zerofill = opts.flags == macho.S_ZEROFILL or opts.flags == macho.S_THREAD_LOCAL_ZEROFILL;5019 const is_zerofill = opts.flags == macho.S_ZEROFILL or opts.flags == macho.S_THREAD_LOCAL_ZEROFILL;
5020 const use_llvm = build_options.have_llvm and self.base.options.use_llvm;
5015 const use_stage1 = build_options.is_stage1 and self.base.options.use_stage1;5021 const use_stage1 = build_options.is_stage1 and self.base.options.use_stage1;
50165022
5017 // TODO handle zerofill in stage25023 // TODO handle zerofill in stage2
5018 if (!(is_zerofill and use_stage1)) {5024 if (!(is_zerofill and (use_stage1 or use_llvm))) {
5019 sect.offset = @intCast(u32, off);5025 sect.offset = @intCast(u32, off);
5020 }5026 }
5021 }5027 }
test/behavior/cast.zig+36
...@@ -112,6 +112,42 @@ test "@intToFloat" {...@@ -112,6 +112,42 @@ test "@intToFloat" {
112 comptime try S.doTheTest();112 comptime try S.doTheTest();
113}113}
114114
115test "@intToFloat(f80)" {
116 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
117
118 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
119 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
120 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
121 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
122 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
123
124 const S = struct {
125 fn doTheTest(comptime Int: type) !void {
126 try testIntToFloat(Int, -2);
127 }
128
129 fn testIntToFloat(comptime Int: type, k: Int) !void {
130 const f = @intToFloat(f80, k);
131 const i = @floatToInt(Int, f);
132 try expect(i == k);
133 }
134 };
135 try S.doTheTest(i31);
136 try S.doTheTest(i32);
137 try S.doTheTest(i45);
138 try S.doTheTest(i64);
139 try S.doTheTest(i80);
140 try S.doTheTest(i128);
141 // try S.doTheTest(i256); // TODO missing compiler_rt symbols
142 comptime try S.doTheTest(i31);
143 comptime try S.doTheTest(i32);
144 comptime try S.doTheTest(i45);
145 comptime try S.doTheTest(i64);
146 comptime try S.doTheTest(i80);
147 comptime try S.doTheTest(i128);
148 comptime try S.doTheTest(i256);
149}
150
115test "@floatToInt" {151test "@floatToInt" {
116 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO152 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
117 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO153 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
test/tests.zig+133-46
...@@ -34,6 +34,7 @@ const TestTarget = struct {...@@ -34,6 +34,7 @@ const TestTarget = struct {
34 link_libc: bool = false,34 link_libc: bool = false,
35 single_threaded: bool = false,35 single_threaded: bool = false,
36 disable_native: bool = false,36 disable_native: bool = false,
37 backend: ?std.builtin.CompilerBackend = null,
37};38};
3839
39const test_targets = blk: {40const test_targets = blk: {
...@@ -42,15 +43,73 @@ const test_targets = blk: {...@@ -42,15 +43,73 @@ const test_targets = blk: {
42 // lot of branches)43 // lot of branches)
43 @setEvalBranchQuota(50000);44 @setEvalBranchQuota(50000);
44 break :blk [_]TestTarget{45 break :blk [_]TestTarget{
45 TestTarget{},46 .{},
46 TestTarget{47 .{
47 .link_libc = true,48 .link_libc = true,
48 },49 },
49 TestTarget{50 .{
50 .single_threaded = true,51 .single_threaded = true,
51 },52 },
5253
53 TestTarget{54 .{
55 .link_libc = true,
56 .backend = .stage2_c,
57 },
58 .{
59 .target = .{
60 .cpu_arch = .x86_64,
61 .os_tag = .linux,
62 .abi = .none,
63 },
64 .backend = .stage2_x86_64,
65 },
66 .{
67 .target = .{
68 .cpu_arch = .aarch64,
69 .os_tag = .linux,
70 },
71 .backend = .stage2_aarch64,
72 },
73 .{
74 .target = .{
75 .cpu_arch = .wasm32,
76 .os_tag = .wasi,
77 },
78 .single_threaded = true,
79 .backend = .stage2_wasm,
80 },
81 .{
82 .target = .{
83 .cpu_arch = .arm,
84 .os_tag = .linux,
85 },
86 .backend = .stage2_wasm,
87 },
88 .{
89 .target = CrossTarget.parse(.{
90 .arch_os_abi = "arm-linux-none",
91 .cpu_features = "generic+v8a",
92 }) catch unreachable,
93 .backend = .stage2_arm,
94 },
95 .{
96 .target = .{
97 .cpu_arch = .aarch64,
98 .os_tag = .macos,
99 .abi = .gnu,
100 },
101 .backend = .stage2_aarch64,
102 },
103 .{
104 .target = .{
105 .cpu_arch = .x86_64,
106 .os_tag = .macos,
107 .abi = .gnu,
108 },
109 .backend = .stage2_x86_64,
110 },
111
112 .{
54 .target = .{113 .target = .{
55 .cpu_arch = .wasm32,114 .cpu_arch = .wasm32,
56 .os_tag = .wasi,115 .os_tag = .wasi,
...@@ -58,7 +117,7 @@ const test_targets = blk: {...@@ -58,7 +117,7 @@ const test_targets = blk: {
58 .link_libc = false,117 .link_libc = false,
59 .single_threaded = true,118 .single_threaded = true,
60 },119 },
61 TestTarget{120 .{
62 .target = .{121 .target = .{
63 .cpu_arch = .wasm32,122 .cpu_arch = .wasm32,
64 .os_tag = .wasi,123 .os_tag = .wasi,
...@@ -67,14 +126,14 @@ const test_targets = blk: {...@@ -67,14 +126,14 @@ const test_targets = blk: {
67 .single_threaded = true,126 .single_threaded = true,
68 },127 },
69128
70 TestTarget{129 .{
71 .target = .{130 .target = .{
72 .cpu_arch = .x86_64,131 .cpu_arch = .x86_64,
73 .os_tag = .linux,132 .os_tag = .linux,
74 .abi = .none,133 .abi = .none,
75 },134 },
76 },135 },
77 TestTarget{136 .{
78 .target = .{137 .target = .{
79 .cpu_arch = .x86_64,138 .cpu_arch = .x86_64,
80 .os_tag = .linux,139 .os_tag = .linux,
...@@ -82,7 +141,7 @@ const test_targets = blk: {...@@ -82,7 +141,7 @@ const test_targets = blk: {
82 },141 },
83 .link_libc = true,142 .link_libc = true,
84 },143 },
85 TestTarget{144 .{
86 .target = .{145 .target = .{
87 .cpu_arch = .x86_64,146 .cpu_arch = .x86_64,
88 .os_tag = .linux,147 .os_tag = .linux,
...@@ -91,14 +150,14 @@ const test_targets = blk: {...@@ -91,14 +150,14 @@ const test_targets = blk: {
91 .link_libc = true,150 .link_libc = true,
92 },151 },
93152
94 TestTarget{153 .{
95 .target = .{154 .target = .{
96 .cpu_arch = .i386,155 .cpu_arch = .i386,
97 .os_tag = .linux,156 .os_tag = .linux,
98 .abi = .none,157 .abi = .none,
99 },158 },
100 },159 },
101 TestTarget{160 .{
102 .target = .{161 .target = .{
103 .cpu_arch = .i386,162 .cpu_arch = .i386,
104 .os_tag = .linux,163 .os_tag = .linux,
...@@ -106,7 +165,7 @@ const test_targets = blk: {...@@ -106,7 +165,7 @@ const test_targets = blk: {
106 },165 },
107 .link_libc = true,166 .link_libc = true,
108 },167 },
109 TestTarget{168 .{
110 .target = .{169 .target = .{
111 .cpu_arch = .i386,170 .cpu_arch = .i386,
112 .os_tag = .linux,171 .os_tag = .linux,
...@@ -115,14 +174,14 @@ const test_targets = blk: {...@@ -115,14 +174,14 @@ const test_targets = blk: {
115 .link_libc = true,174 .link_libc = true,
116 },175 },
117176
118 TestTarget{177 .{
119 .target = .{178 .target = .{
120 .cpu_arch = .aarch64,179 .cpu_arch = .aarch64,
121 .os_tag = .linux,180 .os_tag = .linux,
122 .abi = .none,181 .abi = .none,
123 },182 },
124 },183 },
125 TestTarget{184 .{
126 .target = .{185 .target = .{
127 .cpu_arch = .aarch64,186 .cpu_arch = .aarch64,
128 .os_tag = .linux,187 .os_tag = .linux,
...@@ -130,7 +189,7 @@ const test_targets = blk: {...@@ -130,7 +189,7 @@ const test_targets = blk: {
130 },189 },
131 .link_libc = true,190 .link_libc = true,
132 },191 },
133 TestTarget{192 .{
134 .target = .{193 .target = .{
135 .cpu_arch = .aarch64,194 .cpu_arch = .aarch64,
136 .os_tag = .linux,195 .os_tag = .linux,
...@@ -138,7 +197,7 @@ const test_targets = blk: {...@@ -138,7 +197,7 @@ const test_targets = blk: {
138 },197 },
139 .link_libc = true,198 .link_libc = true,
140 },199 },
141 TestTarget{200 .{
142 .target = .{201 .target = .{
143 .cpu_arch = .aarch64,202 .cpu_arch = .aarch64,
144 .os_tag = .windows,203 .os_tag = .windows,
...@@ -147,13 +206,13 @@ const test_targets = blk: {...@@ -147,13 +206,13 @@ const test_targets = blk: {
147 .link_libc = true,206 .link_libc = true,
148 },207 },
149208
150 TestTarget{209 .{
151 .target = CrossTarget.parse(.{210 .target = CrossTarget.parse(.{
152 .arch_os_abi = "arm-linux-none",211 .arch_os_abi = "arm-linux-none",
153 .cpu_features = "generic+v8a",212 .cpu_features = "generic+v8a",
154 }) catch unreachable,213 }) catch unreachable,
155 },214 },
156 TestTarget{215 .{
157 .target = CrossTarget.parse(.{216 .target = CrossTarget.parse(.{
158 .arch_os_abi = "arm-linux-musleabihf",217 .arch_os_abi = "arm-linux-musleabihf",
159 .cpu_features = "generic+v8a",218 .cpu_features = "generic+v8a",
...@@ -161,7 +220,7 @@ const test_targets = blk: {...@@ -161,7 +220,7 @@ const test_targets = blk: {
161 .link_libc = true,220 .link_libc = true,
162 },221 },
163 // https://github.com/ziglang/zig/issues/3287222 // https://github.com/ziglang/zig/issues/3287
164 //TestTarget{223 //.{
165 // .target = CrossTarget.parse(.{224 // .target = CrossTarget.parse(.{
166 // .arch_os_abi = "arm-linux-gnueabihf",225 // .arch_os_abi = "arm-linux-gnueabihf",
167 // .cpu_features = "generic+v8a",226 // .cpu_features = "generic+v8a",
...@@ -169,7 +228,7 @@ const test_targets = blk: {...@@ -169,7 +228,7 @@ const test_targets = blk: {
169 // .link_libc = true,228 // .link_libc = true,
170 //},229 //},
171230
172 TestTarget{231 .{
173 .target = .{232 .target = .{
174 .cpu_arch = .mips,233 .cpu_arch = .mips,
175 .os_tag = .linux,234 .os_tag = .linux,
...@@ -177,7 +236,7 @@ const test_targets = blk: {...@@ -177,7 +236,7 @@ const test_targets = blk: {
177 },236 },
178 },237 },
179238
180 TestTarget{239 .{
181 .target = .{240 .target = .{
182 .cpu_arch = .mips,241 .cpu_arch = .mips,
183 .os_tag = .linux,242 .os_tag = .linux,
...@@ -187,7 +246,7 @@ const test_targets = blk: {...@@ -187,7 +246,7 @@ const test_targets = blk: {
187 },246 },
188247
189 // https://github.com/ziglang/zig/issues/4927248 // https://github.com/ziglang/zig/issues/4927
190 //TestTarget{249 //.{
191 // .target = .{250 // .target = .{
192 // .cpu_arch = .mips,251 // .cpu_arch = .mips,
193 // .os_tag = .linux,252 // .os_tag = .linux,
...@@ -196,7 +255,7 @@ const test_targets = blk: {...@@ -196,7 +255,7 @@ const test_targets = blk: {
196 // .link_libc = true,255 // .link_libc = true,
197 //},256 //},
198257
199 TestTarget{258 .{
200 .target = .{259 .target = .{
201 .cpu_arch = .mipsel,260 .cpu_arch = .mipsel,
202 .os_tag = .linux,261 .os_tag = .linux,
...@@ -204,7 +263,7 @@ const test_targets = blk: {...@@ -204,7 +263,7 @@ const test_targets = blk: {
204 },263 },
205 },264 },
206265
207 TestTarget{266 .{
208 .target = .{267 .target = .{
209 .cpu_arch = .mipsel,268 .cpu_arch = .mipsel,
210 .os_tag = .linux,269 .os_tag = .linux,
...@@ -214,7 +273,7 @@ const test_targets = blk: {...@@ -214,7 +273,7 @@ const test_targets = blk: {
214 },273 },
215274
216 // https://github.com/ziglang/zig/issues/4927275 // https://github.com/ziglang/zig/issues/4927
217 //TestTarget{276 //.{
218 // .target = .{277 // .target = .{
219 // .cpu_arch = .mipsel,278 // .cpu_arch = .mipsel,
220 // .os_tag = .linux,279 // .os_tag = .linux,
...@@ -223,14 +282,14 @@ const test_targets = blk: {...@@ -223,14 +282,14 @@ const test_targets = blk: {
223 // .link_libc = true,282 // .link_libc = true,
224 //},283 //},
225284
226 TestTarget{285 .{
227 .target = .{286 .target = .{
228 .cpu_arch = .powerpc,287 .cpu_arch = .powerpc,
229 .os_tag = .linux,288 .os_tag = .linux,
230 .abi = .none,289 .abi = .none,
231 },290 },
232 },291 },
233 TestTarget{292 .{
234 .target = .{293 .target = .{
235 .cpu_arch = .powerpc,294 .cpu_arch = .powerpc,
236 .os_tag = .linux,295 .os_tag = .linux,
...@@ -239,7 +298,7 @@ const test_targets = blk: {...@@ -239,7 +298,7 @@ const test_targets = blk: {
239 .link_libc = true,298 .link_libc = true,
240 },299 },
241 // https://github.com/ziglang/zig/issues/2256300 // https://github.com/ziglang/zig/issues/2256
242 //TestTarget{301 //.{
243 // .target = .{302 // .target = .{
244 // .cpu_arch = .powerpc,303 // .cpu_arch = .powerpc,
245 // .os_tag = .linux,304 // .os_tag = .linux,
...@@ -248,7 +307,7 @@ const test_targets = blk: {...@@ -248,7 +307,7 @@ const test_targets = blk: {
248 // .link_libc = true,307 // .link_libc = true,
249 //},308 //},
250309
251 TestTarget{310 .{
252 .target = .{311 .target = .{
253 .cpu_arch = .riscv64,312 .cpu_arch = .riscv64,
254 .os_tag = .linux,313 .os_tag = .linux,
...@@ -256,7 +315,7 @@ const test_targets = blk: {...@@ -256,7 +315,7 @@ const test_targets = blk: {
256 },315 },
257 },316 },
258317
259 TestTarget{318 .{
260 .target = .{319 .target = .{
261 .cpu_arch = .riscv64,320 .cpu_arch = .riscv64,
262 .os_tag = .linux,321 .os_tag = .linux,
...@@ -266,7 +325,7 @@ const test_targets = blk: {...@@ -266,7 +325,7 @@ const test_targets = blk: {
266 },325 },
267326
268 // https://github.com/ziglang/zig/issues/3340327 // https://github.com/ziglang/zig/issues/3340
269 //TestTarget{328 //.{
270 // .target = .{329 // .target = .{
271 // .cpu_arch = .riscv64,330 // .cpu_arch = .riscv64,
272 // .os = .linux,331 // .os = .linux,
...@@ -275,7 +334,7 @@ const test_targets = blk: {...@@ -275,7 +334,7 @@ const test_targets = blk: {
275 // .link_libc = true,334 // .link_libc = true,
276 //},335 //},
277336
278 TestTarget{337 .{
279 .target = .{338 .target = .{
280 .cpu_arch = .x86_64,339 .cpu_arch = .x86_64,
281 .os_tag = .macos,340 .os_tag = .macos,
...@@ -283,7 +342,7 @@ const test_targets = blk: {...@@ -283,7 +342,7 @@ const test_targets = blk: {
283 },342 },
284 },343 },
285344
286 TestTarget{345 .{
287 .target = .{346 .target = .{
288 .cpu_arch = .aarch64,347 .cpu_arch = .aarch64,
289 .os_tag = .macos,348 .os_tag = .macos,
...@@ -291,7 +350,7 @@ const test_targets = blk: {...@@ -291,7 +350,7 @@ const test_targets = blk: {
291 },350 },
292 },351 },
293352
294 TestTarget{353 .{
295 .target = .{354 .target = .{
296 .cpu_arch = .i386,355 .cpu_arch = .i386,
297 .os_tag = .windows,356 .os_tag = .windows,
...@@ -299,7 +358,7 @@ const test_targets = blk: {...@@ -299,7 +358,7 @@ const test_targets = blk: {
299 },358 },
300 },359 },
301360
302 TestTarget{361 .{
303 .target = .{362 .target = .{
304 .cpu_arch = .x86_64,363 .cpu_arch = .x86_64,
305 .os_tag = .windows,364 .os_tag = .windows,
...@@ -307,7 +366,7 @@ const test_targets = blk: {...@@ -307,7 +366,7 @@ const test_targets = blk: {
307 },366 },
308 },367 },
309368
310 TestTarget{369 .{
311 .target = .{370 .target = .{
312 .cpu_arch = .i386,371 .cpu_arch = .i386,
313 .os_tag = .windows,372 .os_tag = .windows,
...@@ -316,7 +375,7 @@ const test_targets = blk: {...@@ -316,7 +375,7 @@ const test_targets = blk: {
316 .link_libc = true,375 .link_libc = true,
317 },376 },
318377
319 TestTarget{378 .{
320 .target = .{379 .target = .{
321 .cpu_arch = .x86_64,380 .cpu_arch = .x86_64,
322 .os_tag = .windows,381 .os_tag = .windows,
...@@ -326,38 +385,38 @@ const test_targets = blk: {...@@ -326,38 +385,38 @@ const test_targets = blk: {
326 },385 },
327386
328 // Do the release tests last because they take a long time387 // Do the release tests last because they take a long time
329 TestTarget{388 .{
330 .mode = .ReleaseFast,389 .mode = .ReleaseFast,
331 },390 },
332 TestTarget{391 .{
333 .link_libc = true,392 .link_libc = true,
334 .mode = .ReleaseFast,393 .mode = .ReleaseFast,
335 },394 },
336 TestTarget{395 .{
337 .mode = .ReleaseFast,396 .mode = .ReleaseFast,
338 .single_threaded = true,397 .single_threaded = true,
339 },398 },
340399
341 TestTarget{400 .{
342 .mode = .ReleaseSafe,401 .mode = .ReleaseSafe,
343 },402 },
344 TestTarget{403 .{
345 .link_libc = true,404 .link_libc = true,
346 .mode = .ReleaseSafe,405 .mode = .ReleaseSafe,
347 },406 },
348 TestTarget{407 .{
349 .mode = .ReleaseSafe,408 .mode = .ReleaseSafe,
350 .single_threaded = true,409 .single_threaded = true,
351 },410 },
352411
353 TestTarget{412 .{
354 .mode = .ReleaseSmall,413 .mode = .ReleaseSmall,
355 },414 },
356 TestTarget{415 .{
357 .link_libc = true,416 .link_libc = true,
358 .mode = .ReleaseSmall,417 .mode = .ReleaseSmall,
359 },418 },
360 TestTarget{419 .{
361 .mode = .ReleaseSmall,420 .mode = .ReleaseSmall,
362 .single_threaded = true,421 .single_threaded = true,
363 },422 },
...@@ -524,6 +583,9 @@ pub fn addPkgTests(...@@ -524,6 +583,9 @@ pub fn addPkgTests(
524 skip_single_threaded: bool,583 skip_single_threaded: bool,
525 skip_non_native: bool,584 skip_non_native: bool,
526 skip_libc: bool,585 skip_libc: bool,
586 skip_stage1: bool,
587 skip_stage2: bool,
588 is_stage1: bool,
527) *build.Step {589) *build.Step {
528 const step = b.step(b.fmt("test-{s}", .{name}), desc);590 const step = b.step(b.fmt("test-{s}", .{name}), desc);
529591
...@@ -549,6 +611,11 @@ pub fn addPkgTests(...@@ -549,6 +611,11 @@ pub fn addPkgTests(
549 continue;611 continue;
550 }612 }
551613
614 if (test_target.backend) |backend| switch (backend) {
615 .stage1 => if (skip_stage1) continue,
616 else => if (skip_stage2) continue,
617 } else if (is_stage1 and skip_stage1) continue;
618
552 const want_this_mode = for (modes) |m| {619 const want_this_mode = for (modes) |m| {
553 if (m == test_target.mode) break true;620 if (m == test_target.mode) break true;
554 } else false;621 } else false;
...@@ -565,12 +632,14 @@ pub fn addPkgTests(...@@ -565,12 +632,14 @@ pub fn addPkgTests(
565632
566 const these_tests = b.addTest(root_src);633 const these_tests = b.addTest(root_src);
567 const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";634 const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
568 these_tests.setNamePrefix(b.fmt("{s}-{s}-{s}-{s}-{s} ", .{635 const backend_txt = if (test_target.backend) |backend| @tagName(backend) else "default";
636 these_tests.setNamePrefix(b.fmt("{s}-{s}-{s}-{s}-{s}-{s} ", .{
569 name,637 name,
570 triple_prefix,638 triple_prefix,
571 @tagName(test_target.mode),639 @tagName(test_target.mode),
572 libc_prefix,640 libc_prefix,
573 single_threaded_txt,641 single_threaded_txt,
642 backend_txt,
574 }));643 }));
575 these_tests.single_threaded = test_target.single_threaded;644 these_tests.single_threaded = test_target.single_threaded;
576 these_tests.setFilter(test_filter);645 these_tests.setFilter(test_filter);
...@@ -581,6 +650,24 @@ pub fn addPkgTests(...@@ -581,6 +650,24 @@ pub fn addPkgTests(
581 }650 }
582 these_tests.overrideZigLibDir("lib");651 these_tests.overrideZigLibDir("lib");
583 these_tests.addIncludePath("test");652 these_tests.addIncludePath("test");
653 if (test_target.backend) |backend| switch (backend) {
654 .stage1 => {
655 these_tests.use_stage1 = true;
656 },
657 .stage2_llvm => {
658 these_tests.use_stage1 = false;
659 these_tests.use_llvm = true;
660 },
661 .stage2_c => {
662 these_tests.use_stage1 = false;
663 these_tests.use_llvm = false;
664 these_tests.ofmt = .c;
665 },
666 else => {
667 these_tests.use_stage1 = false;
668 these_tests.use_llvm = false;
669 },
670 };
584671
585 step.dependOn(&these_tests.step);672 step.dependOn(&these_tests.step);
586 }673 }