From afac5d28951cfd913851094649e8b9f2136694ca Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 21 Sep 2020 21:14:01 -0700 Subject: [PATCH] fix regressed stage2 test harness --- src/Compilation.zig | 15 +++++++---- src/stage1/stage2.h | 2 +- src/test.zig | 14 ++++++++--- src/windows_sdk.h | 8 +++--- src/zig_clang.h | 2 +- test/stage2/cbe.zig | 2 +- test/stage2/spu-ii.zig | 2 +- test/stage2/test.zig | 56 +++++++++++++++++++++--------------------- test/stage2/zir.zig | 4 +-- 9 files changed, 58 insertions(+), 47 deletions(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index 725e212b9..948eb1840 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -772,7 +772,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { if (build_options.is_stage1 and comp.bin_file.options.use_llvm) { try comp.work_queue.writeItem(.{ .stage1_module = {} }); } - if (is_exe_or_dyn_lib) { + if (is_exe_or_dyn_lib and comp.bin_file.options.use_llvm) { try comp.work_queue.writeItem(.{ .libcompiler_rt = {} }); if (!comp.bin_file.options.link_libc) { try comp.work_queue.writeItem(.{ .zig_libc = {} }); @@ -1128,6 +1128,9 @@ pub fn performAllTheWork(self: *Compilation) error{OutOfMemory}!void { }; }, .stage1_module => { + if (!build_options.is_stage1) + unreachable; + self.updateStage1Module() catch |err| { fatal("unable to build stage1 zig object: {}", .{@errorName(err)}); }; @@ -1685,11 +1688,13 @@ pub fn classifyFileExt(filename: []const u8) FileExt { test "classifyFileExt" { std.testing.expectEqual(FileExt.cpp, classifyFileExt("foo.cc")); std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.nim")); - std.testing.expectEqual(FileExt.so, classifyFileExt("foo.so")); - std.testing.expectEqual(FileExt.so, classifyFileExt("foo.so.1")); - std.testing.expectEqual(FileExt.so, classifyFileExt("foo.so.1.2")); - std.testing.expectEqual(FileExt.so, classifyFileExt("foo.so.1.2.3")); + std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so")); + std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1")); + std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2")); + std.testing.expectEqual(FileExt.shared_library, classifyFileExt("foo.so.1.2.3")); std.testing.expectEqual(FileExt.unknown, classifyFileExt("foo.so.1.2.3~")); + std.testing.expectEqual(FileExt.zig, classifyFileExt("foo.zig")); + std.testing.expectEqual(FileExt.zir, classifyFileExt("foo.zir")); } fn haveFramePointer(comp: *Compilation) bool { diff --git a/src/stage1/stage2.h b/src/stage1/stage2.h index 104faa6ca..613cae2a7 100644 --- a/src/stage1/stage2.h +++ b/src/stage1/stage2.h @@ -29,7 +29,7 @@ #endif // ABI warning: the types and declarations in this file must match both those in -// stage2.cpp and src-self-hosted/stage1.zig. +// stage2.cpp and src/stage1.zig. // ABI warning enum Error { diff --git a/src/test.zig b/src/test.zig index 154a839a3..0f63c3f6a 100644 --- a/src/test.zig +++ b/src/test.zig @@ -458,9 +458,15 @@ pub const TestContext = struct { .path = try std.fs.path.join(arena, &[_][]const u8{ bogus_path, "zig-cache" }), }; - const tmp_src_path = if (case.extension == .Zig) "test_case.zig" else if (case.extension == .ZIR) "test_case.zir" else unreachable; - const root_pkg = try Package.create(allocator, tmp.dir, ".", tmp_src_path); - defer root_pkg.destroy(allocator); + const tmp_src_path = switch (case.extension) { + .Zig => "test_case.zig", + .ZIR => "test_case.zir", + }; + + var root_pkg: Package = .{ + .root_src_directory = .{ .path = bogus_path, .handle = tmp.dir }, + .root_src_path = tmp_src_path, + }; const ofmt: ?std.builtin.ObjectFormat = if (case.cbe) .c else null; const bin_name = try std.zig.binNameAlloc(arena, "test_case", target, case.output_mode, null, ofmt); @@ -486,7 +492,7 @@ pub const TestContext = struct { // TODO: support testing optimizations .optimize_mode = .Debug, .emit_bin = emit_bin, - .root_pkg = root_pkg, + .root_pkg = &root_pkg, .keep_source_files_loaded = true, .object_format = ofmt, .is_native_os = case.target.isNativeOs(), diff --git a/src/windows_sdk.h b/src/windows_sdk.h index e88720955..a4707b3de 100644 --- a/src/windows_sdk.h +++ b/src/windows_sdk.h @@ -16,7 +16,7 @@ #include -// ABI warning - src-self-hosted/windows_sdk.zig +// ABI warning - src/windows_sdk.zig struct ZigWindowsSDK { const char *path10_ptr; size_t path10_len; @@ -34,7 +34,7 @@ struct ZigWindowsSDK { size_t msvc_lib_dir_len; }; -// ABI warning - src-self-hosted/windows_sdk.zig +// ABI warning - src/windows_sdk.zig enum ZigFindWindowsSdkError { ZigFindWindowsSdkErrorNone, ZigFindWindowsSdkErrorOutOfMemory, @@ -42,10 +42,10 @@ enum ZigFindWindowsSdkError { ZigFindWindowsSdkErrorPathTooLong, }; -// ABI warning - src-self-hosted/windows_sdk.zig +// ABI warning - src/windows_sdk.zig ZIG_EXTERN_C enum ZigFindWindowsSdkError zig_find_windows_sdk(struct ZigWindowsSDK **out_sdk); -// ABI warning - src-self-hosted/windows_sdk.zig +// ABI warning - src/windows_sdk.zig ZIG_EXTERN_C void zig_free_windows_sdk(struct ZigWindowsSDK *sdk); #endif diff --git a/src/zig_clang.h b/src/zig_clang.h index 2c358d880..f9ce9c34e 100644 --- a/src/zig_clang.h +++ b/src/zig_clang.h @@ -14,7 +14,7 @@ // ATTENTION: If you modify this file, be sure to update the corresponding // extern function declarations in the self-hosted compiler file -// src-self-hosted/clang.zig. +// src/clang.zig. struct ZigClangSourceLocation { unsigned ID; diff --git a/test/stage2/cbe.zig b/test/stage2/cbe.zig index 060822186..2a176e036 100644 --- a/test/stage2/cbe.zig +++ b/test/stage2/cbe.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const TestContext = @import("../../src-self-hosted/test.zig").TestContext; +const TestContext = @import("../../src/test.zig").TestContext; // These tests should work with all platforms, but we're using linux_x64 for // now for consistency. Will be expanded eventually. diff --git a/test/stage2/spu-ii.zig b/test/stage2/spu-ii.zig index 1316f19d0..aa091c417 100644 --- a/test/stage2/spu-ii.zig +++ b/test/stage2/spu-ii.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const TestContext = @import("../../src-self-hosted/test.zig").TestContext; +const TestContext = @import("../../src/test.zig").TestContext; const spu = std.zig.CrossTarget{ .cpu_arch = .spu_2, diff --git a/test/stage2/test.zig b/test/stage2/test.zig index b37eb63a2..a22dc23d3 100644 --- a/test/stage2/test.zig +++ b/test/stage2/test.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const TestContext = @import("../../src-self-hosted/test.zig").TestContext; +const TestContext = @import("../../src/test.zig").TestContext; // Self-hosted has differing levels of support for various architectures. For now we pass explicit // target parameters to each test case. At some point we will take this to the next level and have @@ -76,7 +76,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "Hello, World!\n", ); // Now change the message only @@ -108,7 +108,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "What is up? This is a longer message that will force the data to be relocated in virtual address space.\n", ); // Now we print it twice. @@ -184,7 +184,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "Hello, World!\n", ); } @@ -219,7 +219,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "Hello, World!\n", ); } @@ -244,7 +244,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "Hello, World!\n", ); } @@ -271,7 +271,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); } @@ -298,7 +298,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); } @@ -329,7 +329,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); @@ -362,7 +362,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); @@ -398,7 +398,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); @@ -435,7 +435,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); @@ -465,7 +465,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); @@ -499,7 +499,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); @@ -523,7 +523,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); @@ -562,7 +562,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "hello\nhello\nhello\nhello\n", ); @@ -599,7 +599,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); @@ -641,7 +641,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); @@ -693,7 +693,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); @@ -755,7 +755,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); @@ -788,7 +788,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); @@ -820,7 +820,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); @@ -845,7 +845,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); @@ -871,7 +871,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "", ); @@ -904,7 +904,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ ); \\ unreachable; \\} - , + , "hello\nhello\nhello\nhello\nhello\n", ); } @@ -923,7 +923,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ bar(); \\} \\fn bar() void {} - , + , "42\n", ); @@ -941,7 +941,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ bar(); \\} \\fn bar() void {} - , + , "42\n", ); @@ -957,7 +957,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ bar(); \\} \\fn bar() void {} - , + , // This is what you get when you take the bits of the IEE-754 // representation of 42.0 and reinterpret them as an unsigned // integer. Guess that's a bug in wasmtime. diff --git a/test/stage2/zir.zig b/test/stage2/zir.zig index 78d971d10..f87fca374 100644 --- a/test/stage2/zir.zig +++ b/test/stage2/zir.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const TestContext = @import("../../src-self-hosted/test.zig").TestContext; +const TestContext = @import("../../src/test.zig").TestContext; // self-hosted does not yet support PE executable files / COFF object files // or mach-o files. So we do the ZIR transform test cases cross compiling for // x86_64-linux. @@ -156,7 +156,7 @@ pub fn addCases(ctx: *TestContext) !void { \\ %0 = call(@a, []) \\ %1 = returnvoid() \\}) - , + , &[_][]const u8{ ":18:21: error: message", },