diff --git a/doc/langref/test_structs.zig b/doc/langref/test_structs.zig index 936d280586..b62fd3578d 100644 --- a/doc/langref/test_structs.zig +++ b/doc/langref/test_structs.zig @@ -6,28 +6,13 @@ const Point = struct { y: f32, }; -// Maybe we want to pass it to OpenGL so we want to be particular about -// how the bytes are arranged. -const Point2 = packed struct { - x: f32, - y: f32, -}; - // Declare an instance of a struct. -const p = Point{ +const p: Point = .{ .x = 0.12, .y = 0.34, }; -// Maybe we're not ready to fill out some of the fields. -var p2 = Point{ - .x = 0.12, - .y = undefined, -}; - -// Structs can have methods -// Struct methods are not special, they are only namespaced -// functions that you can call with dot syntax. +// Functions in the struct's namespace can be called with dot syntax. const Vec3 = struct { x: f32, y: f32, @@ -46,7 +31,6 @@ const Vec3 = struct { } }; -const expect = @import("std").testing.expect; test "dot product" { const v1 = Vec3.init(1.0, 0.0, 0.0); const v2 = Vec3.init(0.0, 1.0, 0.0); @@ -67,14 +51,14 @@ test "struct namespaced variable" { try expect(Empty.PI == 3.14); try expect(@sizeOf(Empty) == 0); - // you can still instantiate an empty struct - const does_nothing = Empty{}; + // Empty structs can be instantiated the same as usual. + const does_nothing: Empty = .{}; _ = does_nothing; } -// struct field order is determined by the compiler for optimal performance. -// however, you can still calculate a struct base pointer given a field pointer: +// Struct field order is determined by the compiler, however, a base pointer +// can be computed from a field pointer: fn setYBasedOnX(x: *f32, y: f32) void { const point: *Point = @fieldParentPtr("x", x); point.y = y; @@ -88,8 +72,7 @@ test "field parent pointer" { try expect(point.y == 0.9); } -// You can return a struct from a function. This is how we do generics -// in Zig: +// Structs can be returned from functions. fn LinkedList(comptime T: type) type { return struct { pub const Node = struct { @@ -105,8 +88,7 @@ fn LinkedList(comptime T: type) type { } test "linked list" { - // Functions called at compile-time are memoized. This means you can - // do this: + // Functions called at compile-time are memoized. try expect(LinkedList(i32) == LinkedList(i32)); const list = LinkedList(i32){ @@ -139,4 +121,6 @@ test "linked list" { // instead of try expect(list2.first.?.*.data == 1234); } +const expect = @import("std").testing.expect; + // test diff --git a/lib/c.zig b/lib/c.zig index 927d71d82f..734940ff05 100644 --- a/lib/c.zig +++ b/lib/c.zig @@ -11,16 +11,14 @@ const native_os = builtin.os.tag; const native_arch = builtin.cpu.arch; const native_abi = builtin.abi; +const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .internal else .strong; + const is_wasm = switch (native_arch) { .wasm32, .wasm64 => true, else => false, }; -const is_msvc = switch (native_abi) { - .msvc => true, - else => false, -}; const is_freestanding = switch (native_os) { - .freestanding => true, + .freestanding, .other => true, else => false, }; @@ -30,14 +28,14 @@ comptime { } if (builtin.link_libc) { - @export(&strcmp, .{ .name = "strcmp", .linkage = .strong }); - @export(&strncmp, .{ .name = "strncmp", .linkage = .strong }); - @export(&strerror, .{ .name = "strerror", .linkage = .strong }); - @export(&strlen, .{ .name = "strlen", .linkage = .strong }); - @export(&strcpy, .{ .name = "strcpy", .linkage = .strong }); - @export(&strncpy, .{ .name = "strncpy", .linkage = .strong }); - @export(&strcat, .{ .name = "strcat", .linkage = .strong }); - @export(&strncat, .{ .name = "strncat", .linkage = .strong }); + @export(&strcmp, .{ .name = "strcmp", .linkage = linkage }); + @export(&strncmp, .{ .name = "strncmp", .linkage = linkage }); + @export(&strerror, .{ .name = "strerror", .linkage = linkage }); + @export(&strlen, .{ .name = "strlen", .linkage = linkage }); + @export(&strcpy, .{ .name = "strcpy", .linkage = linkage }); + @export(&strncpy, .{ .name = "strncpy", .linkage = linkage }); + @export(&strcat, .{ .name = "strcat", .linkage = linkage }); + @export(&strncat, .{ .name = "strncat", .linkage = linkage }); } } diff --git a/lib/std/Target.zig b/lib/std/Target.zig index 2283004115..b2808255b0 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -1076,7 +1076,7 @@ pub fn toElfMachine(target: Target) std.elf.EM { pub fn toCoffMachine(target: Target) std.coff.MachineType { return switch (target.cpu.arch) { .arm => .ARM, - .thumb => .THUMB, + .thumb => .ARMNT, .aarch64 => .ARM64, .loongarch32 => .LOONGARCH32, .loongarch64 => .LOONGARCH64, diff --git a/lib/std/atomic.zig b/lib/std/atomic.zig index e1a6767590..5630bf6bf5 100644 --- a/lib/std/atomic.zig +++ b/lib/std/atomic.zig @@ -408,79 +408,87 @@ test spinLoopHint { } } +pub fn cacheLineForCpu(cpu: std.Target.Cpu) u16 { + return switch (cpu.arch) { + // x86_64: Starting from Intel's Sandy Bridge, the spatial prefetcher pulls in pairs of 64-byte cache lines at a time. + // - https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-optimization-manual.pdf + // - https://github.com/facebook/folly/blob/1b5288e6eea6df074758f877c849b6e73bbb9fbb/folly/lang/Align.h#L107 + // + // aarch64: Some big.LITTLE ARM archs have "big" cores with 128-byte cache lines: + // - https://www.mono-project.com/news/2016/09/12/arm64-icache/ + // - https://cpufun.substack.com/p/more-m1-fun-hardware-information + // + // - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/arc/Kconfig#L212 + // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_ppc64x.go#L9 + .x86_64, + .aarch64, + .aarch64_be, + .arc, + .powerpc64, + .powerpc64le, + => 128, + + // https://github.com/llvm/llvm-project/blob/e379094328e49731a606304f7e3559d4f1fa96f9/clang/lib/Basic/Targets/Hexagon.h#L145-L151 + .hexagon, + => if (std.Target.hexagon.featureSetHas(cpu.features, .v73)) 64 else 32, + + // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_arm.go#L7 + // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mips.go#L7 + // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mipsle.go#L7 + // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mips64x.go#L9 + // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_riscv64.go#L7 + // - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/sparc/include/asm/cache.h#L14 + .arm, + .armeb, + .thumb, + .thumbeb, + .mips, + .mipsel, + .mips64, + .mips64el, + .riscv32, + .riscv64, + .sparc, + .sparc64, + => 32, + + // - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/m68k/include/asm/cache.h#L10 + .m68k, + => 16, + + // - https://www.ti.com/lit/pdf/slaa498 + .msp430, + => 8, + + // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_s390x.go#L7 + // - https://sxauroratsubasa.sakura.ne.jp/documents/guide/pdfs/Aurora_ISA_guide.pdf + .s390x, + .ve, + => 256, + + // Other x86 and WASM platforms have 64-byte cache lines. + // The rest of the architectures are assumed to be similar. + // - https://github.com/golang/go/blob/dda2991c2ea0c5914714469c4defc2562a907230/src/internal/cpu/cpu_x86.go#L9 + // - https://github.com/golang/go/blob/0a9321ad7f8c91e1b0c7184731257df923977eb9/src/internal/cpu/cpu_loong64.go#L11 + // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_wasm.go#L7 + // - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/xtensa/variants/csp/include/variant/core.h#L209 + // - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/csky/Kconfig#L183 + // - https://www.xmos.com/download/The-XMOS-XS3-Architecture.pdf + else => 64, + }; +} + /// The estimated size of the CPU's cache line when atomically updating memory. /// Add this much padding or align to this boundary to avoid atomically-updated /// memory from forcing cache invalidations on near, but non-atomic, memory. /// /// https://en.wikipedia.org/wiki/False_sharing /// https://github.com/golang/go/search?q=CacheLinePadSize -pub const cache_line = switch (builtin.cpu.arch) { - // x86_64: Starting from Intel's Sandy Bridge, the spatial prefetcher pulls in pairs of 64-byte cache lines at a time. - // - https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-optimization-manual.pdf - // - https://github.com/facebook/folly/blob/1b5288e6eea6df074758f877c849b6e73bbb9fbb/folly/lang/Align.h#L107 - // - // aarch64: Some big.LITTLE ARM archs have "big" cores with 128-byte cache lines: - // - https://www.mono-project.com/news/2016/09/12/arm64-icache/ - // - https://cpufun.substack.com/p/more-m1-fun-hardware-information - // - // - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/arc/Kconfig#L212 - // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_ppc64x.go#L9 - .x86_64, - .aarch64, - .aarch64_be, - .arc, - .powerpc64, - .powerpc64le, - => 128, +pub const cache_line = cacheLineForCpu(builtin.cpu); - // https://github.com/llvm/llvm-project/blob/e379094328e49731a606304f7e3559d4f1fa96f9/clang/lib/Basic/Targets/Hexagon.h#L145-L151 - .hexagon, - => if (std.Target.hexagon.featureSetHas(builtin.target.cpu.features, .v73)) 64 else 32, - - // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_arm.go#L7 - // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mips.go#L7 - // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mipsle.go#L7 - // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mips64x.go#L9 - // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_riscv64.go#L7 - // - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/sparc/include/asm/cache.h#L14 - .arm, - .armeb, - .thumb, - .thumbeb, - .mips, - .mipsel, - .mips64, - .mips64el, - .riscv32, - .riscv64, - .sparc, - .sparc64, - => 32, - - // - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/m68k/include/asm/cache.h#L10 - .m68k, - => 16, - - // - https://www.ti.com/lit/pdf/slaa498 - .msp430, - => 8, - - // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_s390x.go#L7 - // - https://sxauroratsubasa.sakura.ne.jp/documents/guide/pdfs/Aurora_ISA_guide.pdf - .s390x, - .ve, - => 256, - - // Other x86 and WASM platforms have 64-byte cache lines. - // The rest of the architectures are assumed to be similar. - // - https://github.com/golang/go/blob/dda2991c2ea0c5914714469c4defc2562a907230/src/internal/cpu/cpu_x86.go#L9 - // - https://github.com/golang/go/blob/0a9321ad7f8c91e1b0c7184731257df923977eb9/src/internal/cpu/cpu_loong64.go#L11 - // - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_wasm.go#L7 - // - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/xtensa/variants/csp/include/variant/core.h#L209 - // - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/csky/Kconfig#L183 - // - https://www.xmos.com/download/The-XMOS-XS3-Architecture.pdf - else => 64, -}; +test "current CPU has a cache line size" { + _ = cache_line; +} const std = @import("std.zig"); const builtin = @import("builtin"); diff --git a/lib/std/c.zig b/lib/std/c.zig index 81eeba31f6..94d2a3405a 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -8813,7 +8813,7 @@ pub const NOTE = switch (native_os) { pub const EXIT_DETAIL = 0x02000000; /// mask for signal & exit status pub const PDATAMASK = 0x000fffff; - pub const PCTRLMASK = (~PDATAMASK); + pub const PCTRLMASK = 0xf0000000; pub const EXIT_DETAIL_MASK = 0x00070000; pub const EXIT_DECRYPTFAIL = 0x00010000; pub const EXIT_MEMORY = 0x00020000; @@ -8947,7 +8947,7 @@ pub const NOTE = switch (native_os) { pub const EXEC = 0x20000000; /// mask for signal & exit status pub const PDATAMASK = 0x000fffff; - pub const PCTRLMASK = (~PDATAMASK); + pub const PCTRLMASK = 0xf0000000; /// data is seconds pub const SECONDS = 0x00000001; /// data is milliseconds @@ -9669,7 +9669,6 @@ pub const system_info = haiku.system_info; pub const team_id = haiku.team_id; pub const team_info = haiku.team_info; pub const thread_id = haiku.thread_id; -pub const vregs = haiku.vregs; pub const AUTH = openbsd.AUTH; pub const BI = openbsd.BI; diff --git a/lib/std/c/darwin.zig b/lib/std/c/darwin.zig index 573f29150d..b925a15942 100644 --- a/lib/std/c/darwin.zig +++ b/lib/std/c/darwin.zig @@ -59,6 +59,7 @@ pub const EXC = enum(exception_type_t) { pub const SOFT_SIGNAL = 0x10003; pub const MASK = packed struct(u32) { + _0: u1 = 0, BAD_ACCESS: bool = false, BAD_INSTRUCTION: bool = false, ARITHMETIC: bool = false, @@ -72,6 +73,7 @@ pub const EXC = enum(exception_type_t) { RESOURCE: bool = false, GUARD: bool = false, CORPSE_NOTIFY: bool = false, + _14: u18 = 0, pub const MACHINE: MASK = @bitCast(@as(u32, 0)); diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 68e42ec9de..bf0c3e6371 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -7121,6 +7121,19 @@ pub const SIOCPROTOPRIVATE = 0x89E0; pub const IFNAMESIZE = 16; +pub const IFF = packed struct(u16) { + UP: bool = false, + BROADCAST: bool = false, + DEBUG: bool = false, + LOOPBACK: bool = false, + POINTOPOINT: bool = false, + NOTRAILERS: bool = false, + RUNNING: bool = false, + NOARP: bool = false, + PROMISC: bool = false, + _9: u7 = 0, +}; + pub const ifmap = extern struct { mem_start: usize, mem_end: usize, @@ -7140,7 +7153,7 @@ pub const ifreq = extern struct { broadaddr: sockaddr, netmask: sockaddr, hwaddr: sockaddr, - flags: i16, + flags: IFF, ivalue: i32, mtu: i32, map: ifmap, diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 9a18c31363..8cd54409b2 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -1110,7 +1110,7 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil pub const MoveFileError = error{ FileNotFound, AccessDenied, Unexpected }; -pub fn MoveFileEx(old_path: []const u8, new_path: []const u8, flags: DWORD) MoveFileError!void { +pub fn MoveFileEx(old_path: []const u8, new_path: []const u8, flags: DWORD) (MoveFileError || Wtf8ToPrefixedFileWError)!void { const old_path_w = try sliceToPrefixedFileW(null, old_path); const new_path_w = try sliceToPrefixedFileW(null, new_path); return MoveFileExW(old_path_w.span().ptr, new_path_w.span().ptr, flags); @@ -1518,7 +1518,7 @@ pub const GetFileAttributesError = error{ Unexpected, }; -pub fn GetFileAttributes(filename: []const u8) GetFileAttributesError!DWORD { +pub fn GetFileAttributes(filename: []const u8) (GetFileAttributesError || Wtf8ToPrefixedFileWError)!DWORD { const filename_w = try sliceToPrefixedFileW(null, filename); return GetFileAttributesW(filename_w.span().ptr); } @@ -1667,7 +1667,7 @@ pub fn getpeername(s: ws2_32.SOCKET, name: *ws2_32.sockaddr, namelen: *ws2_32.so pub fn sendmsg( s: ws2_32.SOCKET, - msg: *const ws2_32.WSAMSG, + msg: *ws2_32.WSAMSG_const, flags: u32, ) i32 { var bytes_send: DWORD = undefined; diff --git a/lib/std/posix.zig b/lib/std/posix.zig index bb21a79690..d46307dbdf 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -104,6 +104,7 @@ pub const SIOCGIFINDEX = system.SIOCGIFINDEX; pub const SO = system.SO; pub const SOCK = system.SOCK; pub const SOL = system.SOL; +pub const IFF = system.IFF; pub const STDERR_FILENO = system.STDERR_FILENO; pub const STDIN_FILENO = system.STDIN_FILENO; pub const STDOUT_FILENO = system.STDOUT_FILENO; @@ -154,7 +155,6 @@ pub const socklen_t = system.socklen_t; pub const stack_t = system.stack_t; pub const time_t = system.time_t; pub const timespec = system.timespec; -pub const timestamp_t = system.timestamp_t; pub const timeval = system.timeval; pub const timezone = system.timezone; pub const ucontext_t = system.ucontext_t; @@ -5614,7 +5614,7 @@ pub const ClockGetTimeError = error{UnsupportedClock} || UnexpectedError; /// TODO: change this to return the timespec as a return value pub fn clock_gettime(clock_id: clockid_t, tp: *timespec) ClockGetTimeError!void { if (native_os == .wasi and !builtin.link_libc) { - var ts: timestamp_t = undefined; + var ts: wasi.timestamp_t = undefined; switch (system.clock_time_get(clock_id, 1, &ts)) { .SUCCESS => { tp.* = .{ @@ -5655,7 +5655,7 @@ pub fn clock_gettime(clock_id: clockid_t, tp: *timespec) ClockGetTimeError!void pub fn clock_getres(clock_id: clockid_t, res: *timespec) ClockGetTimeError!void { if (native_os == .wasi and !builtin.link_libc) { - var ts: timestamp_t = undefined; + var ts: wasi.timestamp_t = undefined; switch (system.clock_res_get(@bitCast(clock_id), &ts)) { .SUCCESS => res.* = .{ .sec = @intCast(ts / std.time.ns_per_s), diff --git a/lib/std/testing.zig b/lib/std/testing.zig index 91caa7d922..fb75672fbd 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -41,14 +41,14 @@ fn print(comptime fmt: []const u8, args: anytype) void { pub fn expectError(expected_error: anyerror, actual_error_union: anytype) !void { if (actual_error_union) |actual_payload| { print("expected error.{s}, found {any}\n", .{ @errorName(expected_error), actual_payload }); - return error.TestUnexpectedError; + return error.TestExpectedError; } else |actual_error| { if (expected_error != actual_error) { print("expected error.{s}, found error.{s}\n", .{ @errorName(expected_error), @errorName(actual_error), }); - return error.TestExpectedError; + return error.TestUnexpectedError; } } } diff --git a/lib/std/zig/AstGen.zig b/lib/std/zig/AstGen.zig index 807d634886..abec1f354a 100644 --- a/lib/std/zig/AstGen.zig +++ b/lib/std/zig/AstGen.zig @@ -2435,6 +2435,7 @@ fn blockExpr( if (!block_scope.endsWithNoReturn()) { // As our last action before the break, "pop" the error trace if needed _ = try gz.addRestoreErrRetIndex(.{ .block = block_inst }, .always, block_node); + // No `rvalue` call here, as the block result is always `void`, so we do that below. _ = try block_scope.addBreak(.@"break", block_inst, .void_value); } @@ -2531,7 +2532,8 @@ fn labeledBlockExpr( if (!block_scope.endsWithNoReturn()) { // As our last action before the return, "pop" the error trace if needed _ = try gz.addRestoreErrRetIndex(.{ .block = block_inst }, .always, block_node); - _ = try block_scope.addBreak(.@"break", block_inst, .void_value); + const result = try rvalue(gz, block_scope.break_result_info, .void_value, block_node); + _ = try block_scope.addBreak(.@"break", block_inst, result); } if (!block_scope.label.?.used) { diff --git a/src/Compilation.zig b/src/Compilation.zig index 51877d7973..a228d61257 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -89,7 +89,6 @@ windows_libs: std.StringArrayHashMapUnmanaged(void), version: ?std.SemanticVersion, libc_installation: ?*const LibCInstallation, skip_linker_dependencies: bool, -no_builtin: bool, function_sections: bool, data_sections: bool, link_eh_frame_hdr: bool, @@ -852,6 +851,7 @@ pub const cache_helpers = struct { hh.add(mod.fuzz); hh.add(mod.unwind_tables); hh.add(mod.structured_cfg); + hh.add(mod.no_builtin); hh.addListOfBytes(mod.cc_argv); } @@ -1057,7 +1057,6 @@ pub const CreateOptions = struct { want_lto: ?bool = null, function_sections: bool = false, data_sections: bool = false, - no_builtin: bool = false, time_report: bool = false, stack_report: bool = false, link_eh_frame_hdr: bool = false, @@ -1299,7 +1298,11 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil }, .fully_qualified_name = "compiler_rt", .cc_argv = &.{}, - .inherited = .{}, + .inherited = .{ + .stack_check = false, + .stack_protector = 0, + .no_builtin = true, + }, .global = options.config, .parent = options.root_mod, .builtin_mod = options.root_mod.getBuiltinDependency(), @@ -1353,7 +1356,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil cache.hash.add(options.config.link_mode); cache.hash.add(options.function_sections); cache.hash.add(options.data_sections); - cache.hash.add(options.no_builtin); cache.hash.add(link_libc); cache.hash.add(options.config.link_libcpp); cache.hash.add(options.config.link_libunwind); @@ -1490,7 +1492,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil .framework_dirs = options.framework_dirs, .llvm_opt_bisect_limit = options.llvm_opt_bisect_limit, .skip_linker_dependencies = options.skip_linker_dependencies, - .no_builtin = options.no_builtin, .job_queued_update_builtin_zig = have_zcu, .function_sections = options.function_sections, .data_sections = options.data_sections, @@ -5261,7 +5262,7 @@ pub fn addCCArgs( try argv.append("-fdata-sections"); } - if (comp.no_builtin) { + if (mod.no_builtin) { try argv.append("-fno-builtin"); } @@ -5624,6 +5625,10 @@ pub fn addCCArgs( }, } + if (comp.mingw_unicode_entry_point) { + try argv.append("-municode"); + } + if (target.cpu.arch.isThumb()) { try argv.append("-mthumb"); } @@ -6154,7 +6159,6 @@ fn buildOutputFromZig( assert(output_mode != .Exe); - const unwind_tables = comp.link_eh_frame_hdr; const strip = comp.compilerRtStrip(); const optimize_mode = comp.compilerRtOptMode(); @@ -6168,7 +6172,6 @@ fn buildOutputFromZig( .root_optimize_mode = optimize_mode, .root_strip = strip, .link_libc = comp.config.link_libc, - .any_unwind_tables = unwind_tables, }); const root_mod = try Package.Module.create(arena, .{ @@ -6185,10 +6188,11 @@ fn buildOutputFromZig( .stack_protector = 0, .red_zone = comp.root_mod.red_zone, .omit_frame_pointer = comp.root_mod.omit_frame_pointer, - .unwind_tables = unwind_tables, + .unwind_tables = comp.root_mod.unwind_tables, .pic = comp.root_mod.pic, .optimize_mode = optimize_mode, .structured_cfg = comp.root_mod.structured_cfg, + .no_builtin = true, .code_model = comp.root_mod.code_model, }, .global = config, @@ -6237,7 +6241,6 @@ fn buildOutputFromZig( }, .function_sections = true, .data_sections = true, - .no_builtin = true, .emit_h = null, .verbose_cc = comp.verbose_cc, .verbose_link = comp.verbose_link, @@ -6262,16 +6265,24 @@ fn buildOutputFromZig( comp.queueLinkTaskMode(crt_file.full_object_path, output_mode); } +pub const CrtFileOptions = struct { + function_sections: ?bool = null, + data_sections: ?bool = null, + omit_frame_pointer: ?bool = null, + pic: ?bool = null, + no_builtin: ?bool = null, +}; + pub fn build_crt_file( comp: *Compilation, root_name: []const u8, output_mode: std.builtin.OutputMode, - pic: ?bool, misc_task_tag: MiscTask, prog_node: std.Progress.Node, /// These elements have to get mutated to add the owner module after it is /// created within this function. c_source_files: []CSourceFile, + options: CrtFileOptions, ) !void { const tracy_trace = trace(@src()); defer tracy_trace.end(); @@ -6316,13 +6327,16 @@ pub fn build_crt_file( .sanitize_c = false, .sanitize_thread = false, .red_zone = comp.root_mod.red_zone, - .omit_frame_pointer = comp.root_mod.omit_frame_pointer, + // Some libcs (e.g. musl) are opinionated about -fomit-frame-pointer. + .omit_frame_pointer = options.omit_frame_pointer orelse comp.root_mod.omit_frame_pointer, .valgrind = false, .unwind_tables = false, - // Some CRT objects (rcrt1.o, Scrt1.o) are opinionated about PIC. - .pic = pic orelse comp.root_mod.pic, + // Some CRT objects (e.g. musl's rcrt1.o and Scrt1.o) are opinionated about PIC. + .pic = options.pic orelse comp.root_mod.pic, .optimize_mode = comp.compilerRtOptMode(), .structured_cfg = comp.root_mod.structured_cfg, + // Some libcs (e.g. musl) are opinionated about -fno-builtin. + .no_builtin = options.no_builtin orelse comp.root_mod.no_builtin, }, .global = config, .cc_argv = &.{}, @@ -6350,6 +6364,8 @@ pub fn build_crt_file( .directory = null, // Put it in the cache directory. .basename = basename, }, + .function_sections = options.function_sections orelse false, + .data_sections = options.data_sections orelse false, .emit_h = null, .c_source_files = c_source_files, .verbose_cc = comp.verbose_cc, diff --git a/src/Package/Fetch.zig b/src/Package/Fetch.zig index 6e7469425b..6017a234e4 100644 --- a/src/Package/Fetch.zig +++ b/src/Package/Fetch.zig @@ -662,6 +662,9 @@ fn queueJobsForDeps(f: *Fetch) RunError!void { // * path-based location is used without a hash. // - Hash is added to the table based on the path alone before // calling run(); no need to add it again. + // + // If we add a dep as lazy and then later try to add the same dep as eager, + // eagerness takes precedence and the existing entry is updated. for (dep_names, deps) |dep_name, dep| { const new_fetch = &new_fetches[new_fetch_index]; @@ -673,7 +676,12 @@ fn queueJobsForDeps(f: *Fetch) RunError!void { const digest_len = @typeInfo(Manifest.MultiHashHexDigest).array.len; const multihash_digest = h[0..digest_len].*; const gop = f.job_queue.table.getOrPutAssumeCapacity(multihash_digest); - if (gop.found_existing) continue; + if (gop.found_existing) { + if (!dep.lazy) { + gop.value_ptr.*.lazy_status = .eager; + } + continue; + } gop.value_ptr.* = new_fetch; break :h multihash_digest; }, @@ -684,7 +692,12 @@ fn queueJobsForDeps(f: *Fetch) RunError!void { const new_root = try f.package_root.resolvePosix(parent_arena, rel_path); const multihash_digest = relativePathDigest(new_root, cache_root); const gop = f.job_queue.table.getOrPutAssumeCapacity(multihash_digest); - if (gop.found_existing) continue; + if (gop.found_existing) { + if (!dep.lazy) { + gop.value_ptr.*.lazy_status = .eager; + } + continue; + } gop.value_ptr.* = new_fetch; break :l .{ .relative_path = new_root }; }, diff --git a/src/Package/Module.zig b/src/Package/Module.zig index 0a3d754e7a..0e777145d9 100644 --- a/src/Package/Module.zig +++ b/src/Package/Module.zig @@ -31,6 +31,7 @@ unwind_tables: bool, cc_argv: []const []const u8, /// (SPIR-V) whether to generate a structured control flow graph or not structured_cfg: bool, +no_builtin: bool, /// If the module is an `@import("builtin")` module, this is the `File` that /// is preallocated for it. Otherwise this field is null. @@ -95,6 +96,7 @@ pub const CreateOptions = struct { sanitize_thread: ?bool = null, fuzz: ?bool = null, structured_cfg: ?bool = null, + no_builtin: ?bool = null, }; }; @@ -298,6 +300,13 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { }; }; + const no_builtin = b: { + if (options.inherited.no_builtin) |x| break :b x; + if (options.parent) |p| break :b p.no_builtin; + + break :b target.cpu.arch.isBpf(); + }; + const llvm_cpu_features: ?[*:0]const u8 = b: { if (resolved_target.llvm_cpu_features) |x| break :b x; if (!options.global.use_llvm) break :b null; @@ -350,6 +359,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { .unwind_tables = unwind_tables, .cc_argv = options.cc_argv, .structured_cfg = structured_cfg, + .no_builtin = no_builtin, .builtin_file = null, }; @@ -442,6 +452,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { .unwind_tables = unwind_tables, .cc_argv = &.{}, .structured_cfg = structured_cfg, + .no_builtin = no_builtin, .builtin_file = new_file, }; new_file.* = .{ @@ -502,6 +513,7 @@ pub fn createLimited(gpa: Allocator, options: LimitedOptions) Allocator.Error!*P .unwind_tables = undefined, .cc_argv = undefined, .structured_cfg = undefined, + .no_builtin = undefined, .builtin_file = null, }; return mod; diff --git a/src/arch/x86_64/Lower.zig b/src/arch/x86_64/Lower.zig index 058201c2d7..6ac79378c1 100644 --- a/src/arch/x86_64/Lower.zig +++ b/src/arch/x86_64/Lower.zig @@ -532,6 +532,8 @@ fn emit(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operand) }, else => unreachable, }; + } else { + return lower.fail("TODO: bin format '{s}'", .{@tagName(lower.bin_file.tag)}); } }, }, diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 3a8fde75da..fb20d4d622 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -3222,8 +3222,6 @@ pub const Object = struct { owner_mod: *Package.Module, omit_frame_pointer: bool, ) Allocator.Error!void { - const comp = o.pt.zcu.comp; - if (!owner_mod.red_zone) { try attributes.addFnAttr(.noredzone, &o.builder); } @@ -3242,8 +3240,7 @@ pub const Object = struct { if (owner_mod.unwind_tables) { try attributes.addFnAttr(.{ .uwtable = Builder.Attribute.UwTable.default }, &o.builder); } - const target = owner_mod.resolved_target.result; - if (comp.skip_linker_dependencies or comp.no_builtin or target.cpu.arch.isBpf()) { + if (owner_mod.no_builtin) { // The intent here is for compiler-rt and libc functions to not generate // infinite recursion. For example, if we are compiling the memcpy function, // and llvm detects that the body is equivalent to memcpy, it may replace the @@ -3258,6 +3255,7 @@ pub const Object = struct { try attributes.addFnAttr(.minsize, &o.builder); try attributes.addFnAttr(.optsize, &o.builder); } + const target = owner_mod.resolved_target.result; if (target.cpu.model.llvm_name) |s| { try attributes.addFnAttr(.{ .string = .{ .kind = try o.builder.string("target-cpu"), @@ -5578,6 +5576,10 @@ pub const FuncGen = struct { var attributes: Builder.FunctionAttributes.Wip = .{}; defer attributes.deinit(&o.builder); + if (self.ng.ownerModule().no_builtin) { + try attributes.addFnAttr(.nobuiltin, &o.builder); + } + switch (modifier) { .auto, .never_tail, .always_tail => {}, .never_inline => try attributes.addFnAttr(.@"noinline", &o.builder), @@ -12728,6 +12730,8 @@ fn backendSupportsF16(target: std.Target) bool { .mips64, .mips64el, .s390x, + .sparc, + .sparc64, => false, .arm, .armeb, diff --git a/lib/compiler/fmt.zig b/src/fmt.zig similarity index 96% rename from lib/compiler/fmt.zig rename to src/fmt.zig index b078198480..b545905367 100644 --- a/lib/compiler/fmt.zig +++ b/src/fmt.zig @@ -1,10 +1,3 @@ -const std = @import("std"); -const mem = std.mem; -const fs = std.fs; -const process = std.process; -const Allocator = std.mem.Allocator; -const Color = std.zig.Color; - const usage_fmt = \\Usage: zig fmt [file]... \\ @@ -36,14 +29,11 @@ const Fmt = struct { const SeenMap = std.AutoHashMap(fs.File.INode, void); }; -pub fn main() !void { - var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator); - defer arena_instance.deinit(); - const arena = arena_instance.allocator(); - const gpa = arena; - - const args = try process.argsAlloc(arena); - +pub fn run( + gpa: Allocator, + arena: Allocator, + args: []const []const u8, +) !void { var color: Color = .auto; var stdin_flag: bool = false; var check_flag: bool = false; @@ -54,7 +44,7 @@ pub fn main() !void { defer excluded_files.deinit(); { - var i: usize = 1; + var i: usize = 0; while (i < args.len) : (i += 1) { const arg = args[i]; if (mem.startsWith(u8, arg, "-")) { @@ -337,7 +327,10 @@ fn fmtPathFile( } } -fn fatal(comptime format: []const u8, args: anytype) noreturn { - std.log.err(format, args); - process.exit(1); -} +const std = @import("std"); +const mem = std.mem; +const fs = std.fs; +const process = std.process; +const Allocator = std.mem.Allocator; +const Color = std.zig.Color; +const fatal = std.process.fatal; diff --git a/src/glibc.zig b/src/glibc.zig index 65161cec4e..f1ac544163 100644 --- a/src/glibc.zig +++ b/src/glibc.zig @@ -221,7 +221,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre .owner = comp.root_mod, }, }; - return comp.build_crt_file("crti", .Obj, null, .@"glibc crti.o", prog_node, &files); + return comp.build_crt_file("crti", .Obj, .@"glibc crti.o", prog_node, &files, .{}); }, .crtn_o => { var args = std.ArrayList([]const u8).init(arena); @@ -242,7 +242,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre .owner = undefined, }, }; - return comp.build_crt_file("crtn", .Obj, null, .@"glibc crtn.o", prog_node, &files); + return comp.build_crt_file("crtn", .Obj, .@"glibc crtn.o", prog_node, &files, .{}); }, .scrt1_o => { const start_o: Compilation.CSourceFile = blk: { @@ -295,7 +295,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre }; var files = [_]Compilation.CSourceFile{ start_o, abi_note_o, init_o }; const basename = if (comp.config.output_mode == .Exe and !comp.config.pie) "crt1" else "Scrt1"; - return comp.build_crt_file(basename, .Obj, null, .@"glibc Scrt1.o", prog_node, &files); + return comp.build_crt_file(basename, .Obj, .@"glibc Scrt1.o", prog_node, &files, .{}); }, .libc_nonshared_a => { const s = path.sep_str; @@ -373,7 +373,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre "-fmerge-all-constants", "-frounding-math", "-Wno-unsupported-floating-point-opt", // For targets that don't support -frounding-math. - "-fno-stack-protector", "-fno-common", "-fmath-errno", "-ftls-model=initial-exec", @@ -413,7 +412,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre files_index += 1; } const files = files_buf[0..files_index]; - return comp.build_crt_file("c_nonshared", .Lib, null, .@"glibc libc_nonshared.a", prog_node, files); + return comp.build_crt_file("c_nonshared", .Lib, .@"glibc libc_nonshared.a", prog_node, files, .{}); }, } } diff --git a/src/libcxx.zig b/src/libcxx.zig index a9f3030c42..ec89ac1cfc 100644 --- a/src/libcxx.zig +++ b/src/libcxx.zig @@ -195,7 +195,7 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: std.Progress.Node) BuildError! .valgrind = false, .optimize_mode = optimize_mode, .structured_cfg = comp.root_mod.structured_cfg, - .pic = comp.root_mod.pic, + .pic = if (target_util.supports_fpic(target)) true else null, }, .global = config, .cc_argv = &.{}, @@ -278,9 +278,6 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: std.Progress.Node) BuildError! try cflags.append("-faligned-allocation"); } - if (target_util.supports_fpic(target)) { - try cflags.append("-fPIC"); - } try cflags.append("-nostdinc++"); try cflags.append("-std=c++23"); try cflags.append("-Wno-user-defined-literals"); diff --git a/src/libtsan.zig b/src/libtsan.zig index d078fa2a38..8b2427df1b 100644 --- a/src/libtsan.zig +++ b/src/libtsan.zig @@ -29,11 +29,11 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo const root_name = switch (target.os.tag) { // On Apple platforms, we use the same name as LLVM because the // TSAN library implementation hard-codes a check for these names. - .macos => "clang_rt.tsan_osx_dynamic", - .ios => switch (target.abi) { - .simulator => "clang_rt.tsan_iossim_dynamic", - else => "clang_rt.tsan_ios_dynamic", - }, + .driverkit, .macos => "clang_rt.tsan_osx_dynamic", + .ios => if (target.abi == .simulator) "clang_rt.tsan_iossim_dynamic" else "clang_rt.tsan_ios_dynamic", + .tvos => if (target.abi == .simulator) "clang_rt.tsan_tvossim_dynamic" else "clang_rt.tsan_tvos_dynamic", + .visionos => if (target.abi == .simulator) "clang_rt.tsan_xrossim_dynamic" else "clang_rt.tsan_xros_dynamic", + .watchos => if (target.abi == .simulator) "clang_rt.tsan_watchossim_dynamic" else "clang_rt.tsan_watchos_dynamic", else => "tsan", }; const link_mode: std.builtin.LinkMode = if (target.isDarwin()) .dynamic else .static; @@ -93,11 +93,12 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo .sanitize_c = false, .sanitize_thread = false, .red_zone = comp.root_mod.red_zone, - .omit_frame_pointer = comp.root_mod.omit_frame_pointer, + .omit_frame_pointer = optimize_mode != .Debug and !target.os.tag.isDarwin(), .valgrind = false, .optimize_mode = optimize_mode, .structured_cfg = comp.root_mod.structured_cfg, .pic = true, + .no_builtin = true, }, .global = config, .cc_argv = &common_flags, @@ -123,10 +124,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try cflags.append("-I"); try cflags.append(tsan_include_path); - try cflags.append("-nostdinc++"); - try cflags.append("-fvisibility-inlines-hidden"); - try cflags.append("-std=c++17"); - try cflags.append("-fno-rtti"); + try addCcArgs(target, &cflags); c_source_files.appendAssumeCapacity(.{ .src_path = try comp.zig_lib_directory.join(arena, &.{ "tsan", tsan_src }), @@ -147,10 +145,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try cflags.append("-I"); try cflags.append(tsan_include_path); - try cflags.append("-nostdinc++"); - try cflags.append("-fvisibility-inlines-hidden"); - try cflags.append("-std=c++17"); - try cflags.append("-fno-rtti"); + try addCcArgs(target, &cflags); c_source_files.appendAssumeCapacity(.{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "tsan", tsan_src }), @@ -195,10 +190,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try cflags.append("-I"); try cflags.append(tsan_include_path); - try cflags.append("-nostdinc++"); - try cflags.append("-fvisibility-inlines-hidden"); - try cflags.append("-std=c++17"); - try cflags.append("-fno-rtti"); + try addCcArgs(target, &cflags); c_source_files.appendAssumeCapacity(.{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ @@ -222,10 +214,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try cflags.append("-I"); try cflags.append(tsan_include_path); - try cflags.append("-nostdinc++"); - try cflags.append("-fvisibility-inlines-hidden"); - try cflags.append("-std=c++17"); - try cflags.append("-fno-rtti"); + try addCcArgs(target, &cflags); c_source_files.appendAssumeCapacity(.{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ @@ -243,10 +232,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try cflags.append("-I"); try cflags.append(tsan_include_path); - try cflags.append("-nostdinc++"); - try cflags.append("-fvisibility-inlines-hidden"); - try cflags.append("-std=c++17"); - try cflags.append("-fno-rtti"); + try addCcArgs(target, &cflags); c_source_files.appendAssumeCapacity(.{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ @@ -272,10 +258,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo try cflags.append("-I"); try cflags.append(tsan_include_path); - try cflags.append("-nostdinc++"); - try cflags.append("-fvisibility-inlines-hidden"); - try cflags.append("-std=c++17"); - try cflags.append("-fno-rtti"); + try addCcArgs(target, &cflags); c_source_files.appendAssumeCapacity(.{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ @@ -348,6 +331,25 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo comp.tsan_lib = crt_file; } +fn addCcArgs(target: std.Target, args: *std.ArrayList([]const u8)) error{OutOfMemory}!void { + try args.appendSlice(&[_][]const u8{ + "-nostdinc++", + "-fvisibility=hidden", + "-fvisibility-inlines-hidden", + "-std=c++17", + "-fno-rtti", + "-fno-exceptions", + }); + + if (target.abi.isAndroid() and target.os.version_range.linux.android >= 29) { + try args.append("-fno-emulated-tls"); + } + + if (target.isMinGW()) { + try args.append("-fms-extensions"); + } +} + const tsan_sources = [_][]const u8{ "tsan_debugging.cpp", "tsan_external.cpp", diff --git a/src/libunwind.zig b/src/libunwind.zig index d7b22e2067..1e101da229 100644 --- a/src/libunwind.zig +++ b/src/libunwind.zig @@ -46,6 +46,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr ); return error.SubCompilationFailed; }; + const target = comp.root_mod.resolved_target.result; const root_mod = Module.create(arena, .{ .global_cache_directory = comp.global_cache_directory, .paths = .{ @@ -63,8 +64,9 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr .valgrind = false, .sanitize_c = false, .sanitize_thread = false, - .unwind_tables = false, - .pic = comp.root_mod.pic, + // necessary so that libunwind can unwind through its own stack frames + .unwind_tables = true, + .pic = if (target_util.supports_fpic(target)) true else null, .optimize_mode = comp.compilerRtOptMode(), }, .global = config, @@ -83,7 +85,6 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr const root_name = "unwind"; const link_mode = .static; - const target = comp.root_mod.resolved_target.result; const basename = try std.zig.binNameAlloc(arena, .{ .root_name = root_name, .target = target, @@ -114,16 +115,11 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr try cflags.append("-fno-exceptions"); try cflags.append("-I"); try cflags.append(try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libunwind", "include" })); - if (target_util.supports_fpic(target)) { - try cflags.append("-fPIC"); - } try cflags.append("-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS"); try cflags.append("-Wa,--noexecstack"); try cflags.append("-fvisibility=hidden"); try cflags.append("-fvisibility-inlines-hidden"); try cflags.append("-fvisibility-global-new-delete=force-hidden"); - // necessary so that libunwind can unwind through its own stack frames - try cflags.append("-funwind-tables"); // This is intentionally always defined because the macro definition means, should it only // build for the target specified by compiler defines. Since we pass -target the compiler diff --git a/src/main.zig b/src/main.zig index 24fc0aa60c..9b245b3eda 100644 --- a/src/main.zig +++ b/src/main.zig @@ -309,10 +309,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { .server = use_server, }); } else if (mem.eql(u8, cmd, "fmt")) { - return jitCmd(gpa, arena, cmd_args, .{ - .cmd_name = "fmt", - .root_src_path = "fmt.zig", - }); + return @import("fmt.zig").run(gpa, arena, cmd_args); } else if (mem.eql(u8, cmd, "objcopy")) { return jitCmd(gpa, arena, cmd_args, .{ .cmd_name = "objcopy", @@ -810,7 +807,6 @@ fn buildOutputType( var compatibility_version: ?std.SemanticVersion = null; var function_sections = false; var data_sections = false; - var no_builtin = false; var listen: Listen = .none; var debug_compile_errors = false; var verbose_link = (native_os != .wasi or builtin.link_libc) and @@ -1550,9 +1546,9 @@ fn buildOutputType( } else if (mem.eql(u8, arg, "-fno-data-sections")) { data_sections = false; } else if (mem.eql(u8, arg, "-fbuiltin")) { - no_builtin = false; + mod_opts.no_builtin = false; } else if (mem.eql(u8, arg, "-fno-builtin")) { - no_builtin = true; + mod_opts.no_builtin = true; } else if (mem.startsWith(u8, arg, "-fopt-bisect-limit=")) { const next_arg = arg["-fopt-bisect-limit=".len..]; llvm_opt_bisect_limit = std.fmt.parseInt(c_int, next_arg, 0) catch |err| @@ -1963,8 +1959,8 @@ fn buildOutputType( .no_function_sections => function_sections = false, .data_sections => data_sections = true, .no_data_sections => data_sections = false, - .builtin => no_builtin = false, - .no_builtin => no_builtin = true, + .builtin => mod_opts.no_builtin = false, + .no_builtin => mod_opts.no_builtin = true, .color_diagnostics => color = .on, .no_color_diagnostics => color = .off, .stack_check => mod_opts.stack_check = true, @@ -3468,7 +3464,6 @@ fn buildOutputType( .image_base = image_base, .function_sections = function_sections, .data_sections = data_sections, - .no_builtin = no_builtin, .clang_passthrough_mode = clang_passthrough_mode, .clang_preprocessor_mode = clang_preprocessor_mode, .version = optional_version, diff --git a/src/mingw.zig b/src/mingw.zig index d4ef1ac5a7..cdee9acb07 100644 --- a/src/mingw.zig +++ b/src/mingw.zig @@ -41,7 +41,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre .owner = undefined, }, }; - return comp.build_crt_file("crt2", .Obj, null, .@"mingw-w64 crt2.o", prog_node, &files); + return comp.build_crt_file("crt2", .Obj, .@"mingw-w64 crt2.o", prog_node, &files, .{}); }, .dllcrt2_o => { @@ -56,7 +56,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre .owner = undefined, }, }; - return comp.build_crt_file("dllcrt2", .Obj, null, .@"mingw-w64 dllcrt2.o", prog_node, &files); + return comp.build_crt_file("dllcrt2", .Obj, .@"mingw-w64 dllcrt2.o", prog_node, &files, .{}); }, .mingw32_lib => { @@ -118,7 +118,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre } else { @panic("unsupported arch"); } - return comp.build_crt_file("mingw32", .Lib, null, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items); + return comp.build_crt_file("mingw32", .Lib, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items, .{}); }, } } diff --git a/src/musl.zig b/src/musl.zig index 3a0aeb9417..d1b2fd2e2d 100644 --- a/src/musl.zig +++ b/src/musl.zig @@ -38,7 +38,12 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro .owner = undefined, }, }; - return comp.build_crt_file("crti", .Obj, null, .@"musl crti.o", prog_node, &files); + return comp.build_crt_file("crti", .Obj, .@"musl crti.o", prog_node, &files, .{ + .function_sections = true, + .data_sections = true, + .omit_frame_pointer = true, + .no_builtin = true, + }); }, .crtn_o => { var args = std.ArrayList([]const u8).init(arena); @@ -50,15 +55,17 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro .owner = undefined, }, }; - return comp.build_crt_file("crtn", .Obj, null, .@"musl crtn.o", prog_node, &files); + return comp.build_crt_file("crtn", .Obj, .@"musl crtn.o", prog_node, &files, .{ + .function_sections = true, + .data_sections = true, + .omit_frame_pointer = true, + .no_builtin = true, + }); }, .crt1_o => { var args = std.ArrayList([]const u8).init(arena); try addCcArgs(comp, arena, &args, false); - try args.appendSlice(&[_][]const u8{ - "-fno-stack-protector", - "-DCRT", - }); + try args.append("-DCRT"); var files = [_]Compilation.CSourceFile{ .{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ @@ -68,15 +75,17 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro .owner = undefined, }, }; - return comp.build_crt_file("crt1", .Obj, null, .@"musl crt1.o", prog_node, &files); + return comp.build_crt_file("crt1", .Obj, .@"musl crt1.o", prog_node, &files, .{ + .function_sections = true, + .data_sections = true, + .omit_frame_pointer = true, + .no_builtin = true, + }); }, .rcrt1_o => { var args = std.ArrayList([]const u8).init(arena); try addCcArgs(comp, arena, &args, false); - try args.appendSlice(&[_][]const u8{ - "-fno-stack-protector", - "-DCRT", - }); + try args.append("-DCRT"); var files = [_]Compilation.CSourceFile{ .{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ @@ -86,15 +95,18 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro .owner = undefined, }, }; - return comp.build_crt_file("rcrt1", .Obj, true, .@"musl rcrt1.o", prog_node, &files); + return comp.build_crt_file("rcrt1", .Obj, .@"musl rcrt1.o", prog_node, &files, .{ + .function_sections = true, + .data_sections = true, + .omit_frame_pointer = true, + .pic = true, + .no_builtin = true, + }); }, .scrt1_o => { var args = std.ArrayList([]const u8).init(arena); try addCcArgs(comp, arena, &args, false); - try args.appendSlice(&[_][]const u8{ - "-fno-stack-protector", - "-DCRT", - }); + try args.append("-DCRT"); var files = [_]Compilation.CSourceFile{ .{ .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ @@ -104,7 +116,13 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro .owner = undefined, }, }; - return comp.build_crt_file("Scrt1", .Obj, true, .@"musl Scrt1.o", prog_node, &files); + return comp.build_crt_file("Scrt1", .Obj, .@"musl Scrt1.o", prog_node, &files, .{ + .function_sections = true, + .data_sections = true, + .omit_frame_pointer = true, + .pic = true, + .no_builtin = true, + }); }, .libc_a => { // When there is a src//foo.* then it should substitute for src/foo.* @@ -197,7 +215,12 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro .owner = undefined, }; } - return comp.build_crt_file("c", .Lib, null, .@"musl libc.a", prog_node, c_source_files.items); + return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items, .{ + .function_sections = true, + .data_sections = true, + .omit_frame_pointer = true, + .no_builtin = true, + }); }, .libc_so => { const optimize_mode = comp.compilerRtOptMode(); @@ -410,7 +433,6 @@ fn addCcArgs( try args.appendSlice(&[_][]const u8{ "-std=c99", "-ffreestanding", - "-fno-builtin", "-fexcess-precision=standard", "-frounding-math", "-ffp-contract=off", @@ -441,12 +463,6 @@ fn addCcArgs( o_arg, - "-fomit-frame-pointer", - "-fno-unwind-tables", - "-fno-asynchronous-unwind-tables", - "-ffunction-sections", - "-fdata-sections", - "-Qunused-arguments", "-w", // disable all warnings }); diff --git a/src/target.zig b/src/target.zig index 94bb842b12..6297d21bfc 100644 --- a/src/target.zig +++ b/src/target.zig @@ -327,9 +327,8 @@ pub fn libcFullLinkFlags(target: std.Target) []const []const u8 { } pub fn clangMightShellOutForAssembly(target: std.Target) bool { - // Clang defaults to using the system assembler over the internal one - // when targeting a non-BSD OS. - return target.cpu.arch.isSPARC(); + // Clang defaults to using the system assembler in some cases. + return target.cpu.arch.isNvptx() or target.cpu.arch == .xcore; } /// Each backend architecture in Clang has a different codepath which may or may not diff --git a/src/wasi_libc.zig b/src/wasi_libc.zig index 3b9d9c5446..ce6131a470 100644 --- a/src/wasi_libc.zig +++ b/src/wasi_libc.zig @@ -81,7 +81,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre .owner = undefined, }, }; - return comp.build_crt_file("crt1-reactor", .Obj, null, .@"wasi crt1-reactor.o", prog_node, &files); + return comp.build_crt_file("crt1-reactor", .Obj, .@"wasi crt1-reactor.o", prog_node, &files, .{}); }, .crt1_command_o => { var args = std.ArrayList([]const u8).init(arena); @@ -96,7 +96,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre .owner = undefined, }, }; - return comp.build_crt_file("crt1-command", .Obj, null, .@"wasi crt1-command.o", prog_node, &files); + return comp.build_crt_file("crt1-command", .Obj, .@"wasi crt1-command.o", prog_node, &files, .{}); }, .libc_a => { var libc_sources = std.ArrayList(Compilation.CSourceFile).init(arena); @@ -150,7 +150,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre } } - try comp.build_crt_file("c", .Lib, null, .@"wasi libc.a", prog_node, libc_sources.items); + try comp.build_crt_file("c", .Lib, .@"wasi libc.a", prog_node, libc_sources.items, .{}); }, .libwasi_emulated_process_clocks_a => { var args = std.ArrayList([]const u8).init(arena); @@ -167,7 +167,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre .owner = undefined, }); } - try comp.build_crt_file("wasi-emulated-process-clocks", .Lib, null, .@"libwasi-emulated-process-clocks.a", prog_node, emu_clocks_sources.items); + try comp.build_crt_file("wasi-emulated-process-clocks", .Lib, .@"libwasi-emulated-process-clocks.a", prog_node, emu_clocks_sources.items, .{}); }, .libwasi_emulated_getpid_a => { var args = std.ArrayList([]const u8).init(arena); @@ -184,7 +184,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre .owner = undefined, }); } - try comp.build_crt_file("wasi-emulated-getpid", .Lib, null, .@"libwasi-emulated-getpid.a", prog_node, emu_getpid_sources.items); + try comp.build_crt_file("wasi-emulated-getpid", .Lib, .@"libwasi-emulated-getpid.a", prog_node, emu_getpid_sources.items, .{}); }, .libwasi_emulated_mman_a => { var args = std.ArrayList([]const u8).init(arena); @@ -201,7 +201,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre .owner = undefined, }); } - try comp.build_crt_file("wasi-emulated-mman", .Lib, null, .@"libwasi-emulated-mman.a", prog_node, emu_mman_sources.items); + try comp.build_crt_file("wasi-emulated-mman", .Lib, .@"libwasi-emulated-mman.a", prog_node, emu_mman_sources.items, .{}); }, .libwasi_emulated_signal_a => { var emu_signal_sources = std.ArrayList(Compilation.CSourceFile).init(arena); @@ -238,7 +238,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre } } - try comp.build_crt_file("wasi-emulated-signal", .Lib, null, .@"libwasi-emulated-signal.a", prog_node, emu_signal_sources.items); + try comp.build_crt_file("wasi-emulated-signal", .Lib, .@"libwasi-emulated-signal.a", prog_node, emu_signal_sources.items, .{}); }, } } @@ -279,7 +279,6 @@ fn addCCArgs( try args.appendSlice(&[_][]const u8{ "-std=gnu17", "-fno-trapping-math", - "-fno-stack-protector", "-w", // ignore all warnings o_arg, diff --git a/test/cases/adding_numbers_at_runtime_and_comptime.0.zig b/test/cases/adding_numbers_at_runtime_and_comptime.0.zig deleted file mode 100644 index e8c2196813..0000000000 --- a/test/cases/adding_numbers_at_runtime_and_comptime.0.zig +++ /dev/null @@ -1,10 +0,0 @@ -pub fn main() void { - add(3, 4); -} - -fn add(a: u32, b: u32) void { - if (a + b != 7) unreachable; -} - -// run -// diff --git a/test/cases/adding_numbers_at_runtime_and_comptime.1.zig b/test/cases/adding_numbers_at_runtime_and_comptime.1.zig deleted file mode 100644 index d90dc6884d..0000000000 --- a/test/cases/adding_numbers_at_runtime_and_comptime.1.zig +++ /dev/null @@ -1,12 +0,0 @@ -pub fn main() void { - if (x - 7 != 0) unreachable; -} - -fn add(a: u32, b: u32) u32 { - return a + b; -} - -const x = add(3, 4); - -// run -// diff --git a/test/cases/adding_numbers_at_runtime_and_comptime.2.zig b/test/cases/adding_numbers_at_runtime_and_comptime.2.zig deleted file mode 100644 index d6d8755dc3..0000000000 --- a/test/cases/adding_numbers_at_runtime_and_comptime.2.zig +++ /dev/null @@ -1,13 +0,0 @@ -pub fn main() void { - var x: usize = 3; - _ = &x; - const y = add(1, 2, x); - if (y - 6 != 0) unreachable; -} - -inline fn add(a: usize, b: usize, c: usize) usize { - return a + b + c; -} - -// run -// diff --git a/test/cases/arithmetic_operations.0.zig b/test/cases/arithmetic_operations.0.zig deleted file mode 100644 index ea22e22216..0000000000 --- a/test/cases/arithmetic_operations.0.zig +++ /dev/null @@ -1,17 +0,0 @@ -const std = @import("std"); - -pub fn main() void { - print(2, 4); - print(1, 7); -} - -fn print(a: u32, b: u32) void { - const str = "123456789"; - const len = a + b; - _ = std.posix.write(1, str[0..len]) catch {}; -} - -// run -// target=x86_64-linux,x86_64-macos -// -// 12345612345678 diff --git a/test/cases/arithmetic_operations.1.zig b/test/cases/arithmetic_operations.1.zig deleted file mode 100644 index 31f77317d5..0000000000 --- a/test/cases/arithmetic_operations.1.zig +++ /dev/null @@ -1,16 +0,0 @@ -const std = @import("std"); - -pub fn main() void { - print(10, 5); - print(4, 3); -} - -fn print(a: u32, b: u32) void { - const str = "123456789"; - const len = a - b; - _ = std.posix.write(1, str[0..len]) catch {}; -} - -// run -// -// 123451 diff --git a/test/cases/arithmetic_operations.2.zig b/test/cases/arithmetic_operations.2.zig deleted file mode 100644 index 4ef5bec8d6..0000000000 --- a/test/cases/arithmetic_operations.2.zig +++ /dev/null @@ -1,16 +0,0 @@ -const std = @import("std"); - -pub fn main() void { - print(8, 9); - print(3, 7); -} - -fn print(a: u32, b: u32) void { - const str = "123456789"; - const len = a & b; - _ = std.posix.write(1, str[0..len]) catch {}; -} - -// run -// -// 12345678123 diff --git a/test/cases/arithmetic_operations.3.zig b/test/cases/arithmetic_operations.3.zig deleted file mode 100644 index a16fdbc2d1..0000000000 --- a/test/cases/arithmetic_operations.3.zig +++ /dev/null @@ -1,16 +0,0 @@ -const std = @import("std"); - -pub fn main() void { - print(4, 2); - print(3, 7); -} - -fn print(a: u32, b: u32) void { - const str = "123456789"; - const len = a | b; - _ = std.posix.write(1, str[0..len]) catch {}; -} - -// run -// -// 1234561234567 diff --git a/test/cases/arithmetic_operations.4.zig b/test/cases/arithmetic_operations.4.zig deleted file mode 100644 index 5037ad7485..0000000000 --- a/test/cases/arithmetic_operations.4.zig +++ /dev/null @@ -1,16 +0,0 @@ -const std = @import("std"); - -pub fn main() void { - print(42, 42); - print(3, 5); -} - -fn print(a: u32, b: u32) void { - const str = "123456789"; - const len = a ^ b; - _ = std.posix.write(1, str[0..len]) catch {}; -} - -// run -// -// 123456 diff --git a/test/cases/arithmetic_operations.5.zig b/test/cases/arithmetic_operations.5.zig deleted file mode 100644 index b1c18ca7da..0000000000 --- a/test/cases/arithmetic_operations.5.zig +++ /dev/null @@ -1,15 +0,0 @@ -pub fn main() void { - var x: u32 = 1; - assert(x << 1 == 2); - - x <<= 1; - assert(x << 2 == 8); - assert(x << 3 == 16); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/arithmetic_operations.6.zig b/test/cases/arithmetic_operations.6.zig deleted file mode 100644 index e03731173c..0000000000 --- a/test/cases/arithmetic_operations.6.zig +++ /dev/null @@ -1,21 +0,0 @@ -pub fn main() void { - var a: u32 = 1024; - assert(a >> 1 == 512); - - a >>= 1; - assert(a >> 2 == 128); - assert(a >> 3 == 64); - assert(a >> 4 == 32); - assert(a >> 5 == 16); - assert(a >> 6 == 8); - assert(a >> 7 == 4); - assert(a >> 8 == 2); - assert(a >> 9 == 1); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/assert_function.0.zig b/test/cases/assert_function.0.zig deleted file mode 100644 index 7a832e522b..0000000000 --- a/test/cases/assert_function.0.zig +++ /dev/null @@ -1,15 +0,0 @@ -pub fn main() void { - add(3, 4); -} - -fn add(a: u32, b: u32) void { - assert(a + b == 7); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// target=x86_64-macos,x86_64-linux -// link_libc=true diff --git a/test/cases/assert_function.1.zig b/test/cases/assert_function.1.zig deleted file mode 100644 index ac2df25d85..0000000000 --- a/test/cases/assert_function.1.zig +++ /dev/null @@ -1,17 +0,0 @@ -pub fn main() void { - add(3, 4); -} - -fn add(a: u32, b: u32) void { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - assert(e == 14); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/assert_function.10.zig b/test/cases/assert_function.10.zig deleted file mode 100644 index b3f1610cd6..0000000000 --- a/test/cases/assert_function.10.zig +++ /dev/null @@ -1,27 +0,0 @@ -pub fn main() void { - assert(add(3, 4) == 116); -} - -fn add(a: u32, b: u32) u32 { - const x: u32 = blk: { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - const f = d + e; // 24 - const g = e + f; // 38 - const h = f + g; // 62 - const i = g + h; // 100 - const j = i + d; // 110 - break :blk j; - }; - const y = x + a; // 113 - const z = y + a; // 116 - return z; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/assert_function.11.zig b/test/cases/assert_function.11.zig deleted file mode 100644 index d64130a677..0000000000 --- a/test/cases/assert_function.11.zig +++ /dev/null @@ -1,66 +0,0 @@ -pub fn main() void { - assert(add(3, 4) == 1221); - assert(mul(3, 4) == 21609); -} - -fn add(a: u32, b: u32) u32 { - const x: u32 = blk: { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - const f = d + e; // 24 - const g = e + f; // 38 - const h = f + g; // 62 - const i = g + h; // 100 - const j = i + d; // 110 - const k = i + j; // 210 - const l = j + k; // 320 - const m = l + c; // 327 - const n = m + d; // 337 - const o = n + e; // 351 - const p = o + f; // 375 - const q = p + g; // 413 - const r = q + h; // 475 - const s = r + i; // 575 - const t = s + j; // 685 - const u = t + k; // 895 - const v = u + l; // 1215 - break :blk v; - }; - const y = x + a; // 1218 - const z = y + a; // 1221 - return z; -} - -fn mul(a: u32, b: u32) u32 { - const x: u32 = blk: { - const c = a * a * a * a; // 81 - const d = a * a * a * b; // 108 - const e = a * a * b * a; // 108 - const f = a * a * b * b; // 144 - const g = a * b * a * a; // 108 - const h = a * b * a * b; // 144 - const i = a * b * b * a; // 144 - const j = a * b * b * b; // 192 - const k = b * a * a * a; // 108 - const l = b * a * a * b; // 144 - const m = b * a * b * a; // 144 - const n = b * a * b * b; // 192 - const o = b * b * a * a; // 144 - const p = b * b * a * b; // 192 - const q = b * b * b * a; // 192 - const r = b * b * b * b; // 256 - const s = c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r; // 2401 - break :blk s; - }; - const y = x * a; // 7203 - const z = y * a; // 21609 - return z; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/assert_function.12.zig b/test/cases/assert_function.12.zig deleted file mode 100644 index 4f64c1e062..0000000000 --- a/test/cases/assert_function.12.zig +++ /dev/null @@ -1,47 +0,0 @@ -pub fn main() void { - assert(add(3, 4) == 791); - assert(add(4, 3) == 79); -} - -fn add(a: u32, b: u32) u32 { - const x: u32 = if (a < b) blk: { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - const f = d + e; // 24 - const g = e + f; // 38 - const h = f + g; // 62 - const i = g + h; // 100 - const j = i + d; // 110 - const k = i + j; // 210 - const l = k + c; // 217 - const m = l + d; // 227 - const n = m + e; // 241 - const o = n + f; // 265 - const p = o + g; // 303 - const q = p + h; // 365 - const r = q + i; // 465 - const s = r + j; // 575 - const t = s + k; // 785 - break :blk t; - } else blk: { - const t = b + b + a; // 10 - const c = a + t; // 14 - const d = c + t; // 24 - const e = d + t; // 34 - const f = e + t; // 44 - const g = f + t; // 54 - const h = c + g; // 68 - break :blk h + b; // 71 - }; - const y = x + a; // 788, 75 - const z = y + a; // 791, 79 - return z; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/assert_function.13.zig b/test/cases/assert_function.13.zig deleted file mode 100644 index 240abf0108..0000000000 --- a/test/cases/assert_function.13.zig +++ /dev/null @@ -1,19 +0,0 @@ -pub fn main() void { - const ignore = - \\ cool thx - \\ - ; - _ = ignore; - add('ぁ', '\x03'); -} - -fn add(a: u32, b: u32) void { - assert(a + b == 12356); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/assert_function.14.zig b/test/cases/assert_function.14.zig deleted file mode 100644 index d25100dcce..0000000000 --- a/test/cases/assert_function.14.zig +++ /dev/null @@ -1,17 +0,0 @@ -pub fn main() void { - add(aa, bb); -} - -const aa = 'ぁ'; -const bb = '\x03'; - -fn add(a: u32, b: u32) void { - assert(a + b == 12356); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/assert_function.15.zig b/test/cases/assert_function.15.zig deleted file mode 100644 index 33ae1ed5af..0000000000 --- a/test/cases/assert_function.15.zig +++ /dev/null @@ -1,10 +0,0 @@ -pub fn main() void { - assert("hello"[0] == 'h'); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/assert_function.16.zig b/test/cases/assert_function.16.zig deleted file mode 100644 index eef1136423..0000000000 --- a/test/cases/assert_function.16.zig +++ /dev/null @@ -1,11 +0,0 @@ -const hello = "hello".*; -pub fn main() void { - assert(hello[1] == 'e'); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/assert_function.17.zig b/test/cases/assert_function.17.zig deleted file mode 100644 index 01c4a5ca3c..0000000000 --- a/test/cases/assert_function.17.zig +++ /dev/null @@ -1,12 +0,0 @@ -pub fn main() void { - var i: u64 = 0xFFEEDDCCBBAA9988; - _ = &i; - assert(i == 0xFFEEDDCCBBAA9988); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/assert_function.18.zig b/test/cases/assert_function.18.zig deleted file mode 100644 index ac0f97c40f..0000000000 --- a/test/cases/assert_function.18.zig +++ /dev/null @@ -1,20 +0,0 @@ -const builtin = @import("builtin"); - -extern "c" fn write(c_int, usize, usize) usize; - -pub fn main() void { - for ("hello") |_| print(); -} - -fn print() void { - _ = write(1, @intFromPtr("hello\n"), 6); -} - -// run -// -// hello -// hello -// hello -// hello -// hello -// diff --git a/test/cases/assert_function.2.zig b/test/cases/assert_function.2.zig deleted file mode 100644 index 8c1c510486..0000000000 --- a/test/cases/assert_function.2.zig +++ /dev/null @@ -1,21 +0,0 @@ -pub fn main() void { - add(3, 4); -} - -fn add(a: u32, b: u32) void { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - const f = d + e; // 24 - const g = e + f; // 38 - const h = f + g; // 62 - const i = g + h; // 100 - assert(i == 100); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/assert_function.3.zig b/test/cases/assert_function.3.zig deleted file mode 100644 index a6829f8e02..0000000000 --- a/test/cases/assert_function.3.zig +++ /dev/null @@ -1,22 +0,0 @@ -pub fn main() void { - add(3, 4); -} - -fn add(a: u32, b: u32) void { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - const f = d + e; // 24 - const g = e + f; // 38 - const h = f + g; // 62 - const i = g + h; // 100 - const j = i + d; // 110 - assert(j == 110); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/assert_function.4.zig b/test/cases/assert_function.4.zig deleted file mode 100644 index 69df4354c3..0000000000 --- a/test/cases/assert_function.4.zig +++ /dev/null @@ -1,15 +0,0 @@ -pub fn main() void { - assert(add(3, 4) == 7); - assert(add(20, 10) == 30); -} - -fn add(a: u32, b: u32) u32 { - return a + b; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/assert_function.5.zig b/test/cases/assert_function.5.zig deleted file mode 100644 index 89f3f7df4f..0000000000 --- a/test/cases/assert_function.5.zig +++ /dev/null @@ -1,19 +0,0 @@ -pub fn main() void { - assert(add(3, 4) == 7); - assert(add(20, 10) == 30); -} - -fn add(a: u32, b: u32) u32 { - var x: u32 = undefined; - x = 0; - x += a; - x += b; - return x; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/assert_function.6.zig b/test/cases/assert_function.6.zig deleted file mode 100644 index 1b1b75e68e..0000000000 --- a/test/cases/assert_function.6.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - const a: u32 = 2; - const b: ?u32 = a; - const c = b.?; - if (c != 2) unreachable; -} - -// run -// diff --git a/test/cases/assert_function.7.zig b/test/cases/assert_function.7.zig deleted file mode 100644 index 9db604d3b9..0000000000 --- a/test/cases/assert_function.7.zig +++ /dev/null @@ -1,23 +0,0 @@ -extern "c" fn write(c_int, usize, usize) usize; - -pub fn main() void { - var i: u32 = 0; - while (i < 4) : (i += 1) print(); - assert(i == 4); -} - -fn print() void { - _ = write(1, @intFromPtr("hello\n"), 6); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// -// hello -// hello -// hello -// hello -// diff --git a/test/cases/assert_function.8.zig b/test/cases/assert_function.8.zig deleted file mode 100644 index 02b486a8cb..0000000000 --- a/test/cases/assert_function.8.zig +++ /dev/null @@ -1,20 +0,0 @@ -extern "c" fn write(c_int, usize, usize) usize; - -pub fn main() void { - var i: u32 = 0; - inline while (i < 4) : (i += 1) print(); - assert(i == 4); -} - -fn print() void { - _ = write(1, @intFromPtr("hello\n"), 6); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// error -// -// :5:21: error: unable to resolve comptime value -// :5:21: note: condition in comptime branch must be comptime-known diff --git a/test/cases/assert_function.9.zig b/test/cases/assert_function.9.zig deleted file mode 100644 index c754bb7711..0000000000 --- a/test/cases/assert_function.9.zig +++ /dev/null @@ -1,22 +0,0 @@ -pub fn main() void { - assert(add(3, 4) == 20); -} - -fn add(a: u32, b: u32) u32 { - const x: u32 = blk: { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - break :blk e; - }; - const y = x + a; // 17 - const z = y + a; // 20 - return z; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/binary_operands.0.zig b/test/cases/binary_operands.0.zig deleted file mode 100644 index e3688232aa..0000000000 --- a/test/cases/binary_operands.0.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var i: u8 = 5; - i += 20; - if (i != 25) unreachable; -} - -// run -// target=wasm32-wasi -// diff --git a/test/cases/binary_operands.1.zig b/test/cases/binary_operands.1.zig deleted file mode 100644 index 2b244b194a..0000000000 --- a/test/cases/binary_operands.1.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var i: i32 = 2147483647; - _ = &i; - if (i +% 1 != -2147483648) unreachable; - return; -} - -// run -// diff --git a/test/cases/binary_operands.10.zig b/test/cases/binary_operands.10.zig deleted file mode 100644 index 721a921743..0000000000 --- a/test/cases/binary_operands.10.zig +++ /dev/null @@ -1,14 +0,0 @@ -pub fn main() void { - var i: u32 = 5; - i *= 7; - var result: u32 = foo(i, 10); - _ = &result; - if (result != 350) unreachable; - return; -} -fn foo(x: u32, y: u32) u32 { - return x * y; -} - -// run -// diff --git a/test/cases/binary_operands.11.zig b/test/cases/binary_operands.11.zig deleted file mode 100644 index f6a8755178..0000000000 --- a/test/cases/binary_operands.11.zig +++ /dev/null @@ -1,10 +0,0 @@ -pub fn main() void { - var i: i32 = 2147483647; - _ = &i; - const result = i *% 2; - if (result != -2) unreachable; - return; -} - -// run -// diff --git a/test/cases/binary_operands.12.zig b/test/cases/binary_operands.12.zig deleted file mode 100644 index d8b369764f..0000000000 --- a/test/cases/binary_operands.12.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var i: u3 = 3; - _ = &i; - if (i *% 3 != 1) unreachable; - return; -} - -// run -// diff --git a/test/cases/binary_operands.13.zig b/test/cases/binary_operands.13.zig deleted file mode 100644 index 680d82a919..0000000000 --- a/test/cases/binary_operands.13.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var i: i4 = 3; - _ = &i; - if (i *% 3 != -7) unreachable; - return; -} - -// run -// diff --git a/test/cases/binary_operands.14.zig b/test/cases/binary_operands.14.zig deleted file mode 100644 index aa1d62bcde..0000000000 --- a/test/cases/binary_operands.14.zig +++ /dev/null @@ -1,13 +0,0 @@ -pub fn main() void { - var i: u32 = 352; - i /= 7; // i = 50 - const result: u32 = foo(i, 7); - if (result != 7) unreachable; - return; -} -fn foo(x: u32, y: u32) u32 { - return x / y; -} - -// run -// diff --git a/test/cases/binary_operands.15.zig b/test/cases/binary_operands.15.zig deleted file mode 100644 index c709e5dfd2..0000000000 --- a/test/cases/binary_operands.15.zig +++ /dev/null @@ -1,8 +0,0 @@ -pub fn main() u8 { - var i: u8 = 5; - i &= 6; - return i - 4; -} - -// run -// diff --git a/test/cases/binary_operands.16.zig b/test/cases/binary_operands.16.zig deleted file mode 100644 index fe1813b877..0000000000 --- a/test/cases/binary_operands.16.zig +++ /dev/null @@ -1,8 +0,0 @@ -pub fn main() u8 { - var i: u8 = 5; - i |= 6; - return i - 7; -} - -// run -// diff --git a/test/cases/binary_operands.17.zig b/test/cases/binary_operands.17.zig deleted file mode 100644 index 439d3d6d6b..0000000000 --- a/test/cases/binary_operands.17.zig +++ /dev/null @@ -1,8 +0,0 @@ -pub fn main() u8 { - var i: u8 = 5; - i ^= 6; - return i - 3; -} - -// run -// diff --git a/test/cases/binary_operands.18.zig b/test/cases/binary_operands.18.zig deleted file mode 100644 index c21aa586c5..0000000000 --- a/test/cases/binary_operands.18.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var b: bool = false; - b = b or false; - if (b) unreachable; - return; -} - -// run -// diff --git a/test/cases/binary_operands.19.zig b/test/cases/binary_operands.19.zig deleted file mode 100644 index e95470391c..0000000000 --- a/test/cases/binary_operands.19.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var b: bool = true; - b = b or false; - if (!b) unreachable; - return; -} - -// run -// diff --git a/test/cases/binary_operands.2.zig b/test/cases/binary_operands.2.zig deleted file mode 100644 index 5b08fecc04..0000000000 --- a/test/cases/binary_operands.2.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var i: i4 = 7; - _ = &i; - if (i +% 1 != -8) unreachable; - return; -} - -// run -// diff --git a/test/cases/binary_operands.20.zig b/test/cases/binary_operands.20.zig deleted file mode 100644 index 9238bf97c0..0000000000 --- a/test/cases/binary_operands.20.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var b: bool = false; - b = b or true; - if (!b) unreachable; - return; -} - -// run -// diff --git a/test/cases/binary_operands.21.zig b/test/cases/binary_operands.21.zig deleted file mode 100644 index a2d427bda9..0000000000 --- a/test/cases/binary_operands.21.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var b: bool = true; - b = b or true; - if (!b) unreachable; - return; -} - -// run -// diff --git a/test/cases/binary_operands.22.zig b/test/cases/binary_operands.22.zig deleted file mode 100644 index aa8439a361..0000000000 --- a/test/cases/binary_operands.22.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var b: bool = false; - b = b and false; - if (b) unreachable; - return; -} - -// run -// diff --git a/test/cases/binary_operands.23.zig b/test/cases/binary_operands.23.zig deleted file mode 100644 index 8596ea7709..0000000000 --- a/test/cases/binary_operands.23.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var b: bool = true; - b = b and false; - if (b) unreachable; - return; -} - -// run -// diff --git a/test/cases/binary_operands.24.zig b/test/cases/binary_operands.24.zig deleted file mode 100644 index 08dc4430a2..0000000000 --- a/test/cases/binary_operands.24.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var b: bool = false; - b = b and true; - if (b) unreachable; - return; -} - -// run -// diff --git a/test/cases/binary_operands.25.zig b/test/cases/binary_operands.25.zig deleted file mode 100644 index 8aa0acfdb5..0000000000 --- a/test/cases/binary_operands.25.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var b: bool = true; - b = b and true; - if (!b) unreachable; - return; -} - -// run -// diff --git a/test/cases/binary_operands.3.zig b/test/cases/binary_operands.3.zig deleted file mode 100644 index 75d78d522a..0000000000 --- a/test/cases/binary_operands.3.zig +++ /dev/null @@ -1,8 +0,0 @@ -pub fn main() u8 { - var i: u8 = 255; - _ = &i; - return i +% 1; -} - -// run -// diff --git a/test/cases/binary_operands.4.zig b/test/cases/binary_operands.4.zig deleted file mode 100644 index b3fd9fc289..0000000000 --- a/test/cases/binary_operands.4.zig +++ /dev/null @@ -1,12 +0,0 @@ -pub fn main() u8 { - var i: u8 = 5; - i += 20; - const result: u8 = foo(i, 10); - return result - 35; -} -fn foo(x: u8, y: u8) u8 { - return x + y; -} - -// run -// diff --git a/test/cases/binary_operands.5.zig b/test/cases/binary_operands.5.zig deleted file mode 100644 index 51ab437475..0000000000 --- a/test/cases/binary_operands.5.zig +++ /dev/null @@ -1,8 +0,0 @@ -pub fn main() u8 { - var i: u8 = 20; - i -= 5; - return i - 15; -} - -// run -// diff --git a/test/cases/binary_operands.6.zig b/test/cases/binary_operands.6.zig deleted file mode 100644 index b6e04e609e..0000000000 --- a/test/cases/binary_operands.6.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var i: i32 = -2147483648; - _ = &i; - if (i -% 1 != 2147483647) unreachable; - return; -} - -// run -// diff --git a/test/cases/binary_operands.7.zig b/test/cases/binary_operands.7.zig deleted file mode 100644 index ae69df2c55..0000000000 --- a/test/cases/binary_operands.7.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var i: i7 = -64; - _ = &i; - if (i -% 1 != 63) unreachable; - return; -} - -// run -// diff --git a/test/cases/binary_operands.8.zig b/test/cases/binary_operands.8.zig deleted file mode 100644 index fb2741cab6..0000000000 --- a/test/cases/binary_operands.8.zig +++ /dev/null @@ -1,8 +0,0 @@ -pub fn main() void { - var i: u4 = 0; - _ = &i; - if (i -% 1 != 15) unreachable; -} - -// run -// diff --git a/test/cases/binary_operands.9.zig b/test/cases/binary_operands.9.zig deleted file mode 100644 index a9d62b96e3..0000000000 --- a/test/cases/binary_operands.9.zig +++ /dev/null @@ -1,13 +0,0 @@ -pub fn main() u8 { - var i: u8 = 5; - i -= 3; - var result: u8 = foo(i, 10); - _ = &result; - return result - 8; -} -fn foo(x: u8, y: u8) u8 { - return y - x; -} - -// run -// diff --git a/test/cases/break_continue.0.zig b/test/cases/break_continue.0.zig deleted file mode 100644 index 6684bcb0d0..0000000000 --- a/test/cases/break_continue.0.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - while (true) { - break; - } -} - -// run -// target=x86_64-linux,x86_64-macos -// diff --git a/test/cases/break_continue.1.zig b/test/cases/break_continue.1.zig deleted file mode 100644 index 9e4f79bd14..0000000000 --- a/test/cases/break_continue.1.zig +++ /dev/null @@ -1,8 +0,0 @@ -pub fn main() void { - foo: while (true) { - break :foo; - } -} - -// run -// diff --git a/test/cases/break_continue.2.zig b/test/cases/break_continue.2.zig deleted file mode 100644 index ba12f33e3f..0000000000 --- a/test/cases/break_continue.2.zig +++ /dev/null @@ -1,10 +0,0 @@ -pub fn main() void { - var i: u64 = 0; - while (true) : (i += 1) { - if (i == 4) return; - continue; - } -} - -// run -// diff --git a/test/cases/break_continue.3.zig b/test/cases/break_continue.3.zig deleted file mode 100644 index 03e224d265..0000000000 --- a/test/cases/break_continue.3.zig +++ /dev/null @@ -1,10 +0,0 @@ -pub fn main() void { - var i: u64 = 0; - foo: while (true) : (i += 1) { - if (i == 4) return; - continue :foo; - } -} - -// run -// diff --git a/test/cases/catch_at_comptime.0.zig b/test/cases/catch_at_comptime.0.zig deleted file mode 100644 index af1545832d..0000000000 --- a/test/cases/catch_at_comptime.0.zig +++ /dev/null @@ -1,11 +0,0 @@ -pub fn main() void { - const i: anyerror!u64 = 0; - const caught = i catch 5; - assert(caught == 0); -} -fn assert(b: bool) void { - if (!b) unreachable; -} - -// run -// diff --git a/test/cases/catch_at_comptime.1.zig b/test/cases/catch_at_comptime.1.zig deleted file mode 100644 index e05caeae6d..0000000000 --- a/test/cases/catch_at_comptime.1.zig +++ /dev/null @@ -1,11 +0,0 @@ -pub fn main() void { - const i: anyerror!u64 = error.B; - const caught = i catch 5; - assert(caught == 5); -} -fn assert(b: bool) void { - if (!b) unreachable; -} - -// run -// diff --git a/test/cases/catch_at_comptime.2.zig b/test/cases/catch_at_comptime.2.zig deleted file mode 100644 index 326e6f0b61..0000000000 --- a/test/cases/catch_at_comptime.2.zig +++ /dev/null @@ -1,11 +0,0 @@ -pub fn main() void { - const a: anyerror!comptime_int = 42; - const b: *const comptime_int = &(a catch unreachable); - assert(b.* == 42); -} -fn assert(b: bool) void { - if (!b) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/catch_at_comptime.3.zig b/test/cases/catch_at_comptime.3.zig deleted file mode 100644 index d00317f697..0000000000 --- a/test/cases/catch_at_comptime.3.zig +++ /dev/null @@ -1,10 +0,0 @@ -pub fn main() void { - const a: anyerror!u32 = error.B; - _ = &(a catch |err| assert(err == error.B)); -} -fn assert(b: bool) void { - if (!b) unreachable; -} - -// run -// diff --git a/test/cases/catch_at_comptime.4.zig b/test/cases/catch_at_comptime.4.zig deleted file mode 100644 index 57cb602641..0000000000 --- a/test/cases/catch_at_comptime.4.zig +++ /dev/null @@ -1,10 +0,0 @@ -pub fn main() void { - const a: anyerror!u32 = error.Bar; - a catch |err| assert(err == error.Bar); -} -fn assert(b: bool) void { - if (!b) unreachable; -} - -// run -// diff --git a/test/cases/compile_errors/labeled_block_implicit_value.zig b/test/cases/compile_errors/labeled_block_implicit_value.zig new file mode 100644 index 0000000000..ce02f6a4ef --- /dev/null +++ b/test/cases/compile_errors/labeled_block_implicit_value.zig @@ -0,0 +1,10 @@ +export fn foo() void { + const result: u32 = b: { + if (false) break :b 1; + }; + _ = result; +} + +// error +// +// :2:28: error: expected type 'u32', found 'void' diff --git a/test/cases/compile_log.0.zig b/test/cases/compile_log.0.zig deleted file mode 100644 index 07b7c71551..0000000000 --- a/test/cases/compile_log.0.zig +++ /dev/null @@ -1,22 +0,0 @@ -export fn _start() noreturn { - const b = true; - var f: u32 = 1; - @compileLog(b, 20, f, x); - @compileLog(1000); - var bruh: usize = true; - _ = .{ &f, &bruh }; - unreachable; -} -export fn other() void { - @compileLog(1234); -} -fn x() void {} - -// error -// -// :6:23: error: expected type 'usize', found 'bool' -// -// Compile Log Output: -// @as(bool, true), @as(comptime_int, 20), @as(u32, [runtime value]), @as(fn () void, (function 'x')) -// @as(comptime_int, 1000) -// @as(comptime_int, 1234) diff --git a/test/cases/compile_log.1.zig b/test/cases/compile_log.1.zig deleted file mode 100644 index fa3e93bfbf..0000000000 --- a/test/cases/compile_log.1.zig +++ /dev/null @@ -1,21 +0,0 @@ -export fn _start() noreturn { - const b = true; - var f: u32 = 1; - _ = &f; - @compileLog(b, 20, f, x); - @compileLog(1000); - unreachable; -} -export fn other() void { - @compileLog(1234); -} -fn x() void {} - -// error -// -// :9:5: error: found compile log statement -// :4:5: note: also here -// -// Compile Log Output: -// @as(bool, true), @as(comptime_int, 20), @as(u32, [runtime value]), @as(fn () void, (function 'x')) -// @as(comptime_int, 1000) diff --git a/test/cases/comptime_var.0.zig b/test/cases/comptime_var.0.zig deleted file mode 100644 index 7044e0fb2a..0000000000 --- a/test/cases/comptime_var.0.zig +++ /dev/null @@ -1,14 +0,0 @@ -pub fn main() void { - var a: u32 = 0; - _ = &a; - comptime var b: u32 = 0; - if (a == 0) b = 3; -} - -// error -// output_mode=Exe -// target=x86_64-macos,x86_64-linux -// link_libc=true -// -// :5:19: error: store to comptime variable depends on runtime condition -// :5:11: note: runtime condition here diff --git a/test/cases/comptime_var.1.zig b/test/cases/comptime_var.1.zig deleted file mode 100644 index d914ab45b5..0000000000 --- a/test/cases/comptime_var.1.zig +++ /dev/null @@ -1,14 +0,0 @@ -pub fn main() void { - var a: u32 = 0; - _ = &a; - comptime var b: u32 = 0; - switch (a) { - 0 => {}, - else => b = 3, - } -} - -// error -// -// :6:19: error: store to comptime variable depends on runtime condition -// :4:13: note: runtime condition here diff --git a/test/cases/comptime_var.2.zig b/test/cases/comptime_var.2.zig deleted file mode 100644 index 2d717cb802..0000000000 --- a/test/cases/comptime_var.2.zig +++ /dev/null @@ -1,17 +0,0 @@ -extern "c" fn write(c_int, usize, usize) usize; - -pub fn main() void { - comptime var len: u32 = 5; - print(len); - len += 9; - print(len); -} - -fn print(len: usize) void { - _ = write(1, @intFromPtr("Hello, World!\n"), len); -} - -// run -// -// HelloHello, World! -// diff --git a/test/cases/comptime_var.3.zig b/test/cases/comptime_var.3.zig deleted file mode 100644 index 5d25d6556e..0000000000 --- a/test/cases/comptime_var.3.zig +++ /dev/null @@ -1,10 +0,0 @@ -comptime { - var x: i32 = 1; - x += 1; - if (x != 1) unreachable; -} -pub fn main() void {} - -// error -// -// :4:17: error: reached unreachable code diff --git a/test/cases/comptime_var.4.zig b/test/cases/comptime_var.4.zig deleted file mode 100644 index 74da6ef448..0000000000 --- a/test/cases/comptime_var.4.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - comptime var i: u64 = 0; - while (i < 5) : (i += 1) {} -} - -// error -// -// :3:24: error: cannot store to comptime variable in non-inline loop -// :3:5: note: non-inline loop here diff --git a/test/cases/comptime_var.5.zig b/test/cases/comptime_var.5.zig deleted file mode 100644 index bd3d878fa7..0000000000 --- a/test/cases/comptime_var.5.zig +++ /dev/null @@ -1,16 +0,0 @@ -pub fn main() void { - var a: u32 = 0; - _ = &a; - if (a == 0) { - comptime var b: u32 = 0; - b = 1; - } -} -comptime { - var x: i32 = 1; - x += 1; - if (x != 2) unreachable; -} - -// run -// diff --git a/test/cases/comptime_var.6.zig b/test/cases/comptime_var.6.zig deleted file mode 100644 index d4e96106bb..0000000000 --- a/test/cases/comptime_var.6.zig +++ /dev/null @@ -1,15 +0,0 @@ -extern "c" fn write(c_int, usize, usize) usize; - -pub fn main() void { - comptime var i: u64 = 2; - inline while (i < 6) : (i += 1) { - print(i); - } -} -fn print(len: usize) void { - _ = write(1, @intFromPtr("Hello"), len); -} - -// run -// -// HeHelHellHello diff --git a/test/cases/conditional_branches.0.zig b/test/cases/conditional_branches.0.zig deleted file mode 100644 index d1fce95b2c..0000000000 --- a/test/cases/conditional_branches.0.zig +++ /dev/null @@ -1,23 +0,0 @@ -extern "c" fn write(c_int, usize, usize) usize; - -pub fn main() void { - foo(123); -} - -fn foo(x: u64) void { - if (x > 42) { - print(); - } -} - -fn print() void { - const str = "Hello, World!\n"; - _ = write(1, @intFromPtr(str.ptr), ptr.len); -} - -// run -// target=x86_64-linux,x86_64-macos -// link_libc=true -// -// Hello, World! -// diff --git a/test/cases/conditional_branches.1.zig b/test/cases/conditional_branches.1.zig deleted file mode 100644 index f402cd3bd4..0000000000 --- a/test/cases/conditional_branches.1.zig +++ /dev/null @@ -1,25 +0,0 @@ -extern "c" fn write(c_int, usize, usize) usize; - -pub fn main() void { - foo(true); -} - -fn foo(x: bool) void { - if (x) { - print(); - print(); - } else { - print(); - } -} - -fn print() void { - const str = "Hello, World!\n"; - _ = write(1, @intFromPtr(str.ptr), ptr.len); -} - -// run -// -// Hello, World! -// Hello, World! -// diff --git a/test/cases/conditions.0.zig b/test/cases/conditions.0.zig deleted file mode 100644 index 1167ea85a4..0000000000 --- a/test/cases/conditions.0.zig +++ /dev/null @@ -1,11 +0,0 @@ -pub fn main() u8 { - var i: u8 = 5; - if (i > @as(u8, 4)) { - i += 10; - } - return i - 15; -} - -// run -// target=wasm32-wasi -// diff --git a/test/cases/conditions.1.zig b/test/cases/conditions.1.zig deleted file mode 100644 index f9f03808b9..0000000000 --- a/test/cases/conditions.1.zig +++ /dev/null @@ -1,12 +0,0 @@ -pub fn main() u8 { - var i: u8 = 5; - if (i < @as(u8, 4)) { - i += 10; - } else { - i = 2; - } - return i - 2; -} - -// run -// diff --git a/test/cases/conditions.2.zig b/test/cases/conditions.2.zig deleted file mode 100644 index a80ead9ea5..0000000000 --- a/test/cases/conditions.2.zig +++ /dev/null @@ -1,12 +0,0 @@ -pub fn main() u8 { - var i: u8 = 5; - if (i < @as(u8, 4)) { - i += 10; - } else if (i == @as(u8, 5)) { - i = 20; - } - return i - 20; -} - -// run -// diff --git a/test/cases/conditions.3.zig b/test/cases/conditions.3.zig deleted file mode 100644 index bd016a47f3..0000000000 --- a/test/cases/conditions.3.zig +++ /dev/null @@ -1,16 +0,0 @@ -pub fn main() u8 { - var i: u8 = 11; - if (i < @as(u8, 4)) { - i += 10; - } else { - if (i > @as(u8, 10)) { - i += 20; - } else { - i = 20; - } - } - return i - 31; -} - -// run -// diff --git a/test/cases/conditions.4.zig b/test/cases/conditions.4.zig deleted file mode 100644 index e1bd9ce0f7..0000000000 --- a/test/cases/conditions.4.zig +++ /dev/null @@ -1,15 +0,0 @@ -pub fn main() void { - assert(foo(true) != @as(i32, 30)); -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -fn foo(ok: bool) i32 { - const x = if (ok) @as(i32, 20) else @as(i32, 10); - return x; -} - -// run -// diff --git a/test/cases/conditions.5.zig b/test/cases/conditions.5.zig deleted file mode 100644 index 9b2dfdb58e..0000000000 --- a/test/cases/conditions.5.zig +++ /dev/null @@ -1,21 +0,0 @@ -pub fn main() void { - assert(foo(false) == @as(i32, 20)); - assert(foo(true) == @as(i32, 30)); -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -fn foo(ok: bool) i32 { - const val: i32 = blk: { - var x: i32 = 1; - _ = &x; - if (!ok) break :blk x + @as(i32, 9); - break :blk x + @as(i32, 19); - }; - return val + 10; -} - -// run -// diff --git a/test/cases/double_ampersand.0.zig b/test/cases/double_ampersand.0.zig deleted file mode 100644 index b14c30ecb0..0000000000 --- a/test/cases/double_ampersand.0.zig +++ /dev/null @@ -1,6 +0,0 @@ -pub const a = if (true && false) 1 else 2; - -// error -// output_mode=Exe -// -// :1:24: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND diff --git a/test/cases/double_ampersand.1.zig b/test/cases/double_ampersand.1.zig deleted file mode 100644 index cd5bba02fd..0000000000 --- a/test/cases/double_ampersand.1.zig +++ /dev/null @@ -1,11 +0,0 @@ -pub fn main() void { - const a = true; - const b = false; - _ = a & &b; -} - -// error -// -// :4:11: error: incompatible types: 'bool' and '*const bool' -// :4:9: note: type 'bool' here -// :4:13: note: type '*const bool' here diff --git a/test/cases/double_ampersand.2.zig b/test/cases/double_ampersand.2.zig deleted file mode 100644 index c6f461d661..0000000000 --- a/test/cases/double_ampersand.2.zig +++ /dev/null @@ -1,7 +0,0 @@ -pub fn main() void { - const b: u8 = 1; - _ = &&b; -} - -// run -// diff --git a/test/cases/enum_values.0.zig b/test/cases/enum_values.0.zig deleted file mode 100644 index 3e4ee60925..0000000000 --- a/test/cases/enum_values.0.zig +++ /dev/null @@ -1,18 +0,0 @@ -const Number = enum { One, Two, Three }; - -pub fn main() void { - var number1 = Number.One; - var number2: Number = .Two; - if (false) { - &number1; - &number2; - } - const number3: Number = @enumFromInt(2); - if (@intFromEnum(number3) != 2) { - unreachable; - } - return; -} - -// run -// diff --git a/test/cases/enum_values.1.zig b/test/cases/enum_values.1.zig deleted file mode 100644 index 7679a87361..0000000000 --- a/test/cases/enum_values.1.zig +++ /dev/null @@ -1,25 +0,0 @@ -const Number = enum { One, Two, Three }; - -pub fn main() void { - var number1 = Number.One; - _ = &number1; - var number2: Number = .Two; - _ = &number2; - const number3: Number = @enumFromInt(2); - assert(number1 != number2); - assert(number2 != number3); - assert(@intFromEnum(number1) == 0); - assert(@intFromEnum(number2) == 1); - assert(@intFromEnum(number3) == 2); - var x: Number = .Two; - _ = &x; - assert(number2 == x); - - return; -} -fn assert(val: bool) void { - if (!val) unreachable; -} - -// run -// diff --git a/test/cases/error_unions.0.zig b/test/cases/error_unions.0.zig deleted file mode 100644 index 89646e4681..0000000000 --- a/test/cases/error_unions.0.zig +++ /dev/null @@ -1,16 +0,0 @@ -pub fn main() void { - var e1 = error.Foo; - var e2 = error.Bar; - _ = .{ &e1, &e2 }; - assert(e1 != e2); - assert(e1 == error.Foo); - assert(e2 == error.Bar); -} - -fn assert(b: bool) void { - if (!b) unreachable; -} - -// run -// target=wasm32-wasi -// diff --git a/test/cases/error_unions.1.zig b/test/cases/error_unions.1.zig deleted file mode 100644 index 792bc88412..0000000000 --- a/test/cases/error_unions.1.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() u8 { - var e: anyerror!u8 = 5; - _ = &e; - const i = e catch 10; - return i - 5; -} - -// run -// diff --git a/test/cases/error_unions.2.zig b/test/cases/error_unions.2.zig deleted file mode 100644 index cc61263aa7..0000000000 --- a/test/cases/error_unions.2.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() u8 { - var e: anyerror!u8 = error.Foo; - _ = &e; - const i = e catch 10; - return i - 10; -} - -// run -// diff --git a/test/cases/error_unions.3.zig b/test/cases/error_unions.3.zig deleted file mode 100644 index 2661e3bc19..0000000000 --- a/test/cases/error_unions.3.zig +++ /dev/null @@ -1,13 +0,0 @@ -pub fn main() u8 { - var e = foo(); - _ = &e; - const i = e catch 69; - return i - 5; -} - -fn foo() anyerror!u8 { - return 5; -} - -// run -// diff --git a/test/cases/error_unions.4.zig b/test/cases/error_unions.4.zig deleted file mode 100644 index d6d121e1d6..0000000000 --- a/test/cases/error_unions.4.zig +++ /dev/null @@ -1,13 +0,0 @@ -pub fn main() u8 { - var e = foo(); - _ = &e; - const i = e catch 69; - return i - 69; -} - -fn foo() anyerror!u8 { - return error.Bruh; -} - -// run -// diff --git a/test/cases/error_unions.5.zig b/test/cases/error_unions.5.zig deleted file mode 100644 index 0204cef926..0000000000 --- a/test/cases/error_unions.5.zig +++ /dev/null @@ -1,13 +0,0 @@ -pub fn main() u8 { - var e = foo(); - _ = &e; - const i = e catch 42; - return i - 42; -} - -fn foo() anyerror!u8 { - return error.Dab; -} - -// run -// diff --git a/test/cases/errors.0.zig b/test/cases/errors.0.zig deleted file mode 100644 index f61ebc42b7..0000000000 --- a/test/cases/errors.0.zig +++ /dev/null @@ -1,15 +0,0 @@ -const std = @import("std"); - -pub fn main() void { - foo() catch print(); -} - -fn foo() anyerror!void {} - -fn print() void { - _ = std.posix.write(1, "Hello, World!\n") catch {}; -} - -// run -// target=x86_64-macos -// diff --git a/test/cases/errors.1.zig b/test/cases/errors.1.zig deleted file mode 100644 index ead3262f84..0000000000 --- a/test/cases/errors.1.zig +++ /dev/null @@ -1,18 +0,0 @@ -const std = @import("std"); - -pub fn main() void { - foo() catch print(); -} - -fn foo() anyerror!void { - return error.Test; -} - -fn print() void { - _ = std.posix.write(1, "Hello, World!\n") catch {}; -} - -// run -// -// Hello, World! -// diff --git a/test/cases/errors.2.zig b/test/cases/errors.2.zig deleted file mode 100644 index a1b9aef97d..0000000000 --- a/test/cases/errors.2.zig +++ /dev/null @@ -1,27 +0,0 @@ -pub fn main() void { - foo() catch |err| { - assert(err == error.Foo); - assert(err != error.Bar); - assert(err != error.Baz); - }; - bar() catch |err| { - assert(err != error.Foo); - assert(err == error.Bar); - assert(err != error.Baz); - }; -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -fn foo() anyerror!void { - return error.Foo; -} - -fn bar() anyerror!void { - return error.Bar; -} - -// run -// diff --git a/test/cases/errors.3.zig b/test/cases/errors.3.zig deleted file mode 100644 index 390696fcfc..0000000000 --- a/test/cases/errors.3.zig +++ /dev/null @@ -1,12 +0,0 @@ -pub fn main() void { - foo() catch unreachable; -} - -fn foo() anyerror!void { - try bar(); -} - -fn bar() anyerror!void {} - -// run -// diff --git a/test/cases/extern_variable_has_no_type.0.zig b/test/cases/extern_variable_has_no_type.0.zig deleted file mode 100644 index e141551828..0000000000 --- a/test/cases/extern_variable_has_no_type.0.zig +++ /dev/null @@ -1,10 +0,0 @@ -comptime { - const x = foo + foo; - _ = x; -} -extern var foo: i32; - -// error -// -// :2:19: error: unable to evaluate comptime expression -// :2:15: note: operation is runtime due to this operand diff --git a/test/cases/extern_variable_has_no_type.1.zig b/test/cases/extern_variable_has_no_type.1.zig deleted file mode 100644 index f5c31244e5..0000000000 --- a/test/cases/extern_variable_has_no_type.1.zig +++ /dev/null @@ -1,8 +0,0 @@ -export fn entry() void { - _ = foo; -} -extern var foo; - -// error -// -// :4:8: error: unable to infer variable type diff --git a/test/cases/function_calls.0.zig b/test/cases/function_calls.0.zig deleted file mode 100644 index eb388bc49f..0000000000 --- a/test/cases/function_calls.0.zig +++ /dev/null @@ -1,12 +0,0 @@ -pub fn main() void { - foo(); - bar(); -} -fn foo() void { - bar(); - bar(); -} -fn bar() void {} - -// run -// diff --git a/test/cases/function_calls.1.zig b/test/cases/function_calls.1.zig deleted file mode 100644 index 60bc061bca..0000000000 --- a/test/cases/function_calls.1.zig +++ /dev/null @@ -1,15 +0,0 @@ -pub fn main() void { - bar(); - foo(); - foo(); - bar(); - foo(); - bar(); -} -fn foo() void { - bar(); -} -fn bar() void {} - -// run -// diff --git a/test/cases/function_calls.2.zig b/test/cases/function_calls.2.zig deleted file mode 100644 index ce5627378a..0000000000 --- a/test/cases/function_calls.2.zig +++ /dev/null @@ -1,14 +0,0 @@ -pub fn main() void { - bar(); - foo(); - return; -} -fn foo() void { - bar(); - bar(); - bar(); -} -fn bar() void {} - -// run -// diff --git a/test/cases/function_calls.3.zig b/test/cases/function_calls.3.zig deleted file mode 100644 index 0316d9042d..0000000000 --- a/test/cases/function_calls.3.zig +++ /dev/null @@ -1,10 +0,0 @@ -pub fn main() void { - foo(10, 20); -} -fn foo(x: u8, y: u8) void { - _ = x; - _ = y; -} - -// run -// diff --git a/test/cases/hello_world_with_updates.0.zig b/test/cases/hello_world_with_updates.0.zig deleted file mode 100644 index 2cebc2c047..0000000000 --- a/test/cases/hello_world_with_updates.0.zig +++ /dev/null @@ -1,6 +0,0 @@ -// error -// output_mode=Exe -// target=x86_64-linux,x86_64-macos -// link_libc=true -// -// :?:?: error: root source file struct 'tmp' has no member named 'main' diff --git a/test/cases/hello_world_with_updates.1.zig b/test/cases/hello_world_with_updates.1.zig deleted file mode 100644 index dcf18bbf87..0000000000 --- a/test/cases/hello_world_with_updates.1.zig +++ /dev/null @@ -1,6 +0,0 @@ -pub export fn main() noreturn {} - -// error -// -// :1:22: error: function declared 'noreturn' implicitly returns -// :1:32: note: control flow reaches end of body here diff --git a/test/cases/hello_world_with_updates.2.zig b/test/cases/hello_world_with_updates.2.zig deleted file mode 100644 index db5564e3a7..0000000000 --- a/test/cases/hello_world_with_updates.2.zig +++ /dev/null @@ -1,19 +0,0 @@ -extern "c" fn write(c_int, usize, usize) usize; -extern "c" fn exit(c_int) noreturn; - -pub export fn main() noreturn { - print(); - - exit(0); -} - -fn print() void { - const msg = @intFromPtr("Hello, World!\n"); - const len = 14; - _ = write(1, msg, len); -} - -// run -// -// Hello, World! -// diff --git a/test/cases/hello_world_with_updates.3.zig b/test/cases/hello_world_with_updates.3.zig deleted file mode 100644 index 8c57d52924..0000000000 --- a/test/cases/hello_world_with_updates.3.zig +++ /dev/null @@ -1,16 +0,0 @@ -extern "c" fn write(c_int, usize, usize) usize; - -pub fn main() void { - print(); -} - -fn print() void { - const msg = @intFromPtr("Hello, World!\n"); - const len = 14; - _ = write(1, msg, len); -} - -// run -// -// Hello, World! -// diff --git a/test/cases/hello_world_with_updates.4.zig b/test/cases/hello_world_with_updates.4.zig deleted file mode 100644 index 54641a3ad5..0000000000 --- a/test/cases/hello_world_with_updates.4.zig +++ /dev/null @@ -1,22 +0,0 @@ -extern "c" fn write(c_int, usize, usize) usize; - -pub fn main() void { - print(); - print(); - print(); - print(); -} - -fn print() void { - const msg = @intFromPtr("Hello, World!\n"); - const len = 14; - _ = write(1, msg, len); -} - -// run -// -// Hello, World! -// Hello, World! -// Hello, World! -// Hello, World! -// diff --git a/test/cases/hello_world_with_updates.5.zig b/test/cases/hello_world_with_updates.5.zig deleted file mode 100644 index ae57d9b7b6..0000000000 --- a/test/cases/hello_world_with_updates.5.zig +++ /dev/null @@ -1,16 +0,0 @@ -extern "c" fn write(c_int, usize, usize) usize; - -pub fn main() void { - print(); -} - -fn print() void { - const msg = @intFromPtr("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n"); - const len = 104; - _ = write(1, msg, len); -} - -// run -// -// What is up? This is a longer message that will force the data to be relocated in virtual address space. -// diff --git a/test/cases/hello_world_with_updates.6.zig b/test/cases/hello_world_with_updates.6.zig deleted file mode 100644 index 76f006992e..0000000000 --- a/test/cases/hello_world_with_updates.6.zig +++ /dev/null @@ -1,20 +0,0 @@ -const builtin = @import("builtin"); - -extern "c" fn write(c_int, usize, usize) usize; - -pub fn main() void { - print(); - print(); -} - -fn print() void { - const msg = @intFromPtr("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n"); - const len = 104; - _ = write(1, msg, len); -} - -// run -// -// What is up? This is a longer message that will force the data to be relocated in virtual address space. -// What is up? This is a longer message that will force the data to be relocated in virtual address space. -// diff --git a/test/cases/int_to_ptr.0.zig b/test/cases/int_to_ptr.0.zig deleted file mode 100644 index 09efb8b1a5..0000000000 --- a/test/cases/int_to_ptr.0.zig +++ /dev/null @@ -1,8 +0,0 @@ -pub fn main() void { - _ = @as(*u8, @ptrFromInt(0)); -} - -// error -// output_mode=Exe -// -// :2:18: error: pointer type '*u8' does not allow address zero diff --git a/test/cases/int_to_ptr.1.zig b/test/cases/int_to_ptr.1.zig deleted file mode 100644 index d5aed471e1..0000000000 --- a/test/cases/int_to_ptr.1.zig +++ /dev/null @@ -1,7 +0,0 @@ -pub fn main() void { - _ = @as(*u32, @ptrFromInt(2)); -} - -// error -// -// :2:19: error: pointer type '*u32' requires aligned address diff --git a/test/cases/locals.0.zig b/test/cases/locals.0.zig deleted file mode 100644 index 5698a66dcf..0000000000 --- a/test/cases/locals.0.zig +++ /dev/null @@ -1,14 +0,0 @@ -pub fn main() void { - var i: u8 = 5; - var y: f32 = 42.0; - var x: u8 = 10; - if (false) { - &y; - &x / &i; - } - if (i != 5) unreachable; -} - -// run -// target=wasm32-wasi -// diff --git a/test/cases/locals.1.zig b/test/cases/locals.1.zig deleted file mode 100644 index 0d0b63f636..0000000000 --- a/test/cases/locals.1.zig +++ /dev/null @@ -1,18 +0,0 @@ -pub fn main() void { - var i: u8 = 5; - var y: f32 = 42.0; - _ = &y; - var x: u8 = 10; - _ = &x; - foo(i, x); - i = x; - if (i != 10) unreachable; -} -fn foo(x: u8, y: u8) void { - _ = y; - var i: u8 = 10; - i = x; -} - -// run -// diff --git a/test/cases/lower_unnamed_consts_structs.0.zig b/test/cases/lower_unnamed_consts_structs.0.zig deleted file mode 100644 index 3123299646..0000000000 --- a/test/cases/lower_unnamed_consts_structs.0.zig +++ /dev/null @@ -1,25 +0,0 @@ -const Foo = struct { - a: u8, - b: u32, - - fn first(self: *Foo) u8 { - return self.a; - } - - fn second(self: *Foo) u32 { - return self.b; - } -}; - -pub fn main() void { - var foo = Foo{ .a = 1, .b = 5 }; - assert(foo.first() == 1); - assert(foo.second() == 5); -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -// run -// diff --git a/test/cases/lower_unnamed_consts_structs.1.zig b/test/cases/lower_unnamed_consts_structs.1.zig deleted file mode 100644 index 37afdc8a09..0000000000 --- a/test/cases/lower_unnamed_consts_structs.1.zig +++ /dev/null @@ -1,35 +0,0 @@ -const Foo = struct { - a: u8, - b: u32, - - fn first(self: *Foo) u8 { - return self.a; - } - - fn second(self: *Foo) u32 { - return self.b; - } -}; - -pub fn main() void { - var foo = Foo{ .a = 1, .b = 5 }; - assert(foo.first() == 1); - assert(foo.second() == 5); - - foo.a = 10; - foo.b = 255; - - assert(foo.first() == 10); - assert(foo.second() == 255); - - var foo2 = Foo{ .a = 15, .b = 255 }; - assert(foo2.first() == 15); - assert(foo2.second() == 255); -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -// run -// diff --git a/test/cases/lower_unnamed_consts_structs.2.zig b/test/cases/lower_unnamed_consts_structs.2.zig deleted file mode 100644 index b437c4a030..0000000000 --- a/test/cases/lower_unnamed_consts_structs.2.zig +++ /dev/null @@ -1,25 +0,0 @@ -const Foo = struct { - a: u8, - b: u32, - - fn first(self: *Foo) u8 { - return self.a; - } - - fn second(self: *Foo) u32 { - return self.b; - } -}; - -pub fn main() void { - var foo2 = Foo{ .a = 15, .b = 255 }; - assert(foo2.first() == 15); - assert(foo2.second() == 255); -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -// run -// diff --git a/test/cases/merge_error_sets.0.zig b/test/cases/merge_error_sets.0.zig deleted file mode 100644 index f1f3b96883..0000000000 --- a/test/cases/merge_error_sets.0.zig +++ /dev/null @@ -1,18 +0,0 @@ -pub fn main() void { - const E = error{ A, B, D } || error{ A, B, C }; - E.A catch {}; - E.B catch {}; - E.C catch {}; - E.D catch {}; - const E2 = error{ X, Y } || @TypeOf(error.Z); - E2.X catch {}; - E2.Y catch {}; - E2.Z catch {}; - assert(anyerror || error{Z} == anyerror); -} -fn assert(b: bool) void { - if (!b) unreachable; -} - -// run -// diff --git a/test/cases/merge_error_sets.1.zig b/test/cases/merge_error_sets.1.zig deleted file mode 100644 index 81c1cad134..0000000000 --- a/test/cases/merge_error_sets.1.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - const z = true || false; - _ = z; -} - -// error -// -// :2:15: error: expected error set type, found 'bool' -// :2:20: note: '||' merges error sets; 'or' performs boolean OR diff --git a/test/cases/multiplying_numbers_at_runtime_and_comptime.0.zig b/test/cases/multiplying_numbers_at_runtime_and_comptime.0.zig deleted file mode 100644 index f113928982..0000000000 --- a/test/cases/multiplying_numbers_at_runtime_and_comptime.0.zig +++ /dev/null @@ -1,11 +0,0 @@ -pub fn main() void { - mul(3, 4); -} - -fn mul(a: u32, b: u32) void { - if (a * b != 12) unreachable; -} - -// run -// target=x86_64-linux,x86_64-macos -// diff --git a/test/cases/multiplying_numbers_at_runtime_and_comptime.1.zig b/test/cases/multiplying_numbers_at_runtime_and_comptime.1.zig deleted file mode 100644 index 1dff884900..0000000000 --- a/test/cases/multiplying_numbers_at_runtime_and_comptime.1.zig +++ /dev/null @@ -1,12 +0,0 @@ -pub fn main() void { - if (x - 12 != 0) unreachable; -} - -fn mul(a: u32, b: u32) u32 { - return a * b; -} - -const x = mul(3, 4); - -// run -// diff --git a/test/cases/multiplying_numbers_at_runtime_and_comptime.2.zig b/test/cases/multiplying_numbers_at_runtime_and_comptime.2.zig deleted file mode 100644 index 8afbc51f53..0000000000 --- a/test/cases/multiplying_numbers_at_runtime_and_comptime.2.zig +++ /dev/null @@ -1,13 +0,0 @@ -pub fn main() void { - var x: usize = 5; - _ = &x; - const y = mul(2, 3, x); - if (y - 30 != 0) unreachable; -} - -inline fn mul(a: usize, b: usize, c: usize) usize { - return a * b * c; -} - -// run -// diff --git a/test/cases/only_1_function_and_it_gets_updated.0.zig b/test/cases/only_1_function_and_it_gets_updated.0.zig deleted file mode 100644 index eada595db8..0000000000 --- a/test/cases/only_1_function_and_it_gets_updated.0.zig +++ /dev/null @@ -1,7 +0,0 @@ -pub export fn _start() noreturn { - while (true) {} -} - -// run -// target=x86_64-linux,x86_64-macos -// diff --git a/test/cases/only_1_function_and_it_gets_updated.1.zig b/test/cases/only_1_function_and_it_gets_updated.1.zig deleted file mode 100644 index 9982ca9ab8..0000000000 --- a/test/cases/only_1_function_and_it_gets_updated.1.zig +++ /dev/null @@ -1,8 +0,0 @@ -pub export fn _start() noreturn { - var dummy: u32 = 10; - _ = &dummy; - while (true) {} -} - -// run -// diff --git a/test/cases/optional_payload.0.zig b/test/cases/optional_payload.0.zig deleted file mode 100644 index 65296875ff..0000000000 --- a/test/cases/optional_payload.0.zig +++ /dev/null @@ -1,19 +0,0 @@ -pub fn main() void { - var x: u32 = undefined; - const maybe_x = byPtr(&x); - assert(maybe_x != null); - maybe_x.?.* = 123; - assert(x == 123); -} - -fn byPtr(x: *u32) ?*u32 { - return x; -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -// run -// target=x86_64-linux,x86_64-macos -// diff --git a/test/cases/optional_payload.1.zig b/test/cases/optional_payload.1.zig deleted file mode 100644 index 2d4dafffb9..0000000000 --- a/test/cases/optional_payload.1.zig +++ /dev/null @@ -1,17 +0,0 @@ -pub fn main() void { - var x: u32 = undefined; - const maybe_x = byPtr(&x); - assert(maybe_x == null); -} - -fn byPtr(x: *u32) ?*u32 { - _ = x; - return null; -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -// run -// diff --git a/test/cases/optional_payload.2.zig b/test/cases/optional_payload.2.zig deleted file mode 100644 index 608310923b..0000000000 --- a/test/cases/optional_payload.2.zig +++ /dev/null @@ -1,18 +0,0 @@ -pub fn main() void { - var x: u8 = undefined; - const maybe_x = byPtr(&x); - assert(maybe_x != null); - maybe_x.?.* = 255; - assert(x == 255); -} - -fn byPtr(x: *u8) ?*u8 { - return x; -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -// run -// diff --git a/test/cases/optional_payload.3.zig b/test/cases/optional_payload.3.zig deleted file mode 100644 index b81ec398c7..0000000000 --- a/test/cases/optional_payload.3.zig +++ /dev/null @@ -1,18 +0,0 @@ -pub fn main() void { - var x: i8 = undefined; - const maybe_x = byPtr(&x); - assert(maybe_x != null); - maybe_x.?.* = -1; - assert(x == -1); -} - -fn byPtr(x: *i8) ?*i8 { - return x; -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -// run -// diff --git a/test/cases/optionals.0.zig b/test/cases/optionals.0.zig deleted file mode 100644 index 49841ac593..0000000000 --- a/test/cases/optionals.0.zig +++ /dev/null @@ -1,13 +0,0 @@ -pub fn main() u8 { - var x: ?u8 = 5; - _ = &x; - var y: u8 = 0; - if (x) |val| { - y = val; - } - return y - 5; -} - -// run -// target=wasm32-wasi -// diff --git a/test/cases/optionals.1.zig b/test/cases/optionals.1.zig deleted file mode 100644 index 4bba10fc36..0000000000 --- a/test/cases/optionals.1.zig +++ /dev/null @@ -1,12 +0,0 @@ -pub fn main() u8 { - var x: ?u8 = null; - _ = &x; - var y: u8 = 0; - if (x) |val| { - y = val; - } - return y; -} - -// run -// diff --git a/test/cases/optionals.2.zig b/test/cases/optionals.2.zig deleted file mode 100644 index 0464db3542..0000000000 --- a/test/cases/optionals.2.zig +++ /dev/null @@ -1,8 +0,0 @@ -pub fn main() u8 { - var x: ?u8 = 5; - _ = &x; - return x.? - 5; -} - -// run -// diff --git a/test/cases/optionals.3.zig b/test/cases/optionals.3.zig deleted file mode 100644 index 849914fbb5..0000000000 --- a/test/cases/optionals.3.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() u8 { - var x: u8 = 5; - var y: ?u8 = x; - _ = .{ &x, &y }; - return y.? - 5; -} - -// run -// diff --git a/test/cases/optionals.4.zig b/test/cases/optionals.4.zig deleted file mode 100644 index af3400b322..0000000000 --- a/test/cases/optionals.4.zig +++ /dev/null @@ -1,13 +0,0 @@ -pub fn main() u8 { - var val: ?u8 = 5; - while (val) |*v| { - v.* -= 1; - if (v.* == 2) { - val = null; - } - } - return 0; -} - -// run -// diff --git a/test/cases/orelse_at_comptime.0.zig b/test/cases/orelse_at_comptime.0.zig deleted file mode 100644 index 5397ca3b0a..0000000000 --- a/test/cases/orelse_at_comptime.0.zig +++ /dev/null @@ -1,11 +0,0 @@ -pub fn main() void { - const i: ?u64 = 0; - const result = i orelse 5; - assert(result == 0); -} -fn assert(b: bool) void { - if (!b) unreachable; -} - -// run -// diff --git a/test/cases/orelse_at_comptime.1.zig b/test/cases/orelse_at_comptime.1.zig deleted file mode 100644 index 7d4fcd3178..0000000000 --- a/test/cases/orelse_at_comptime.1.zig +++ /dev/null @@ -1,11 +0,0 @@ -pub fn main() void { - const i: ?u64 = null; - const result = i orelse 5; - assert(result == 5); -} -fn assert(b: bool) void { - if (!b) unreachable; -} - -// run -// diff --git a/test/cases/parameters_and_return_values.0.zig b/test/cases/parameters_and_return_values.0.zig deleted file mode 100644 index bf07cf2921..0000000000 --- a/test/cases/parameters_and_return_values.0.zig +++ /dev/null @@ -1,20 +0,0 @@ -const std = @import("std"); - -pub fn main() void { - print(id(14)); -} - -fn id(x: u32) u32 { - return x; -} - -fn print(len: u32) void { - const str = "Hello, World!\n"; - _ = std.posix.write(1, str[0..len]) catch {}; -} - -// run -// target=x86_64-macos -// -// Hello, World! -// diff --git a/test/cases/parameters_and_return_values.1.zig b/test/cases/parameters_and_return_values.1.zig deleted file mode 100644 index f2bc35d22e..0000000000 --- a/test/cases/parameters_and_return_values.1.zig +++ /dev/null @@ -1,14 +0,0 @@ -pub fn main() void { - assert(add(1, 2, 3, 4, 5, 6) == 21); -} - -fn add(a: u32, b: u32, c: u32, d: u32, e: u32, f: u32) u32 { - return a + b + c + d + e + f; -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/pointers.0.zig b/test/cases/pointers.0.zig deleted file mode 100644 index 958ee5ac88..0000000000 --- a/test/cases/pointers.0.zig +++ /dev/null @@ -1,14 +0,0 @@ -pub fn main() u8 { - var x: u8 = 0; - - foo(&x); - return x - 2; -} - -fn foo(x: *u8) void { - x.* = 2; -} - -// run -// target=wasm32-wasi -// diff --git a/test/cases/pointers.1.zig b/test/cases/pointers.1.zig deleted file mode 100644 index b3649cf520..0000000000 --- a/test/cases/pointers.1.zig +++ /dev/null @@ -1,18 +0,0 @@ -pub fn main() u8 { - var x: u8 = 0; - - foo(&x); - bar(&x); - return x - 4; -} - -fn foo(x: *u8) void { - x.* = 2; -} - -fn bar(x: *u8) void { - x.* += 2; -} - -// run -// diff --git a/test/cases/redundant_comptime.0.zig b/test/cases/redundant_comptime.0.zig deleted file mode 100644 index c1ecbf7ace..0000000000 --- a/test/cases/redundant_comptime.0.zig +++ /dev/null @@ -1,7 +0,0 @@ -pub fn main() void { - var a: comptime u32 = 0; -} - -// error -// -// :2:12: error: redundant comptime keyword in already comptime scope diff --git a/test/cases/redundant_comptime.1.zig b/test/cases/redundant_comptime.1.zig deleted file mode 100644 index 79226ae8a6..0000000000 --- a/test/cases/redundant_comptime.1.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - comptime { - var a: u32 = comptime 0; - } -} - -// error -// -// :3:22: error: redundant comptime keyword in already comptime scope diff --git a/test/cases/spilling_registers.0.zig b/test/cases/spilling_registers.0.zig deleted file mode 100644 index eb580cf5d8..0000000000 --- a/test/cases/spilling_registers.0.zig +++ /dev/null @@ -1,38 +0,0 @@ -pub fn main() void { - assert(add(3, 4) == 791); -} - -fn add(a: u32, b: u32) u32 { - const x: u32 = blk: { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - const f = d + e; // 24 - const g = e + f; // 38 - const h = f + g; // 62 - const i = g + h; // 100 - const j = i + d; // 110 - const k = i + j; // 210 - const l = k + c; // 217 - const m = l + d; // 227 - const n = m + e; // 241 - const o = n + f; // 265 - const p = o + g; // 303 - const q = p + h; // 365 - const r = q + i; // 465 - const s = r + j; // 575 - const t = s + k; // 785 - break :blk t; - }; - const y = x + a; // 788 - const z = y + a; // 791 - return z; -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -// run -// target=x86_64-linux,x86_64-macos -// diff --git a/test/cases/spilling_registers.1.zig b/test/cases/spilling_registers.1.zig deleted file mode 100644 index f401a5d7b7..0000000000 --- a/test/cases/spilling_registers.1.zig +++ /dev/null @@ -1,37 +0,0 @@ -pub fn main() void { - assert(addMul(3, 4) == 357747496); -} - -fn addMul(a: u32, b: u32) u32 { - const x: u32 = blk: { - const c = a + b; // 7 - const d = a + c; // 10 - const e = d + b; // 14 - const f = d + e; // 24 - const g = e + f; // 38 - const h = f + g; // 62 - const i = g + h; // 100 - const j = i + d; // 110 - const k = i + j; // 210 - const l = k + c; // 217 - const m = l * d; // 2170 - const n = m + e; // 2184 - const o = n * f; // 52416 - const p = o + g; // 52454 - const q = p * h; // 3252148 - const r = q + i; // 3252248 - const s = r * j; // 357747280 - const t = s + k; // 357747490 - break :blk t; - }; - const y = x + a; // 357747493 - const z = y + a; // 357747496 - return z; -} - -fn assert(ok: bool) void { - if (!ok) unreachable; -} - -// run -// diff --git a/test/cases/structs.0.zig b/test/cases/structs.0.zig deleted file mode 100644 index 306cf73ebf..0000000000 --- a/test/cases/structs.0.zig +++ /dev/null @@ -1,11 +0,0 @@ -const Example = struct { x: u8 }; - -pub fn main() u8 { - var example: Example = .{ .x = 5 }; - _ = &example; - return example.x - 5; -} - -// run -// target=wasm32-wasi -// diff --git a/test/cases/structs.1.zig b/test/cases/structs.1.zig deleted file mode 100644 index 8d4250e4a2..0000000000 --- a/test/cases/structs.1.zig +++ /dev/null @@ -1,10 +0,0 @@ -const Example = struct { x: u8 }; - -pub fn main() u8 { - var example: Example = .{ .x = 5 }; - example.x = 10; - return example.x - 10; -} - -// run -// diff --git a/test/cases/structs.2.zig b/test/cases/structs.2.zig deleted file mode 100644 index 7593284301..0000000000 --- a/test/cases/structs.2.zig +++ /dev/null @@ -1,10 +0,0 @@ -const Example = struct { x: u8, y: u8 }; - -pub fn main() u8 { - var example: Example = .{ .x = 5, .y = 10 }; - _ = &example; - return example.y + example.x - 15; -} - -// run -// diff --git a/test/cases/structs.3.zig b/test/cases/structs.3.zig deleted file mode 100644 index cfc064d671..0000000000 --- a/test/cases/structs.3.zig +++ /dev/null @@ -1,13 +0,0 @@ -const Example = struct { x: u8, y: u8 }; - -pub fn main() u8 { - var example: Example = .{ .x = 5, .y = 10 }; - var example2: Example = .{ .x = 10, .y = 20 }; - _ = &example2; - - example = example2; - return example.y + example.x - 30; -} - -// run -// diff --git a/test/cases/structs.4.zig b/test/cases/structs.4.zig deleted file mode 100644 index 2d37446c56..0000000000 --- a/test/cases/structs.4.zig +++ /dev/null @@ -1,11 +0,0 @@ -const Example = struct { x: u8, y: u8 }; - -pub fn main() u8 { - var example: Example = .{ .x = 5, .y = 10 }; - - example = .{ .x = 10, .y = 20 }; - return example.y + example.x - 30; -} - -// run -// diff --git a/test/cases/switch.0.zig b/test/cases/switch.0.zig deleted file mode 100644 index f4a79fa772..0000000000 --- a/test/cases/switch.0.zig +++ /dev/null @@ -1,16 +0,0 @@ -pub fn main() u8 { - var val: u8 = 1; - _ = &val; - const a: u8 = switch (val) { - 0, 1 => 2, - 2 => 3, - 3 => 4, - else => 5, - }; - - return a - 2; -} - -// run -// target=wasm32-wasi -// diff --git a/test/cases/switch.1.zig b/test/cases/switch.1.zig deleted file mode 100644 index d93e1ccb47..0000000000 --- a/test/cases/switch.1.zig +++ /dev/null @@ -1,16 +0,0 @@ -pub fn main() u8 { - var val: u8 = 2; - _ = &val; - var a: u8 = switch (val) { - 0, 1 => 2, - 2 => 3, - 3 => 4, - else => 5, - }; - _ = &a; - - return a - 3; -} - -// run -// diff --git a/test/cases/switch.2.zig b/test/cases/switch.2.zig deleted file mode 100644 index 1506d822d1..0000000000 --- a/test/cases/switch.2.zig +++ /dev/null @@ -1,15 +0,0 @@ -pub fn main() u8 { - var val: u8 = 10; - _ = &val; - const a: u8 = switch (val) { - 0, 1 => 2, - 2 => 3, - 3 => 4, - else => 5, - }; - - return a - 5; -} - -// run -// diff --git a/test/cases/switch.3.zig b/test/cases/switch.3.zig deleted file mode 100644 index 6225dda3ff..0000000000 --- a/test/cases/switch.3.zig +++ /dev/null @@ -1,16 +0,0 @@ -const MyEnum = enum { One, Two, Three }; - -pub fn main() u8 { - var val: MyEnum = .Two; - _ = &val; - const a: u8 = switch (val) { - .One => 1, - .Two => 2, - .Three => 3, - }; - - return a - 2; -} - -// run -// diff --git a/test/cases/type_of.0.zig b/test/cases/type_of.0.zig deleted file mode 100644 index 823572c863..0000000000 --- a/test/cases/type_of.0.zig +++ /dev/null @@ -1,13 +0,0 @@ -pub fn main() void { - var x: usize = 0; - _ = &x; - const z = @TypeOf(x, @as(u128, 5)); - assert(z == u128); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/type_of.1.zig b/test/cases/type_of.1.zig deleted file mode 100644 index 86d7d87a19..0000000000 --- a/test/cases/type_of.1.zig +++ /dev/null @@ -1,11 +0,0 @@ -pub fn main() void { - const z = @TypeOf(true); - assert(z == bool); -} - -pub fn assert(ok: bool) void { - if (!ok) unreachable; // assertion failure -} - -// run -// diff --git a/test/cases/type_of.2.zig b/test/cases/type_of.2.zig deleted file mode 100644 index cdbc8121fd..0000000000 --- a/test/cases/type_of.2.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - _ = @TypeOf(true, 1); -} - -// error -// -// :2:9: error: incompatible types: 'bool' and 'comptime_int' -// :2:17: note: type 'bool' here -// :2:23: note: type 'comptime_int' here diff --git a/test/cases/unused_labels.0.zig b/test/cases/unused_labels.0.zig deleted file mode 100644 index 9afa5facdd..0000000000 --- a/test/cases/unused_labels.0.zig +++ /dev/null @@ -1,8 +0,0 @@ -comptime { - foo: {} -} - -// error -// output_mode=Exe -// -// :2:5: error: unused block label diff --git a/test/cases/unused_labels.1.zig b/test/cases/unused_labels.1.zig deleted file mode 100644 index c7ff576875..0000000000 --- a/test/cases/unused_labels.1.zig +++ /dev/null @@ -1,7 +0,0 @@ -comptime { - foo: while (true) {} -} - -// error -// -// :2:5: error: unused while loop label diff --git a/test/cases/unused_labels.2.zig b/test/cases/unused_labels.2.zig deleted file mode 100644 index babe3c7b0a..0000000000 --- a/test/cases/unused_labels.2.zig +++ /dev/null @@ -1,7 +0,0 @@ -comptime { - foo: for ("foo") |_| {} -} - -// error -// -// :2:5: error: unused for loop label diff --git a/test/cases/unused_labels.3.zig b/test/cases/unused_labels.3.zig deleted file mode 100644 index 36c9aa2319..0000000000 --- a/test/cases/unused_labels.3.zig +++ /dev/null @@ -1,10 +0,0 @@ -comptime { - blk: { - blk: {} - } -} - -// error -// -// :2:11: error: redefinition of label 'blk' -// :2:5: note: previous definition here diff --git a/test/cases/variable_shadowing.0.zig b/test/cases/variable_shadowing.0.zig deleted file mode 100644 index accfda758f..0000000000 --- a/test/cases/variable_shadowing.0.zig +++ /dev/null @@ -1,11 +0,0 @@ -pub fn main() void { - var i: u32 = 10; - var i: u32 = 10; -} - -// error -// backend=stage2 -// target=x86_64-linux,x86_64-macos -// -// :3:9: error: redeclaration of local variable 'i' -// :2:9: note: previous declaration here diff --git a/test/cases/variable_shadowing.1.zig b/test/cases/variable_shadowing.1.zig deleted file mode 100644 index 2a2945a65f..0000000000 --- a/test/cases/variable_shadowing.1.zig +++ /dev/null @@ -1,9 +0,0 @@ -var testing: i64 = 10; -pub fn main() void { - var testing: i64 = 20; -} - -// error -// -// :3:9: error: local variable shadows declaration of 'testing' -// :1:1: note: declared here diff --git a/test/cases/variable_shadowing.10.zig b/test/cases/variable_shadowing.10.zig deleted file mode 100644 index 6aa9f5a9bf..0000000000 --- a/test/cases/variable_shadowing.10.zig +++ /dev/null @@ -1,9 +0,0 @@ -fn foo() !void { - var i: anyerror!usize = 1; - _ = i catch |i| return i; -} - -// error -// -// :3:18: error: redeclaration of local variable 'i' -// :2:9: note: previous declaration here diff --git a/test/cases/variable_shadowing.2.zig b/test/cases/variable_shadowing.2.zig deleted file mode 100644 index a44372f9b9..0000000000 --- a/test/cases/variable_shadowing.2.zig +++ /dev/null @@ -1,13 +0,0 @@ -fn a() type { - return struct { - pub fn b() void { - const c = 6; - const c = 69; - } - }; -} - -// error -// -// :5:19: error: redeclaration of local constant 'c' -// :4:19: note: previous declaration here diff --git a/test/cases/variable_shadowing.3.zig b/test/cases/variable_shadowing.3.zig deleted file mode 100644 index af16bccc14..0000000000 --- a/test/cases/variable_shadowing.3.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var i = 0; - for ("n", 0..) |_, i| {} -} - -// error -// -// :3:24: error: capture 'i' shadows local variable from outer scope -// :2:9: note: previous declaration here diff --git a/test/cases/variable_shadowing.4.zig b/test/cases/variable_shadowing.4.zig deleted file mode 100644 index 3653c2457d..0000000000 --- a/test/cases/variable_shadowing.4.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var i = 0; - for ("n") |i| {} -} - -// error -// -// :3:16: error: capture 'i' shadows local variable from outer scope -// :2:9: note: previous declaration here diff --git a/test/cases/variable_shadowing.5.zig b/test/cases/variable_shadowing.5.zig deleted file mode 100644 index 78247e68fe..0000000000 --- a/test/cases/variable_shadowing.5.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var i = 0; - while ("n") |i| {} -} - -// error -// -// :3:18: error: capture 'i' shadows local variable from outer scope -// :2:9: note: previous declaration here diff --git a/test/cases/variable_shadowing.6.zig b/test/cases/variable_shadowing.6.zig deleted file mode 100644 index a3ae7bc346..0000000000 --- a/test/cases/variable_shadowing.6.zig +++ /dev/null @@ -1,11 +0,0 @@ -pub fn main() void { - var i = 0; - while ("n") |bruh| { - _ = bruh; - } else |i| {} -} - -// error -// -// :5:13: error: capture 'i' shadows local variable from outer scope -// :2:9: note: previous declaration here diff --git a/test/cases/variable_shadowing.7.zig b/test/cases/variable_shadowing.7.zig deleted file mode 100644 index e8368699b4..0000000000 --- a/test/cases/variable_shadowing.7.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var i = 0; - if (true) |i| {} -} - -// error -// -// :3:16: error: capture 'i' shadows local variable from outer scope -// :2:9: note: previous declaration here diff --git a/test/cases/variable_shadowing.8.zig b/test/cases/variable_shadowing.8.zig deleted file mode 100644 index 1a3f560589..0000000000 --- a/test/cases/variable_shadowing.8.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var i = 0; - if (true) |i| {} else |e| {} -} - -// error -// -// :3:16: error: capture 'i' shadows local variable from outer scope -// :2:9: note: previous declaration here diff --git a/test/cases/variable_shadowing.9.zig b/test/cases/variable_shadowing.9.zig deleted file mode 100644 index 28e2b16834..0000000000 --- a/test/cases/variable_shadowing.9.zig +++ /dev/null @@ -1,9 +0,0 @@ -pub fn main() void { - var i = 0; - if (true) |_| {} else |i| {} -} - -// error -// -// :3:28: error: capture 'i' shadows local variable from outer scope -// :2:9: note: previous declaration here diff --git a/test/cases/while_loops.0.zig b/test/cases/while_loops.0.zig deleted file mode 100644 index 721b127ff5..0000000000 --- a/test/cases/while_loops.0.zig +++ /dev/null @@ -1,12 +0,0 @@ -pub fn main() u8 { - var i: u8 = 0; - while (i < @as(u8, 5)) { - i += 1; - } - - return i - 5; -} - -// run -// target=wasm32-wasi -// diff --git a/test/cases/while_loops.1.zig b/test/cases/while_loops.1.zig deleted file mode 100644 index 283398adbc..0000000000 --- a/test/cases/while_loops.1.zig +++ /dev/null @@ -1,12 +0,0 @@ -pub fn main() u8 { - var i: u8 = 0; - while (i < @as(u8, 10)) { - var x: u8 = 1; - _ = &x; - i += x; - } - return i - 10; -} - -// run -// diff --git a/test/cases/while_loops.2.zig b/test/cases/while_loops.2.zig deleted file mode 100644 index fa4f9ed26c..0000000000 --- a/test/cases/while_loops.2.zig +++ /dev/null @@ -1,13 +0,0 @@ -pub fn main() u8 { - var i: u8 = 0; - while (i < @as(u8, 10)) { - var x: u8 = 1; - _ = &x; - i += x; - if (i == @as(u8, 5)) break; - } - return i - 5; -} - -// run -// diff --git a/test/cases/x86_64-linux/inline_assembly.0.zig b/test/cases/x86_64-linux/inline_assembly.0.zig deleted file mode 100644 index 8356e05d80..0000000000 --- a/test/cases/x86_64-linux/inline_assembly.0.zig +++ /dev/null @@ -1,16 +0,0 @@ -pub fn main() void { - const number = 1234; - const x = asm volatile ("syscall" - : [o] "{rax}" (-> number), - : [number] "{rax}" (231), - [arg1] "{rdi}" (60), - : "rcx", "r11", "memory" - ); - _ = x; -} - -// error -// output_mode=Exe -// target=x86_64-linux -// -// :4:27: error: expected type 'type', found 'comptime_int' diff --git a/test/cases/x86_64-linux/inline_assembly.1.zig b/test/cases/x86_64-linux/inline_assembly.1.zig deleted file mode 100644 index b35014b0f6..0000000000 --- a/test/cases/x86_64-linux/inline_assembly.1.zig +++ /dev/null @@ -1,15 +0,0 @@ -const S = struct { - comptime { - asm volatile ( - \\zig_moment: - \\syscall - ); - } -}; -pub fn main() void { - _ = S; -} - -// error -// -// :3:13: error: volatile is meaningless on global assembly diff --git a/test/cases/x86_64-linux/inline_assembly.2.zig b/test/cases/x86_64-linux/inline_assembly.2.zig deleted file mode 100644 index 7958d0df71..0000000000 --- a/test/cases/x86_64-linux/inline_assembly.2.zig +++ /dev/null @@ -1,12 +0,0 @@ -pub fn main() void { - var bruh: u32 = 1; - asm ("" - : - : [bruh] "{rax}" (4), - : "memory" - ); -} - -// error -// -// :3:5: error: assembly expression with no output must be marked volatile diff --git a/test/cases/x86_64-linux/inline_assembly.3.zig b/test/cases/x86_64-linux/inline_assembly.3.zig deleted file mode 100644 index a6f57e832a..0000000000 --- a/test/cases/x86_64-linux/inline_assembly.3.zig +++ /dev/null @@ -1,12 +0,0 @@ -pub fn main() void {} -comptime { - asm ("" - : - : [bruh] "{rax}" (4), - : "memory" - ); -} - -// error -// -// :3:5: error: global assembly cannot have inputs, outputs, or clobbers diff --git a/test/incremental/change_fn_type b/test/incremental/change_fn_type new file mode 100644 index 0000000000..892d0dd9b6 --- /dev/null +++ b/test/incremental/change_fn_type @@ -0,0 +1,35 @@ +#target=x86_64-linux-selfhosted +#target=x86_64-linux-cbe +#target=x86_64-windows-cbe +#update=initial version +#file=main.zig +pub fn main() !void { + try foo(123); +} +fn foo(x: u8) !void { + return std.io.getStdOut().writer().print("{d}\n", .{x}); +} +const std = @import("std"); +#expect_stdout="123\n" + +#update=change function type +#file=main.zig +pub fn main() !void { + try foo(123); +} +fn foo(x: i64) !void { + return std.io.getStdOut().writer().print("{d}\n", .{x}); +} +const std = @import("std"); +#expect_stdout="123\n" + +#update=change function argument +#file=main.zig +pub fn main() !void { + try foo(-42); +} +fn foo(x: i64) !void { + return std.io.getStdOut().writer().print("{d}\n", .{x}); +} +const std = @import("std"); +#expect_stdout="-42\n" diff --git a/test/incremental/change_shift_op b/test/incremental/change_shift_op new file mode 100644 index 0000000000..bd88a70def --- /dev/null +++ b/test/incremental/change_shift_op @@ -0,0 +1,23 @@ +#target=x86_64-linux-selfhosted +#target=x86_64-linux-cbe +#target=x86_64-windows-cbe +#update=initial version +#file=main.zig +pub fn main() !void { + try foo(0x1300); +} +fn foo(x: u16) !void { + try std.io.getStdOut().writer().print("0x{x}\n", .{x << 4}); +} +const std = @import("std"); +#expect_stdout="0x3000\n" +#update=change to right shift +#file=main.zig +pub fn main() !void { + try foo(0x1300); +} +fn foo(x: u16) !void { + try std.io.getStdOut().writer().print("0x{x}\n", .{x >> 4}); +} +const std = @import("std"); +#expect_stdout="0x130\n" diff --git a/test/incremental/change_struct_same_fields b/test/incremental/change_struct_same_fields new file mode 100644 index 0000000000..f742bab870 --- /dev/null +++ b/test/incremental/change_struct_same_fields @@ -0,0 +1,50 @@ +#target=x86_64-linux-selfhosted +#target=x86_64-linux-cbe +#target=x86_64-windows-cbe +#update=initial version +#file=main.zig +const S = extern struct { x: u8, y: u8 }; +pub fn main() !void { + const val: S = .{ .x = 100, .y = 200 }; + try foo(&val); +} +fn foo(val: *const S) !void { + try std.io.getStdOut().writer().print( + "{d} {d}\n", + .{ val.x, val.y }, + ); +} +const std = @import("std"); +#expect_stdout="100 200\n" + +#update=change struct layout +#file=main.zig +const S = extern struct { x: u32, y: u32 }; +pub fn main() !void { + const val: S = .{ .x = 100, .y = 200 }; + try foo(&val); +} +fn foo(val: *const S) !void { + try std.io.getStdOut().writer().print( + "{d} {d}\n", + .{ val.x, val.y }, + ); +} +const std = @import("std"); +#expect_stdout="100 200\n" + +#update=change values +#file=main.zig +const S = extern struct { x: u32, y: u32 }; +pub fn main() !void { + const val: S = .{ .x = 1234, .y = 5678 }; + try foo(&val); +} +fn foo(val: *const S) !void { + try std.io.getStdOut().writer().print( + "{d} {d}\n", + .{ val.x, val.y }, + ); +} +const std = @import("std"); +#expect_stdout="1234 5678\n" diff --git a/test/incremental/compile_error_then_log b/test/incremental/compile_error_then_log new file mode 100644 index 0000000000..00ccef9290 --- /dev/null +++ b/test/incremental/compile_error_then_log @@ -0,0 +1,21 @@ +#target=x86_64-linux-selfhosted +#target=x86_64-linux-cbe +#target=x86_64-windows-cbe +#update=initial version with compile error +#file=main.zig +comptime { + @compileError("this is an error"); +} +comptime { + @compileLog("this is a log"); +} +#expect_error=ignored +#update=remove the compile error +#file=main.zig +comptime { + //@compileError("this is an error"); +} +comptime { + @compileLog("this is a log"); +} +#expect_error=ignored diff --git a/test/incremental/function_becomes_inline b/test/incremental/function_becomes_inline new file mode 100644 index 0000000000..b7e604bfac --- /dev/null +++ b/test/incremental/function_becomes_inline @@ -0,0 +1,35 @@ +//#target=x86_64-linux-selfhosted +#target=x86_64-linux-cbe +#target=x86_64-windows-cbe +#update=non-inline version +#file=main.zig +pub fn main() !void { + try foo(); +} +fn foo() !void { + try std.io.getStdOut().writer().writeAll("Hello, World!\n"); +} +const std = @import("std"); +#expect_stdout="Hello, World!\n" + +#update=make function inline +#file=main.zig +pub fn main() !void { + try foo(); +} +inline fn foo() !void { + try std.io.getStdOut().writer().writeAll("Hello, World!\n"); +} +const std = @import("std"); +#expect_stdout="Hello, World!\n" + +#update=change string +#file=main.zig +pub fn main() !void { + try foo(); +} +inline fn foo() !void { + try std.io.getStdOut().writer().writeAll("Hello, `inline` World!\n"); +} +const std = @import("std"); +#expect_stdout="Hello, `inline` World!\n" diff --git a/test/incremental/recursive_function_becomes_non_recursive b/test/incremental/recursive_function_becomes_non_recursive new file mode 100644 index 0000000000..7a9eb5d26f --- /dev/null +++ b/test/incremental/recursive_function_becomes_non_recursive @@ -0,0 +1,28 @@ +//#target=x86_64-linux-selfhosted +#target=x86_64-linux-cbe +#target=x86_64-windows-cbe +#update=initial version +#file=main.zig +pub fn main() !void { + try foo(false); +} +fn foo(recurse: bool) !void { + const stdout = std.io.getStdOut().writer(); + if (recurse) return foo(true); + try stdout.writeAll("non-recursive path\n"); +} +const std = @import("std"); +#expect_stdout="non-recursive path\n" + +#update=eliminate recursion and change argument +#file=main.zig +pub fn main() !void { + try foo(true); +} +fn foo(recurse: bool) !void { + const stdout = std.io.getStdOut().writer(); + if (recurse) return stdout.writeAll("x==1\n"); + try stdout.writeAll("non-recursive path\n"); +} +const std = @import("std"); +#expect_stdout="x==1\n"