authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-29 08:24:02+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-04-29 08:24:02+02:00
log3b8187072fc76966da9d9ab1a6a0ecd7aff4e090
treea998ecb0837408b309851b558b7eb5f2d5d42dbe
parentfda143d5d81da852af73386a2100e18784bd0d3c
parentd25f06a71c058aa4ff8bf40749345028bda6e017
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #11530 from ziglang/test-harness

test: move compare and run tests to new test harness

964 files changed, 6901 insertions(+), 5757 deletions(-)

ci/zinc/linux_test.sh+1-1
...@@ -45,7 +45,7 @@ cd $WORKSPACE...@@ -45,7 +45,7 @@ cd $WORKSPACE
4545
46# Look for non-conforming code formatting.46# Look for non-conforming code formatting.
47# Formatting errors can be fixed by running `zig fmt` on the files printed here.47# Formatting errors can be fixed by running `zig fmt` on the files printed here.
48$ZIG fmt --check . --exclude test/compile_errors/48$ZIG fmt --check . --exclude test/compile_errors/ --exclude test/incremental/
4949
50# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.50# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.
51$ZIG build -p stage2 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"51$ZIG build -p stage2 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
src/test.zig+359-143
...@@ -34,42 +34,28 @@ test {...@@ -34,42 +34,28 @@ test {
34 var ctx = TestContext.init(std.testing.allocator, arena);34 var ctx = TestContext.init(std.testing.allocator, arena);
35 defer ctx.deinit();35 defer ctx.deinit();
3636
37 const compile_errors_dir_path = try std.fs.path.join(arena, &.{
38 std.fs.path.dirname(@src().file).?, "..", "test", "compile_errors",
39 });
40
41 var compile_errors_dir = try std.fs.cwd().openDir(compile_errors_dir_path, .{});
42 defer compile_errors_dir.close();
43
44 {37 {
45 var stage2_dir = try compile_errors_dir.openDir("stage2", .{ .iterate = true });38 const dir_path = try std.fs.path.join(arena, &.{
46 defer stage2_dir.close();39 std.fs.path.dirname(@src().file).?, "..", "test", "compile_errors",
40 });
41
42 var dir = try std.fs.cwd().openDir(dir_path, .{ .iterate = true });
43 defer dir.close();
4744
48 // TODO make this incremental once the bug is solved that it triggers45 // TODO make this incremental once the bug is solved that it triggers
49 // See: https://github.com/ziglang/zig/issues/1134446 // See: https://github.com/ziglang/zig/issues/11344
50 ctx.addErrorCasesFromDir("stage2", stage2_dir, .stage2, .Obj, false, .independent);47 ctx.addTestCasesFromDir(dir, .independent);
51 }48 }
5249
53 if (!skip_stage1) {50 {
54 var stage1_dir = try compile_errors_dir.openDir("stage1", .{});51 const dir_path = try std.fs.path.join(arena, &.{
55 defer stage1_dir.close();52 std.fs.path.dirname(@src().file).?, "..", "test", "incremental",
5653 });
57 const Config = struct {
58 name: []const u8,
59 is_test: bool,
60 output_mode: std.builtin.OutputMode,
61 };
6254
63 for ([_]Config{55 var dir = try std.fs.cwd().openDir(dir_path, .{ .iterate = true });
64 .{ .name = "obj", .is_test = false, .output_mode = .Obj },56 defer dir.close();
65 .{ .name = "exe", .is_test = false, .output_mode = .Exe },
66 .{ .name = "test", .is_test = true, .output_mode = .Exe },
67 }) |config| {
68 var dir = try stage1_dir.openDir(config.name, .{ .iterate = true });
69 defer dir.close();
7057
71 ctx.addErrorCasesFromDir("stage1", dir, .stage1, config.output_mode, config.is_test, .independent);58 ctx.addTestCasesFromDir(dir, .incremental);
72 }
73 }59 }
7460
75 try @import("test_cases").addCases(&ctx);61 try @import("test_cases").addCases(&ctx);
...@@ -154,6 +140,261 @@ const ErrorMsg = union(enum) {...@@ -154,6 +140,261 @@ const ErrorMsg = union(enum) {
154 }140 }
155};141};
156142
143/// Default config values for known test manifest key-value pairings.
144/// Currently handled defaults are:
145/// * backend
146/// * target
147/// * output_mode
148/// * is_test
149const TestManifestConfigDefaults = struct {
150 /// Asserts if the key doesn't exist - yep, it's an oversight alright.
151 fn get(@"type": TestManifest.Type, key: []const u8) []const u8 {
152 if (std.mem.eql(u8, key, "backend")) {
153 return "stage2";
154 } else if (std.mem.eql(u8, key, "target")) {
155 comptime {
156 var defaults: []const u8 = "";
157 // TODO should we only return "mainstream" targets by default here?
158 // TODO we should also specify ABIs explicitly as the backends are
159 // getting more and more complete
160 // Linux
161 inline for (&[_][]const u8{ "x86_64", "arm", "aarch64" }) |arch| {
162 defaults = defaults ++ arch ++ "-linux" ++ ",";
163 }
164 // macOS
165 inline for (&[_][]const u8{ "x86_64", "aarch64" }) |arch| {
166 defaults = defaults ++ arch ++ "-macos" ++ ",";
167 }
168 // Wasm
169 defaults = defaults ++ "wasm32-wasi";
170 return defaults;
171 }
172 } else if (std.mem.eql(u8, key, "output_mode")) {
173 return switch (@"type") {
174 .@"error" => "Obj",
175 .run => "Exe",
176 .cli => @panic("TODO test harness for CLI tests"),
177 };
178 } else if (std.mem.eql(u8, key, "is_test")) {
179 return "0";
180 } else unreachable;
181 }
182};
183
184/// Manifest syntax example:
185/// (see https://github.com/ziglang/zig/issues/11288)
186///
187/// error
188/// backend=stage1,stage2
189/// output_mode=exe
190///
191/// :3:19: error: foo
192///
193/// run
194/// target=x86_64-linux,aarch64-macos
195///
196/// I am expected stdout! Hello!
197///
198/// cli
199///
200/// build test
201const TestManifest = struct {
202 @"type": Type,
203 config_map: std.StringHashMap([]const u8),
204 trailing_bytes: []const u8 = "",
205
206 const Type = enum {
207 @"error",
208 run,
209 cli,
210 };
211
212 const TrailingIterator = struct {
213 inner: std.mem.TokenIterator(u8),
214
215 fn next(self: *TrailingIterator) ?[]const u8 {
216 const next_inner = self.inner.next() orelse return null;
217 return std.mem.trim(u8, next_inner[2..], " \t");
218 }
219 };
220
221 fn ConfigValueIterator(comptime T: type) type {
222 return struct {
223 inner: std.mem.SplitIterator(u8),
224 parse_fn: ParseFn(T),
225
226 fn next(self: *@This()) ?T {
227 const next_raw = self.inner.next() orelse return null;
228 return self.parse_fn(next_raw);
229 }
230 };
231 }
232
233 fn parse(arena: Allocator, bytes: []const u8) !TestManifest {
234 // The manifest is the last contiguous block of comments in the file
235 // We scan for the beginning by searching backward for the first non-empty line that does not start with "//"
236 var start: ?usize = null;
237 var end: usize = bytes.len;
238 if (bytes.len > 0) {
239 var cursor: usize = bytes.len - 1;
240 while (true) {
241 // Move to beginning of line
242 while (cursor > 0 and bytes[cursor - 1] != '\n') cursor -= 1;
243
244 if (std.mem.startsWith(u8, bytes[cursor..], "//")) {
245 start = cursor; // Contiguous comment line, include in manifest
246 } else {
247 if (start != null) break; // Encountered non-comment line, end of manifest
248
249 // We ignore all-whitespace lines following the comment block, but anything else
250 // means that there is no manifest present.
251 if (std.mem.trim(u8, bytes[cursor..end], " \r\n\t").len == 0) {
252 end = cursor;
253 } else break; // If it's not whitespace, there is no manifest
254 }
255
256 // Move to previous line
257 if (cursor != 0) cursor -= 1 else break;
258 }
259 }
260
261 const actual_start = start orelse return error.MissingTestManifest;
262 const manifest_bytes = bytes[actual_start..end];
263
264 var it = std.mem.tokenize(u8, manifest_bytes, "\r\n");
265
266 // First line is the test type
267 const tt: Type = blk: {
268 const line = it.next() orelse return error.MissingTestCaseType;
269 const raw = std.mem.trim(u8, line[2..], " \t");
270 if (std.mem.eql(u8, raw, "error")) {
271 break :blk .@"error";
272 } else if (std.mem.eql(u8, raw, "run")) {
273 break :blk .run;
274 } else if (std.mem.eql(u8, raw, "cli")) {
275 break :blk .cli;
276 } else {
277 std.log.warn("unknown test case type requested: {s}", .{raw});
278 return error.UnknownTestCaseType;
279 }
280 };
281
282 var manifest: TestManifest = .{
283 .@"type" = tt,
284 .config_map = std.StringHashMap([]const u8).init(arena),
285 };
286
287 // Any subsequent line until a blank comment line is key=value(s) pair
288 while (it.next()) |line| {
289 const trimmed = std.mem.trim(u8, line[2..], " \t");
290 if (trimmed.len == 0) break;
291
292 // Parse key=value(s)
293 var kv_it = std.mem.split(u8, trimmed, "=");
294 const key = kv_it.next() orelse return error.MissingKeyForConfig;
295 try manifest.config_map.putNoClobber(key, kv_it.next() orelse return error.MissingValuesForConfig);
296 }
297
298 // Finally, trailing is expected output
299 manifest.trailing_bytes = manifest_bytes[it.index..];
300
301 return manifest;
302 }
303
304 fn getConfigForKeyCustomParser(
305 self: TestManifest,
306 key: []const u8,
307 comptime T: type,
308 parse_fn: ParseFn(T),
309 ) ConfigValueIterator(T) {
310 const bytes = self.config_map.get(key) orelse TestManifestConfigDefaults.get(self.@"type", key);
311 return ConfigValueIterator(T){
312 .inner = std.mem.split(u8, bytes, ","),
313 .parse_fn = parse_fn,
314 };
315 }
316
317 fn getConfigForKey(
318 self: TestManifest,
319 key: []const u8,
320 comptime T: type,
321 ) ConfigValueIterator(T) {
322 return self.getConfigForKeyCustomParser(key, T, getDefaultParser(T));
323 }
324
325 fn getConfigForKeyAlloc(
326 self: TestManifest,
327 allocator: Allocator,
328 key: []const u8,
329 comptime T: type,
330 ) error{OutOfMemory}![]const T {
331 var out = std.ArrayList(T).init(allocator);
332 defer out.deinit();
333 var it = self.getConfigForKey(key, T);
334 while (it.next()) |item| {
335 try out.append(item);
336 }
337 return out.toOwnedSlice();
338 }
339
340 fn getConfigForKeyAssertSingle(self: TestManifest, key: []const u8, comptime T: type) T {
341 var it = self.getConfigForKey(key, T);
342 const res = it.next().?;
343 assert(it.next() == null);
344 return res;
345 }
346
347 fn trailing(self: TestManifest) TrailingIterator {
348 return .{
349 .inner = std.mem.tokenize(u8, self.trailing_bytes, "\r\n"),
350 };
351 }
352
353 fn trailingAlloc(self: TestManifest, allocator: Allocator) error{OutOfMemory}![]const []const u8 {
354 var out = std.ArrayList([]const u8).init(allocator);
355 defer out.deinit();
356 var it = self.trailing();
357 while (it.next()) |line| {
358 try out.append(line);
359 }
360 return out.toOwnedSlice();
361 }
362
363 fn ParseFn(comptime T: type) type {
364 return fn ([]const u8) ?T;
365 }
366
367 fn getDefaultParser(comptime T: type) ParseFn(T) {
368 switch (@typeInfo(T)) {
369 .Int => return struct {
370 fn parse(str: []const u8) ?T {
371 return std.fmt.parseInt(T, str, 0) catch null;
372 }
373 }.parse,
374 .Bool => return struct {
375 fn parse(str: []const u8) ?T {
376 const as_int = std.fmt.parseInt(u1, str, 0) catch return null;
377 return as_int > 0;
378 }
379 }.parse,
380 .Enum => return struct {
381 fn parse(str: []const u8) ?T {
382 return std.meta.stringToEnum(T, str);
383 }
384 }.parse,
385 .Struct => if (comptime std.mem.eql(u8, @typeName(T), "CrossTarget")) return struct {
386 fn parse(str: []const u8) ?T {
387 var opts = CrossTarget.ParseOptions{
388 .arch_os_abi = str,
389 };
390 return CrossTarget.parse(opts) catch null;
391 }
392 }.parse else @compileError("no default parser for " ++ @typeName(T)),
393 else => @compileError("no default parser for " ++ @typeName(T)),
394 }
395 }
396};
397
157pub const TestContext = struct {398pub const TestContext = struct {
158 arena: Allocator,399 arena: Allocator,
159 cases: std.ArrayList(Case),400 cases: std.ArrayList(Case),
...@@ -663,26 +904,15 @@ pub const TestContext = struct {...@@ -663,26 +904,15 @@ pub const TestContext = struct {
663 incremental,904 incremental,
664 };905 };
665906
666 /// Adds a compile-error test for each file in the provided directory, using the907 /// Adds a test for each file in the provided directory, using the selected strategy.
667 /// selected backend and output mode. If `one_test_case_per_file` is true, a new908 /// Recurses nested directories.
668 /// test case is created for each file. Otherwise, a single test case is used for
669 /// all tests.
670 ///909 ///
671 /// Each file should include a test manifest as a contiguous block of comments at910 /// Each file should include a test manifest as a contiguous block of comments at
672 /// the end of the file. The first line should be the test case name, followed by911 /// the end of the file. The first line should be the test type, followed by a set of
673 /// a blank line, then one expected errors on each line in the form912 /// key-value config values, followed by a blank line, then the expected output.
674 /// `:line:column: error: message`913 pub fn addTestCasesFromDir(ctx: *TestContext, dir: std.fs.Dir, strategy: Strategy) void {
675 pub fn addErrorCasesFromDir(
676 ctx: *TestContext,
677 name: []const u8,
678 dir: std.fs.Dir,
679 backend: Backend,
680 output_mode: std.builtin.OutputMode,
681 is_test: bool,
682 strategy: Strategy,
683 ) void {
684 var current_file: []const u8 = "none";914 var current_file: []const u8 = "none";
685 addErrorCasesFromDirInner(ctx, name, dir, backend, output_mode, is_test, strategy, &current_file) catch |err| {915 ctx.addTestCasesFromDirInner(dir, strategy, &current_file) catch |err| {
686 std.debug.panic("test harness failed to process file '{s}': {s}\n", .{916 std.debug.panic("test harness failed to process file '{s}': {s}\n", .{
687 current_file, @errorName(err),917 current_file, @errorName(err),
688 });918 });
...@@ -749,33 +979,28 @@ pub const TestContext = struct {...@@ -749,33 +979,28 @@ pub const TestContext = struct {
749 std.sort.sort([]const u8, filenames, Context{}, Context.lessThan);979 std.sort.sort([]const u8, filenames, Context{}, Context.lessThan);
750 }980 }
751981
752 fn addErrorCasesFromDirInner(982 fn addTestCasesFromDirInner(
753 ctx: *TestContext,983 ctx: *TestContext,
754 name: []const u8,
755 dir: std.fs.Dir,984 dir: std.fs.Dir,
756 backend: Backend,
757 output_mode: std.builtin.OutputMode,
758 is_test: bool,
759 strategy: Strategy,985 strategy: Strategy,
760 /// This is kept up to date with the currently being processed file so986 /// This is kept up to date with the currently being processed file so
761 /// that if any errors occur the caller knows it happened during this file.987 /// that if any errors occur the caller knows it happened during this file.
762 current_file: *[]const u8,988 current_file: *[]const u8,
763 ) !void {989 ) !void {
764 var opt_case: ?*Case = null;990 var cases = std.ArrayList(usize).init(ctx.arena);
765991
766 var it = dir.iterate();992 var it = try dir.walk(ctx.arena);
767 var filenames = std.ArrayList([]const u8).init(ctx.arena);993 var filenames = std.ArrayList([]const u8).init(ctx.arena);
768 defer filenames.deinit();
769994
770 while (try it.next()) |entry| {995 while (try it.next()) |entry| {
771 if (entry.kind != .File) continue;996 if (entry.kind != .File) continue;
772997
773 // Ignore stuff such as .swp files998 // Ignore stuff such as .swp files
774 switch (Compilation.classifyFileExt(entry.name)) {999 switch (Compilation.classifyFileExt(entry.basename)) {
775 .unknown => continue,1000 .unknown => continue,
776 else => {},1001 else => {},
777 }1002 }
778 try filenames.append(try ctx.arena.dupe(u8, entry.name));1003 try filenames.append(try ctx.arena.dupe(u8, entry.path));
779 }1004 }
7801005
781 // Sort filenames, so that incremental tests are contiguous and in-order1006 // Sort filenames, so that incremental tests are contiguous and in-order
...@@ -785,108 +1010,99 @@ pub const TestContext = struct {...@@ -785,108 +1010,99 @@ pub const TestContext = struct {
785 for (filenames.items) |filename| {1010 for (filenames.items) |filename| {
786 current_file.* = filename;1011 current_file.* = filename;
7871012
788 { // First, check if this file is part of an incremental update sequence1013 // First, check if this file is part of an incremental update sequence
7891014 // Split filename into "<base_name>.<index>.<file_ext>"
790 // Split filename into "<base_name>.<index>.<file_ext>"1015 const prev_parts = getTestFileNameParts(prev_filename);
791 const prev_parts = getTestFileNameParts(prev_filename);1016 const new_parts = getTestFileNameParts(filename);
792 const new_parts = getTestFileNameParts(filename);1017
7931018 // If base_name and file_ext match, these files are in the same test sequence
794 // If base_name and file_ext match, these files are in the same test sequence1019 // and the new one should be the incremented version of the previous test
795 // and the new one should be the incremented version of the previous test1020 if (std.mem.eql(u8, prev_parts.base_name, new_parts.base_name) and
796 if (std.mem.eql(u8, prev_parts.base_name, new_parts.base_name) and1021 std.mem.eql(u8, prev_parts.file_ext, new_parts.file_ext))
797 std.mem.eql(u8, prev_parts.file_ext, new_parts.file_ext))1022 {
798 {1023 // This is "foo.X.zig" followed by "foo.Y.zig". Make sure that X = Y + 1
7991024 if (prev_parts.test_index == null) return error.InvalidIncrementalTestIndex;
800 // This is "foo.X.zig" followed by "foo.Y.zig". Make sure that X = Y + 11025 if (new_parts.test_index == null) return error.InvalidIncrementalTestIndex;
801 if (prev_parts.test_index == null) return error.InvalidIncrementalTestIndex;1026 if (new_parts.test_index.? != prev_parts.test_index.? + 1) return error.InvalidIncrementalTestIndex;
802 if (new_parts.test_index == null) return error.InvalidIncrementalTestIndex;1027 } else {
803 if (new_parts.test_index.? != prev_parts.test_index.? + 1) return error.InvalidIncrementalTestIndex;1028 // This is not the same test sequence, so the new file must be the first file
804 } else {1029 // in a new sequence ("*.0.zig") or an independent test file ("*.zig")
8051030 if (new_parts.test_index != null and new_parts.test_index.? != 0) return error.InvalidIncrementalTestIndex;
806 // This is not the same test sequence, so the new file must be the first file1031 cases.clearRetainingCapacity();
807 // in a new sequence ("*.0.zig") or an independent test file ("*.zig")
808 if (new_parts.test_index != null and new_parts.test_index.? != 0) return error.InvalidIncrementalTestIndex;
809
810 if (strategy == .independent)
811 opt_case = null; // Generate a new independent test case for this update
812 }
813 }1032 }
814 prev_filename = filename;1033 prev_filename = filename;
8151034
816 const max_file_size = 10 * 1024 * 1024;1035 const max_file_size = 10 * 1024 * 1024;
817 const src = try dir.readFileAllocOptions(ctx.arena, filename, max_file_size, null, 1, 0);1036 const src = try dir.readFileAllocOptions(ctx.arena, filename, max_file_size, null, 1, 0);
8181037
819 // The manifest is the last contiguous block of comments in the file1038 // Parse the manifest
820 // We scan for the beginning by searching backward for the first non-empty line that does not start with "//"1039 var manifest = try TestManifest.parse(ctx.arena, src);
821 var manifest_start: ?usize = null;
822 var manifest_end: usize = src.len;
823 if (src.len > 0) {
824 var cursor: usize = src.len - 1;
825 while (true) {
826 // Move to beginning of line
827 while (cursor > 0 and src[cursor - 1] != '\n') cursor -= 1;
828
829 if (std.mem.startsWith(u8, src[cursor..], "//")) {
830 manifest_start = cursor; // Contiguous comment line, include in manifest
831 } else {
832 if (manifest_start != null) break; // Encountered non-comment line, end of manifest
8331040
834 // We ignore all-whitespace lines following the comment block, but anything else1041 if (cases.items.len == 0) {
835 // means that there is no manifest present.1042 const backends = try manifest.getConfigForKeyAlloc(ctx.arena, "backend", Backend);
836 if (std.mem.trim(u8, src[cursor..manifest_end], " \r\n\t").len == 0) {1043 const targets = try manifest.getConfigForKeyAlloc(ctx.arena, "target", CrossTarget);
837 manifest_end = cursor;1044 const is_test = manifest.getConfigForKeyAssertSingle("is_test", bool);
838 } else break; // If it's not whitespace, there is no manifest1045 const output_mode = manifest.getConfigForKeyAssertSingle("output_mode", std.builtin.OutputMode);
839 }
8401046
841 // Move to previous line1047 const name_prefix = blk: {
842 if (cursor != 0) cursor -= 1 else break;1048 const ext_index = std.mem.lastIndexOfScalar(u8, current_file.*, '.') orelse
843 }1049 return error.InvalidFilename;
844 }1050 const index = std.mem.lastIndexOfScalar(u8, current_file.*[0..ext_index], '.') orelse ext_index;
8451051 break :blk current_file.*[0..index];
846 var errors = std.ArrayList([]const u8).init(ctx.arena);1052 };
847
848 if (manifest_start) |start| {
849 // Due to the above processing, we know that this is a contiguous block of comments
850 // and do not need to re-validate the leading "//" on each line
851 var manifest_it = std.mem.tokenize(u8, src[start..manifest_end], "\r\n");
852
853 // First line is the test case name
854 const first_line = manifest_it.next() orelse return error.MissingTestCaseName;
855 const case_name = try std.mem.concat(ctx.arena, u8, &.{ name, ": ", std.mem.trim(u8, first_line[2..], " \t") });
8561053
857 // If the second line is present, it should be blank1054 // Cross-product to get all possible test combinations
858 if (manifest_it.next()) |second_line| {1055 for (backends) |backend| {
859 if (std.mem.trim(u8, second_line[2..], " \t").len != 0) return error.SecondLineNotBlank;1056 for (targets) |target| {
1057 const name = try std.fmt.allocPrint(ctx.arena, "{s} ({s}, {s})", .{
1058 name_prefix,
1059 @tagName(backend),
1060 try target.zigTriple(ctx.arena),
1061 });
1062 const next = ctx.cases.items.len;
1063 try ctx.cases.append(.{
1064 .name = name,
1065 .target = target,
1066 .backend = backend,
1067 .updates = std.ArrayList(TestContext.Update).init(ctx.cases.allocator),
1068 .is_test = is_test,
1069 .output_mode = output_mode,
1070 .link_libc = backend == .llvm,
1071 .files = std.ArrayList(TestContext.File).init(ctx.cases.allocator),
1072 });
1073 try cases.append(next);
1074 }
860 }1075 }
1076 }
8611077
862 // All following lines are expected error messages1078 for (cases.items) |case_index| {
863 while (manifest_it.next()) |line| try errors.append(try ctx.arena.dupe(u8, std.mem.trim(u8, line[2..], " \t")));1079 const case = &ctx.cases.items[case_index];
8641080 switch (manifest.@"type") {
865 const case = opt_case orelse case: {1081 .@"error" => {
866 ctx.cases.append(TestContext.Case{1082 const errors = try manifest.trailingAlloc(ctx.arena);
867 .name = name,1083 switch (strategy) {
868 .target = .{},1084 .independent => {
869 .backend = backend,1085 case.addError(src, errors);
870 .updates = std.ArrayList(TestContext.Update).init(ctx.cases.allocator),1086 },
871 .is_test = is_test,1087 .incremental => {
872 .output_mode = output_mode,1088 case.addErrorNamed("update", src, errors);
873 .files = std.ArrayList(TestContext.File).init(ctx.cases.allocator),1089 },
874 }) catch @panic("out of memory");1090 }
875 const case = &ctx.cases.items[ctx.cases.items.len - 1];
876 opt_case = case;
877 break :case case;
878 };
879 switch (strategy) {
880 .independent => {
881 case.name = case_name;
882 case.addError(src, errors.items);
883 },1091 },
884 .incremental => {1092 .run => {
885 case.addErrorNamed(case_name, src, errors.items);1093 var output = std.ArrayList(u8).init(ctx.arena);
1094 var trailing_it = manifest.trailing();
1095 while (trailing_it.next()) |line| {
1096 try output.appendSlice(line);
1097 try output.append('\n');
1098 }
1099 if (output.items.len > 0) {
1100 try output.resize(output.items.len - 1);
1101 }
1102 case.addCompareOutput(src, output.toOwnedSlice());
886 },1103 },
1104 .cli => @panic("TODO cli tests"),
887 }1105 }
888 } else {
889 return error.MissingManifest;
890 }1106 }
891 }1107 }
892 }1108 }
test/behavior.zig+2
...@@ -69,8 +69,10 @@ test {...@@ -69,8 +69,10 @@ test {
69 _ = @import("behavior/bugs/7003.zig");69 _ = @import("behavior/bugs/7003.zig");
70 _ = @import("behavior/bugs/7027.zig");70 _ = @import("behavior/bugs/7027.zig");
71 _ = @import("behavior/bugs/7047.zig");71 _ = @import("behavior/bugs/7047.zig");
72 _ = @import("behavior/bugs/7187.zig");
72 _ = @import("behavior/bugs/7250.zig");73 _ = @import("behavior/bugs/7250.zig");
73 _ = @import("behavior/bugs/9584.zig");74 _ = @import("behavior/bugs/9584.zig");
75 _ = @import("behavior/bugs/10138.zig");
74 _ = @import("behavior/bugs/10147.zig");76 _ = @import("behavior/bugs/10147.zig");
75 _ = @import("behavior/bugs/10970.zig");77 _ = @import("behavior/bugs/10970.zig");
76 _ = @import("behavior/bugs/11046.zig");78 _ = @import("behavior/bugs/11046.zig");
test/behavior/bugs/10138.zig created+34
...@@ -0,0 +1,34 @@
1const std = @import("std");
2const builtin = @import("builtin");
3
4test "registers get overwritten when ignoring return" {
5 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
6 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
7 if (builtin.cpu.arch != .x86_64 or builtin.os.tag != .linux) return error.SkipZigTest;
8
9 const fd = open();
10 _ = write(fd, "a", 1);
11 _ = close(fd);
12}
13
14fn open() usize {
15 return 42;
16}
17
18fn write(fd: usize, a: [*]const u8, len: usize) usize {
19 return syscall4(.WRITE, fd, @ptrToInt(a), len);
20}
21
22fn syscall4(n: enum { WRITE }, a: usize, b: usize, c: usize) usize {
23 _ = n;
24 _ = a;
25 _ = b;
26 _ = c;
27 return 23;
28}
29
30fn close(fd: usize) usize {
31 if (fd != 42)
32 unreachable;
33 return 0;
34}
test/behavior/bugs/7187.zig created+18
...@@ -0,0 +1,18 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const expect = std.testing.expect;
4
5test "miscompilation with bool return type" {
6 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
7 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
8
9 var x: usize = 1;
10 var y: bool = getFalse();
11 _ = y;
12
13 try expect(x == 1);
14}
15
16fn getFalse() bool {
17 return false;
18}
test/cases.zig-13
...@@ -1,22 +1,9 @@...@@ -1,22 +1,9 @@
1const std = @import("std");1const std = @import("std");
2const TestContext = @import("../src/test.zig").TestContext;2const TestContext = @import("../src/test.zig").TestContext;
33
4// Self-hosted has differing levels of support for various architectures. For now we pass explicit
5// target parameters to each test case. At some point we will take this to the next level and have
6// a set of targets that all test cases run on unless specifically overridden. For now, each test
7// case applies to only the specified target.
8
9pub fn addCases(ctx: *TestContext) !void {4pub fn addCases(ctx: *TestContext) !void {
10 try @import("compile_errors.zig").addCases(ctx);5 try @import("compile_errors.zig").addCases(ctx);
11 try @import("stage2/cbe.zig").addCases(ctx);6 try @import("stage2/cbe.zig").addCases(ctx);
12 try @import("stage2/arm.zig").addCases(ctx);
13 try @import("stage2/aarch64.zig").addCases(ctx);
14 try @import("stage2/llvm.zig").addCases(ctx);
15 try @import("stage2/wasm.zig").addCases(ctx);
16 try @import("stage2/riscv64.zig").addCases(ctx);
17 try @import("stage2/plan9.zig").addCases(ctx);
18 try @import("stage2/x86_64.zig").addCases(ctx);
19 try @import("stage2/sparcv9.zig").addCases(ctx);
20 // https://github.com/ziglang/zig/issues/109687 // https://github.com/ziglang/zig/issues/10968
21 //try @import("stage2/nvptx.zig").addCases(ctx);8 //try @import("stage2/nvptx.zig").addCases(ctx);
22}9}
test/compile_errors.zig-218
...@@ -3,207 +3,6 @@ const builtin = @import("builtin");...@@ -3,207 +3,6 @@ const builtin = @import("builtin");
3const TestContext = @import("../src/test.zig").TestContext;3const TestContext = @import("../src/test.zig").TestContext;
44
5pub fn addCases(ctx: *TestContext) !void {5pub fn addCases(ctx: *TestContext) !void {
6 {
7 const case = ctx.obj("callconv(.Interrupt) on unsupported platform", .{
8 .cpu_arch = .aarch64,
9 .os_tag = .linux,
10 .abi = .none,
11 });
12 case.backend = .stage1;
13 case.addError(
14 \\export fn entry() callconv(.Interrupt) void {}
15 , &[_][]const u8{
16 "tmp.zig:1:28: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64",
17 });
18 }
19 {
20 var case = ctx.obj("callconv(.Signal) on unsupported platform", .{
21 .cpu_arch = .x86_64,
22 .os_tag = .linux,
23 .abi = .none,
24 });
25 case.backend = .stage1;
26 case.addError(
27 \\export fn entry() callconv(.Signal) void {}
28 , &[_][]const u8{
29 "tmp.zig:1:28: error: callconv 'Signal' is only available on AVR, not x86_64",
30 });
31 }
32 {
33 const case = ctx.obj("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", .{
34 .cpu_arch = .x86_64,
35 .os_tag = .linux,
36 .abi = .none,
37 });
38 case.backend = .stage1;
39 case.addError(
40 \\const F1 = fn () callconv(.Stdcall) void;
41 \\const F2 = fn () callconv(.Fastcall) void;
42 \\const F3 = fn () callconv(.Thiscall) void;
43 \\export fn entry1() void { var a: F1 = undefined; _ = a; }
44 \\export fn entry2() void { var a: F2 = undefined; _ = a; }
45 \\export fn entry3() void { var a: F3 = undefined; _ = a; }
46 , &[_][]const u8{
47 "tmp.zig:1:27: error: callconv 'Stdcall' is only available on x86, not x86_64",
48 "tmp.zig:2:27: error: callconv 'Fastcall' is only available on x86, not x86_64",
49 "tmp.zig:3:27: error: callconv 'Thiscall' is only available on x86, not x86_64",
50 });
51 }
52 {
53 const case = ctx.obj("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", .{
54 .cpu_arch = .x86_64,
55 .os_tag = .linux,
56 .abi = .none,
57 });
58 case.backend = .stage1;
59 case.addError(
60 \\export fn entry1() callconv(.Stdcall) void {}
61 \\export fn entry2() callconv(.Fastcall) void {}
62 \\export fn entry3() callconv(.Thiscall) void {}
63 , &[_][]const u8{
64 "tmp.zig:1:29: error: callconv 'Stdcall' is only available on x86, not x86_64",
65 "tmp.zig:2:29: error: callconv 'Fastcall' is only available on x86, not x86_64",
66 "tmp.zig:3:29: error: callconv 'Thiscall' is only available on x86, not x86_64",
67 });
68 }
69 {
70 const case = ctx.obj("callconv(.Vectorcall) on unsupported platform", .{
71 .cpu_arch = .x86_64,
72 .os_tag = .linux,
73 .abi = .none,
74 });
75 case.backend = .stage1;
76 case.addError(
77 \\export fn entry() callconv(.Vectorcall) void {}
78 , &[_][]const u8{
79 "tmp.zig:1:28: error: callconv 'Vectorcall' is only available on x86 and AArch64, not x86_64",
80 });
81 }
82 {
83 const case = ctx.obj("callconv(.APCS, .AAPCS, .AAPCSVFP) on unsupported platform", .{
84 .cpu_arch = .x86_64,
85 .os_tag = .linux,
86 .abi = .none,
87 });
88 case.backend = .stage1;
89 case.addError(
90 \\export fn entry1() callconv(.APCS) void {}
91 \\export fn entry2() callconv(.AAPCS) void {}
92 \\export fn entry3() callconv(.AAPCSVFP) void {}
93 , &[_][]const u8{
94 "tmp.zig:1:29: error: callconv 'APCS' is only available on ARM, not x86_64",
95 "tmp.zig:2:29: error: callconv 'AAPCS' is only available on ARM, not x86_64",
96 "tmp.zig:3:29: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64",
97 });
98 }
99
100 {
101 const case = ctx.obj("call with new stack on unsupported target", .{
102 .cpu_arch = .wasm32,
103 .os_tag = .wasi,
104 .abi = .none,
105 });
106 case.backend = .stage1;
107 case.addError(
108 \\var buf: [10]u8 align(16) = undefined;
109 \\export fn entry() void {
110 \\ @call(.{.stack = &buf}, foo, .{});
111 \\}
112 \\fn foo() void {}
113 , &[_][]const u8{
114 "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack",
115 });
116 }
117
118 // Note: One of the error messages here is backwards. It would be nice to fix, but that's not
119 // going to stop me from merging this branch which fixes a bunch of other stuff.
120 ctx.objErrStage1("incompatible sentinels",
121 \\export fn entry1(ptr: [*:255]u8) [*:0]u8 {
122 \\ return ptr;
123 \\}
124 \\export fn entry2(ptr: [*]u8) [*:0]u8 {
125 \\ return ptr;
126 \\}
127 \\export fn entry3() void {
128 \\ var array: [2:0]u8 = [_:255]u8{1, 2};
129 \\ _ = array;
130 \\}
131 \\export fn entry4() void {
132 \\ var array: [2:0]u8 = [_]u8{1, 2};
133 \\ _ = array;
134 \\}
135 , &[_][]const u8{
136 "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'",
137 "tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel",
138 "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'",
139 "tmp.zig:5:12: note: destination pointer requires a terminating '0' sentinel",
140
141 "tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'",
142 "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel",
143 "tmp.zig:12:31: error: expected type '[2:0]u8', found '[2]u8'",
144 "tmp.zig:12:31: note: destination array requires a terminating '0' sentinel",
145 });
146
147 {
148 const case = ctx.obj("variable in inline assembly template cannot be found", .{
149 .cpu_arch = .x86_64,
150 .os_tag = .linux,
151 .abi = .gnu,
152 });
153 case.backend = .stage1;
154 case.addError(
155 \\export fn entry() void {
156 \\ var sp = asm volatile (
157 \\ "mov %[foo], sp"
158 \\ : [bar] "=r" (-> usize)
159 \\ );
160 \\ _ = sp;
161 \\}
162 , &[_][]const u8{
163 "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs",
164 });
165 }
166
167 {
168 const case = ctx.obj("bad alignment in @asyncCall", .{
169 .cpu_arch = .aarch64,
170 .os_tag = .linux,
171 .abi = .none,
172 });
173 case.backend = .stage1;
174 case.addError(
175 \\export fn entry() void {
176 \\ var ptr: fn () callconv(.Async) void = func;
177 \\ var bytes: [64]u8 = undefined;
178 \\ _ = @asyncCall(&bytes, {}, ptr, .{});
179 \\}
180 \\fn func() callconv(.Async) void {}
181 , &[_][]const u8{
182 "tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8'",
183 });
184 }
185
186 if (builtin.os.tag == .linux) {
187 ctx.testErrStage1("implicit dependency on libc",
188 \\extern "c" fn exit(u8) void;
189 \\export fn entry() void {
190 \\ exit(0);
191 \\}
192 , &[_][]const u8{
193 "tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command",
194 });
195
196 ctx.testErrStage1("libc headers note",
197 \\const c = @cImport(@cInclude("stdio.h"));
198 \\export fn entry() void {
199 \\ _ = c.printf("hello, world!\n");
200 \\}
201 , &[_][]const u8{
202 "tmp.zig:1:11: error: C import failed",
203 "tmp.zig:1:11: note: libc headers not available; compilation does not link against libc",
204 });
205 }
206
207 {6 {
208 const case = ctx.obj("wrong same named struct", .{});7 const case = ctx.obj("wrong same named struct", .{});
209 case.backend = .stage1;8 case.backend = .stage1;
...@@ -366,21 +165,4 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -366,21 +165,4 @@ pub fn addCases(ctx: *TestContext) !void {
366 //, &[_][]const u8{165 //, &[_][]const u8{
367 // "tmp.zig:4:1: error: unable to inline function",166 // "tmp.zig:4:1: error: unable to inline function",
368 //});167 //});
369
370 {
371 const case = ctx.obj("align(N) expr function pointers is a compile error", .{
372 .cpu_arch = .wasm32,
373 .os_tag = .freestanding,
374 .abi = .none,
375 });
376 case.backend = .stage1;
377
378 case.addError(
379 \\export fn foo() align(1) void {
380 \\ return;
381 \\}
382 , &[_][]const u8{
383 "tmp.zig:1:23: error: align(N) expr is not allowed on function prototypes in wasm32/wasm64",
384 });
385 }
386}168}
test/compile_errors/stage1/exe/main_missing_name.zig+4-1
...@@ -1,5 +1,8 @@...@@ -1,5 +1,8 @@
1pub fn (main) void {}1pub fn (main) void {}
22
3// main missing name3// error
4// backend=stage1
5// target=native
6// output_mode=Exe
4//7//
5// tmp.zig:1:5: error: missing function name8// tmp.zig:1:5: error: missing function name
test/compile_errors/stage1/exe/missing_main_fn_in_executable.zig+4-1
...@@ -1,5 +1,8 @@...@@ -1,5 +1,8 @@
11
22
3// missing main fn in executable3// error
4// backend=stage1
5// target=native
6// output_mode=Exe
4//7//
5// error: root source file has no member called 'main'8// error: root source file has no member called 'main'
test/compile_errors/stage1/exe/private_main_fn.zig+4-1
...@@ -1,6 +1,9 @@...@@ -1,6 +1,9 @@
1fn main() void {}1fn main() void {}
22
3// private main fn3// error
4// backend=stage1
5// target=native
6// output_mode=Exe
4//7//
5// error: 'main' is private8// error: 'main' is private
6// tmp.zig:1:1: note: declared here9// tmp.zig:1:1: note: declared here
test/compile_errors/stage1/obj/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig+3-1
...@@ -5,6 +5,8 @@ export fn a() void {...@@ -5,6 +5,8 @@ export fn a() void {
5 _ = t;5 _ = t;
6}6}
77
8// C pointer pointing to non C ABI compatible type or has align attr8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'12// tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'
test/compile_errors/stage1/obj/C_pointer_to_anyopaque.zig+3-1
...@@ -4,6 +4,8 @@ export fn a() void {...@@ -4,6 +4,8 @@ export fn a() void {
4 _ = y;4 _ = y;
5}5}
66
7// C pointer to anyopaque7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:16: error: C pointers cannot point to opaque types11// tmp.zig:3:16: error: C pointers cannot point to opaque types
test/compile_errors/stage1/obj/Frame_of_generic_function.zig+3-1
...@@ -7,6 +7,8 @@ fn func(comptime T: type) void {...@@ -7,6 +7,8 @@ fn func(comptime T: type) void {
7 _ = x;7 _ = x;
8}8}
99
10// @Frame() of generic function10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:2:16: error: @Frame() of generic function14// tmp.zig:2:16: error: @Frame() of generic function
test/compile_errors/stage1/obj/Issue_5586_Make_unary_minus_for_unsigned_types_a_compile_error.zig+3-1
...@@ -8,7 +8,9 @@ export fn f2(x: V(4, u32)) V(4, u32) {...@@ -8,7 +8,9 @@ export fn f2(x: V(4, u32)) V(4, u32) {
8 return -y;8 return -y;
9}9}
1010
11// Issue #5586: Make unary minus for unsigned types a compile error11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:3:12: error: negation of type 'u32'15// tmp.zig:3:12: error: negation of type 'u32'
14// tmp.zig:8:12: error: negation of type 'u32'16// tmp.zig:8:12: error: negation of type 'u32'
test/compile_errors/stage1/obj/Issue_6823_dont_allow_._to_be_followed_by_.zig+3-1
...@@ -3,6 +3,8 @@ fn foo() void {...@@ -3,6 +3,8 @@ fn foo() void {
3 _ = sequence;3 _ = sequence;
4}4}
55
6// Issue #6823: don't allow .* to be followed by **6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:28: error: '.*' cannot be followed by '*'. Are you missing a space?10// tmp.zig:2:28: error: '.*' cannot be followed by '*'. Are you missing a space?
test/compile_errors/stage1/obj/Issue_9165_windows_tcp_server_compilation_error.zig+3-1
...@@ -9,6 +9,8 @@ pub fn main() !void {...@@ -9,6 +9,8 @@ pub fn main() !void {
9 }9 }
10}10}
1111
12// Issue #9165: windows tcp server compilation error12// error
13// backend=stage1
14// target=native
13//15//
14// error: Unsupported OS16// error: Unsupported OS
test/compile_errors/stage1/obj/access_non-existent_member_of_error_set.zig+3-1
...@@ -4,6 +4,8 @@ comptime {...@@ -4,6 +4,8 @@ comptime {
4 _ = z;4 _ = z;
5}5}
66
7// access non-existent member of error set7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:18: error: no error named 'Bar' in 'Foo'11// tmp.zig:3:18: error: no error named 'Bar' in 'Foo'
test/compile_errors/stage1/obj/accessing_runtime_parameter_from_outer_function.zig+3-1
...@@ -12,7 +12,9 @@ export fn entry() void {...@@ -12,7 +12,9 @@ export fn entry() void {
12 _ = x;12 _ = x;
13}13}
1414
15// accessing runtime parameter from outer function15// error
16// backend=stage1
17// target=native
16//18//
17// tmp.zig:4:24: error: 'y' not accessible from inner function19// tmp.zig:4:24: error: 'y' not accessible from inner function
18// tmp.zig:3:28: note: crossed function definition here20// tmp.zig:3:28: note: crossed function definition here
test/compile_errors/stage1/obj/add_assign_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 a += a;3 a += a;
4}4}
55
6// add assign on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/add_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a + a;3 _ = a + a;
4}4}
55
6// add on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/add_overflow_in_function_evaluation.zig+3-1
...@@ -5,6 +5,8 @@ fn add(a: u16, b: u16) u16 {...@@ -5,6 +5,8 @@ fn add(a: u16, b: u16) u16 {
55
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
77
8// add overflow in function evaluation8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:3:14: error: operation caused overflow12// tmp.zig:3:14: error: operation caused overflow
test/compile_errors/stage1/obj/add_wrap_assign_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 a +%= a;3 a +%= a;
4}4}
55
6// add wrap assign on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/add_wrap_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a +% a;3 _ = a +% a;
4}4}
55
6// add wrap on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/addition_with_non_numbers.zig+3-1
...@@ -5,6 +5,8 @@ const x = Foo {.field = 1} + Foo {.field = 2};...@@ -5,6 +5,8 @@ const x = Foo {.field = 1} + Foo {.field = 2};
55
6export fn entry() usize { return @sizeOf(@TypeOf(x)); }6export fn entry() usize { return @sizeOf(@TypeOf(x)); }
77
8// addition with non numbers8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'12// tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'
test/compile_errors/stage1/obj/address_of_number_literal.zig+3-1
...@@ -3,6 +3,8 @@ const y = &x;...@@ -3,6 +3,8 @@ const y = &x;
3fn foo() *const i32 { return y; }3fn foo() *const i32 { return y; }
4export fn entry() usize { return @sizeOf(@TypeOf(foo)); }4export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
55
6// address of number literal6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'10// tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'
test/compile_errors/stage1/obj/alignCast_expects_pointer_or_slice.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() void {...@@ -2,6 +2,8 @@ export fn entry() void {
2 @alignCast(4, @as(u32, 3));2 @alignCast(4, @as(u32, 3));
3}3}
44
5// @alignCast expects pointer or slice5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:19: error: expected pointer or slice, found 'u32'9// tmp.zig:2:19: error: expected pointer or slice, found 'u32'
test/compile_errors/stage1/obj/align_n_expr_function_pointers_is_a_compile_error.zig created+9
...@@ -0,0 +1,9 @@
1export fn foo() align(1) void {
2 return;
3}
4
5// error
6// backend=stage1
7// target=wasm32-freestanding-none
8//
9// tmp.zig:1:23: error: align(N) expr is not allowed on function prototypes in wasm32/wasm64
test/compile_errors/stage1/obj/aligned_variable_of_zero-bit_type.zig+3-1
...@@ -3,6 +3,8 @@ export fn f() void {...@@ -3,6 +3,8 @@ export fn f() void {
3 _ = s;3 _ = s;
4}4}
55
6// aligned variable of zero-bit type6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned10// tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned
test/compile_errors/stage1/obj/alignment_of_enum_field_specified.zig+3-1
...@@ -7,6 +7,8 @@ export fn entry1() void {...@@ -7,6 +7,8 @@ export fn entry1() void {
7 _ = x;7 _ = x;
8}8}
99
10// alignment of enum field specified10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:3:7: error: expected ',' after field14// tmp.zig:3:7: error: expected ',' after field
test/compile_errors/stage1/obj/ambiguous_decl_reference.zig+3-1
...@@ -12,7 +12,9 @@ export fn entry() void {...@@ -12,7 +12,9 @@ export fn entry() void {
12 bar();12 bar();
13}13}
1414
15// ambiguous decl reference15// error
16// backend=stage1
17// target=native
16//18//
17// tmp.zig:5:13: error: ambiguous reference19// tmp.zig:5:13: error: ambiguous reference
18// tmp.zig:7:9: note: declared here20// tmp.zig:7:9: note: declared here
test/compile_errors/stage1/obj/and_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a and a;3 _ = a and a;
4}4}
55
6// and on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/array_access_of_non_array.zig+3-1
...@@ -7,7 +7,9 @@ export fn g() void {...@@ -7,7 +7,9 @@ export fn g() void {
7 _ = bad[0];7 _ = bad[0];
8}8}
99
10// array access of non array10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:3:8: error: array access of non-array type 'bool'14// tmp.zig:3:8: error: array access of non-array type 'bool'
13// tmp.zig:7:12: error: array access of non-array type 'bool'15// tmp.zig:7:12: error: array access of non-array type 'bool'
test/compile_errors/stage1/obj/array_access_of_type.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo() void {...@@ -3,6 +3,8 @@ export fn foo() void {
3 _ = b;3 _ = b;
4}4}
55
6// array access of type6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:14: error: array access of non-array type 'type'10// tmp.zig:2:14: error: array access of non-array type 'type'
test/compile_errors/stage1/obj/array_access_of_undeclared_identifier.zig+3-1
...@@ -2,6 +2,8 @@ export fn f() void {...@@ -2,6 +2,8 @@ export fn f() void {
2 i[i] = i[i];2 i[i] = i[i];
3}3}
44
5// array access of undeclared identifier5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:5: error: use of undeclared identifier 'i'9// tmp.zig:2:5: error: use of undeclared identifier 'i'
test/compile_errors/stage1/obj/array_access_with_non_integer_index.zig+3-1
...@@ -9,7 +9,9 @@ export fn g() void {...@@ -9,7 +9,9 @@ export fn g() void {
9 _ = array[bad];9 _ = array[bad];
10}10}
1111
12// array access with non integer index12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:4:11: error: expected type 'usize', found 'bool'16// tmp.zig:4:11: error: expected type 'usize', found 'bool'
15// tmp.zig:9:15: error: expected type 'usize', found 'bool'17// tmp.zig:9:15: error: expected type 'usize', found 'bool'
test/compile_errors/stage1/obj/array_concatenation_with_wrong_type.zig+3-1
...@@ -4,6 +4,8 @@ const a = derp ++ "foo";...@@ -4,6 +4,8 @@ const a = derp ++ "foo";
44
5export fn entry() usize { return @sizeOf(@TypeOf(a)); }5export fn entry() usize { return @sizeOf(@TypeOf(a)); }
66
7// array concatenation with wrong type7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:11: error: expected array, found 'usize'11// tmp.zig:3:11: error: expected array, found 'usize'
test/compile_errors/stage1/obj/array_in_c_exported_function.zig+3-1
...@@ -6,7 +6,9 @@ export fn zig_return_array() [10]u8 {...@@ -6,7 +6,9 @@ export fn zig_return_array() [10]u8 {
6 return "1234567890".*;6 return "1234567890".*;
7}7}
88
9// array in c exported function9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:1:24: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'13// tmp.zig:1:24: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'
12// tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'14// tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/asm_at_compile_time.zig+3-1
...@@ -10,6 +10,8 @@ fn doSomeAsm() void {...@@ -10,6 +10,8 @@ fn doSomeAsm() void {
10 );10 );
11}11}
1212
13// asm at compile time13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:6:5: error: unable to evaluate constant expression17// tmp.zig:6:5: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/assign_inline_fn_to_non-comptime_var.zig+3-1
...@@ -4,7 +4,9 @@ export fn entry() void {...@@ -4,7 +4,9 @@ export fn entry() void {
4}4}
5fn b() callconv(.Inline) void { }5fn b() callconv(.Inline) void { }
66
7// assign inline fn to non-comptime var7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var11// tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var
10// tmp.zig:5:1: note: declared here12// tmp.zig:5:1: note: declared here
test/compile_errors/stage1/obj/assign_null_to_non-optional_pointer.zig+3-1
...@@ -2,6 +2,8 @@ const a: *u8 = null;...@@ -2,6 +2,8 @@ const a: *u8 = null;
22
3export fn entry() usize { return @sizeOf(@TypeOf(a)); }3export fn entry() usize { return @sizeOf(@TypeOf(a)); }
44
5// assign null to non-optional pointer5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:1:16: error: expected type '*u8', found '@Type(.Null)'9// tmp.zig:1:16: error: expected type '*u8', found '@Type(.Null)'
test/compile_errors/stage1/obj/assign_through_constant_pointer.zig+3-1
...@@ -3,6 +3,8 @@ export fn f() void {...@@ -3,6 +3,8 @@ export fn f() void {
3 cstr[0] = 'W';3 cstr[0] = 'W';
4}4}
55
6// assign through constant pointer6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:13: error: cannot assign to constant10// tmp.zig:3:13: error: cannot assign to constant
test/compile_errors/stage1/obj/assign_through_constant_slice.zig+3-1
...@@ -3,6 +3,8 @@ export fn f() void {...@@ -3,6 +3,8 @@ export fn f() void {
3 cstr[0] = 'W';3 cstr[0] = 'W';
4}4}
55
6// assign through constant slice6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:13: error: cannot assign to constant10// tmp.zig:3:13: error: cannot assign to constant
test/compile_errors/stage1/obj/assign_to_constant_field.zig+3-1
...@@ -6,6 +6,8 @@ export fn derp() void {...@@ -6,6 +6,8 @@ export fn derp() void {
6 f.field = 0;6 f.field = 0;
7}7}
88
9// assign to constant field9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:6:15: error: cannot assign to constant13// tmp.zig:6:15: error: cannot assign to constant
test/compile_errors/stage1/obj/assign_to_constant_variable.zig+3-1
...@@ -3,6 +3,8 @@ export fn f() void {...@@ -3,6 +3,8 @@ export fn f() void {
3 a = 4;3 a = 4;
4}4}
55
6// assign to constant variable6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: cannot assign to constant10// tmp.zig:3:9: error: cannot assign to constant
test/compile_errors/stage1/obj/assign_to_invalid_dereference.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() void {...@@ -2,6 +2,8 @@ export fn entry() void {
2 'a'.* = 1;2 'a'.* = 1;
3}3}
44
5// assign to invalid dereference5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'9// tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'
test/compile_errors/stage1/obj/assign_too_big_number_to_u16.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo() void {...@@ -3,6 +3,8 @@ export fn foo() void {
3 _ = vga_mem;3 _ = vga_mem;
4}4}
55
6// assign too big number to u166// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'10// tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'
test/compile_errors/stage1/obj/assign_unreachable.zig+3-1
...@@ -2,7 +2,9 @@ export fn f() void {...@@ -2,7 +2,9 @@ export fn f() void {
2 const a = return;2 const a = return;
3}3}
44
5// assign unreachable5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:5: error: unreachable code9// tmp.zig:2:5: error: unreachable code
8// tmp.zig:2:15: note: control flow is diverted here10// tmp.zig:2:15: note: control flow is diverted here
test/compile_errors/stage1/obj/assigning_to_struct_or_union_fields_that_are_not_optionals_with_a_function_that_returns_an_optional.zig+3-1
...@@ -14,6 +14,8 @@ export fn entry() void {...@@ -14,6 +14,8 @@ export fn entry() void {
14 _ = s;14 _ = s;
15}15}
1616
17// assigning to struct or union fields that are not optionals with a function that returns an optional17// error
18// backend=stage1
19// target=native
18//20//
19// tmp.zig:11:27: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'u8', found '?u8'21// tmp.zig:11:27: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'u8', found '?u8'
test/compile_errors/stage1/obj/async_function_depends_on_its_own_frame.zig+3-1
...@@ -6,6 +6,8 @@ fn amain() callconv(.Async) void {...@@ -6,6 +6,8 @@ fn amain() callconv(.Async) void {
6 _ = x;6 _ = x;
7}7}
88
9// async function depends on its own frame9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet13// tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet
test/compile_errors/stage1/obj/async_function_indirectly_depends_on_its_own_frame.zig+3-1
...@@ -9,7 +9,9 @@ fn other() void {...@@ -9,7 +9,9 @@ fn other() void {
9 _ = x;9 _ = x;
10}10}
1111
12// async function indirectly depends on its own frame12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:4:1: error: unable to determine async function frame of 'amain'16// tmp.zig:4:1: error: unable to determine async function frame of 'amain'
15// tmp.zig:5:10: note: analysis of function 'other' depends on the frame17// tmp.zig:5:10: note: analysis of function 'other' depends on the frame
test/compile_errors/stage1/obj/atomic_orderings_of_atomicStore_Acquire_or_AcqRel.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 @atomicStore(u32, &x, 1, .Acquire);3 @atomicStore(u32, &x, 1, .Acquire);
4}4}
55
6// atomic orderings of atomicStore Acquire or AcqRel6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel10// tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel
test/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-failure_stricter_than_success.zig+3-1
...@@ -4,6 +4,8 @@ export fn f() void {...@@ -4,6 +4,8 @@ export fn f() void {
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
5}5}
66
7// atomic orderings of cmpxchg - failure stricter than success7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:4:81: error: failure atomic ordering must be no stricter than success11// tmp.zig:4:81: error: failure atomic ordering must be no stricter than success
test/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-success_Monotonic_or_stricter.zig+3-1
...@@ -4,6 +4,8 @@ export fn f() void {...@@ -4,6 +4,8 @@ export fn f() void {
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
5}5}
66
7// atomic orderings of cmpxchg - success Monotonic or stricter7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter11// tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter
test/compile_errors/stage1/obj/atomic_orderings_of_fence_Acquire_or_stricter.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() void {...@@ -2,6 +2,8 @@ export fn entry() void {
2 @fence(.Monotonic);2 @fence(.Monotonic);
3}3}
44
5// atomic orderings of fence Acquire or stricter5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:12: error: atomic ordering must be Acquire or stricter9// tmp.zig:2:12: error: atomic ordering must be Acquire or stricter
test/compile_errors/stage1/obj/atomicrmw_with_bool_op_not_.Xchg.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = @atomicRmw(bool, &x, .Add, true, .SeqCst);3 _ = @atomicRmw(bool, &x, .Add, true, .SeqCst);
4}4}
55
6// atomicrmw with bool op not .Xchg6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:30: error: @atomicRmw with bool only allowed with .Xchg10// tmp.zig:3:30: error: @atomicRmw with bool only allowed with .Xchg
test/compile_errors/stage1/obj/atomicrmw_with_enum_op_not_.Xchg.zig+3-1
...@@ -9,6 +9,8 @@ export fn entry() void {...@@ -9,6 +9,8 @@ export fn entry() void {
9 _ = @atomicRmw(E, &x, .Add, .b, .SeqCst);9 _ = @atomicRmw(E, &x, .Add, .b, .SeqCst);
10}10}
1111
12// atomicrmw with enum op not .Xchg12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:9:27: error: @atomicRmw with enum only allowed with .Xchg16// tmp.zig:9:27: error: @atomicRmw with enum only allowed with .Xchg
test/compile_errors/stage1/obj/atomicrmw_with_float_op_not_.Xchg_.Add_or_.Sub.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = @atomicRmw(f32, &x, .And, 2, .SeqCst);3 _ = @atomicRmw(f32, &x, .And, 2, .SeqCst);
4}4}
55
6// atomicrmw with float op not .Xchg, .Add or .Sub6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:29: error: @atomicRmw with float only allowed with .Xchg, .Add and .Sub10// tmp.zig:3:29: error: @atomicRmw with float only allowed with .Xchg, .Add and .Sub
test/compile_errors/stage1/obj/attempt_to_cast_enum_literal_to_error.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 }4 }
5}5}
66
7// attempt to cast enum literal to error7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:9: error: expected type 'error{Hi}', found '@Type(.EnumLiteral)'11// tmp.zig:3:9: error: expected type 'error{Hi}', found '@Type(.EnumLiteral)'
test/compile_errors/stage1/obj/attempt_to_close_over_comptime_variable_from_outer_scope.zig+3-1
...@@ -5,7 +5,9 @@ fn SimpleList(comptime L: usize) type {...@@ -5,7 +5,9 @@ fn SimpleList(comptime L: usize) type {
5 };5 };
6}6}
77
8// attempt to close over comptime variable from outer scope8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:19: error: mutable 'T' not accessible from here12// tmp.zig:4:19: error: mutable 'T' not accessible from here
11// tmp.zig:2:9: note: declared mutable here13// tmp.zig:2:9: note: declared mutable here
test/compile_errors/stage1/obj/attempt_to_create_17_bit_float_type.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = @Type(.{ .Float = .{ .bits = 17 } });3 _ = @Type(.{ .Float = .{ .bits = 17 } });
4}4}
55
6// attempt to create 17 bit float type6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:16: error: 17-bit float unsupported10// tmp.zig:3:16: error: 17-bit float unsupported
test/compile_errors/stage1/obj/attempt_to_negate_a_non-integer_non-float_or_non-vector_type.zig+3-1
...@@ -7,6 +7,8 @@ export fn entry() void {...@@ -7,6 +7,8 @@ export fn entry() void {
7 _ = x;7 _ = x;
8}8}
99
10// attempt to negate a non-integer, non-float or non-vector type10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:6:15: error: negation of type 'anyerror!u32'14// tmp.zig:6:15: error: negation of type 'anyerror!u32'
test/compile_errors/stage1/obj/attempt_to_use_0_bit_type_in_extern_fn.zig+3-1
...@@ -9,7 +9,9 @@ export fn entry2() void {...@@ -9,7 +9,9 @@ export fn entry2() void {
9 bar(&{});9 bar(&{});
10}10}
1111
12// attempt to use 0 bit type in extern fn12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:1:23: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'16// tmp.zig:1:23: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'
15// tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'17// tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/attempted_double_ampersand.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry(a: bool, b: bool) i32 {...@@ -5,6 +5,8 @@ export fn entry(a: bool, b: bool) i32 {
5 return 5678;5 return 5678;
6}6}
77
8// attempted `&&`8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:2:11: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND12// tmp.zig:2:11: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND
test/compile_errors/stage1/obj/attempted_double_pipe_on_boolean_values.zig+3-1
...@@ -5,7 +5,9 @@ export fn entry(a: bool, b: bool) i32 {...@@ -5,7 +5,9 @@ export fn entry(a: bool, b: bool) i32 {
5 return 5678;5 return 5678;
6}6}
77
8// attempted `||` on boolean values8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:2:9: error: expected error set type, found 'bool'12// tmp.zig:2:9: error: expected error set type, found 'bool'
11// tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR13// tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR
test/compile_errors/stage1/obj/attempted_implicit_cast_from_T_to_slice_const_T.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = x;3 _ = x;
4}4}
55
6// attempted implicit cast from T to [*]const T6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'10// tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'
test/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig+3-1
...@@ -6,7 +6,9 @@ export fn entry(byte: u8) void {...@@ -6,7 +6,9 @@ export fn entry(byte: u8) void {
6 _ = byte;6 _ = byte;
7}7}
88
9// attempted implicit cast from *const T to *[1]T9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'13// tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'
12// tmp.zig:4:22: note: cast discards const qualifier14// tmp.zig:4:22: note: cast discards const qualifier
test/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_sliceT.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 _ = x;4 _ = x;
5}5}
66
7// attempted implicit cast from *const T to []T7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:23: error: expected type '[]u32', found '*const u32'11// tmp.zig:3:23: error: expected type '[]u32', found '*const u32'
test/compile_errors/stage1/obj/bad_alignCast_at_comptime.zig+3-1
...@@ -4,6 +4,8 @@ comptime {...@@ -4,6 +4,8 @@ comptime {
4 _ = aligned;4 _ = aligned;
5}5}
66
7// bad @alignCast at comptime7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes11// tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes
test/compile_errors/stage1/obj/bad_alignment_in_asynccall.zig created+12
...@@ -0,0 +1,12 @@
1export fn entry() void {
2 var ptr: fn () callconv(.Async) void = func;
3 var bytes: [64]u8 = undefined;
4 _ = @asyncCall(&bytes, {}, ptr, .{});
5}
6fn func() callconv(.Async) void {}
7
8// error
9// backend=stage1
10// target=aarch64-linux-none
11//
12// tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8'
test/compile_errors/stage1/obj/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig+3-1
...@@ -4,6 +4,8 @@ export fn a() void {...@@ -4,6 +4,8 @@ export fn a() void {
4 _ = y;4 _ = y;
5}5}
66
7// bad alignment in implicit cast from array pointer to slice7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'11// tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'
test/compile_errors/stage1/obj/bad_alignment_type.zig+3-1
...@@ -7,7 +7,9 @@ export fn entry2() void {...@@ -7,7 +7,9 @@ export fn entry2() void {
7 _ = x;7 _ = x;
8}8}
99
10// bad alignment type10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:2:20: error: expected type 'u29', found 'bool'14// tmp.zig:2:20: error: expected type 'u29', found 'bool'
13// tmp.zig:6:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'15// tmp.zig:6:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'
test/compile_errors/stage1/obj/bad_identifier_in_function_with_struct_defined_inside_function_which_references_local_const.zig+3-1
...@@ -10,6 +10,8 @@ export fn entry() void {...@@ -10,6 +10,8 @@ export fn entry() void {
10 _ = Block;10 _ = Block;
11}11}
1212
13// bad identifier in function with struct defined inside function which references local const13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:8:5: error: use of undeclared identifier 'bogus'17// tmp.zig:8:5: error: use of undeclared identifier 'bogus'
test/compile_errors/stage1/obj/bad_import.zig+3-1
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1const bogus = @import("bogus-does-not-exist.zig",);1const bogus = @import("bogus-does-not-exist.zig",);
22
3// bad import3// error
4// backend=stage1
5// target=native
4//6//
5// tmp.zig:1:23: error: unable to load '${DIR}bogus-does-not-exist.zig': FileNotFound7// tmp.zig:1:23: error: unable to load '${DIR}bogus-does-not-exist.zig': FileNotFound
test/compile_errors/stage1/obj/bad_usage_of_call.zig+3-1
...@@ -19,7 +19,9 @@ fn bar() callconv(.Inline) void {}...@@ -19,7 +19,9 @@ fn bar() callconv(.Inline) void {}
19fn baz1() void {}19fn baz1() void {}
20fn baz2() void {}20fn baz2() void {}
2121
22// bad usage of @call22// error
23// backend=stage1
24// target=native
23//25//
24// tmp.zig:2:21: error: expected tuple or struct, found 'void'26// tmp.zig:2:21: error: expected tuple or struct, found 'void'
25// tmp.zig:5:14: error: unable to perform 'never_inline' call at compile-time27// tmp.zig:5:14: error: unable to perform 'never_inline' call at compile-time
test/compile_errors/stage1/obj/bin_and_assign_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 a &= a;3 a &= a;
4}4}
55
6// bin and assign on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_and_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a & a;3 _ = a & a;
4}4}
55
6// bin and on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_not_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = ~a;3 _ = ~a;
4}4}
55
6// bin not on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:10: error: use of undefined value here causes undefined behavior10// tmp.zig:3:10: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_or_assign_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 a |= a;3 a |= a;
4}4}
55
6// bin or assign on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_or_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a | a;3 _ = a | a;
4}4}
55
6// bin or on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_xor_assign_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 a ^= a;3 a ^= a;
4}4}
55
6// bin xor assign on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_xor_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a ^ a;3 _ = a ^ a;
4}4}
55
6// bin xor on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/binary_not_on_number_literal.zig+3-1
...@@ -4,6 +4,8 @@ var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE -...@@ -4,6 +4,8 @@ var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE -
44
5export fn entry() usize { return @sizeOf(@TypeOf(block_aligned_stuff)); }5export fn entry() usize { return @sizeOf(@TypeOf(block_aligned_stuff)); }
66
7// binary not on number literal7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'11// tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'
test/compile_errors/stage1/obj/bitCast_same_size_but_bit_count_mismatch.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry(byte: u8) void {...@@ -3,6 +3,8 @@ export fn entry(byte: u8) void {
3 _ = oops;3 _ = oops;
4}4}
55
6// @bitCast same size but bit count mismatch6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits10// tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits
test/compile_errors/stage1/obj/bitCast_to_enum_type.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = y;3 _ = y;
4}4}
55
6// bitCast to enum type6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:24: error: cannot cast a value of type 'y'10// tmp.zig:2:24: error: cannot cast a value of type 'y'
test/compile_errors/stage1/obj/bitCast_with_different_sizes_inside_an_expression.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = foo;3 _ = foo;
4}4}
55
6// @bitCast with different sizes inside an expression6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 410// tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4
test/compile_errors/stage1/obj/bit_shifting_only_works_on_integer_types.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = x;3 _ = x;
4}4}
55
6// bit shifting only works on integer types6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8'10// tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8'
test/compile_errors/stage1/obj/bogus_compile_var.zig+3-1
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1const x = @import("builtin").bogus;1const x = @import("builtin").bogus;
2export fn entry() usize { return @sizeOf(@TypeOf(x)); }2export fn entry() usize { return @sizeOf(@TypeOf(x)); }
33
4// bogus compile var4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'8// tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'
test/compile_errors/stage1/obj/bogus_method_call_on_slice.zig+3-1
...@@ -4,6 +4,8 @@ fn f(m: []const u8) void {...@@ -4,6 +4,8 @@ fn f(m: []const u8) void {
4}4}
5export fn entry() usize { return @sizeOf(@TypeOf(f)); }5export fn entry() usize { return @sizeOf(@TypeOf(f)); }
66
7// bogus method call on slice7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:6: error: no member named 'copy' in '[]const u8'11// tmp.zig:3:6: error: no member named 'copy' in '[]const u8'
test/compile_errors/stage1/obj/bool_not_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = !a;3 _ = !a;
4}4}
55
6// bool not on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:10: error: use of undefined value here causes undefined behavior10// tmp.zig:3:10: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/branch_on_undefined_value.zig+3-1
...@@ -2,6 +2,8 @@ const x = if (undefined) true else false;...@@ -2,6 +2,8 @@ const x = if (undefined) true else false;
22
3export fn entry() usize { return @sizeOf(@TypeOf(x)); }3export fn entry() usize { return @sizeOf(@TypeOf(x)); }
44
5// branch on undefined value5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:1:15: error: use of undefined value here causes undefined behavior9// tmp.zig:1:15: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/cImport_with_bogus_include.zig+3-1
...@@ -1,7 +1,9 @@...@@ -1,7 +1,9 @@
1const c = @cImport(@cInclude("bogus.h"));1const c = @cImport(@cInclude("bogus.h"));
2export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); }2export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); }
33
4// @cImport with bogus include4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:1:11: error: C import failed8// tmp.zig:1:11: error: C import failed
7// .h:1:10: note: 'bogus.h' file not found9// .h:1:10: note: 'bogus.h' file not found
test/compile_errors/stage1/obj/call_assigned_to_constant.zig+3-1
...@@ -16,7 +16,9 @@ export fn entry1() void {...@@ -16,7 +16,9 @@ export fn entry1() void {
16 baz = bar(42);16 baz = bar(42);
17}17}
1818
19// call assigned to constant19// error
20// backend=stage1
21// target=native
20//22//
21// tmp.zig:12:14: error: cannot assign to constant23// tmp.zig:12:14: error: cannot assign to constant
22// tmp.zig:16:14: error: cannot assign to constant24// tmp.zig:16:14: error: cannot assign to constant
test/compile_errors/stage1/obj/call_with_new_stack_on_unsupported_target.zig created+11
...@@ -0,0 +1,11 @@
1var buf: [10]u8 align(16) = undefined;
2export fn entry() void {
3 @call(.{ .stack = &buf }, foo, .{});
4}
5fn foo() void {}
6
7// error
8// backend=stage1
9// target=wasm32-wasi-none
10//
11// tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack
test/compile_errors/stage1/obj/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry1() callconv(.APCS) void {}
2export fn entry2() callconv(.AAPCS) void {}
3export fn entry3() callconv(.AAPCSVFP) void {}
4
5// error
6// backend=stage1
7// target=x86_64-linux-none
8//
9// tmp.zig:1:29: error: callconv 'APCS' is only available on ARM, not x86_64
10// tmp.zig:2:29: error: callconv 'AAPCS' is only available on ARM, not x86_64
11// tmp.zig:3:29: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64
test/compile_errors/stage1/obj/callconv_interrupt_on_unsupported_platform.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() callconv(.Interrupt) void {}
2
3// error
4// backend=stage1
5// target=aarch64-linux-none
6//
7// tmp.zig:1:28: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64
test/compile_errors/stage1/obj/callconv_signal_on_unsupported_platform.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() callconv(.Signal) void {}
2
3// error
4// backend=stage1
5// target=x86_64-linux-none
6//
7// tmp.zig:1:28: error: callconv 'Signal' is only available on AVR, not x86_64
test/compile_errors/stage1/obj/callconv_stdcall_fastcall_thiscall_on_unsupported_platform-0.zig created+23
...@@ -0,0 +1,23 @@
1const F1 = fn () callconv(.Stdcall) void;
2const F2 = fn () callconv(.Fastcall) void;
3const F3 = fn () callconv(.Thiscall) void;
4export fn entry1() void {
5 var a: F1 = undefined;
6 _ = a;
7}
8export fn entry2() void {
9 var a: F2 = undefined;
10 _ = a;
11}
12export fn entry3() void {
13 var a: F3 = undefined;
14 _ = a;
15}
16
17// error
18// backend=stage1
19// target=x86_64-linux-none
20//
21// tmp.zig:1:27: error: callconv 'Stdcall' is only available on x86, not x86_64
22// tmp.zig:2:27: error: callconv 'Fastcall' is only available on x86, not x86_64
23// tmp.zig:3:27: error: callconv 'Thiscall' is only available on x86, not x86_64
test/compile_errors/stage1/obj/callconv_stdcall_fastcall_thiscall_on_unsupported_platform-1.zig created+11
...@@ -0,0 +1,11 @@
1export fn entry1() callconv(.Stdcall) void {}
2export fn entry2() callconv(.Fastcall) void {}
3export fn entry3() callconv(.Thiscall) void {}
4
5// error
6// backend=stage1
7// target=x86_64-linux-none
8//
9// tmp.zig:1:29: error: callconv 'Stdcall' is only available on x86, not x86_64
10// tmp.zig:2:29: error: callconv 'Fastcall' is only available on x86, not x86_64
11// tmp.zig:3:29: error: callconv 'Thiscall' is only available on x86, not x86_64
test/compile_errors/stage1/obj/callconv_vectorcall_on_unsupported_platform.zig created+7
...@@ -0,0 +1,7 @@
1export fn entry() callconv(.Vectorcall) void {}
2
3// error
4// backend=stage1
5// target=x86_64-linux-none
6//
7// tmp.zig:1:28: error: callconv 'Vectorcall' is only available on x86 and AArch64, not x86_64
test/compile_errors/stage1/obj/calling_a_generic_function_only_known_at_runtime.zig+3-1
...@@ -7,6 +7,8 @@ pub fn main() !void {...@@ -7,6 +7,8 @@ pub fn main() !void {
7 foos[0](true);7 foos[0](true);
8}8}
99
10// calling a generic function only known at runtime10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:7:9: error: calling a generic function requires compile-time known function value14// tmp.zig:7:9: error: calling a generic function requires compile-time known function value
test/compile_errors/stage1/obj/calling_function_with_naked_calling_convention.zig+3-1
...@@ -3,7 +3,9 @@ export fn entry() void {...@@ -3,7 +3,9 @@ export fn entry() void {
3}3}
4fn foo() callconv(.Naked) void { }4fn foo() callconv(.Naked) void { }
55
6// calling function with naked calling convention6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:5: error: unable to call function with naked calling convention10// tmp.zig:2:5: error: unable to call function with naked calling convention
9// tmp.zig:4:1: note: declared here11// tmp.zig:4:1: note: declared here
test/compile_errors/stage1/obj/calling_var_args_extern_function_passing_array_instead_of_pointer.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3}3}
4pub extern fn foo(format: *const u8, ...) void;4pub extern fn foo(format: *const u8, ...) void;
55
6// calling var args extern function, passing array instead of pointer6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'10// tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'
test/compile_errors/stage1/obj/cannot_break_out_of_defer_expression.zig+3-1
...@@ -6,6 +6,8 @@ export fn foo() void {...@@ -6,6 +6,8 @@ export fn foo() void {
6 }6 }
7}7}
88
9// cannot break out of defer expression9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:4:13: error: cannot break out of defer expression13// tmp.zig:4:13: error: cannot break out of defer expression
test/compile_errors/stage1/obj/cannot_continue_out_of_defer_expression.zig+3-1
...@@ -6,6 +6,8 @@ export fn foo() void {...@@ -6,6 +6,8 @@ export fn foo() void {
6 }6 }
7}7}
88
9// cannot continue out of defer expression9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:4:13: error: cannot continue out of defer expression13// tmp.zig:4:13: error: cannot continue out of defer expression
test/compile_errors/stage1/obj/capture_group_on_switch_prong_with_incompatible_payload_types.zig+3-1
...@@ -12,7 +12,9 @@ comptime {...@@ -12,7 +12,9 @@ comptime {
12 }12 }
13}13}
1414
15// capture group on switch prong with incompatible payload types15// error
16// backend=stage1
17// target=native
16//18//
17// tmp.zig:8:20: error: capture group with incompatible types19// tmp.zig:8:20: error: capture group with incompatible types
18// tmp.zig:8:9: note: type 'usize' here20// tmp.zig:8:9: note: type 'usize' here
test/compile_errors/stage1/obj/cast_enum_literal_to_enum_but_it_doesnt_match.zig+3-1
...@@ -7,7 +7,9 @@ export fn entry() void {...@@ -7,7 +7,9 @@ export fn entry() void {
7 _ = x;7 _ = x;
8}8}
99
10// cast enum literal to enum but it doesn't match10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:6:20: error: enum 'Foo' has no field named 'c'14// tmp.zig:6:20: error: enum 'Foo' has no field named 'c'
13// tmp.zig:1:13: note: 'Foo' declared here15// tmp.zig:1:13: note: 'Foo' declared here
test/compile_errors/stage1/obj/cast_error_union_of_global_error_set_to_error_union_of_smaller_error_set.zig+3-1
...@@ -7,7 +7,9 @@ fn foo() anyerror!i32 {...@@ -7,7 +7,9 @@ fn foo() anyerror!i32 {
7 return error.B;7 return error.B;
8}8}
99
10// cast error union of global error set to error union of smaller error set10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32'14// tmp.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32'
13// tmp.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet'15// tmp.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet'
test/compile_errors/stage1/obj/cast_global_error_set_to_error_set.zig+3-1
...@@ -7,7 +7,9 @@ fn foo() anyerror {...@@ -7,7 +7,9 @@ fn foo() anyerror {
7 return error.B;7 return error.B;
8}8}
99
10// cast global error set to error set10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'14// tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'
13// tmp.zig:3:31: note: cannot cast global error set into smaller set15// tmp.zig:3:31: note: cannot cast global error set into smaller set
test/compile_errors/stage1/obj/cast_negative_integer_literal_to_usize.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = x;3 _ = x;
4}4}
55
6// cast negative integer literal to usize6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'10// tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'
test/compile_errors/stage1/obj/cast_negative_value_to_unsigned_integer.zig+3-1
...@@ -9,7 +9,9 @@ export fn entry1() void {...@@ -9,7 +9,9 @@ export fn entry1() void {
9 _ = unsigned;9 _ = unsigned;
10}10}
1111
12// cast negative value to unsigned integer12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:3:22: error: attempt to cast negative value to unsigned integer16// tmp.zig:3:22: error: attempt to cast negative value to unsigned integer
15// tmp.zig:8:27: error: cannot cast negative value -1 to unsigned integer type 'u32'17// tmp.zig:8:27: error: cannot cast negative value -1 to unsigned integer type 'u32'
test/compile_errors/stage1/obj/cast_unreachable.zig+3-1
...@@ -3,7 +3,9 @@ fn f() i32 {...@@ -3,7 +3,9 @@ fn f() i32 {
3}3}
4export fn entry() void { _ = f(); }4export fn entry() void { _ = f(); }
55
6// cast unreachable6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:12: error: unreachable code10// tmp.zig:2:12: error: unreachable code
9// tmp.zig:2:21: note: control flow is diverted here11// tmp.zig:2:21: note: control flow is diverted here
test/compile_errors/stage1/obj/casting_bit_offset_pointer_to_regular_pointer.zig+3-1
...@@ -14,6 +14,8 @@ fn bar(x: *const u3) u3 {...@@ -14,6 +14,8 @@ fn bar(x: *const u3) u3 {
1414
15export fn entry() usize { return @sizeOf(@TypeOf(foo)); }15export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1616
17// casting bit offset pointer to regular pointer17// error
18// backend=stage1
19// target=native
18//20//
19// tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'21// tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'
test/compile_errors/stage1/obj/catch_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a catch false;3 _ = a catch false;
4}4}
55
6// catch on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:11: error: use of undefined value here causes undefined behavior10// tmp.zig:3:11: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/chained_comparison_operators.zig+3-1
...@@ -2,6 +2,8 @@ export fn a(value: u32) bool {...@@ -2,6 +2,8 @@ export fn a(value: u32) bool {
2 return 1 < value < 1000;2 return 1 < value < 1000;
3}3}
44
5// chained comparison operators5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:22: error: comparison operators cannot be chained9// tmp.zig:2:22: error: comparison operators cannot be chained
test/compile_errors/stage1/obj/cmpxchg_with_float.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst);3 _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst);
4}4}
55
6// cmpxchg with float6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32'10// tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32'
test/compile_errors/stage1/obj/colliding_invalid_top_level_functions.zig+3-1
...@@ -2,7 +2,9 @@ fn func() bogus {}...@@ -2,7 +2,9 @@ fn func() bogus {}
2fn func() bogus {}2fn func() bogus {}
3export fn entry() usize { return @sizeOf(@TypeOf(func)); }3export fn entry() usize { return @sizeOf(@TypeOf(func)); }
44
5// colliding invalid top level functions5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:1: error: redeclaration of 'func'9// tmp.zig:2:1: error: redeclaration of 'func'
8// tmp.zig:1:1: note: other declaration here10// tmp.zig:1:1: note: other declaration here
test/compile_errors/stage1/obj/compare_optional_to_non-optional_with_invalid_types.zig+3-1
...@@ -22,7 +22,9 @@ export fn invalidChildType() void {...@@ -22,7 +22,9 @@ export fn invalidChildType() void {
22 _ = (x == y);22 _ = (x == y);
23}23}
2424
25// compare optional to non-optional with invalid types25// error
26// backend=stage1
27// target=native
26//28//
27// :4:12: error: cannot compare types '?i32' and 'comptime_int'29// :4:12: error: cannot compare types '?i32' and 'comptime_int'
28// :4:12: note: optional child type 'i32' must be the same as non-optional type 'comptime_int'30// :4:12: note: optional child type 'i32' must be the same as non-optional type 'comptime_int'
test/compile_errors/stage1/obj/comparing_a_non-optional_pointer_against_null.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = &x == null;3 _ = &x == null;
4}4}
55
6// comparing a non-optional pointer against null6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:12: error: comparison of '*i32' with null10// tmp.zig:3:12: error: comparison of '*i32' with null
test/compile_errors/stage1/obj/comparing_against_undefined_produces_undefined_value.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() void {...@@ -2,6 +2,8 @@ export fn entry() void {
2 if (2 == undefined) {}2 if (2 == undefined) {}
3}3}
44
5// comparing against undefined produces undefined value5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:11: error: use of undefined value here causes undefined behavior9// tmp.zig:2:11: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/comparison_operators_with_undefined_value.zig+3-1
...@@ -35,7 +35,9 @@ comptime {...@@ -35,7 +35,9 @@ comptime {
35 if (a <= a) x += 1;35 if (a <= a) x += 1;
36}36}
3737
38// comparison operators with undefined value38// error
39// backend=stage1
40// target=native
39//41//
40// tmp.zig:5:11: error: use of undefined value here causes undefined behavior42// tmp.zig:5:11: error: use of undefined value here causes undefined behavior
41// tmp.zig:11:11: error: use of undefined value here causes undefined behavior43// tmp.zig:11:11: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/comparison_with_error_union_and_error_value.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = number_or_error == error.SomethingAwful;3 _ = number_or_error == error.SomethingAwful;
4}4}
55
6// comparison with error union and error value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'10// tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'
test/compile_errors/stage1/obj/compile-time_division_by_zero.zig+3-1
...@@ -5,6 +5,8 @@ comptime {...@@ -5,6 +5,8 @@ comptime {
5 _ = c;5 _ = c;
6}6}
77
8// compile-time division by zero8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:17: error: division by zero12// tmp.zig:4:17: error: division by zero
test/compile_errors/stage1/obj/compile-time_remainder_division_by_zero.zig+3-1
...@@ -5,6 +5,8 @@ comptime {...@@ -5,6 +5,8 @@ comptime {
5 _ = c;5 _ = c;
6}6}
77
8// compile-time remainder division by zero8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:17: error: division by zero12// tmp.zig:4:17: error: division by zero
test/compile_errors/stage1/obj/compileError_shows_traceback_of_references_that_caused_it.zig+3-1
...@@ -7,6 +7,8 @@ export fn entry() i32 {...@@ -7,6 +7,8 @@ export fn entry() i32 {
7 return bar;7 return bar;
8}8}
99
10// @compileError shows traceback of references that caused it10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:1:13: error: aoeu14// tmp.zig:1:13: error: aoeu
test/compile_errors/stage1/obj/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig+3-1
...@@ -10,6 +10,8 @@ pub fn main () void {...@@ -10,6 +10,8 @@ pub fn main () void {
10 comptime testCompileLog(Bar{.X = 123});10 comptime testCompileLog(Bar{.X = 123});
11}11}
1212
13// compileLog of tagged enum doesn't crash the compiler13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:6:5: error: found compile log statement17// tmp.zig:6:5: error: found compile log statement
test/compile_errors/stage1/obj/compile_error_in_struct_init_expression.zig+3-1
...@@ -9,6 +9,8 @@ export fn entry() void {...@@ -9,6 +9,8 @@ export fn entry() void {
9 _ = x;9 _ = x;
10}10}
1111
12// compile error in struct init expression12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:2:14: error: use of undeclared identifier 'crap'16// tmp.zig:2:14: error: use of undeclared identifier 'crap'
test/compile_errors/stage1/obj/compile_error_when_evaluating_return_type_of_inferred_error_set.zig+3-1
...@@ -7,6 +7,8 @@ export fn entry() void {...@@ -7,6 +7,8 @@ export fn entry() void {
7 _ = car;7 _ = car;
8}8}
99
10// compile error when evaluating return type of inferred error set10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'14// tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'
test/compile_errors/stage1/obj/compile_log.zig+3-1
...@@ -7,7 +7,9 @@ fn bar(a: i32, b: []const u8) void {...@@ -7,7 +7,9 @@ fn bar(a: i32, b: []const u8) void {
7 @compileLog("end",);7 @compileLog("end",);
8}8}
99
10// compile log10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:5:5: error: found compile log statement14// tmp.zig:5:5: error: found compile log statement
13// tmp.zig:6:5: error: found compile log statement15// tmp.zig:6:5: error: found compile log statement
test/compile_errors/stage1/obj/compile_log_a_pointer_to_an_opaque_value.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() void {...@@ -2,6 +2,8 @@ export fn entry() void {
2 @compileLog(@ptrCast(*const anyopaque, &entry));2 @compileLog(@ptrCast(*const anyopaque, &entry));
3}3}
44
5// compile log a pointer to an opaque value5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:5: error: found compile log statement9// tmp.zig:2:5: error: found compile log statement
test/compile_errors/stage1/obj/compile_log_statement_inside_function_which_must_be_comptime_evaluated.zig+3-1
...@@ -7,6 +7,8 @@ export fn entry() void {...@@ -7,6 +7,8 @@ export fn entry() void {
7 _ = @typeName(Foo(i32));7 _ = @typeName(Foo(i32));
8}8}
99
10// compile log statement inside function which must be comptime evaluated10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:2:5: error: found compile log statement14// tmp.zig:2:5: error: found compile log statement
test/compile_errors/stage1/obj/compile_log_statement_warning_deduplication_in_generic_fn.zig+3-1
...@@ -7,6 +7,8 @@ fn inner(comptime n: usize) void {...@@ -7,6 +7,8 @@ fn inner(comptime n: usize) void {
7 inline while (i < n) : (i += 1) { @compileLog("!@#$"); }7 inline while (i < n) : (i += 1) { @compileLog("!@#$"); }
8}8}
99
10// compile log statement warning deduplication in generic fn10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:7:39: error: found compile log statement14// tmp.zig:7:39: error: found compile log statement
test/compile_errors/stage1/obj/compile_time_division_by_zero.zig+3-1
...@@ -5,6 +5,8 @@ fn foo(x: u32) u32 {...@@ -5,6 +5,8 @@ fn foo(x: u32) u32 {
55
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
77
8// compile time division by zero8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:3:14: error: division by zero12// tmp.zig:3:14: error: division by zero
test/compile_errors/stage1/obj/comptime_cast_enum_to_union_but_field_has_payload.zig+3-1
...@@ -9,7 +9,9 @@ export fn entry() void {...@@ -9,7 +9,9 @@ export fn entry() void {
9 _ = x;9 _ = x;
10}10}
1111
12// comptime cast enum to union but field has payload12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'16// tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'
15// tmp.zig:3:5: note: field 'A' declared here17// tmp.zig:3:5: note: field 'A' declared here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_catch.zig+3-1
...@@ -8,7 +8,9 @@ fn bad() !void {...@@ -8,7 +8,9 @@ fn bad() !void {
8 return error.Bad;8 return error.Bad;
9}9}
1010
11// comptime continue inside runtime catch11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:4:21: error: comptime control flow inside runtime block15// tmp.zig:4:21: error: comptime control flow inside runtime block
14// tmp.zig:4:15: note: runtime block created here16// tmp.zig:4:15: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_bool.zig+3-1
...@@ -7,7 +7,9 @@ export fn entry() void {...@@ -7,7 +7,9 @@ export fn entry() void {
7 }7 }
8}8}
99
10// comptime continue inside runtime if bool10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:5:22: error: comptime control flow inside runtime block14// tmp.zig:5:22: error: comptime control flow inside runtime block
13// tmp.zig:5:9: note: runtime block created here15// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_error.zig+3-1
...@@ -7,7 +7,9 @@ export fn entry() void {...@@ -7,7 +7,9 @@ export fn entry() void {
7 }7 }
8}8}
99
10// comptime continue inside runtime if error10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:5:20: error: comptime control flow inside runtime block14// tmp.zig:5:20: error: comptime control flow inside runtime block
13// tmp.zig:5:9: note: runtime block created here15// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_optional.zig+3-1
...@@ -7,7 +7,9 @@ export fn entry() void {...@@ -7,7 +7,9 @@ export fn entry() void {
7 }7 }
8}8}
99
10// comptime continue inside runtime if optional10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:5:20: error: comptime control flow inside runtime block14// tmp.zig:5:20: error: comptime control flow inside runtime block
13// tmp.zig:5:9: note: runtime block created here15// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_switch.zig+3-1
...@@ -10,7 +10,9 @@ export fn entry() void {...@@ -10,7 +10,9 @@ export fn entry() void {
10 }10 }
11}11}
1212
13// comptime continue inside runtime switch13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:6:19: error: comptime control flow inside runtime block17// tmp.zig:6:19: error: comptime control flow inside runtime block
16// tmp.zig:5:9: note: runtime block created here18// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_bool.zig+3-1
...@@ -7,7 +7,9 @@ export fn entry() void {...@@ -7,7 +7,9 @@ export fn entry() void {
7 }7 }
8}8}
99
10// comptime continue inside runtime while bool10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:5:25: error: comptime control flow inside runtime block14// tmp.zig:5:25: error: comptime control flow inside runtime block
13// tmp.zig:5:9: note: runtime block created here15// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_error.zig+3-1
...@@ -9,7 +9,9 @@ export fn entry() void {...@@ -9,7 +9,9 @@ export fn entry() void {
9 }9 }
10}10}
1111
12// comptime continue inside runtime while error12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:6:13: error: comptime control flow inside runtime block16// tmp.zig:6:13: error: comptime control flow inside runtime block
15// tmp.zig:5:9: note: runtime block created here17// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_optional.zig+3-1
...@@ -7,7 +7,9 @@ export fn entry() void {...@@ -7,7 +7,9 @@ export fn entry() void {
7 }7 }
8}8}
99
10// comptime continue inside runtime while optional10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:5:23: error: comptime control flow inside runtime block14// tmp.zig:5:23: error: comptime control flow inside runtime block
13// tmp.zig:5:9: note: runtime block created here15// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_float_in_asm_input.zig+3-1
...@@ -2,6 +2,8 @@ export fn foo() void {...@@ -2,6 +2,8 @@ export fn foo() void {
2 asm volatile ("" : : [bar]"r"(3.17) : "");2 asm volatile ("" : : [bar]"r"(3.17) : "");
3}3}
44
5// comptime_float in asm input5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float9// tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float
test/compile_errors/stage1/obj/comptime_implicit_cast_f64_to_f32.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 _ = y;4 _ = y;
5}5}
66
7// comptime implicit cast f64 to f327// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information11// tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information
test/compile_errors/stage1/obj/comptime_int_in_asm_input.zig+3-1
...@@ -2,6 +2,8 @@ export fn foo() void {...@@ -2,6 +2,8 @@ export fn foo() void {
2 asm volatile ("" : : [bar]"r"(3) : "");2 asm volatile ("" : : [bar]"r"(3) : "");
3}3}
44
5// comptime_int in asm input5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int9// tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int
test/compile_errors/stage1/obj/comptime_ptrcast_of_zero-sized_type.zig+3-1
...@@ -5,6 +5,8 @@ fn foo() void {...@@ -5,6 +5,8 @@ fn foo() void {
5}5}
6comptime { foo(); }6comptime { foo(); }
77
8// comptime ptrcast of zero-sized type8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation12// tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation
test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig+3-1
...@@ -54,7 +54,9 @@ export fn foo_slice() void {...@@ -54,7 +54,9 @@ export fn foo_slice() void {
54 }54 }
55}55}
5656
57// comptime slice-sentinel does not match memory at target index (terminated)57// error
58// backend=stage1
59// target=native
58//60//
59// :4:29: error: slice-sentinel does not match memory at target index61// :4:29: error: slice-sentinel does not match memory at target index
60// :12:29: error: slice-sentinel does not match memory at target index62// :12:29: error: slice-sentinel does not match memory at target index
test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig+3-1
...@@ -54,7 +54,9 @@ export fn foo_slice() void {...@@ -54,7 +54,9 @@ export fn foo_slice() void {
54 }54 }
55}55}
5656
57// comptime slice-sentinel does not match memory at target index (unterminated)57// error
58// backend=stage1
59// target=native
58//60//
59// :4:29: error: slice-sentinel does not match memory at target index61// :4:29: error: slice-sentinel does not match memory at target index
60// :12:29: error: slice-sentinel does not match memory at target index62// :12:29: error: slice-sentinel does not match memory at target index
test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_target-sentinel.zig+3-1
...@@ -54,7 +54,9 @@ export fn foo_slice() void {...@@ -54,7 +54,9 @@ export fn foo_slice() void {
54 }54 }
55}55}
5656
57// comptime slice-sentinel does not match target-sentinel57// error
58// backend=stage1
59// target=native
58//60//
59// :4:29: error: slice-sentinel does not match target-sentinel61// :4:29: error: slice-sentinel does not match target-sentinel
60// :12:29: error: slice-sentinel does not match target-sentinel62// :12:29: error: slice-sentinel does not match target-sentinel
test/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_terminated.zig+3-1
...@@ -54,7 +54,9 @@ export fn foo_slice() void {...@@ -54,7 +54,9 @@ export fn foo_slice() void {
54 }54 }
55}55}
5656
57// comptime slice-sentinel is out of bounds (terminated)57// error
58// backend=stage1
59// target=native
58//60//
59// :4:29: error: out of bounds slice61// :4:29: error: out of bounds slice
60// :12:29: error: out of bounds slice62// :12:29: error: out of bounds slice
test/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig+3-1
...@@ -54,7 +54,9 @@ export fn foo_slice() void {...@@ -54,7 +54,9 @@ export fn foo_slice() void {
54 }54 }
55}55}
5656
57// comptime slice-sentinel is out of bounds (unterminated)57// error
58// backend=stage1
59// target=native
58//60//
59// :4:29: error: slice-sentinel is out of bounds61// :4:29: error: slice-sentinel is out of bounds
60// :12:29: error: slice-sentinel is out of bounds62// :12:29: error: slice-sentinel is out of bounds
test/compile_errors/stage1/obj/comptime_slice_of_an_undefined_slice.zig+3-1
...@@ -4,6 +4,8 @@ comptime {...@@ -4,6 +4,8 @@ comptime {
4 _ = b;4 _ = b;
5}5}
66
7// comptime slice of an undefined slice7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:14: error: slice of undefined11// tmp.zig:3:14: error: slice of undefined
test/compile_errors/stage1/obj/comptime_slice_of_undefined_pointer_non-zero_len.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = slice;3 _ = slice;
4}4}
55
6// comptime slice of undefined pointer non-zero len6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:41: error: non-zero length slice of undefined pointer10// tmp.zig:2:41: error: non-zero length slice of undefined pointer
test/compile_errors/stage1/obj/comptime_struct_field_no_init_value.zig+3-1
...@@ -6,6 +6,8 @@ export fn entry() void {...@@ -6,6 +6,8 @@ export fn entry() void {
6 _ = f;6 _ = f;
7}7}
88
9// comptime struct field, no init value9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:2:5: error: comptime field without default initialization value13// tmp.zig:2:5: error: comptime field without default initialization value
test/compile_errors/stage1/obj/const_frame_cast_to_anyframe.zig+3-1
...@@ -11,7 +11,9 @@ fn func() void {...@@ -11,7 +11,9 @@ fn func() void {
11 suspend {}11 suspend {}
12}12}
1313
14// const frame cast to anyframe14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)'18// tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)'
17// tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'19// tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'
test/compile_errors/stage1/obj/const_is_a_statement_not_an_expression.zig+3-1
...@@ -2,6 +2,8 @@ export fn f() void {...@@ -2,6 +2,8 @@ export fn f() void {
2 (const a = 0);2 (const a = 0);
3}3}
44
5// const is a statement, not an expression5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:6: error: expected expression, found 'const'9// tmp.zig:2:6: error: expected expression, found 'const'
test/compile_errors/stage1/obj/container_init_with_non-type.zig+3-1
...@@ -3,6 +3,8 @@ const a = zero{1};...@@ -3,6 +3,8 @@ const a = zero{1};
33
4export fn entry() usize { return @sizeOf(@TypeOf(a)); }4export fn entry() usize { return @sizeOf(@TypeOf(a)); }
55
6// container init with non-type6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:11: error: expected type 'type', found 'i32'10// tmp.zig:2:11: error: expected type 'type', found 'i32'
test/compile_errors/stage1/obj/control_flow_uses_comptime_var_at_runtime.zig+3-1
...@@ -7,7 +7,9 @@ export fn foo() void {...@@ -7,7 +7,9 @@ export fn foo() void {
77
8fn bar() void { }8fn bar() void { }
99
10// control flow uses comptime var at runtime10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:3:5: error: control flow attempts to use compile-time variable at runtime14// tmp.zig:3:5: error: control flow attempts to use compile-time variable at runtime
13// tmp.zig:3:24: note: compile-time variable assigned here15// tmp.zig:3:24: note: compile-time variable assigned here
test/compile_errors/stage1/obj/control_reaches_end_of_non-void_function.zig+3-1
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1fn a() i32 {}1fn a() i32 {}
2export fn entry() void { _ = a(); }2export fn entry() void { _ = a(); }
33
4// control reaches end of non-void function4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:1:12: error: expected type 'i32', found 'void'8// tmp.zig:1:12: error: expected type 'i32', found 'void'
test/compile_errors/stage1/obj/declaration_between_fields.zig+3-1
...@@ -15,7 +15,9 @@ comptime {...@@ -15,7 +15,9 @@ comptime {
15 _ = S;15 _ = S;
16}16}
1717
18// declaration between fields18// error
19// backend=stage1
20// target=native
19//21//
20// tmp.zig:9:5: error: declarations are not allowed between container fields22// tmp.zig:9:5: error: declarations are not allowed between container fields
21// tmp.zig:5:5: note: field before declarations here23// tmp.zig:5:5: note: field before declarations here
test/compile_errors/stage1/obj/declaration_with_same_name_as_primitive_must_use_special_syntax.zig+3-1
...@@ -4,7 +4,9 @@ export fn entry() void {...@@ -4,7 +4,9 @@ export fn entry() void {
4 _ = a;4 _ = a;
5}5}
66
7// declaration with same name as primitive must use special syntax7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:1:7: error: name shadows primitive 'u8'11// tmp.zig:1:7: error: name shadows primitive 'u8'
10// tmp.zig:1:7: note: consider using @"u8" to disambiguate12// tmp.zig:1:7: note: consider using @"u8" to disambiguate
test/compile_errors/stage1/obj/deduplicate_undeclared_identifier.zig+3-1
...@@ -5,6 +5,8 @@ export fn b() void {...@@ -5,6 +5,8 @@ export fn b() void {
5 x += 1;5 x += 1;
6}6}
77
8// deduplicate undeclared identifier8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:2:5: error: use of undeclared identifier 'x'12// tmp.zig:2:5: error: use of undeclared identifier 'x'
test/compile_errors/stage1/obj/deref_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a.*;3 _ = a.*;
4}4}
55
6// deref on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: attempt to dereference undefined value10// tmp.zig:3:9: error: attempt to dereference undefined value
test/compile_errors/stage1/obj/deref_slice_and_get_len_field.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = a.*.len;3 _ = a.*.len;
4}4}
55
6// deref slice and get len field6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'10// tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'
test/compile_errors/stage1/obj/dereference_an_array.zig+3-1
...@@ -7,6 +7,8 @@ pub fn pass(in: []u8) []u8 {...@@ -7,6 +7,8 @@ pub fn pass(in: []u8) []u8 {
77
8export fn entry() usize { return @sizeOf(@TypeOf(pass)); }8export fn entry() usize { return @sizeOf(@TypeOf(pass)); }
99
10// dereference an array10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'14// tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'
test/compile_errors/stage1/obj/dereference_unknown_length_pointer.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry(x: [*]i32) i32 {...@@ -2,6 +2,8 @@ export fn entry(x: [*]i32) i32 {
2 return x.*;2 return x.*;
3}3}
44
5// dereference unknown length pointer5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'9// tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'
test/compile_errors/stage1/obj/direct_struct_loop.zig+3-1
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1const A = struct { a : A, };1const A = struct { a : A, };
2export fn entry() usize { return @sizeOf(A); }2export fn entry() usize { return @sizeOf(A); }
33
4// direct struct loop4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:1:11: error: struct 'A' depends on itself8// tmp.zig:1:11: error: struct 'A' depends on itself
test/compile_errors/stage1/obj/directly_embedding_opaque_type_in_struct_and_union.zig+3-1
...@@ -20,7 +20,9 @@ export fn c() void {...@@ -20,7 +20,9 @@ export fn c() void {
20 _ = qux;20 _ = qux;
21}21}
2222
23// directly embedding opaque type in struct and union23// error
24// backend=stage1
25// target=native
24//26//
25// tmp.zig:3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs27// tmp.zig:3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs
26// tmp.zig:7:5: error: opaque types have unknown size and therefore cannot be directly embedded in unions28// tmp.zig:7:5: error: opaque types have unknown size and therefore cannot be directly embedded in unions
test/compile_errors/stage1/obj/disallow_coercion_from_non-null-terminated_pointer_to_null-terminated_pointer.zig+3-1
...@@ -5,6 +5,8 @@ pub fn main() void {...@@ -5,6 +5,8 @@ pub fn main() void {
5 _ = puts(no_zero_ptr);5 _ = puts(no_zero_ptr);
6}6}
77
8// disallow coercion from non-null-terminated pointer to null-terminated pointer8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'12// tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'
test/compile_errors/stage1/obj/discarding_error_value.zig+3-1
...@@ -5,6 +5,8 @@ fn foo() !void {...@@ -5,6 +5,8 @@ fn foo() !void {
5 return error.OutOfMemory;5 return error.OutOfMemory;
6}6}
77
8// discarding error value8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`12// tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`
test/compile_errors/stage1/obj/div_assign_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 a /= a;3 a /= a;
4}4}
55
6// div assign on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/div_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a / a;3 _ = a / a;
4}4}
55
6// div on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/division_by_zero.zig+3-1
...@@ -8,7 +8,9 @@ export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); }...@@ -8,7 +8,9 @@ export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); }
8export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); }8export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); }
9export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); }9export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); }
1010
11// division by zero11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:1:21: error: division by zero15// tmp.zig:1:21: error: division by zero
14// tmp.zig:2:25: error: division by zero16// tmp.zig:2:25: error: division by zero
test/compile_errors/stage1/obj/dont_implicit_cast_double_pointer_to_anyopaque.zig+3-1
...@@ -6,6 +6,8 @@ export fn entry() void {...@@ -6,6 +6,8 @@ export fn entry() void {
6 _ = ptr2;6 _ = ptr2;
7}7}
88
9// don't implicit cast double pointer to *anyopaque9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:5:29: error: expected type '*anyopaque', found '**u32'13// tmp.zig:5:29: error: expected type '*anyopaque', found '**u32'
test/compile_errors/stage1/obj/double_optional_on_main_return_value.zig+3-1
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1pub fn main() ??void {1pub fn main() ??void {
2}2}
33
4// double ?? on main return value4// error
5// backend=stage1
6// target=native
5//7//
6// error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'8// error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'
test/compile_errors/stage1/obj/duplicate_boolean_switch_value.zig+3-1
...@@ -15,7 +15,9 @@ comptime {...@@ -15,7 +15,9 @@ comptime {
15 _ = x;15 _ = x;
16}16}
1717
18// duplicate boolean switch value18// error
19// backend=stage1
20// target=native
19//21//
20// tmp.zig:5:9: error: duplicate switch value22// tmp.zig:5:9: error: duplicate switch value
21// tmp.zig:13:9: error: duplicate switch value23// tmp.zig:13:9: error: duplicate switch value
test/compile_errors/stage1/obj/duplicate_enum_field.zig+3-1
...@@ -8,7 +8,9 @@ export fn entry() void {...@@ -8,7 +8,9 @@ export fn entry() void {
8 _ = a;8 _ = a;
9}9}
1010
11// duplicate enum field11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:3:5: error: duplicate enum field: 'Bar'15// tmp.zig:3:5: error: duplicate enum field: 'Bar'
14// tmp.zig:2:5: note: other field here16// tmp.zig:2:5: note: other field here
test/compile_errors/stage1/obj/duplicate_error_in_switch.zig+3-1
...@@ -14,7 +14,9 @@ fn foo(x: i32) !void {...@@ -14,7 +14,9 @@ fn foo(x: i32) !void {
14 }14 }
15}15}
1616
17// duplicate error in switch17// error
18// backend=stage1
19// target=native
18//20//
19// tmp.zig:5:14: error: duplicate switch value: '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set.Foo'21// tmp.zig:5:14: error: duplicate switch value: '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set.Foo'
20// tmp.zig:3:14: note: other value here22// tmp.zig:3:14: note: other value here
test/compile_errors/stage1/obj/duplicate_error_value_in_error_set.zig+3-1
...@@ -7,7 +7,9 @@ export fn entry() void {...@@ -7,7 +7,9 @@ export fn entry() void {
7 _ = a;7 _ = a;
8}8}
99
10// duplicate error value in error set10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:3:5: error: duplicate error set field 'Bar'14// tmp.zig:3:5: error: duplicate error set field 'Bar'
13// tmp.zig:2:5: note: previous declaration here15// tmp.zig:2:5: note: previous declaration here
test/compile_errors/stage1/obj/duplicate_field_in_struct_value_expression.zig+3-1
...@@ -13,6 +13,8 @@ export fn f() void {...@@ -13,6 +13,8 @@ export fn f() void {
13 _ = a;13 _ = a;
14}14}
1515
16// duplicate field in struct value expression16// error
17// backend=stage1
18// target=native
17//19//
18// tmp.zig:11:9: error: duplicate field20// tmp.zig:11:9: error: duplicate field
test/compile_errors/stage1/obj/duplicate_struct_field.zig+3-1
...@@ -7,7 +7,9 @@ export fn entry() void {...@@ -7,7 +7,9 @@ export fn entry() void {
7 _ = a;7 _ = a;
8}8}
99
10// duplicate struct field10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:3:5: error: duplicate struct field: 'Bar'14// tmp.zig:3:5: error: duplicate struct field: 'Bar'
13// tmp.zig:2:5: note: other field here15// tmp.zig:2:5: note: other field here
test/compile_errors/stage1/obj/duplicate_union_field.zig+3-1
...@@ -7,7 +7,9 @@ export fn entry() void {...@@ -7,7 +7,9 @@ export fn entry() void {
7 _ = a;7 _ = a;
8}8}
99
10// duplicate union field10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:3:5: error: duplicate union field: 'Bar'14// tmp.zig:3:5: error: duplicate union field: 'Bar'
13// tmp.zig:2:5: note: other field here15// tmp.zig:2:5: note: other field here
test/compile_errors/stage1/obj/embedFile_with_bogus_file.zig+3-1
...@@ -2,6 +2,8 @@ const resource = @embedFile("bogus.txt",);...@@ -2,6 +2,8 @@ const resource = @embedFile("bogus.txt",);
22
3export fn entry() usize { return @sizeOf(@TypeOf(resource)); }3export fn entry() usize { return @sizeOf(@TypeOf(resource)); }
44
5// @embedFile with bogus file5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:1:29: error: unable to find '9// tmp.zig:1:29: error: unable to find '
test/compile_errors/stage1/obj/empty_for_loop_body.zig+3-1
...@@ -2,6 +2,8 @@ export fn a() void {...@@ -2,6 +2,8 @@ export fn a() void {
2 for(undefined) |x|;2 for(undefined) |x|;
3}3}
44
5// empty for loop body5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:23: error: expected block or assignment, found ';'9// tmp.zig:2:23: error: expected block or assignment, found ';'
test/compile_errors/stage1/obj/empty_if_body.zig+3-1
...@@ -2,6 +2,8 @@ export fn a() void {...@@ -2,6 +2,8 @@ export fn a() void {
2 if(true);2 if(true);
3}3}
44
5// empty if body5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:13: error: expected block or assignment, found ';'9// tmp.zig:2:13: error: expected block or assignment, found ';'
test/compile_errors/stage1/obj/empty_switch_on_an_integer.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 switch(x) {}3 switch(x) {}
4}4}
55
6// empty switch on an integer6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: switch must handle all possibilities10// tmp.zig:3:5: error: switch must handle all possibilities
test/compile_errors/stage1/obj/empty_while_loop_body.zig+3-1
...@@ -2,6 +2,8 @@ export fn a() void {...@@ -2,6 +2,8 @@ export fn a() void {
2 while(true);2 while(true);
3}3}
44
5// empty while loop body5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:16: error: expected block or assignment, found ';'9// tmp.zig:2:16: error: expected block or assignment, found ';'
test/compile_errors/stage1/obj/endless_loop_in_function_evaluation.zig+3-1
...@@ -5,6 +5,8 @@ fn fibonacci(x: i32) i32 {...@@ -5,6 +5,8 @@ fn fibonacci(x: i32) i32 {
55
6export fn entry() usize { return @sizeOf(@TypeOf(seventh_fib_number)); }6export fn entry() usize { return @sizeOf(@TypeOf(seventh_fib_number)); }
77
8// endless loop in function evaluation8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches12// tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches
test/compile_errors/stage1/obj/enum_field_value_references_enum.zig+3-1
...@@ -8,6 +8,8 @@ export fn entry() void {...@@ -8,6 +8,8 @@ export fn entry() void {
8}8}
9const D = 1;9const D = 1;
1010
11// enum field value references enum11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:1:17: error: enum 'Foo' depends on itself15// tmp.zig:1:17: error: enum 'Foo' depends on itself
test/compile_errors/stage1/obj/enum_in_field_count_range_but_not_matching_tag.zig+3-1
...@@ -7,7 +7,9 @@ export fn entry() void {...@@ -7,7 +7,9 @@ export fn entry() void {
7 _ = x;7 _ = x;
8}8}
99
10// enum in field count range but not matching tag10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 014// tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0
13// tmp.zig:1:13: note: 'Foo' declared here15// tmp.zig:1:13: note: 'Foo' declared here
test/compile_errors/stage1/obj/enum_value_already_taken.zig+3-1
...@@ -10,7 +10,9 @@ export fn entry() void {...@@ -10,7 +10,9 @@ export fn entry() void {
10 _ = x;10 _ = x;
11}11}
1212
13// enum value already taken13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:6:5: error: enum tag value 60 already taken17// tmp.zig:6:5: error: enum tag value 60 already taken
16// tmp.zig:4:5: note: other occurrence here18// tmp.zig:4:5: note: other occurrence here
test/compile_errors/stage1/obj/enum_with_0_fields.zig+3-1
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1const Foo = enum {};1const Foo = enum {};
22
3// enum with 0 fields3// error
4// backend=stage1
5// target=native
4//6//
5// tmp.zig:1:13: error: enum declarations must have at least one tag7// tmp.zig:1:13: error: enum declarations must have at least one tag
test/compile_errors/stage1/obj/enum_with_declarations_unavailable_for_reify_type.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() void {...@@ -2,6 +2,8 @@ export fn entry() void {
2 _ = @Type(@typeInfo(enum { foo, const bar = 1; }));2 _ = @Type(@typeInfo(enum { foo, const bar = 1; }));
3}3}
44
5// enum with declarations unavailable for @Type5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:15: error: Type.Enum.decls must be empty for @Type9// tmp.zig:2:15: error: Type.Enum.decls must be empty for @Type
test/compile_errors/stage1/obj/error_equality_but_sets_have_no_common_members.zig+3-1
...@@ -9,6 +9,8 @@ fn foo(x: Set1) void {...@@ -9,6 +9,8 @@ fn foo(x: Set1) void {
9 }9 }
10}10}
1111
12// error equality but sets have no common members12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors16// tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors
test/compile_errors/stage1/obj/error_not_handled_in_switch.zig+3-1
...@@ -12,7 +12,9 @@ fn foo(x: i32) !void {...@@ -12,7 +12,9 @@ fn foo(x: i32) !void {
12 }12 }
13}13}
1414
15// error not handled in switch15// error
16// backend=stage1
17// target=native
16//18//
17// tmp.zig:2:26: error: error.Baz not handled in switch19// tmp.zig:2:26: error: error.Baz not handled in switch
18// tmp.zig:2:26: error: error.Bar not handled in switch20// tmp.zig:2:26: error: error.Bar not handled in switch
test/compile_errors/stage1/obj/error_note_for_function_parameter_incompatibility.zig+3-1
...@@ -4,7 +4,9 @@ export fn entry() void {...@@ -4,7 +4,9 @@ export fn entry() void {
4 do_the_thing(bar);4 do_the_thing(bar);
5}5}
66
7// error note for function parameter incompatibility7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void11// tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void
10// tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'12// tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'
test/compile_errors/stage1/obj/error_union_operator_with_non_error_set_LHS.zig+3-1
...@@ -4,6 +4,8 @@ comptime {...@@ -4,6 +4,8 @@ comptime {
4 _ = x;4 _ = x;
5}5}
66
7// error union operator with non error set LHS7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:2:15: error: expected error set type, found type 'i32'11// tmp.zig:2:15: error: expected error set type, found type 'i32'
test/compile_errors/stage1/obj/error_when_evaluating_return_type.zig+3-1
...@@ -10,6 +10,8 @@ export fn entry() void {...@@ -10,6 +10,8 @@ export fn entry() void {
10 _ = rule_set;10 _ = rule_set;
11}11}
1212
13// error when evaluating return type13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:2:19: error: expected type 'i32', found 'type'17// tmp.zig:2:19: error: expected type 'i32', found 'type'
test/compile_errors/stage1/obj/exceeded_maximum_bit_width_of_integer.zig+3-1
...@@ -7,7 +7,9 @@ export fn entry2() void {...@@ -7,7 +7,9 @@ export fn entry2() void {
7 _ = x;7 _ = x;
8}8}
99
10// exceeded maximum bit width of integer10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:2:15: error: primitive integer type 'u65536' exceeds maximum bit width of 6553514// tmp.zig:2:15: error: primitive integer type 'u65536' exceeds maximum bit width of 65535
13// tmp.zig:6:12: error: primitive integer type 'i65536' exceeds maximum bit width of 6553515// tmp.zig:6:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535
test/compile_errors/stage1/obj/explicit_cast_float_literal_to_integer_when_there_is_a_fraction_component.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() i32 {...@@ -2,6 +2,8 @@ export fn entry() i32 {
2 return @as(i32, 12.34);2 return @as(i32, 12.34);
3}3}
44
5// explicit cast float literal to integer when there is a fraction component5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'9// tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'
test/compile_errors/stage1/obj/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig+3-1
...@@ -6,6 +6,8 @@ comptime {...@@ -6,6 +6,8 @@ comptime {
6 _ = y;6 _ = y;
7}7}
88
9// explicit error set cast known at comptime violates error sets9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:5:13: error: error.B not a member of error set 'Set2'13// tmp.zig:5:13: error: error.B not a member of error set 'Set2'
test/compile_errors/stage1/obj/explicitly_casting_non_tag_type_to_enum.zig+3-1
...@@ -11,6 +11,8 @@ export fn entry() void {...@@ -11,6 +11,8 @@ export fn entry() void {
11 _ = x;11 _ = x;
12}12}
1313
14// explicitly casting non tag type to enum14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:10:31: error: expected integer type, found 'f32'18// tmp.zig:10:31: error: expected integer type, found 'f32'
test/compile_errors/stage1/obj/export_function_with_comptime_parameter.zig+3-1
...@@ -2,6 +2,8 @@ export fn foo(comptime x: i32, y: i32) i32{...@@ -2,6 +2,8 @@ export fn foo(comptime x: i32, y: i32) i32{
2 return x + y;2 return x + y;
3}3}
44
5// export function with comptime parameter5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'9// tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/export_generic_function.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo(num: anytype) i32 {...@@ -3,6 +3,8 @@ export fn foo(num: anytype) i32 {
3 return 0;3 return 0;
4}4}
55
6// export generic function6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'10// tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/exported_async_function.zig+3-1
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1export fn foo() callconv(.Async) void {}1export fn foo() callconv(.Async) void {}
22
3// exported async function3// error
4// backend=stage1
5// target=native
4//6//
5// tmp.zig:1:1: error: exported function cannot be async7// tmp.zig:1:1: error: exported function cannot be async
test/compile_errors/stage1/obj/exported_enum_without_explicit_integer_tag_type.zig+3-1
...@@ -7,7 +7,9 @@ comptime {...@@ -7,7 +7,9 @@ comptime {
7 @export(e, .{ .name = "e" });7 @export(e, .{ .name = "e" });
8}8}
99
10// exported enum without explicit integer tag type10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:3:13: error: exported enum without explicit integer tag type14// tmp.zig:3:13: error: exported enum without explicit integer tag type
13// tmp.zig:7:13: error: exported enum value without explicit integer tag type15// tmp.zig:7:13: error: exported enum value without explicit integer tag type
test/compile_errors/stage1/obj/extern_function_pointer_mismatch.zig+3-1
...@@ -5,6 +5,8 @@ export fn c(x: i32) i32 {return x + 2;}...@@ -5,6 +5,8 @@ export fn c(x: i32) i32 {return x + 2;}
55
6export fn entry() usize { return @sizeOf(@TypeOf(fns)); }6export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
77
8// extern function pointer mismatch8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'12// tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'
test/compile_errors/stage1/obj/extern_function_with_comptime_parameter.zig+3-1
...@@ -4,6 +4,8 @@ fn f() i32 {...@@ -4,6 +4,8 @@ fn f() i32 {
4}4}
5export fn entry() usize { return @sizeOf(@TypeOf(f)); }5export fn entry() usize { return @sizeOf(@TypeOf(f)); }
66
7// extern function with comptime parameter7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'11// tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/extern_struct_with_extern-compatible_but_inferred_integer_tag_type.zig+3-1
...@@ -36,6 +36,8 @@ export fn entry() void {...@@ -36,6 +36,8 @@ export fn entry() void {
36 _ = s;36 _ = s;
37}37}
3838
39// extern struct with extern-compatible but inferred integer tag type39// error
40// backend=stage1
41// target=native
40//42//
41// tmp.zig:31:5: error: extern structs cannot contain fields of type 'E'43// tmp.zig:31:5: error: extern structs cannot contain fields of type 'E'
test/compile_errors/stage1/obj/extern_struct_with_non-extern-compatible_integer_tag_type.zig+3-1
...@@ -7,6 +7,8 @@ export fn entry() void {...@@ -7,6 +7,8 @@ export fn entry() void {
7 _ = s;7 _ = s;
8}8}
99
10// extern struct with non-extern-compatible integer tag type10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'14// tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'
test/compile_errors/stage1/obj/extern_union_field_missing_type.zig+3-1
...@@ -6,6 +6,8 @@ export fn entry() void {...@@ -6,6 +6,8 @@ export fn entry() void {
6 _ = a;6 _ = a;
7}7}
88
9// extern union field missing type9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:2:5: error: union field missing type13// tmp.zig:2:5: error: union field missing type
test/compile_errors/stage1/obj/extern_union_given_enum_tag_type.zig+3-1
...@@ -13,6 +13,8 @@ export fn entry() void {...@@ -13,6 +13,8 @@ export fn entry() void {
13 _ = a;13 _ = a;
14}14}
1515
16// extern union given enum tag type16// error
17// backend=stage1
18// target=native
17//19//
18// tmp.zig:6:30: error: extern union does not support enum tag type20// tmp.zig:6:30: error: extern union does not support enum tag type
test/compile_errors/stage1/obj/extern_variable_has_no_type.zig+3-1
...@@ -3,6 +3,8 @@ pub export fn entry() void {...@@ -3,6 +3,8 @@ pub export fn entry() void {
3 foo;3 foo;
4}4}
55
6// extern variable has no type6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:1:8: error: unable to infer variable type10// tmp.zig:1:8: error: unable to infer variable type
test/compile_errors/stage1/obj/fieldParentPtr-bad_field_name.zig+3-1
...@@ -5,6 +5,8 @@ export fn foo(a: *i32) *Foo {...@@ -5,6 +5,8 @@ export fn foo(a: *i32) *Foo {
5 return @fieldParentPtr(Foo, "a", a);5 return @fieldParentPtr(Foo, "a", a);
6}6}
77
8// @fieldParentPtr - bad field name8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:5:33: error: struct 'Foo' has no field 'a'12// tmp.zig:5:33: error: struct 'Foo' has no field 'a'
test/compile_errors/stage1/obj/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig+3-1
...@@ -10,6 +10,8 @@ comptime {...@@ -10,6 +10,8 @@ comptime {
10 _ = another_foo_ptr;10 _ = another_foo_ptr;
11}11}
1212
13// @fieldParentPtr - comptime field ptr not based on struct13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:9:55: error: pointer value not based on parent struct17// tmp.zig:9:55: error: pointer value not based on parent struct
test/compile_errors/stage1/obj/fieldParentPtr-comptime_wrong_field_index.zig+3-1
...@@ -9,6 +9,8 @@ comptime {...@@ -9,6 +9,8 @@ comptime {
9 _ = another_foo_ptr;9 _ = another_foo_ptr;
10}10}
1111
12// @fieldParentPtr - comptime wrong field index12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'16// tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'
test/compile_errors/stage1/obj/fieldParentPtr-field_pointer_is_not_pointer.zig+3-1
...@@ -5,6 +5,8 @@ export fn foo(a: i32) *Foo {...@@ -5,6 +5,8 @@ export fn foo(a: i32) *Foo {
5 return @fieldParentPtr(Foo, "a", a);5 return @fieldParentPtr(Foo, "a", a);
6}6}
77
8// @fieldParentPtr - field pointer is not pointer8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:5:38: error: expected pointer, found 'i32'12// tmp.zig:5:38: error: expected pointer, found 'i32'
test/compile_errors/stage1/obj/fieldParentPtr-non_struct.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo(a: *i32) *Foo {...@@ -3,6 +3,8 @@ export fn foo(a: *i32) *Foo {
3 return @fieldParentPtr(Foo, "a", a);3 return @fieldParentPtr(Foo, "a", a);
4}4}
55
6// @fieldParentPtr - non struct6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:28: error: expected struct type, found 'i32'10// tmp.zig:3:28: error: expected struct type, found 'i32'
test/compile_errors/stage1/obj/field_access_of_opaque_type.zig+3-1
...@@ -9,6 +9,8 @@ fn bar(x: *MyType) bool {...@@ -9,6 +9,8 @@ fn bar(x: *MyType) bool {
9 return x.blah;9 return x.blah;
10}10}
1111
12// field access of opaque type12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'16// tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'
test/compile_errors/stage1/obj/field_access_of_slices.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 _ = info;4 _ = info;
5}5}
66
7// field access of slices7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:32: error: type 'type' does not support field access11// tmp.zig:3:32: error: type 'type' does not support field access
test/compile_errors/stage1/obj/field_access_of_unknown_length_pointer.zig+3-1
...@@ -6,6 +6,8 @@ export fn entry(foo: [*]Foo) void {...@@ -6,6 +6,8 @@ export fn entry(foo: [*]Foo) void {
6 foo.a += 1;6 foo.a += 1;
7}7}
88
9// field access of unknown length pointer9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:6:8: error: type '[*]Foo' does not support field access13// tmp.zig:6:8: error: type '[*]Foo' does not support field access
test/compile_errors/stage1/obj/field_type_supplied_in_an_enum.zig+3-1
...@@ -4,7 +4,9 @@ const Letter = enum {...@@ -4,7 +4,9 @@ const Letter = enum {
4 C,4 C,
5};5};
66
7// field type supplied in an enum7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:2:8: error: enum fields do not have types11// tmp.zig:2:8: error: enum fields do not have types
10// tmp.zig:1:16: note: consider 'union(enum)' here to make it a tagged union12// tmp.zig:1:16: note: consider 'union(enum)' here to make it a tagged union
test/compile_errors/stage1/obj/floatToInt_comptime_safety.zig+3-1
...@@ -8,7 +8,9 @@ comptime {...@@ -8,7 +8,9 @@ comptime {
8 _ = @floatToInt(u8, @as(f32, 256.1));8 _ = @floatToInt(u8, @as(f32, 256.1));
9}9}
1010
11// @floatToInt comptime safety11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'15// tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'
14// tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8'16// tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8'
test/compile_errors/stage1/obj/float_literal_too_large_error.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a;3 _ = a;
4}4}
55
6// float literal too large error6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:15: error: float literal out of range of any type10// tmp.zig:2:15: error: float literal out of range of any type
test/compile_errors/stage1/obj/float_literal_too_small_error_denormal.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a;3 _ = a;
4}4}
55
6// float literal too small error (denormal)6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:15: error: float literal out of range of any type10// tmp.zig:2:15: error: float literal out of range of any type
test/compile_errors/stage1/obj/for_loop_body_expression_ignored.zig+3-1
...@@ -10,7 +10,9 @@ export fn f2() void {...@@ -10,7 +10,9 @@ export fn f2() void {
10 _ = x;10 _ = x;
11}11}
1212
13// for loop body expression ignored13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:5:30: error: expression value is ignored17// tmp.zig:5:30: error: expression value is ignored
16// tmp.zig:9:30: error: expression value is ignored18// tmp.zig:9:30: error: expression value is ignored
test/compile_errors/stage1/obj/frame_called_outside_of_function_definition.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() bool {...@@ -4,6 +4,8 @@ export fn entry() bool {
4 return handle_undef == handle_dummy;4 return handle_undef == handle_dummy;
5}5}
66
7// @frame() called outside of function definition7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:2:30: error: @frame() called outside of function definition11// tmp.zig:2:30: error: @frame() called outside of function definition
test/compile_errors/stage1/obj/frame_causes_function_to_be_async.zig+3-1
...@@ -5,7 +5,9 @@ fn func() void {...@@ -5,7 +5,9 @@ fn func() void {
5 _ = @frame();5 _ = @frame();
6}6}
77
8// @frame() causes function to be async8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:1:1: error: function with calling convention 'C' cannot be async12// tmp.zig:1:1: error: function with calling convention 'C' cannot be async
11// tmp.zig:5:9: note: @frame() causes function to be async13// tmp.zig:5:9: note: @frame() causes function to be async
test/compile_errors/stage1/obj/function_alignment_non_power_of_2.zig+3-1
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1extern fn foo() align(3) void;1extern fn foo() align(3) void;
2export fn entry() void { return foo(); }2export fn entry() void { return foo(); }
33
4// function alignment non power of 24// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:1:23: error: alignment value 3 is not a power of 28// tmp.zig:1:23: error: alignment value 3 is not a power of 2
test/compile_errors/stage1/obj/function_call_assigned_to_incorrect_type.zig+3-1
...@@ -6,6 +6,8 @@ fn concat() [16]f32 {...@@ -6,6 +6,8 @@ fn concat() [16]f32 {
6 return [1]f32{0}**16;6 return [1]f32{0}**16;
7}7}
88
9// function call assigned to incorrect type9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'13// tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'
test/compile_errors/stage1/obj/function_parameter_is_opaque.zig+3-1
...@@ -19,7 +19,9 @@ export fn entry4() void {...@@ -19,7 +19,9 @@ export fn entry4() void {
19 _ = bar;19 _ = bar;
20}20}
2121
22// function parameter is opaque22// error
23// backend=stage1
24// target=native
23//25//
24// tmp.zig:3:28: error: parameter of opaque type 'FooType' not allowed26// tmp.zig:3:28: error: parameter of opaque type 'FooType' not allowed
25// tmp.zig:8:28: error: parameter of type '@Type(.Null)' not allowed27// tmp.zig:8:28: error: parameter of type '@Type(.Null)' not allowed
test/compile_errors/stage1/obj/function_prototype_with_no_body.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 foo();3 foo();
4}4}
55
6// function prototype with no body6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:1:1: error: non-extern function has no body10// tmp.zig:1:1: error: non-extern function has no body
test/compile_errors/stage1/obj/function_returning_opaque_type.zig+3-1
...@@ -9,7 +9,9 @@ export fn baz() !@TypeOf(undefined) {...@@ -9,7 +9,9 @@ export fn baz() !@TypeOf(undefined) {
9 return error.InvalidValue;9 return error.InvalidValue;
10}10}
1111
12// function returning opaque type12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:2:18: error: Opaque return type 'FooType' not allowed16// tmp.zig:2:18: error: Opaque return type 'FooType' not allowed
15// tmp.zig:1:1: note: type declared here17// tmp.zig:1:1: note: type declared here
test/compile_errors/stage1/obj/function_with_ccc_indirectly_calling_async_function.zig+3-1
...@@ -8,7 +8,9 @@ fn bar() void {...@@ -8,7 +8,9 @@ fn bar() void {
8 suspend {}8 suspend {}
9}9}
1010
11// function with ccc indirectly calling async function11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:1:1: error: function with calling convention 'C' cannot be async15// tmp.zig:1:1: error: function with calling convention 'C' cannot be async
14// tmp.zig:2:8: note: async function call here16// tmp.zig:2:8: note: async function call here
test/compile_errors/stage1/obj/function_with_invalid_return_type.zig+3-1
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1export fn foo() boid {}1export fn foo() boid {}
22
3// function with invalid return type3// error
4// backend=stage1
5// target=native
4//6//
5// tmp.zig:1:17: error: use of undeclared identifier 'boid'7// tmp.zig:1:17: error: use of undeclared identifier 'boid'
test/compile_errors/stage1/obj/function_with_non-extern_non-packed_enum_parameter.zig+3-1
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1const Foo = enum { A, B, C };1const Foo = enum { A, B, C };
2export fn entry(foo: Foo) void { _ = foo; }2export fn entry(foo: Foo) void { _ = foo; }
33
4// function with non-extern non-packed enum parameter4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'8// tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/function_with_non-extern_non-packed_struct_parameter.zig+3-1
...@@ -5,6 +5,8 @@ const Foo = struct {...@@ -5,6 +5,8 @@ const Foo = struct {
5};5};
6export fn entry(foo: Foo) void { _ = foo; }6export fn entry(foo: Foo) void { _ = foo; }
77
8// function with non-extern non-packed struct parameter8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'12// tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/function_with_non-extern_non-packed_union_parameter.zig+3-1
...@@ -5,6 +5,8 @@ const Foo = union {...@@ -5,6 +5,8 @@ const Foo = union {
5};5};
6export fn entry(foo: Foo) void { _ = foo; }6export fn entry(foo: Foo) void { _ = foo; }
77
8// function with non-extern non-packed union parameter8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'12// tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/generic_fn_as_parameter_without_comptime_keyword.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 f(g);4 f(g);
5}5}
66
7// generic fn as parameter without comptime keyword7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime11// tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime
test/compile_errors/stage1/obj/generic_function_call_assigned_to_incorrect_type.zig+3-1
...@@ -6,6 +6,8 @@ fn myAlloc(comptime arg: type) anyerror!arg{...@@ -6,6 +6,8 @@ fn myAlloc(comptime arg: type) anyerror!arg{
6 unreachable;6 unreachable;
7}7}
88
9// generic function call assigned to incorrect type9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i3213// tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32
test/compile_errors/stage1/obj/generic_function_instance_with_non-constant_expression.zig+3-1
...@@ -5,6 +5,8 @@ fn test1(a: i32, b: i32) i32 {...@@ -5,6 +5,8 @@ fn test1(a: i32, b: i32) i32 {
55
6export fn entry() usize { return @sizeOf(@TypeOf(test1)); }6export fn entry() usize { return @sizeOf(@TypeOf(test1)); }
77
8// generic function instance with non-constant expression8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:3:16: error: runtime value cannot be passed to comptime arg12// tmp.zig:3:16: error: runtime value cannot be passed to comptime arg
test/compile_errors/stage1/obj/generic_function_returning_opaque_type.zig+3-1
...@@ -12,7 +12,9 @@ export fn baz() void {...@@ -12,7 +12,9 @@ export fn baz() void {
12 _ = generic(@TypeOf(undefined));12 _ = generic(@TypeOf(undefined));
13}13}
1414
15// generic function returning opaque type15// error
16// backend=stage1
17// target=native
16//18//
17// tmp.zig:6:16: error: call to generic function with Opaque return type 'FooType' not allowed19// tmp.zig:6:16: error: call to generic function with Opaque return type 'FooType' not allowed
18// tmp.zig:2:1: note: function declared here20// tmp.zig:2:1: note: function declared here
test/compile_errors/stage1/obj/generic_function_where_return_type_is_self-referenced.zig+3-1
...@@ -8,6 +8,8 @@ export fn entry() void {...@@ -8,6 +8,8 @@ export fn entry() void {
8 _ = t;8 _ = t;
9}9}
1010
11// generic function where return type is self-referenced11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches15// tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches
test/compile_errors/stage1/obj/global_variable_alignment_non_power_of_2.zig+3-1
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1const some_data: [100]u8 align(3) = undefined;1const some_data: [100]u8 align(3) = undefined;
2export fn entry() usize { return @sizeOf(@TypeOf(some_data)); }2export fn entry() usize { return @sizeOf(@TypeOf(some_data)); }
33
4// global variable alignment non power of 24// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:1:32: error: alignment value 3 is not a power of 28// tmp.zig:1:32: error: alignment value 3 is not a power of 2
test/compile_errors/stage1/obj/global_variable_initializer_must_be_constant_expression.zig+3-1
...@@ -2,6 +2,8 @@ extern fn foo() i32;...@@ -2,6 +2,8 @@ extern fn foo() i32;
2const x = foo();2const x = foo();
3export fn entry() i32 { return x; }3export fn entry() i32 { return x; }
44
5// global variable initializer must be constant expression5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:11: error: unable to evaluate constant expression9// tmp.zig:2:11: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/hasDecl_with_non-container.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() void {...@@ -2,6 +2,8 @@ export fn entry() void {
2 _ = @hasDecl(i32, "hi");2 _ = @hasDecl(i32, "hi");
3}3}
44
5// @hasDecl with non-container5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'9// tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'
test/compile_errors/stage1/obj/if_condition_is_bool_not_int.zig+3-1
...@@ -2,6 +2,8 @@ export fn f() void {...@@ -2,6 +2,8 @@ export fn f() void {
2 if (0) {}2 if (0) {}
3}3}
44
5// if condition is bool, not int5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'9// tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'
test/compile_errors/stage1/obj/ignored_assert-err-ok_return_value.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo() void {...@@ -3,6 +3,8 @@ export fn foo() void {
3}3}
4fn bar() anyerror!i32 { return 0; }4fn bar() anyerror!i32 { return 0; }
55
6// ignored assert-err-ok return value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:11: error: expression value is ignored10// tmp.zig:2:11: error: expression value is ignored
test/compile_errors/stage1/obj/ignored_comptime_statement_value.zig+3-1
...@@ -2,6 +2,8 @@ export fn foo() void {...@@ -2,6 +2,8 @@ export fn foo() void {
2 comptime {1;}2 comptime {1;}
3}3}
44
5// ignored comptime statement value5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:15: error: expression value is ignored9// tmp.zig:2:15: error: expression value is ignored
test/compile_errors/stage1/obj/ignored_comptime_value.zig+3-1
...@@ -2,6 +2,8 @@ export fn foo() void {...@@ -2,6 +2,8 @@ export fn foo() void {
2 comptime 1;2 comptime 1;
3}3}
44
5// ignored comptime value5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:5: error: expression value is ignored9// tmp.zig:2:5: error: expression value is ignored
test/compile_errors/stage1/obj/ignored_deferred_function_call.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo() void {...@@ -3,6 +3,8 @@ export fn foo() void {
3}3}
4fn bar() anyerror!i32 { return 0; }4fn bar() anyerror!i32 { return 0; }
55
6// ignored deferred function call6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`10// tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`
test/compile_errors/stage1/obj/ignored_deferred_statement_value.zig+3-1
...@@ -2,6 +2,8 @@ export fn foo() void {...@@ -2,6 +2,8 @@ export fn foo() void {
2 defer {1;}2 defer {1;}
3}3}
44
5// ignored deferred statement value5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:12: error: expression value is ignored9// tmp.zig:2:12: error: expression value is ignored
test/compile_errors/stage1/obj/ignored_expression_in_while_continuation.zig+3-1
...@@ -13,7 +13,9 @@ fn bad() anyerror!void {...@@ -13,7 +13,9 @@ fn bad() anyerror!void {
13 return error.Bad;13 return error.Bad;
14}14}
1515
16// ignored expression in while continuation16// error
17// backend=stage1
18// target=native
17//19//
18// tmp.zig:2:24: error: error is ignored. consider using `try`, `catch`, or `if`20// tmp.zig:2:24: error: error is ignored. consider using `try`, `catch`, or `if`
19// tmp.zig:6:25: error: error is ignored. consider using `try`, `catch`, or `if`21// tmp.zig:6:25: error: error is ignored. consider using `try`, `catch`, or `if`
test/compile_errors/stage1/obj/ignored_return_value.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo() void {...@@ -3,6 +3,8 @@ export fn foo() void {
3}3}
4fn bar() i32 { return 0; }4fn bar() i32 { return 0; }
55
6// ignored return value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:8: error: expression value is ignored10// tmp.zig:2:8: error: expression value is ignored
test/compile_errors/stage1/obj/ignored_statement_value.zig+3-1
...@@ -2,6 +2,8 @@ export fn foo() void {...@@ -2,6 +2,8 @@ export fn foo() void {
2 1;2 1;
3}3}
44
5// ignored statement value5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:5: error: expression value is ignored9// tmp.zig:2:5: error: expression value is ignored
test/compile_errors/stage1/obj/illegal_comparison_of_types.zig+3-1
...@@ -12,7 +12,9 @@ fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool {...@@ -12,7 +12,9 @@ fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool {
12export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); }12export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); }
13export fn entry2() usize { return @sizeOf(@TypeOf(bad_eql_2)); }13export fn entry2() usize { return @sizeOf(@TypeOf(bad_eql_2)); }
1414
15// illegal comparison of types15// error
16// backend=stage1
17// target=native
16//18//
17// tmp.zig:2:14: error: operator not allowed for type '[]u8'19// tmp.zig:2:14: error: operator not allowed for type '[]u8'
18// tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'20// tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'
test/compile_errors/stage1/obj/implicit_cast_between_C_pointer_and_Zig_pointer-bad_const-align-child.zig+3-1
...@@ -29,7 +29,9 @@ export fn f() void {...@@ -29,7 +29,9 @@ export fn f() void {
29 _ = x;29 _ = x;
30}30}
3131
32// implicit cast between C pointer and Zig pointer - bad const/align/child32// error
33// backend=stage1
34// target=native
33//35//
34// tmp.zig:3:27: error: cast increases pointer alignment36// tmp.zig:3:27: error: cast increases pointer alignment
35// tmp.zig:8:18: error: cast discards const qualifier37// tmp.zig:8:18: error: cast discards const qualifier
test/compile_errors/stage1/obj/implicit_cast_const_array_to_mutable_slice.zig+3-1
...@@ -4,7 +4,9 @@ export fn entry() void {...@@ -4,7 +4,9 @@ export fn entry() void {
4 _ = sliceA;4 _ = sliceA;
5}5}
66
7// implicit cast const array to mutable slice7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:27: error: cannot cast pointer to array literal to slice type '[]u8'11// tmp.zig:3:27: error: cannot cast pointer to array literal to slice type '[]u8'
10// tmp.zig:3:27: note: cast discards const qualifier12// tmp.zig:3:27: note: cast discards const qualifier
test/compile_errors/stage1/obj/implicit_cast_from_array_to_mutable_slice.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 foo(global_array);4 foo(global_array);
5}5}
66
7// implicit cast from array to mutable slice7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'11// tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'
test/compile_errors/stage1/obj/implicit_cast_from_f64_to_f32.zig+3-1
...@@ -3,6 +3,8 @@ var y: f32 = x;...@@ -3,6 +3,8 @@ var y: f32 = x;
33
4export fn entry() usize { return @sizeOf(@TypeOf(y)); }4export fn entry() usize { return @sizeOf(@TypeOf(y)); }
55
6// implicit cast from f64 to f326// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:14: error: expected type 'f32', found 'f64'10// tmp.zig:2:14: error: expected type 'f32', found 'f64'
test/compile_errors/stage1/obj/implicit_cast_of_error_set_not_a_subset.zig+3-1
...@@ -8,7 +8,9 @@ fn foo(set1: Set1) void {...@@ -8,7 +8,9 @@ fn foo(set1: Set1) void {
8 _ = x;8 _ = x;
9}9}
1010
11// implicit cast of error set not a subset11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:7:19: error: expected type 'Set2', found 'Set1'15// tmp.zig:7:19: error: expected type 'Set2', found 'Set1'
14// tmp.zig:1:23: note: 'error.B' not a member of destination error set16// tmp.zig:1:23: note: 'error.B' not a member of destination error set
test/compile_errors/stage1/obj/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig+3-1
...@@ -14,7 +14,9 @@ export fn entry2() void {...@@ -14,7 +14,9 @@ export fn entry2() void {
14 _ = c_ptr;14 _ = c_ptr;
15}15}
1616
17// implicit casting C pointers which would mess up null semantics17// error
18// backend=stage1
19// target=native
18//20//
19// tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'21// tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'
20// tmp.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'22// tmp.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'
test/compile_errors/stage1/obj/implicit_casting_null_c_pointer_to_zig_pointer.zig+3-1
...@@ -4,6 +4,8 @@ comptime {...@@ -4,6 +4,8 @@ comptime {
4 _ = zig_ptr;4 _ = zig_ptr;
5}5}
66
7// implicit casting null c pointer to zig pointer7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:24: error: null pointer casted to type '*u8'11// tmp.zig:3:24: error: null pointer casted to type '*u8'
test/compile_errors/stage1/obj/implicit_casting_too_big_integers_to_C_pointers.zig+3-1
...@@ -8,7 +8,9 @@ export fn b() void {...@@ -8,7 +8,9 @@ export fn b() void {
8 _ = ptr;8 _ = ptr;
9}9}
1010
11// implicit casting too big integers to C pointers11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'15// tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'
14// tmp.zig:7:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'16// tmp.zig:7:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'
test/compile_errors/stage1/obj/implicit_casting_undefined_c_pointer_to_zig_pointer.zig+3-1
...@@ -4,6 +4,8 @@ comptime {...@@ -4,6 +4,8 @@ comptime {
4 _ = zig_ptr;4 _ = zig_ptr;
5}5}
66
7// implicit casting undefined c pointer to zig pointer7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:24: error: use of undefined value here causes undefined behavior11// tmp.zig:3:24: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/implicit_dependency_on_libc.zig created+11
...@@ -0,0 +1,11 @@
1extern "c" fn exit(u8) void;
2export fn entry() void {
3 exit(0);
4}
5
6// error
7// backend=stage1
8// target=native-linux
9// is_test=1
10//
11// tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command
test/compile_errors/stage1/obj/implicit_semicolon-block_expr.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - block expr8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:11: error: expected ';' after statement12// tmp.zig:4:11: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-block_statement.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - block statement8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:9: error: expected ';' after statement12// tmp.zig:4:9: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-comptime_expression.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - comptime expression8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:20: error: expected ';' after statement12// tmp.zig:4:20: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-comptime_statement.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - comptime statement8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:18: error: expected ';' after statement12// tmp.zig:4:18: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-defer.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - defer8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:15: error: expected ';' after statement12// tmp.zig:4:15: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-for_expression.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - for expression8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:26: error: expected ';' after statement12// tmp.zig:4:26: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-for_statement.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - for statement8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:24: error: expected ';' or 'else' after statement12// tmp.zig:4:24: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_expression.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - if-else-if-else expression8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:45: error: expected ';' after statement12// tmp.zig:4:45: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_statement.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - if-else-if-else statement8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:47: error: expected ';' after statement12// tmp.zig:4:47: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else-if_expression.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - if-else-if expression8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:37: error: expected ';' after statement12// tmp.zig:4:37: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else-if_statement.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - if-else-if statement8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:37: error: expected ';' or 'else' after statement12// tmp.zig:4:37: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else_expression.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - if-else expression8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:28: error: expected ';' after statement12// tmp.zig:4:28: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else_statement.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - if-else statement8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:28: error: expected ';' after statement12// tmp.zig:4:28: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if_expression.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - if expression8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:20: error: expected ';' after statement12// tmp.zig:4:20: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if_statement.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - if statement8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:18: error: expected ';' or 'else' after statement12// tmp.zig:4:18: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicit_semicolon-test_expression.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - test expression8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:26: error: expected ';' after statement12// tmp.zig:4:26: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-test_statement.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - test statement8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:24: error: expected ';' or 'else' after statement12// tmp.zig:4:24: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicit_semicolon-while-continue_expression.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - while-continue expression8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:28: error: expected ';' after statement12// tmp.zig:4:28: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-while-continue_statement.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - while-continue statement8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:26: error: expected ';' or 'else' after statement12// tmp.zig:4:26: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicit_semicolon-while_expression.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - while expression8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:23: error: expected ';' after statement12// tmp.zig:4:23: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-while_statement.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 var bad = {};5 var bad = {};
6}6}
77
8// implicit semicolon - while statement8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:18: error: expected ';' or 'else' after statement12// tmp.zig:4:18: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicitly_casting_enum_to_tag_type.zig+3-1
...@@ -10,6 +10,8 @@ export fn entry() void {...@@ -10,6 +10,8 @@ export fn entry() void {
10 _ = x;10 _ = x;
11}11}
1212
13// implicitly casting enum to tag type13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:9:22: error: expected type 'u2', found 'Small'17// tmp.zig:9:22: error: expected type 'u2', found 'Small'
test/compile_errors/stage1/obj/implicitly_increasing_pointer_alignment.zig+3-1
...@@ -12,6 +12,8 @@ fn bar(x: *u32) void {...@@ -12,6 +12,8 @@ fn bar(x: *u32) void {
12 x.* += 1;12 x.* += 1;
13}13}
1414
15// implicitly increasing pointer alignment15// error
16// backend=stage1
17// target=native
16//18//
17// tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'19// tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'
test/compile_errors/stage1/obj/implicitly_increasing_slice_alignment.zig+3-1
...@@ -13,7 +13,9 @@ fn bar(x: []u32) void {...@@ -13,7 +13,9 @@ fn bar(x: []u32) void {
13 x[0] += 1;13 x[0] += 1;
14}14}
1515
16// implicitly increasing slice alignment16// error
17// backend=stage1
18// target=native
17//19//
18// tmp.zig:9:26: error: cast increases pointer alignment20// tmp.zig:9:26: error: cast increases pointer alignment
19// tmp.zig:9:26: note: '*align(1) u32' has alignment 121// tmp.zig:9:26: note: '*align(1) u32' has alignment 1
test/compile_errors/stage1/obj/import_outside_package_path.zig+3-1
...@@ -2,6 +2,8 @@ comptime{...@@ -2,6 +2,8 @@ comptime{
2 _ = @import("../a.zig");2 _ = @import("../a.zig");
3}3}
44
5// import outside package path5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:9: error: import of file outside package path: '../a.zig'9// tmp.zig:2:9: error: import of file outside package path: '../a.zig'
test/compile_errors/stage1/obj/incompatible_sentinels.zig created+29
...@@ -0,0 +1,29 @@
1// Note: One of the error messages here is backwards. It would be nice to fix, but that's not
2// going to stop me from merging this branch which fixes a bunch of other stuff.
3export fn entry1(ptr: [*:255]u8) [*:0]u8 {
4 return ptr;
5}
6export fn entry2(ptr: [*]u8) [*:0]u8 {
7 return ptr;
8}
9export fn entry3() void {
10 var array: [2:0]u8 = [_:255]u8{ 1, 2 };
11 _ = array;
12}
13export fn entry4() void {
14 var array: [2:0]u8 = [_]u8{ 1, 2 };
15 _ = array;
16}
17
18// error
19// backend=stage1
20// target=native
21//
22// tmp.zig:4:12: error: expected type '[*:0]u8', found '[*:255]u8'
23// tmp.zig:4:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel
24// tmp.zig:7:12: error: expected type '[*:0]u8', found '[*]u8'
25// tmp.zig:7:12: note: destination pointer requires a terminating '0' sentinel
26// tmp.zig:10:35: error: expected type '[2:255]u8', found '[2:0]u8'
27// tmp.zig:10:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel
28// tmp.zig:14:31: error: expected type '[2:0]u8', found '[2]u8'
29// tmp.zig:14:31: note: destination array requires a terminating '0' sentinel
test/compile_errors/stage1/obj/incorrect_return_type.zig+3-1
...@@ -14,6 +14,8 @@...@@ -14,6 +14,8 @@
14 unreachable;14 unreachable;
15 }15 }
1616
17// incorrect return type17// error
18// backend=stage1
19// target=native
18//20//
19// tmp.zig:8:16: error: expected type 'A', found 'B'21// tmp.zig:8:16: error: expected type 'A', found 'B'
test/compile_errors/stage1/obj/increase_pointer_alignment_in_ptrCast.zig+3-1
...@@ -4,7 +4,9 @@ export fn entry() u32 {...@@ -4,7 +4,9 @@ export fn entry() u32 {
4 return ptr.*;4 return ptr.*;
5}5}
66
7// increase pointer alignment in @ptrCast7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:17: error: cast increases pointer alignment11// tmp.zig:3:17: error: cast increases pointer alignment
10// tmp.zig:3:38: note: '*u8' has alignment 112// tmp.zig:3:38: note: '*u8' has alignment 1
test/compile_errors/stage1/obj/indexing_a_undefined_slice_at_comptime.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 slice[0] = 2;3 slice[0] = 2;
4}4}
55
6// indexing a undefined slice at comptime6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:10: error: index 0 outside slice of size 010// tmp.zig:3:10: error: index 0 outside slice of size 0
test/compile_errors/stage1/obj/indexing_an_array_of_size_zero.zig+3-1
...@@ -4,6 +4,8 @@ export fn foo() void {...@@ -4,6 +4,8 @@ export fn foo() void {
4 _ = pointer;4 _ = pointer;
5}5}
66
7// indexing an array of size zero7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:27: error: accessing a zero length array is not allowed11// tmp.zig:3:27: error: accessing a zero length array is not allowed
test/compile_errors/stage1/obj/indexing_an_array_of_size_zero_with_runtime_index.zig+3-1
...@@ -5,6 +5,8 @@ export fn foo() void {...@@ -5,6 +5,8 @@ export fn foo() void {
5 _ = pointer;5 _ = pointer;
6}6}
77
8// indexing an array of size zero with runtime index8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:27: error: accessing a zero length array is not allowed12// tmp.zig:4:27: error: accessing a zero length array is not allowed
test/compile_errors/stage1/obj/indexing_single-item_pointer.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry(ptr: *i32) i32 {...@@ -2,6 +2,8 @@ export fn entry(ptr: *i32) i32 {
2 return ptr[1];2 return ptr[1];
3}3}
44
5// indexing single-item pointer5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:15: error: index of single-item pointer9// tmp.zig:2:15: error: index of single-item pointer
test/compile_errors/stage1/obj/indirect_recursion_of_async_functions_detected.zig+3-1
...@@ -27,7 +27,9 @@ fn rangeSumIndirect(x: i32) i32 {...@@ -27,7 +27,9 @@ fn rangeSumIndirect(x: i32) i32 {
27 return child + 1;27 return child + 1;
28}28}
2929
30// indirect recursion of async functions detected30// error
31// backend=stage1
32// target=native
31//33//
32// tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself34// tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself
33// tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here35// tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here
test/compile_errors/stage1/obj/indirect_struct_loop.zig+3-1
...@@ -3,6 +3,8 @@ const B = struct { c : C, };...@@ -3,6 +3,8 @@ const B = struct { c : C, };
3const C = struct { a : A, };3const C = struct { a : A, };
4export fn entry() usize { return @sizeOf(A); }4export fn entry() usize { return @sizeOf(A); }
55
6// indirect struct loop6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:1:11: error: struct 'A' depends on itself10// tmp.zig:1:11: error: struct 'A' depends on itself
test/compile_errors/stage1/obj/inferred_array_size_invalid_here.zig+3-1
...@@ -8,7 +8,9 @@ export fn entry2() void {...@@ -8,7 +8,9 @@ export fn entry2() void {
8 _ = a;8 _ = a;
9}9}
1010
11// inferred array size invalid here11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:2:16: error: unable to infer array size15// tmp.zig:2:16: error: unable to infer array size
14// tmp.zig:6:35: error: unable to infer array size16// tmp.zig:6:35: error: unable to infer array size
test/compile_errors/stage1/obj/inferring_error_set_of_function_pointer.zig+3-1
...@@ -2,6 +2,8 @@ comptime {...@@ -2,6 +2,8 @@ comptime {
2 const z: ?fn()!void = null;2 const z: ?fn()!void = null;
3}3}
44
5// inferring error set of function pointer5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:19: error: function prototype may not have inferred error set9// tmp.zig:2:19: error: function prototype may not have inferred error set
test/compile_errors/stage1/obj/initializing_array_with_struct_syntax.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = x;3 _ = x;
4}4}
55
6// initializing array with struct syntax6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:15: error: initializing array with struct syntax10// tmp.zig:2:15: error: initializing array with struct syntax
test/compile_errors/stage1/obj/instantiating_an_undefined_value_for_an_invalid_struct_that_contains_itself.zig+3-1
...@@ -8,6 +8,8 @@ export fn entry() usize {...@@ -8,6 +8,8 @@ export fn entry() usize {
8 return @sizeOf(@TypeOf(foo.x));8 return @sizeOf(@TypeOf(foo.x));
9}9}
1010
11// instantiating an undefined value for an invalid struct that contains itself11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:1:13: error: struct 'Foo' depends on itself15// tmp.zig:1:13: error: struct 'Foo' depends on itself
test/compile_errors/stage1/obj/intToPtr_with_misaligned_address.zig+3-1
...@@ -3,6 +3,8 @@ pub fn main() void {...@@ -3,6 +3,8 @@ pub fn main() void {
3 _ = y;3 _ = y;
4}4}
55
6// intToPtr with misaligned address6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:13: error: pointer type '[*]align(4) u8' requires aligned address10// tmp.zig:2:13: error: pointer type '[*]align(4) u8' requires aligned address
test/compile_errors/stage1/obj/int_to_err_global_invalid_number.zig+3-1
...@@ -8,6 +8,8 @@ comptime {...@@ -8,6 +8,8 @@ comptime {
8 _ = y;8 _ = y;
9}9}
1010
11// int to err global invalid number11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:7:13: error: integer value 3 represents no error15// tmp.zig:7:13: error: integer value 3 represents no error
test/compile_errors/stage1/obj/int_to_err_non_global_invalid_number.zig+3-1
...@@ -12,6 +12,8 @@ comptime {...@@ -12,6 +12,8 @@ comptime {
12 _ = y;12 _ = y;
13}13}
1414
15// int to err non global invalid number15// error
16// backend=stage1
17// target=native
16//18//
17// tmp.zig:11:13: error: error.B not a member of error set 'Set2'19// tmp.zig:11:13: error: error.B not a member of error set 'Set2'
test/compile_errors/stage1/obj/int_to_ptr_of_0_bits.zig+3-1
...@@ -4,6 +4,8 @@ export fn foo() void {...@@ -4,6 +4,8 @@ export fn foo() void {
4 _ = y;4 _ = y;
5}5}
66
7// int to ptr of 0 bits7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information11// tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information
test/compile_errors/stage1/obj/integer_cast_truncates_bits.zig+3-1
...@@ -19,7 +19,9 @@ export fn entry4() void {...@@ -19,7 +19,9 @@ export fn entry4() void {
19 _ = unsigned;19 _ = unsigned;
20}20}
2121
22// integer cast truncates bits22// error
23// backend=stage1
24// target=native
23//25//
24// tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits26// tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits
25// tmp.zig:8:22: error: integer value 300 cannot be coerced to type 'u8'27// tmp.zig:8:22: error: integer value 300 cannot be coerced to type 'u8'
test/compile_errors/stage1/obj/integer_overflow_error.zig+3-1
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1const x : u8 = 300;1const x : u8 = 300;
2export fn entry() usize { return @sizeOf(@TypeOf(x)); }2export fn entry() usize { return @sizeOf(@TypeOf(x)); }
33
4// integer overflow error4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'8// tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'
test/compile_errors/stage1/obj/integer_underflow_error.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() void {...@@ -2,6 +2,8 @@ export fn entry() void {
2 _ = @intToPtr(*anyopaque, ~@as(usize, @import("std").math.maxInt(usize)) - 1);2 _ = @intToPtr(*anyopaque, ~@as(usize, @import("std").math.maxInt(usize)) - 1);
3}3}
44
5// integer underflow error5// error
6// backend=stage1
7// target=native
6//8//
7// :2:78: error: operation caused overflow9// :2:78: error: operation caused overflow
test/compile_errors/stage1/obj/invalid_break_expression.zig+3-1
...@@ -2,6 +2,8 @@ export fn f() void {...@@ -2,6 +2,8 @@ export fn f() void {
2 break;2 break;
3}3}
44
5// invalid break expression5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:5: error: break expression outside loop9// tmp.zig:2:5: error: break expression outside loop
test/compile_errors/stage1/obj/invalid_builtin_fn.zig+3-1
...@@ -2,6 +2,8 @@ fn f() @bogus(foo) {...@@ -2,6 +2,8 @@ fn f() @bogus(foo) {
2}2}
3export fn entry() void { _ = f(); }3export fn entry() void { _ = f(); }
44
5// invalid builtin fn5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:1:8: error: invalid builtin function: '@bogus'9// tmp.zig:1:8: error: invalid builtin function: '@bogus'
test/compile_errors/stage1/obj/invalid_cast_from_integral_type_to_enum.zig+3-1
...@@ -10,6 +10,8 @@ fn foo(x: usize) void {...@@ -10,6 +10,8 @@ fn foo(x: usize) void {
10 }10 }
11}11}
1212
13// invalid cast from integral type to enum13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:9:10: error: expected type 'usize', found 'E'17// tmp.zig:9:10: error: expected type 'usize', found 'E'
test/compile_errors/stage1/obj/invalid_comparison_for_function_pointers.zig+3-1
...@@ -3,6 +3,8 @@ const invalid = foo > foo;...@@ -3,6 +3,8 @@ const invalid = foo > foo;
33
4export fn entry() usize { return @sizeOf(@TypeOf(invalid)); }4export fn entry() usize { return @sizeOf(@TypeOf(invalid)); }
55
6// invalid comparison for function pointers6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: operator not allowed for type 'fn() void'10// tmp.zig:2:21: error: operator not allowed for type 'fn() void'
test/compile_errors/stage1/obj/invalid_continue_expression.zig+3-1
...@@ -2,6 +2,8 @@ export fn f() void {...@@ -2,6 +2,8 @@ export fn f() void {
2 continue;2 continue;
3}3}
44
5// invalid continue expression5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:5: error: continue expression outside loop9// tmp.zig:2:5: error: continue expression outside loop
test/compile_errors/stage1/obj/invalid_deref_on_switch_target.zig+3-1
...@@ -10,6 +10,8 @@ const Tile = enum {...@@ -10,6 +10,8 @@ const Tile = enum {
10 Filled,10 Filled,
11};11};
1212
13// invalid deref on switch target13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'17// tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'
test/compile_errors/stage1/obj/invalid_empty_unicode_escape.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() void {...@@ -2,6 +2,8 @@ export fn entry() void {
2 const a = '\u{}';2 const a = '\u{}';
3}3}
44
5// invalid empty unicode escape5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:19: error: empty unicode escape sequence9// tmp.zig:2:19: error: empty unicode escape sequence
test/compile_errors/stage1/obj/invalid_exponent_in_float_literal-1.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid exponent in float literal - 16// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:28: note: invalid byte: 'a'11// tmp.zig:2:28: note: invalid byte: 'a'
test/compile_errors/stage1/obj/invalid_exponent_in_float_literal-2.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid exponent in float literal - 26// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:29: note: invalid byte: 'F'11// tmp.zig:2:29: note: invalid byte: 'F'
test/compile_errors/stage1/obj/invalid_field_access_in_comptime.zig+3-1
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1comptime { var x = doesnt_exist.whatever; _ = x; }1comptime { var x = doesnt_exist.whatever; _ = x; }
22
3// invalid field access in comptime3// error
4// backend=stage1
5// target=native
4//6//
5// tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'7// tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'
test/compile_errors/stage1/obj/invalid_field_in_struct_value_expression.zig+3-1
...@@ -12,6 +12,8 @@ export fn f() void {...@@ -12,6 +12,8 @@ export fn f() void {
12 _ = a;12 _ = a;
13}13}
1414
15// invalid field in struct value expression15// error
16// backend=stage1
17// target=native
16//18//
17// tmp.zig:10:9: error: no member named 'foo' in struct 'A'19// tmp.zig:10:9: error: no member named 'foo' in struct 'A'
test/compile_errors/stage1/obj/invalid_float_literal.zig+3-1
...@@ -6,6 +6,8 @@ pub fn main() void {...@@ -6,6 +6,8 @@ pub fn main() void {
6 std.debug.assert(bad_float < 1.0);6 std.debug.assert(bad_float < 1.0);
7}7}
88
9// invalid float literal9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:5:29: error: expected expression, found '.'13// tmp.zig:5:29: error: expected expression, found '.'
test/compile_errors/stage1/obj/invalid_legacy_unicode_escape.zig+3-1
...@@ -2,7 +2,9 @@ export fn entry() void {...@@ -2,7 +2,9 @@ export fn entry() void {
2 const a = '\U1234';2 const a = '\U1234';
3}3}
44
5// invalid legacy unicode escape5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:15: error: expected expression, found 'invalid bytes'9// tmp.zig:2:15: error: expected expression, found 'invalid bytes'
8// tmp.zig:2:18: note: invalid byte: '1'10// tmp.zig:2:18: note: invalid byte: '1'
test/compile_errors/stage1/obj/invalid_maybe_type.zig+3-1
...@@ -2,6 +2,8 @@ export fn f() void {...@@ -2,6 +2,8 @@ export fn f() void {
2 if (true) |x| { _ = x; }2 if (true) |x| { _ = x; }
3}3}
44
5// invalid maybe type5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:9: error: expected optional type, found 'bool'9// tmp.zig:2:9: error: expected optional type, found 'bool'
test/compile_errors/stage1/obj/invalid_member_of_builtin_enum.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 _ = foo;4 _ = foo;
5}5}
66
7// invalid member of builtin enum7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'11// tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'
test/compile_errors/stage1/obj/invalid_multiple_dereferences.zig+3-1
...@@ -11,7 +11,9 @@ pub const Box = struct {...@@ -11,7 +11,9 @@ pub const Box = struct {
11 field: i32,11 field: i32,
12};12};
1313
14// invalid multiple dereferences14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box'18// tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box'
17// tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'19// tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'
test/compile_errors/stage1/obj/invalid_optional_type_in_extern_struct.zig+3-1
...@@ -3,6 +3,8 @@ const stroo = extern struct {...@@ -3,6 +3,8 @@ const stroo = extern struct {
3};3};
4export fn testf(fluff: *stroo) void { _ = fluff; }4export fn testf(fluff: *stroo) void { _ = fluff; }
55
6// invalid optional type in extern struct6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'10// tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'
test/compile_errors/stage1/obj/invalid_pointer_for_var_type.zig+3-1
...@@ -6,6 +6,8 @@ export fn f() void {...@@ -6,6 +6,8 @@ export fn f() void {
6 }6 }
7}7}
88
9// invalid pointer for var type9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:2:13: error: unable to evaluate constant expression13// tmp.zig:2:13: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/invalid_pointer_syntax.zig+3-1
...@@ -2,6 +2,8 @@ export fn foo() void {...@@ -2,6 +2,8 @@ export fn foo() void {
2 var guid: *:0 const u8 = undefined;2 var guid: *:0 const u8 = undefined;
3}3}
44
5// invalid pointer syntax5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:16: error: expected type expression, found ':'9// tmp.zig:2:16: error: expected type expression, found ':'
test/compile_errors/stage1/obj/invalid_shift_amount_error.zig+3-1
...@@ -4,6 +4,8 @@ fn f() u16 {...@@ -4,6 +4,8 @@ fn f() u16 {
4}4}
5export fn entry() u16 { return f(); }5export fn entry() u16 { return f(); }
66
7// invalid shift amount error7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:17: error: integer value 8 cannot be coerced to type 'u3'11// tmp.zig:3:17: error: integer value 8 cannot be coerced to type 'u3'
test/compile_errors/stage1/obj/invalid_struct_field.zig+3-1
...@@ -11,7 +11,9 @@ export fn g() void {...@@ -11,7 +11,9 @@ export fn g() void {
11 _ = y;11 _ = y;
12}12}
1313
14// invalid struct field14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:4:6: error: no member named 'foo' in struct 'A'18// tmp.zig:4:6: error: no member named 'foo' in struct 'A'
17// tmp.zig:10:16: error: no member named 'bar' in struct 'A'19// tmp.zig:10:16: error: no member named 'bar' in struct 'A'
test/compile_errors/stage1/obj/invalid_suspend_in_exported_function.zig+3-1
...@@ -7,7 +7,9 @@ fn func() void {...@@ -7,7 +7,9 @@ fn func() void {
7 suspend {}7 suspend {}
8}8}
99
10// invalid suspend in exported function10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:1:1: error: function with calling convention 'C' cannot be async14// tmp.zig:1:1: error: function with calling convention 'C' cannot be async
13// tmp.zig:3:18: note: await here is a suspend point15// tmp.zig:3:18: note: await here is a suspend point
test/compile_errors/stage1/obj/invalid_type.zig+3-1
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1fn a() bogus {}1fn a() bogus {}
2export fn entry() void { _ = a(); }2export fn entry() void { _ = a(); }
33
4// invalid type4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:1:8: error: use of undeclared identifier 'bogus'8// tmp.zig:1:8: error: use of undeclared identifier 'bogus'
test/compile_errors/stage1/obj/invalid_type_used_in_array_type.zig+3-1
...@@ -7,6 +7,8 @@ export fn entry() void {...@@ -7,6 +7,8 @@ export fn entry() void {
7 _ = a;7 _ = a;
8}8}
99
10// invalid type used in array type10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'14// tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-1.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in float literal - 16// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:23: note: invalid byte: '_'11// tmp.zig:2:23: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-10.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in float literal - 106// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:25: note: invalid byte: '_'11// tmp.zig:2:25: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-11.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in float literal - 116// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:28: note: invalid byte: '_'11// tmp.zig:2:28: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-12.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in float literal - 126// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:23: note: invalid byte: 'x'11// tmp.zig:2:23: note: invalid byte: 'x'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-13.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in float literal - 136// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:23: note: invalid byte: '_'11// tmp.zig:2:23: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-14.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in float literal - 146// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:27: note: invalid byte: 'p'11// tmp.zig:2:27: note: invalid byte: 'p'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-2.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in float literal - 26// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:23: note: invalid byte: '.'11// tmp.zig:2:23: note: invalid byte: '.'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-3.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in float literal - 36// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:25: note: invalid byte: ';'11// tmp.zig:2:25: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-4.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in float literal - 46// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:25: note: invalid byte: '_'11// tmp.zig:2:25: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-5.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in float literal - 56// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:26: note: invalid byte: '_'11// tmp.zig:2:26: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-6.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in float literal - 66// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:26: note: invalid byte: '_'11// tmp.zig:2:26: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-7.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in float literal - 76// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:28: note: invalid byte: ';'11// tmp.zig:2:28: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-9.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in float literal - 96// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:23: note: invalid byte: '_'11// tmp.zig:2:23: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-1.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in int literal - 16// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:26: note: invalid byte: ';'11// tmp.zig:2:26: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-2.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in int literal - 26// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:28: note: invalid byte: ';'11// tmp.zig:2:28: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-3.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in int literal - 36// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:28: note: invalid byte: ';'11// tmp.zig:2:28: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-4.zig+3-1
...@@ -3,7 +3,9 @@ fn main() void {...@@ -3,7 +3,9 @@ fn main() void {
3 _ = bad;3 _ = bad;
4}4}
55
6// invalid underscore placement in int literal - 46// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: expected expression, found 'invalid bytes'10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
9// tmp.zig:2:28: note: invalid byte: ';'11// tmp.zig:2:28: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_union_field_access_in_comptime.zig+3-1
...@@ -8,6 +8,8 @@ comptime {...@@ -8,6 +8,8 @@ comptime {
8 _ = bar_val;8 _ = bar_val;
9}9}
1010
11// invalid union field access in comptime11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set15// tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set
test/compile_errors/stage1/obj/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = foo;3 _ = foo;
4}4}
55
6// compile diagnostic string for top level decl type (issue 2032)6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:27: error: type 'u32' does not support array initialization10// tmp.zig:2:27: error: type 'u32' does not support array initialization
test/compile_errors/stage1/obj/issue_2687_coerce_from_undefined_array_pointer_to_slice.zig+3-1
...@@ -18,7 +18,9 @@ export fn foo3() void {...@@ -18,7 +18,9 @@ export fn foo3() void {
18 }18 }
19}19}
2020
21// issue #2687: coerce from undefined array pointer to slice21// error
22// backend=stage1
23// target=native
22//24//
23// tmp.zig:3:19: error: use of undefined value here causes undefined behavior25// tmp.zig:3:19: error: use of undefined value here causes undefined behavior
24// tmp.zig:9:23: error: use of undefined value here causes undefined behavior26// tmp.zig:9:23: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/issue_3818_bitcast_from_parray-slice_to_u16.zig+3-1
...@@ -9,7 +9,9 @@ export fn foo2() void {...@@ -9,7 +9,9 @@ export fn foo2() void {
9 _ = word;9 _ = word;
10}10}
1111
12// issue #3818: bitcast from parray/slice to u1612// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'16// tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'
15// tmp.zig:8:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 1617// tmp.zig:8:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 16
test/compile_errors/stage1/obj/issue_4207_coerce_from_non-terminated-slice_to_terminated-pointer.zig+3-1
...@@ -3,7 +3,9 @@ export fn foo() [*:0]const u8 {...@@ -3,7 +3,9 @@ export fn foo() [*:0]const u8 {
3 return buffer[0..];3 return buffer[0..];
4}4}
55
6// issue #4207: coerce from non-terminated-slice to terminated-pointer6// error
7// backend=stage1
8// target=native
7//9//
8// :3:18: error: expected type '[*:0]const u8', found '*[64]u8'10// :3:18: error: expected type '[*:0]const u8', found '*[64]u8'
9// :3:18: note: destination pointer requires a terminating '0' sentinel11// :3:18: note: destination pointer requires a terminating '0' sentinel
test/compile_errors/stage1/obj/issue_5221_invalid_struct_init_type_referenced_by_typeInfo_and_passed_into_function.zig+3-1
...@@ -8,7 +8,9 @@ export fn foo() void {...@@ -8,7 +8,9 @@ export fn foo() void {
8 comptime ignore(@typeInfo(MyStruct).Struct.fields[0]);8 comptime ignore(@typeInfo(MyStruct).Struct.fields[0]);
9}9}
1010
11// issue #5221: invalid struct init type referenced by @typeInfo and passed into function11// error
12// backend=stage1
13// target=native
12//14//
13// :5:28: error: cannot cast pointer to array literal to slice type '[]u8'15// :5:28: error: cannot cast pointer to array literal to slice type '[]u8'
14// :5:28: note: cast discards const qualifier16// :5:28: note: cast discards const qualifier
test/compile_errors/stage1/obj/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig+3-1
...@@ -4,6 +4,8 @@ export fn foo() void {...@@ -4,6 +4,8 @@ export fn foo() void {
4 v = u;4 v = u;
5}5}
66
7// Issue #5618: coercion of ?*anyopaque to *anyopaque must fail.7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:4:9: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type '*anyopaque', found '?*anyopaque'11// tmp.zig:4:9: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type '*anyopaque', found '?*anyopaque'
test/compile_errors/stage1/obj/issue_7810-comptime_slice-len_increment_beyond_bounds.zig+3-1
...@@ -7,6 +7,8 @@ export fn foo_slice_len_increment_beyond_bounds() void {...@@ -7,6 +7,8 @@ export fn foo_slice_len_increment_beyond_bounds() void {
7 }7 }
8}8}
99
10// comptime slice-len increment beyond bounds10// error
11// backend=stage1
12// target=native
11//13//
12// :6:12: error: out of bounds slice14// :6:12: error: out of bounds slice
test/compile_errors/stage1/obj/issue_9346_return_outside_of_function_scope.zig+3-1
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1pub const empty = return 1;1pub const empty = return 1;
22
3// issue #9346: return outside of function scope3// error
4// backend=stage1
5// target=native
4//6//
5// tmp.zig:1:19: error: 'return' outside function scope7// tmp.zig:1:19: error: 'return' outside function scope
test/compile_errors/stage1/obj/labeled_break_not_found.zig+3-1
...@@ -6,6 +6,8 @@ export fn entry() void {...@@ -6,6 +6,8 @@ export fn entry() void {
6 }6 }
7}7}
88
9// labeled break not found9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:4:20: error: label not found: 'outer'13// tmp.zig:4:20: error: label not found: 'outer'
test/compile_errors/stage1/obj/labeled_continue_not_found.zig+3-1
...@@ -7,6 +7,8 @@ export fn entry() void {...@@ -7,6 +7,8 @@ export fn entry() void {
7 }7 }
8}8}
99
10// labeled continue not found10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:5:23: error: label not found: 'outer'14// tmp.zig:5:23: error: label not found: 'outer'
test/compile_errors/stage1/obj/lazy_pointer_with_undefined_element_type.zig+3-1
...@@ -5,6 +5,8 @@ export fn foo() void {...@@ -5,6 +5,8 @@ export fn foo() void {
5 _ = I;5 _ = I;
6}6}
77
8// lazy pointer with undefined element type8// error
9// backend=stage1
10// target=native
9//11//
10// :3:28: error: use of undefined value here causes undefined behavior12// :3:28: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/libc_headers_note.zig created+12
...@@ -0,0 +1,12 @@
1const c = @cImport(@cInclude("stdio.h"));
2export fn entry() void {
3 _ = c.printf("hello, world!\n");
4}
5
6// error
7// backend=stage1
8// is_test=1
9// target=native-linux
10//
11// tmp.zig:1:11: error: C import failed
12// tmp.zig:1:11: note: libc headers not available; compilation does not link against libc
test/compile_errors/stage1/obj/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig+3-1
...@@ -6,6 +6,8 @@ export fn entry() void {...@@ -6,6 +6,8 @@ export fn entry() void {
6 _ = int_val;6 _ = int_val;
7}7}
88
9// load too many bytes from comptime reinterpreted pointer9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes13// tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes
test/compile_errors/stage1/obj/load_vector_pointer_with_unknown_runtime_index.zig+3-1
...@@ -10,6 +10,8 @@ fn loadv(ptr: anytype) i32 {...@@ -10,6 +10,8 @@ fn loadv(ptr: anytype) i32 {
10 return ptr.*;10 return ptr.*;
11}11}
1212
13// load vector pointer with unknown runtime index13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:10:12: error: unable to determine vector element index of type '*align(16:0:4:?) i3217// tmp.zig:10:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32
test/compile_errors/stage1/obj/local_shadows_global_that_occurs_later.zig+3-1
...@@ -4,7 +4,9 @@ pub fn main() void {...@@ -4,7 +4,9 @@ pub fn main() void {
4}4}
5fn foo() void {}5fn foo() void {}
66
7// local shadows global that occurs later7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:2:9: error: local shadows declaration of 'foo'11// tmp.zig:2:9: error: local shadows declaration of 'foo'
10// tmp.zig:5:1: note: declared here12// tmp.zig:5:1: note: declared here
test/compile_errors/stage1/obj/local_variable_redeclaration.zig+3-1
...@@ -3,7 +3,9 @@ export fn f() void {...@@ -3,7 +3,9 @@ export fn f() void {
3 var a = 0;3 var a = 0;
4}4}
55
6// local variable redeclaration6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: redeclaration of local constant 'a'10// tmp.zig:3:9: error: redeclaration of local constant 'a'
9// tmp.zig:2:11: note: previous declaration here11// tmp.zig:2:11: note: previous declaration here
test/compile_errors/stage1/obj/local_variable_redeclares_parameter.zig+3-1
...@@ -3,7 +3,9 @@ fn f(a : i32) void {...@@ -3,7 +3,9 @@ fn f(a : i32) void {
3}3}
4export fn entry() void { f(1); }4export fn entry() void { f(1); }
55
6// local variable redeclares parameter6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:11: error: redeclaration of function parameter 'a'10// tmp.zig:2:11: error: redeclaration of function parameter 'a'
9// tmp.zig:1:6: note: previous declaration here11// tmp.zig:1:6: note: previous declaration here
test/compile_errors/stage1/obj/local_variable_shadowing_global.zig+3-1
...@@ -6,7 +6,9 @@ export fn entry() void {...@@ -6,7 +6,9 @@ export fn entry() void {
6 _ = Bar;6 _ = Bar;
7}7}
88
9// local variable shadowing global9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:5:9: error: local shadows declaration of 'Bar'13// tmp.zig:5:9: error: local shadows declaration of 'Bar'
12// tmp.zig:2:1: note: declared here14// tmp.zig:2:1: note: declared here
test/compile_errors/stage1/obj/locally_shadowing_a_primitive_type.zig+3-1
...@@ -4,7 +4,9 @@ export fn foo() void {...@@ -4,7 +4,9 @@ export fn foo() void {
4 _ = a;4 _ = a;
5}5}
66
7// locally shadowing a primitive type7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:2:11: error: name shadows primitive 'u8'11// tmp.zig:2:11: error: name shadows primitive 'u8'
10// tmp.zig:2:11: note: consider using @"u8" to disambiguate12// tmp.zig:2:11: note: consider using @"u8" to disambiguate
test/compile_errors/stage1/obj/main_function_with_bogus_args_type.zig+3-1
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1pub fn main(args: [][]bogus) !void {_ = args;}1pub fn main(args: [][]bogus) !void {_ = args;}
22
3// main function with bogus args type3// error
4// backend=stage1
5// target=native
4//6//
5// tmp.zig:1:23: error: use of undeclared identifier 'bogus'7// tmp.zig:1:23: error: use of undeclared identifier 'bogus'
test/compile_errors/stage1/obj/method_call_with_first_arg_type_primitive.zig+3-1
...@@ -14,6 +14,8 @@ export fn f() void {...@@ -14,6 +14,8 @@ export fn f() void {
14 derp.init();14 derp.init();
15}15}
1616
17// method call with first arg type primitive17// error
18// backend=stage1
19// target=native
18//20//
19// tmp.zig:14:5: error: expected type 'i32', found 'Foo'21// tmp.zig:14:5: error: expected type 'i32', found 'Foo'
test/compile_errors/stage1/obj/method_call_with_first_arg_type_wrong_container.zig+3-1
...@@ -23,6 +23,8 @@ export fn foo() void {...@@ -23,6 +23,8 @@ export fn foo() void {
23 x.init();23 x.init();
24}24}
2525
26// method call with first arg type wrong container26// error
27// backend=stage1
28// target=native
27//29//
28// tmp.zig:23:5: error: expected type '*Allocator', found '*List'30// tmp.zig:23:5: error: expected type '*Allocator', found '*List'
test/compile_errors/stage1/obj/missing_boolean_switch_value.zig+3-1
...@@ -11,7 +11,9 @@ comptime {...@@ -11,7 +11,9 @@ comptime {
11 _ = x;11 _ = x;
12}12}
1313
14// missing boolean switch value14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:2:15: error: switch must handle all possibilities18// tmp.zig:2:15: error: switch must handle all possibilities
17// tmp.zig:8:15: error: switch must handle all possibilities19// tmp.zig:8:15: error: switch must handle all possibilities
test/compile_errors/stage1/obj/missing_const_in_slice_with_nested_array_type.zig+3-1
...@@ -11,6 +11,8 @@ export fn entry() void {...@@ -11,6 +11,8 @@ export fn entry() void {
11 _ = geo_data;11 _ = geo_data;
12}12}
1313
14// missing const in slice with nested array type14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:4:30: error: array literal requires address-of operator (&) to coerce to slice type '[][2]f32'18// tmp.zig:4:30: error: array literal requires address-of operator (&) to coerce to slice type '[][2]f32'
test/compile_errors/stage1/obj/missing_else_clause.zig+3-1
...@@ -8,7 +8,9 @@ fn g(b: bool) void {...@@ -8,7 +8,9 @@ fn g(b: bool) void {
8}8}
9export fn entry() void { f(true); g(true); }9export fn entry() void { f(true); g(true); }
1010
11// missing else clause11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:2:21: error: expected type 'i32', found 'void'15// tmp.zig:2:21: error: expected type 'i32', found 'void'
14// tmp.zig:6:15: error: incompatible types: 'i32' and 'void'16// tmp.zig:6:15: error: incompatible types: 'i32' and 'void'
test/compile_errors/stage1/obj/missing_field_in_struct_value_expression.zig+3-1
...@@ -13,6 +13,8 @@ export fn f() void {...@@ -13,6 +13,8 @@ export fn f() void {
13 _ = a;13 _ = a;
14}14}
1515
16// missing field in struct value expression16// error
17// backend=stage1
18// target=native
17//19//
18// tmp.zig:9:17: error: missing field: 'x'20// tmp.zig:9:17: error: missing field: 'x'
test/compile_errors/stage1/obj/missing_function_call_param.zig+3-1
...@@ -24,6 +24,8 @@ fn f(foo: *const Foo, index: usize) void {...@@ -24,6 +24,8 @@ fn f(foo: *const Foo, index: usize) void {
2424
25export fn entry() usize { return @sizeOf(@TypeOf(f)); }25export fn entry() usize { return @sizeOf(@TypeOf(f)); }
2626
27// missing function call param27// error
28// backend=stage1
29// target=native
28//30//
29// tmp.zig:20:34: error: expected 1 argument(s), found 031// tmp.zig:20:34: error: expected 1 argument(s), found 0
test/compile_errors/stage1/obj/missing_function_name.zig+3-1
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1fn () void {}1fn () void {}
2export fn entry() usize { return @sizeOf(@TypeOf(f)); }2export fn entry() usize { return @sizeOf(@TypeOf(f)); }
33
4// missing function name4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:1:1: error: missing function name8// tmp.zig:1:1: error: missing function name
test/compile_errors/stage1/obj/missing_param_name.zig+3-1
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1fn f(i32) void {}1fn f(i32) void {}
2export fn entry() usize { return @sizeOf(@TypeOf(f)); }2export fn entry() usize { return @sizeOf(@TypeOf(f)); }
33
4// missing param name4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:1:6: error: missing parameter name8// tmp.zig:1:6: error: missing parameter name
test/compile_errors/stage1/obj/missing_parameter_name_of_generic_function.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 dump(a);4 dump(a);
5}5}
66
7// missing parameter name of generic function7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:1:9: error: missing parameter name11// tmp.zig:1:9: error: missing parameter name
test/compile_errors/stage1/obj/missing_result_type_for_phi_node.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 foo() catch 0;5 foo() catch 0;
6}6}
77
8// missing result type for phi node8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'12// tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'
test/compile_errors/stage1/obj/misspelled_type_with_pointer_only_reference.zig+3-1
...@@ -30,6 +30,8 @@ fn foo() void {...@@ -30,6 +30,8 @@ fn foo() void {
3030
31export fn entry() usize { return @sizeOf(@TypeOf(foo)); }31export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
3232
33// misspelled type with pointer only reference33// error
34// backend=stage1
35// target=native
34//36//
35// tmp.zig:5:16: error: use of undeclared identifier 'JsonList'37// tmp.zig:5:16: error: use of undeclared identifier 'JsonList'
test/compile_errors/stage1/obj/mod_assign_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 a %= a;3 a %= a;
4}4}
55
6// mod assign on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/mod_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a % a;3 _ = a % a;
4}4}
55
6// mod on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/mul_overflow_in_function_evaluation.zig+3-1
...@@ -5,6 +5,8 @@ fn mul(a: u16, b: u16) u16 {...@@ -5,6 +5,8 @@ fn mul(a: u16, b: u16) u16 {
55
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
77
8// mul overflow in function evaluation8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:3:14: error: operation caused overflow12// tmp.zig:3:14: error: operation caused overflow
test/compile_errors/stage1/obj/mult_assign_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 a *= a;3 a *= a;
4}4}
55
6// mult assign on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/mult_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a * a;3 _ = a * a;
4}4}
55
6// mult on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/mult_wrap_assign_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 a *%= a;3 a *%= a;
4}4}
55
6// mult wrap assign on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/mult_wrap_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a *% a;3 _ = a *% a;
4}4}
55
6// mult wrap on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/multiple_function_definitions.zig+3-1
...@@ -2,7 +2,9 @@ fn a() void {}...@@ -2,7 +2,9 @@ fn a() void {}
2fn a() void {}2fn a() void {}
3export fn entry() void { a(); }3export fn entry() void { a(); }
44
5// multiple function definitions5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:1: error: redeclaration of 'a'9// tmp.zig:2:1: error: redeclaration of 'a'
8// tmp.zig:1:1: note: other declaration here10// tmp.zig:1:1: note: other declaration here
test/compile_errors/stage1/obj/negate_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = -a;3 _ = -a;
4}4}
55
6// negate on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:10: error: use of undefined value here causes undefined behavior10// tmp.zig:3:10: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/negate_wrap_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = -%a;3 _ = -%a;
4}4}
55
6// negate wrap on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:11: error: use of undefined value here causes undefined behavior10// tmp.zig:3:11: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/negation_overflow_in_function_evaluation.zig+3-1
...@@ -5,6 +5,8 @@ fn neg(x: i8) i8 {...@@ -5,6 +5,8 @@ fn neg(x: i8) i8 {
55
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
77
8// negation overflow in function evaluation8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:3:12: error: negation caused overflow12// tmp.zig:3:12: error: negation caused overflow
test/compile_errors/stage1/obj/nested_error_set_mismatch.zig+3-1
...@@ -10,7 +10,9 @@ fn foo() ?OtherError!i32 {...@@ -10,7 +10,9 @@ fn foo() ?OtherError!i32 {
10 return null;10 return null;
11}11}
1212
13// nested error set mismatch13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32'17// tmp.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32'
16// tmp.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32'18// tmp.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32'
test/compile_errors/stage1/obj/no_else_prong_on_switch_on_global_error_set.zig+3-1
...@@ -7,6 +7,8 @@ fn foo(a: anyerror) void {...@@ -7,6 +7,8 @@ fn foo(a: anyerror) void {
7 }7 }
8}8}
99
10// no else prong on switch on global error set10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:5:5: error: else prong required when switching on type 'anyerror'14// tmp.zig:5:5: error: else prong required when switching on type 'anyerror'
test/compile_errors/stage1/obj/noalias_on_non_pointer_param.zig+3-1
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1fn f(noalias x: i32) void { _ = x; }1fn f(noalias x: i32) void { _ = x; }
2export fn entry() void { f(1234); }2export fn entry() void { f(1234); }
33
4// noalias on non pointer param4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:1:6: error: noalias on non-pointer parameter8// tmp.zig:1:6: error: noalias on non-pointer parameter
test/compile_errors/stage1/obj/non-async_function_pointer_eventually_is_inferred_to_become_async.zig+3-1
...@@ -6,7 +6,9 @@ fn func() void {...@@ -6,7 +6,9 @@ fn func() void {
6 suspend {}6 suspend {}
7}7}
88
9// non-async function pointer eventually is inferred to become async9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:5:1: error: 'func' cannot be async13// tmp.zig:5:1: error: 'func' cannot be async
12// tmp.zig:3:20: note: required to be non-async here14// tmp.zig:3:20: note: required to be non-async here
test/compile_errors/stage1/obj/non-const_expression_function_call_with_struct_return_value_outside_function.zig+3-1
...@@ -10,6 +10,8 @@ var global_side_effect = false;...@@ -10,6 +10,8 @@ var global_side_effect = false;
1010
11export fn entry() usize { return @sizeOf(@TypeOf(a)); }11export fn entry() usize { return @sizeOf(@TypeOf(a)); }
1212
13// non-const expression function call with struct return value outside function13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:6:26: error: unable to evaluate constant expression17// tmp.zig:6:26: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/non-const_expression_in_struct_literal_outside_function.zig+3-1
...@@ -6,6 +6,8 @@ extern fn get_it() i32;...@@ -6,6 +6,8 @@ extern fn get_it() i32;
66
7export fn entry() usize { return @sizeOf(@TypeOf(a)); }7export fn entry() usize { return @sizeOf(@TypeOf(a)); }
88
9// non-const expression in struct literal outside function9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:4:21: error: unable to evaluate constant expression13// tmp.zig:4:21: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/non-const_switch_number_literal.zig+3-1
...@@ -10,6 +10,8 @@ fn bar() i32 {...@@ -10,6 +10,8 @@ fn bar() i32 {
10 return 2;10 return 2;
11}11}
1212
13// non-const switch number literal13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'17// tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'
test/compile_errors/stage1/obj/non-const_variables_of_things_that_require_const_variables.zig+3-1
...@@ -35,7 +35,9 @@ const Foo = struct {...@@ -35,7 +35,9 @@ const Foo = struct {
35 fn bar(self: *const Foo) void {_ = self;}35 fn bar(self: *const Foo) void {_ = self;}
36};36};
3737
38// non-const variables of things that require const variables38// error
39// backend=stage1
40// target=native
39//41//
40// tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime42// tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime
41// tmp.zig:6:4: error: variable of type '@Type(.Undefined)' must be const or comptime43// tmp.zig:6:4: error: variable of type '@Type(.Undefined)' must be const or comptime
test/compile_errors/stage1/obj/non-enum_tag_type_passed_to_union.zig+3-1
...@@ -6,6 +6,8 @@ export fn entry() void {...@@ -6,6 +6,8 @@ export fn entry() void {
6 _ = x;6 _ = x;
7}7}
88
9// non-enum tag type passed to union9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:1:19: error: expected enum tag type, found 'u32'13// tmp.zig:1:19: error: expected enum tag type, found 'u32'
test/compile_errors/stage1/obj/non-extern_function_with_var_args.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 foo();3 foo();
4}4}
55
6// non-extern function with var args6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:1:14: error: expected type expression, found '...'10// tmp.zig:1:14: error: expected type expression, found '...'
test/compile_errors/stage1/obj/non-inline_for_loop_on_a_type_that_requires_comptime.zig+3-1
...@@ -7,6 +7,8 @@ export fn entry() void {...@@ -7,6 +7,8 @@ export fn entry() void {
7 for (xx) |f| { _ = f;}7 for (xx) |f| { _ = f;}
8}8}
99
10// non-inline for loop on a type that requires comptime10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known14// tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known
test/compile_errors/stage1/obj/non-integer_tag_type_to_automatic_union_enum.zig+3-1
...@@ -6,6 +6,8 @@ export fn entry() void {...@@ -6,6 +6,8 @@ export fn entry() void {
6 _ = x;6 _ = x;
7}7}
88
9// non-integer tag type to automatic union enum9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:1:24: error: expected integer tag type, found 'f32'13// tmp.zig:1:24: error: expected integer tag type, found 'f32'
test/compile_errors/stage1/obj/non-pure_function_returns_type.zig+3-1
...@@ -17,6 +17,8 @@ export fn function_with_return_type_type() void {...@@ -17,6 +17,8 @@ export fn function_with_return_type_type() void {
17 list.length = 10;17 list.length = 10;
18}18}
1919
20// non-pure function returns type20// error
21// backend=stage1
22// target=native
21//23//
22// tmp.zig:3:7: error: unable to evaluate constant expression24// tmp.zig:3:7: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/non_async_function_pointer_passed_to_asyncCall.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5}5}
6fn afunc() void { }6fn afunc() void { }
77
8// non async function pointer passed to @asyncCall8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:32: error: expected async function, found 'fn() void'12// tmp.zig:4:32: error: expected async function, found 'fn() void'
test/compile_errors/stage1/obj/non_compile_time_array_concatenation.zig+3-1
...@@ -4,6 +4,8 @@ fn f() []u8 {...@@ -4,6 +4,8 @@ fn f() []u8 {
4var s: [10]u8 = undefined;4var s: [10]u8 = undefined;
5export fn entry() usize { return @sizeOf(@TypeOf(f)); }5export fn entry() usize { return @sizeOf(@TypeOf(f)); }
66
7// non compile time array concatenation7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:2:12: error: unable to evaluate constant expression11// tmp.zig:2:12: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/non_constant_expression_in_array_size.zig+3-1
...@@ -6,7 +6,9 @@ fn get() usize { return global_var; }...@@ -6,7 +6,9 @@ fn get() usize { return global_var; }
66
7export fn entry() usize { return @sizeOf(@TypeOf(Foo)); }7export fn entry() usize { return @sizeOf(@TypeOf(Foo)); }
88
9// non constant expression in array size9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:5:25: error: cannot store runtime value in compile time variable13// tmp.zig:5:25: error: cannot store runtime value in compile time variable
12// tmp.zig:2:12: note: called from here14// tmp.zig:2:12: note: called from here
test/compile_errors/stage1/obj/non_error_sets_used_in_merge_error_sets_operator.zig+3-1
...@@ -7,7 +7,9 @@ export fn bar() void {...@@ -7,7 +7,9 @@ export fn bar() void {
7 _ = Errors;7 _ = Errors;
8}8}
99
10// non error sets used in merge error sets operator10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:2:20: error: expected error set type, found type 'u8'14// tmp.zig:2:20: error: expected error set type, found type 'u8'
13// tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR15// tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR
test/compile_errors/stage1/obj/non_float_passed_to_floatToInt.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = x;3 _ = x;
4}4}
55
6// non float passed to @floatToInt6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:32: error: expected float type, found 'i32'10// tmp.zig:2:32: error: expected float type, found 'i32'
test/compile_errors/stage1/obj/non_int_passed_to_intToFloat.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = x;3 _ = x;
4}4}
55
6// non int passed to @intToFloat6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:32: error: expected int type, found 'comptime_float'10// tmp.zig:2:32: error: expected int type, found 'comptime_float'
test/compile_errors/stage1/obj/non_pointer_given_to_ptrToInt.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry(x: i32) usize {...@@ -2,6 +2,8 @@ export fn entry(x: i32) usize {
2 return @ptrToInt(x);2 return @ptrToInt(x);
3}3}
44
5// non pointer given to @ptrToInt5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:22: error: expected pointer, found 'i32'9// tmp.zig:2:22: error: expected pointer, found 'i32'
test/compile_errors/stage1/obj/normal_string_with_newline.zig+3-1
...@@ -1,7 +1,9 @@...@@ -1,7 +1,9 @@
1const foo = "a1const foo = "a
2b";2b";
33
4// normal string with newline4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:1:13: error: expected expression, found 'invalid bytes'8// tmp.zig:1:13: error: expected expression, found 'invalid bytes'
7// tmp.zig:1:15: note: invalid byte: '\n'9// tmp.zig:1:15: note: invalid byte: '\n'
test/compile_errors/stage1/obj/offsetOf-bad_field_name.zig+3-1
...@@ -5,6 +5,8 @@ export fn foo() usize {...@@ -5,6 +5,8 @@ export fn foo() usize {
5 return @offsetOf(Foo, "a",);5 return @offsetOf(Foo, "a",);
6}6}
77
8// @offsetOf - bad field name8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:5:27: error: struct 'Foo' has no field 'a'12// tmp.zig:5:27: error: struct 'Foo' has no field 'a'
test/compile_errors/stage1/obj/offsetOf-non_struct.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo() usize {...@@ -3,6 +3,8 @@ export fn foo() usize {
3 return @offsetOf(Foo, "a",);3 return @offsetOf(Foo, "a",);
4}4}
55
6// @offsetOf - non struct6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:22: error: expected struct type, found 'i32'10// tmp.zig:3:22: error: expected struct type, found 'i32'
test/compile_errors/stage1/obj/only_equality_binary_operator_allowed_for_error_sets.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = z;3 _ = z;
4}4}
55
6// only equality binary operator allowed for error sets6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:23: error: operator not allowed for errors10// tmp.zig:2:23: error: operator not allowed for errors
test/compile_errors/stage1/obj/opaque_type_with_field.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 _ = foo;4 _ = foo;
5}5}
66
7// opaque type with field7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:1:25: error: opaque types cannot have fields11// tmp.zig:1:25: error: opaque types cannot have fields
test/compile_errors/stage1/obj/optional_pointer_to_void_in_extern_struct.zig+3-1
...@@ -7,6 +7,8 @@ const Bar = extern struct {...@@ -7,6 +7,8 @@ const Bar = extern struct {
7};7};
8export fn entry(bar: *Bar) void {_ = bar;}8export fn entry(bar: *Bar) void {_ = bar;}
99
10// optional pointer to void in extern struct10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'14// tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'
test/compile_errors/stage1/obj/or_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a or a;3 _ = a or a;
4}4}
55
6// or on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/orelse_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a orelse false;3 _ = a orelse false;
4}4}
55
6// orelse on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:11: error: use of undefined value here causes undefined behavior10// tmp.zig:3:11: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/out_of_range_comptime_int_passed_to_floatToInt.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = x;3 _ = x;
4}4}
55
6// out of range comptime_int passed to @floatToInt6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'10// tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'
test/compile_errors/stage1/obj/overflow_in_enum_value_allocation.zig+3-1
...@@ -7,6 +7,8 @@ pub fn main() void {...@@ -7,6 +7,8 @@ pub fn main() void {
7 _ = y;7 _ = y;
8}8}
99
10// overflow in enum value allocation10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'14// tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'
test/compile_errors/stage1/obj/packed_union_given_enum_tag_type.zig+3-1
...@@ -13,6 +13,8 @@ export fn entry() void {...@@ -13,6 +13,8 @@ export fn entry() void {
13 _ = a;13 _ = a;
14}14}
1515
16// packed union given enum tag type16// error
17// backend=stage1
18// target=native
17//19//
18// tmp.zig:6:30: error: packed union does not support enum tag type20// tmp.zig:6:30: error: packed union does not support enum tag type
test/compile_errors/stage1/obj/packed_union_with_automatic_layout_field.zig+3-1
...@@ -11,6 +11,8 @@ export fn entry() void {...@@ -11,6 +11,8 @@ export fn entry() void {
11 _ = a;11 _ = a;
12}12}
1313
14// packed union with automatic layout field14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation18// tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation
test/compile_errors/stage1/obj/panic_called_at_compile_time.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 }4 }
5}5}
66
7// @panic called at compile time7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:9: error: encountered @panic at compile-time11// tmp.zig:3:9: error: encountered @panic at compile-time
test/compile_errors/stage1/obj/parameter_redeclaration.zig+3-1
...@@ -2,7 +2,9 @@ fn f(a : i32, a : i32) void {...@@ -2,7 +2,9 @@ fn f(a : i32, a : i32) void {
2}2}
3export fn entry() void { f(1, 2); }3export fn entry() void { f(1, 2); }
44
5// parameter redeclaration5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:1:15: error: redeclaration of function parameter 'a'9// tmp.zig:1:15: error: redeclaration of function parameter 'a'
8// tmp.zig:1:6: note: previous declaration here10// tmp.zig:1:6: note: previous declaration here
test/compile_errors/stage1/obj/parameter_shadowing_global.zig+3-1
...@@ -4,7 +4,9 @@ export fn entry() void {...@@ -4,7 +4,9 @@ export fn entry() void {
4 f(1234);4 f(1234);
5}5}
66
7// parameter shadowing global7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:2:6: error: local shadows declaration of 'Foo'11// tmp.zig:2:6: error: local shadows declaration of 'Foo'
10// tmp.zig:1:1: note: declared here12// tmp.zig:1:1: note: declared here
test/compile_errors/stage1/obj/pass_const_ptr_to_mutable_ptr_fn.zig+3-1
...@@ -10,6 +10,8 @@ fn ptrEql(a: *[]const u8, b: *[]const u8) bool {...@@ -10,6 +10,8 @@ fn ptrEql(a: *[]const u8, b: *[]const u8) bool {
1010
11export fn entry() usize { return @sizeOf(@TypeOf(foo)); }11export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1212
13// pass const ptr to mutable ptr fn13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'17// tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'
test/compile_errors/stage1/obj/passing_a_not-aligned-enough_pointer_to_cmpxchg.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() bool {...@@ -5,6 +5,8 @@ export fn entry() bool {
5 return x == 5678;5 return x == 5678;
6}6}
77
8// passing a not-aligned-enough pointer to cmpxchg8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'12// tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'
test/compile_errors/stage1/obj/passing_an_under-aligned_function_pointer.zig+3-1
...@@ -6,6 +6,8 @@ fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) i32, answer: i32) void {...@@ -6,6 +6,8 @@ fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) i32, answer: i32) void {
6}6}
7fn alignedSmall() align(4) i32 { return 1234; }7fn alignedSmall() align(4) i32 { return 1234; }
88
9// passing an under-aligned function pointer9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'13// tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'
test/compile_errors/stage1/obj/peer_cast_then_implicit_cast_const_pointer_to_mutable_C_pointer.zig+3-1
...@@ -3,7 +3,9 @@ export fn func() void {...@@ -3,7 +3,9 @@ export fn func() void {
3 strValue = strValue orelse "";3 strValue = strValue orelse "";
4}4}
55
6// peer cast then implicit cast const pointer to mutable C pointer6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8'10// tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8'
9// tmp.zig:3:32: note: cast discards const qualifier11// tmp.zig:3:32: note: cast discards const qualifier
test/compile_errors/stage1/obj/pointer_arithmetic_on_pointer-to-array.zig+3-1
...@@ -5,6 +5,8 @@ export fn foo() void {...@@ -5,6 +5,8 @@ export fn foo() void {
5 _ = z;5 _ = z;
6}6}
77
8// pointer arithmetic on pointer-to-array8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:4:17: error: integer value 1 cannot be coerced to type '*[10]u8'12// tmp.zig:4:17: error: integer value 1 cannot be coerced to type '*[10]u8'
test/compile_errors/stage1/obj/pointer_attributes_checked_when_coercing_pointer_to_anon_literal.zig+3-1
...@@ -12,7 +12,9 @@ comptime {...@@ -12,7 +12,9 @@ comptime {
12 _ = c;12 _ = c;
13}13}
1414
15// pointer attributes checked when coercing pointer to anon literal15// error
16// backend=stage1
17// target=native
16//18//
17// tmp.zig:2:31: error: cannot cast pointer to array literal to slice type '[][]const u8'19// tmp.zig:2:31: error: cannot cast pointer to array literal to slice type '[][]const u8'
18// tmp.zig:2:31: note: cast discards const qualifier20// tmp.zig:2:31: note: cast discards const qualifier
test/compile_errors/stage1/obj/pointer_to_noreturn.zig+3-1
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1fn a() *noreturn {}1fn a() *noreturn {}
2export fn entry() void { _ = a(); }2export fn entry() void { _ = a(); }
33
4// pointer to noreturn4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:1:9: error: pointer to noreturn not allowed8// tmp.zig:1:9: error: pointer to noreturn not allowed
test/compile_errors/stage1/obj/popCount-non-integer.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry(x: f32) u32 {...@@ -2,6 +2,8 @@ export fn entry(x: f32) u32 {
2 return @popCount(f32, x);2 return @popCount(f32, x);
3}3}
44
5// @popCount - non-integer5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:22: error: expected integer type, found 'f32'9// tmp.zig:2:22: error: expected integer type, found 'f32'
test/compile_errors/stage1/obj/prevent_bad_implicit_casting_of_anyframe_types.zig+3-1
...@@ -15,7 +15,9 @@ export fn c() void {...@@ -15,7 +15,9 @@ export fn c() void {
15}15}
16fn func() void {}16fn func() void {}
1717
18// prevent bad implicit casting of anyframe types18// error
19// backend=stage1
20// target=native
19//21//
20// tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'22// tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'
21// tmp.zig:8:28: error: expected type 'anyframe->i32', found 'i32'23// tmp.zig:8:28: error: expected type 'anyframe->i32', found 'i32'
test/compile_errors/stage1/obj/primitives_take_precedence_over_declarations.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 _ = a;4 _ = a;
5}5}
66
7// primitives take precedence over declarations7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:19: error: integer value 300 cannot be coerced to type 'u8'11// tmp.zig:3:19: error: integer value 300 cannot be coerced to type 'u8'
test/compile_errors/stage1/obj/ptrCast_a_0_bit_type_to_a_non-_0_bit_type.zig+3-1
...@@ -4,7 +4,9 @@ export fn entry() bool {...@@ -4,7 +4,9 @@ export fn entry() bool {
4 return p == null;4 return p == null;
5}5}
66
7// @ptrCast a 0 bit type to a non- 0 bit type7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation11// tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation
10// tmp.zig:3:31: note: '*u0' has no in-memory bits12// tmp.zig:3:31: note: '*u0' has no in-memory bits
test/compile_errors/stage1/obj/ptrCast_discards_const_qualifier.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 _ = y;4 _ = y;
5}5}
66
7// @ptrCast discards const qualifier7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:15: error: cast discards const qualifier11// tmp.zig:3:15: error: cast discards const qualifier
test/compile_errors/stage1/obj/ptrToInt_0_to_non_optional_pointer.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = b;3 _ = b;
4}4}
55
6// @ptrToInt 0 to non optional pointer6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:13: error: pointer type '*i32' does not allow address zero10// tmp.zig:2:13: error: pointer type '*i32' does not allow address zero
test/compile_errors/stage1/obj/ptrToInt_on_void.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() bool {...@@ -2,6 +2,8 @@ export fn entry() bool {
2 return @ptrToInt(&{}) == @ptrToInt(&{});2 return @ptrToInt(&{}) == @ptrToInt(&{});
3}3}
44
5// @ptrToInt on *void5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:23: error: pointer to size 0 type has no address9// tmp.zig:2:23: error: pointer to size 0 type has no address
test/compile_errors/stage1/obj/ptrcast_to_non-pointer.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry(a: *i32) usize {...@@ -2,6 +2,8 @@ export fn entry(a: *i32) usize {
2 return @ptrCast(usize, a);2 return @ptrCast(usize, a);
3}3}
44
5// ptrcast to non-pointer5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:21: error: expected pointer, found 'usize'9// tmp.zig:2:21: error: expected pointer, found 'usize'
test/compile_errors/stage1/obj/range_operator_in_switch_used_on_error_set.zig+3-1
...@@ -12,6 +12,8 @@ fn foo(x: i32) !void {...@@ -12,6 +12,8 @@ fn foo(x: i32) !void {
12 }12 }
13}13}
1414
15// range operator in switch used on error set15// error
16// backend=stage1
17// target=native
16//18//
17// tmp.zig:3:17: error: operator not allowed for errors19// tmp.zig:3:17: error: operator not allowed for errors
test/compile_errors/stage1/obj/reading_past_end_of_pointer_casted_array.zig+3-1
...@@ -6,6 +6,8 @@ comptime {...@@ -6,6 +6,8 @@ comptime {
6 _ = deref;6 _ = deref;
7}7}
88
9// reading past end of pointer casted array9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes13// tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes
test/compile_errors/stage1/obj/recursive_inferred_error_set.zig+3-1
...@@ -5,6 +5,8 @@ fn foo() !void {...@@ -5,6 +5,8 @@ fn foo() !void {
5 try foo();5 try foo();
6}6}
77
8// recursive inferred error set8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:5:5: error: cannot resolve inferred error set '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set': function 'foo' not fully analyzed yet12// tmp.zig:5:5: error: cannot resolve inferred error set '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set': function 'foo' not fully analyzed yet
test/compile_errors/stage1/obj/redefinition_of_enums.zig+3-1
...@@ -1,7 +1,9 @@...@@ -1,7 +1,9 @@
1const A = enum {x};1const A = enum {x};
2const A = enum {x};2const A = enum {x};
33
4// redefinition of enums4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:2:1: error: redeclaration of 'A'8// tmp.zig:2:1: error: redeclaration of 'A'
7// tmp.zig:1:1: note: other declaration here9// tmp.zig:1:1: note: other declaration here
test/compile_errors/stage1/obj/redefinition_of_global_variables.zig+3-1
...@@ -1,7 +1,9 @@...@@ -1,7 +1,9 @@
1var a : i32 = 1;1var a : i32 = 1;
2var a : i32 = 2;2var a : i32 = 2;
33
4// redefinition of global variables4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:2:1: error: redeclaration of 'a'8// tmp.zig:2:1: error: redeclaration of 'a'
7// tmp.zig:1:1: note: other declaration here9// tmp.zig:1:1: note: other declaration here
test/compile_errors/stage1/obj/redefinition_of_struct.zig+3-1
...@@ -1,7 +1,9 @@...@@ -1,7 +1,9 @@
1const A = struct { x : i32, };1const A = struct { x : i32, };
2const A = struct { y : i32, };2const A = struct { y : i32, };
33
4// redefinition of struct4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:2:1: error: redeclaration of 'A'8// tmp.zig:2:1: error: redeclaration of 'A'
7// tmp.zig:1:1: note: other declaration here9// tmp.zig:1:1: note: other declaration here
test/compile_errors/stage1/obj/refer_to_the_type_of_a_generic_function.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 f(i32);4 f(i32);
5}5}
66
7// refer to the type of a generic function7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:4:5: error: use of undefined value here causes undefined behavior11// tmp.zig:4:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/referring_to_a_struct_that_is_invalid.zig+3-1
...@@ -10,6 +10,8 @@ fn assert(ok: bool) void {...@@ -10,6 +10,8 @@ fn assert(ok: bool) void {
10 if (!ok) unreachable;10 if (!ok) unreachable;
11}11}
1212
13// referring to a struct that is invalid13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:10:14: error: reached unreachable code17// tmp.zig:10:14: error: reached unreachable code
test/compile_errors/stage1/obj/regression_test_2980_base_type_u32_is_not_type_checked_properly_when_assigning_a_value_within_a_struct.zig+3-1
...@@ -14,6 +14,8 @@ export fn entry() void {...@@ -14,6 +14,8 @@ export fn entry() void {
14 _ = afoo;14 _ = afoo;
15}15}
1616
17// regression test #2980: base type u32 is not type checked properly when assigning a value within a struct17// error
18// backend=stage1
19// target=native
18//20//
19// tmp.zig:12:25: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'21// tmp.zig:12:25: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'
test/compile_errors/stage1/obj/reify_type.Fn_with_is_generic_true.zig+3-1
...@@ -10,6 +10,8 @@ const Foo = @Type(.{...@@ -10,6 +10,8 @@ const Foo = @Type(.{
10});10});
11comptime { _ = Foo; }11comptime { _ = Foo; }
1212
13// @Type(.Fn) with is_generic = true13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:1:20: error: Type.Fn.is_generic must be false for @Type17// tmp.zig:1:20: error: Type.Fn.is_generic must be false for @Type
test/compile_errors/stage1/obj/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig+3-1
...@@ -10,6 +10,8 @@ const Foo = @Type(.{...@@ -10,6 +10,8 @@ const Foo = @Type(.{
10});10});
11comptime { _ = Foo; }11comptime { _ = Foo; }
1212
13// @Type(.Fn) with is_var_args = true and non-C callconv13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:1:20: error: varargs functions must have C calling convention17// tmp.zig:1:20: error: varargs functions must have C calling convention
test/compile_errors/stage1/obj/reify_type.Fn_with_return_type_null.zig+3-1
...@@ -10,6 +10,8 @@ const Foo = @Type(.{...@@ -10,6 +10,8 @@ const Foo = @Type(.{
10});10});
11comptime { _ = Foo; }11comptime { _ = Foo; }
1212
13// @Type(.Fn) with return_type = null13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:1:20: error: Type.Fn.return_type must be non-null for @Type17// tmp.zig:1:20: error: Type.Fn.return_type must be non-null for @Type
test/compile_errors/stage1/obj/reify_type.Pointer_with_invalid_address_space.zig+3-1
...@@ -11,6 +11,8 @@ export fn entry() void {...@@ -11,6 +11,8 @@ export fn entry() void {
11 }});11 }});
12}12}
1313
14// @Type(.Pointer) with invalid address space 14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:2:16: error: address space 'gs' not available in stage 1 compiler, must be .generic18// tmp.zig:2:16: error: address space 'gs' not available in stage 1 compiler, must be .generic
test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig+3-1
...@@ -11,6 +11,8 @@ export fn entry() void {...@@ -11,6 +11,8 @@ export fn entry() void {
11 _ = @intToEnum(Tag, 0);11 _ = @intToEnum(Tag, 0);
12}12}
1313
14// @Type for exhaustive enum with non-integer tag type14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:1:20: error: Type.Enum.tag_type must be an integer type, not 'bool'18// tmp.zig:1:20: error: Type.Enum.tag_type must be an integer type, not 'bool'
test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig+3-1
...@@ -11,6 +11,8 @@ export fn entry() void {...@@ -11,6 +11,8 @@ export fn entry() void {
11 _ = @intToEnum(Tag, 0);11 _ = @intToEnum(Tag, 0);
12}12}
1313
14// @Type for exhaustive enum with undefined tag type14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:1:20: error: use of undefined value here causes undefined behavior18// tmp.zig:1:20: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_zero_fields.zig+3-1
...@@ -11,6 +11,8 @@ export fn entry() void {...@@ -11,6 +11,8 @@ export fn entry() void {
11 _ = @intToEnum(Tag, 0);11 _ = @intToEnum(Tag, 0);
12}12}
1313
14// @Type for exhaustive enum with zero fields14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:1:20: error: enums must have 1 or more fields18// tmp.zig:1:20: error: enums must have 1 or more fields
test/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_enum_field.zig+3-1
...@@ -27,6 +27,8 @@ export fn entry() void {...@@ -27,6 +27,8 @@ export fn entry() void {
27 tagged = .{ .unsigned = 1 };27 tagged = .{ .unsigned = 1 };
28}28}
2929
30// @Type for tagged union with extra enum field30// error
31// backend=stage1
32// target=native
31//33//
32// tmp.zig:14:23: error: enum field missing: 'arst'34// tmp.zig:14:23: error: enum field missing: 'arst'
test/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_union_field.zig+3-1
...@@ -27,7 +27,9 @@ export fn entry() void {...@@ -27,7 +27,9 @@ export fn entry() void {
27 tagged = .{ .unsigned = 1 };27 tagged = .{ .unsigned = 1 };
28}28}
2929
30// @Type for tagged union with extra union field30// error
31// backend=stage1
32// target=native
31//33//
32// tmp.zig:13:23: error: enum field not found: 'arst'34// tmp.zig:13:23: error: enum field not found: 'arst'
33// tmp.zig:1:20: note: enum declared here35// tmp.zig:1:20: note: enum declared here
test/compile_errors/stage1/obj/reify_type_for_union_with_opaque_field.zig+3-1
...@@ -12,6 +12,8 @@ export fn entry() void {...@@ -12,6 +12,8 @@ export fn entry() void {
12 _ = Untagged{};12 _ = Untagged{};
13}13}
1414
15// @Type for union with opaque field15// error
16// backend=stage1
17// target=native
16//18//
17// tmp.zig:1:25: error: opaque types have unknown size and therefore cannot be directly embedded in unions19// tmp.zig:1:25: error: opaque types have unknown size and therefore cannot be directly embedded in unions
test/compile_errors/stage1/obj/reify_type_for_union_with_zero_fields.zig+3-1
...@@ -10,6 +10,8 @@ export fn entry() void {...@@ -10,6 +10,8 @@ export fn entry() void {
10 _ = Untagged{};10 _ = Untagged{};
11}11}
1212
13// @Type for union with zero fields13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:1:25: error: unions must have 1 or more fields17// tmp.zig:1:25: error: unions must have 1 or more fields
test/compile_errors/stage1/obj/reify_type_union_payload_is_undefined.zig+3-1
...@@ -3,6 +3,8 @@ const Foo = @Type(.{...@@ -3,6 +3,8 @@ const Foo = @Type(.{
3});3});
4comptime { _ = Foo; }4comptime { _ = Foo; }
55
6// @Type() union payload is undefined6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:1:20: error: use of undefined value here causes undefined behavior10// tmp.zig:1:20: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/reify_type_with_Type.Int.zig+3-1
...@@ -6,6 +6,8 @@ export fn entry() void {...@@ -6,6 +6,8 @@ export fn entry() void {
6 });6 });
7}7}
88
9// @Type with Type.Int9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:3:31: error: expected type 'std.builtin.Type', found 'std.builtin.Type.Int'13// tmp.zig:3:31: error: expected type 'std.builtin.Type', found 'std.builtin.Type.Int'
test/compile_errors/stage1/obj/reify_type_with_non-constant_expression.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 _ = @Type(globalTypeInfo);4 _ = @Type(globalTypeInfo);
5}5}
66
7// @Type with non-constant expression7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:4:15: error: unable to evaluate constant expression11// tmp.zig:4:15: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/reify_type_with_undefined.zig+3-1
...@@ -12,7 +12,9 @@ comptime {...@@ -12,7 +12,9 @@ comptime {
12 });12 });
13}13}
1414
15// @Type with undefined15// error
16// backend=stage1
17// target=native
16//18//
17// tmp.zig:2:16: error: use of undefined value here causes undefined behavior19// tmp.zig:2:16: error: use of undefined value here causes undefined behavior
18// tmp.zig:5:16: error: use of undefined value here causes undefined behavior20// tmp.zig:5:16: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr.zig+3-1
...@@ -11,6 +11,8 @@ pub const Container = struct {...@@ -11,6 +11,8 @@ pub const Container = struct {
11 not_optional: i32,11 not_optional: i32,
12};12};
1313
14// result location incompatibility mismatching handle_is_ptr14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'18// tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'
test/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig+3-1
...@@ -11,6 +11,8 @@ pub const Container = struct {...@@ -11,6 +11,8 @@ pub const Container = struct {
11 not_optional: i32,11 not_optional: i32,
12};12};
1313
14// result location incompatibility mismatching handle_is_ptr (generic call)14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'18// tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'
test/compile_errors/stage1/obj/return_from_defer_expression.zig+3-1
...@@ -14,6 +14,8 @@ pub fn maybeInt() ?i32 {...@@ -14,6 +14,8 @@ pub fn maybeInt() ?i32 {
1414
15export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); }15export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); }
1616
17// return from defer expression17// error
18// backend=stage1
19// target=native
18//20//
19// tmp.zig:4:11: error: 'try' not allowed inside defer expression21// tmp.zig:4:11: error: 'try' not allowed inside defer expression
test/compile_errors/stage1/obj/returning_error_from_void_async_function.zig+3-1
...@@ -5,6 +5,8 @@ fn amain() callconv(.Async) void {...@@ -5,6 +5,8 @@ fn amain() callconv(.Async) void {
5 return error.ShouldBeCompileError;5 return error.ShouldBeCompileError;
6}6}
77
8// returning error from void async function8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'12// tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'
test/compile_errors/stage1/obj/runtime-known_async_function_called.zig+3-1
...@@ -7,6 +7,8 @@ fn amain() void {...@@ -7,6 +7,8 @@ fn amain() void {
7}7}
8fn afunc() callconv(.Async) void {}8fn afunc() callconv(.Async) void {}
99
10// runtime-known async function called10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:6:12: error: function is not comptime-known; @asyncCall required14// tmp.zig:6:12: error: function is not comptime-known; @asyncCall required
test/compile_errors/stage1/obj/runtime-known_function_called_with_async_keyword.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
55
6fn afunc() callconv(.Async) void { }6fn afunc() callconv(.Async) void { }
77
8// runtime-known function called with async keyword8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:3:15: error: function is not comptime-known; @asyncCall required12// tmp.zig:3:15: error: function is not comptime-known; @asyncCall required
test/compile_errors/stage1/obj/runtime_assignment_to_comptime_struct_type.zig+3-1
...@@ -8,6 +8,8 @@ export fn f() void {...@@ -8,6 +8,8 @@ export fn f() void {
8 _ = foo;8 _ = foo;
9}9}
1010
11// runtime assignment to comptime struct type11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:7:23: error: unable to evaluate constant expression15// tmp.zig:7:23: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/runtime_assignment_to_comptime_union_type.zig+3-1
...@@ -8,6 +8,8 @@ export fn f() void {...@@ -8,6 +8,8 @@ export fn f() void {
8 _ = foo;8 _ = foo;
9}9}
1010
11// runtime assignment to comptime union type11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:7:23: error: unable to evaluate constant expression15// tmp.zig:7:23: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/runtime_cast_to_union_which_has_non-void_fields.zig+3-1
...@@ -12,7 +12,9 @@ fn foo(l: Letter) void {...@@ -12,7 +12,9 @@ fn foo(l: Letter) void {
12 _ = x;12 _ = x;
13}13}
1414
15// runtime cast to union which has non-void fields15// error
16// backend=stage1
17// target=native
16//18//
17// tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields19// tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields
18// tmp.zig:3:5: note: field 'A' has type 'i32'20// tmp.zig:3:5: note: field 'A' has type 'i32'
test/compile_errors/stage1/obj/runtime_index_into_comptime_type_slice.zig+3-1
...@@ -10,6 +10,8 @@ export fn entry() void {...@@ -10,6 +10,8 @@ export fn entry() void {
10 _ = field;10 _ = field;
11}11}
1212
13// runtime index into comptime type slice13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:9:51: error: values of type 'std.builtin.Type.StructField' must be comptime known, but index value is runtime known17// tmp.zig:9:51: error: values of type 'std.builtin.Type.StructField' must be comptime known, but index value is runtime known
test/compile_errors/stage1/obj/saturating_arithmetic_does_not_allow_floats.zig+3-1
...@@ -2,6 +2,8 @@ export fn a() void {...@@ -2,6 +2,8 @@ export fn a() void {
2 _ = @as(f32, 1.0) +| @as(f32, 1.0);2 _ = @as(f32, 1.0) +| @as(f32, 1.0);
3}3}
44
5// saturating arithmetic does not allow floats5// error
6// backend=stage1
7// target=native
6//8//
7// error: invalid operands to binary expression: 'f32' and 'f32'9// error: invalid operands to binary expression: 'f32' and 'f32'
test/compile_errors/stage1/obj/saturating_shl_assign_does_not_allow_negative_rhs_at_comptime.zig+3-1
...@@ -5,6 +5,8 @@ export fn a() void {...@@ -5,6 +5,8 @@ export fn a() void {
5 }5 }
6}6}
77
8// saturating shl assign does not allow negative rhs at comptime8// error
9// backend=stage1
10// target=native
9//11//
10// error: shift by negative value -212// error: shift by negative value -2
test/compile_errors/stage1/obj/saturating_shl_does_not_allow_negative_rhs_at_comptime.zig+3-1
...@@ -2,6 +2,8 @@ export fn a() void {...@@ -2,6 +2,8 @@ export fn a() void {
2 _ = @as(i32, 1) <<| @as(i32, -2);2 _ = @as(i32, 1) <<| @as(i32, -2);
3}3}
44
5// saturating shl does not allow negative rhs at comptime5// error
6// backend=stage1
7// target=native
6//8//
7// error: shift by negative value -29// error: shift by negative value -2
test/compile_errors/stage1/obj/setAlignStack_in_inline_function.zig+3-1
...@@ -5,6 +5,8 @@ fn foo() callconv(.Inline) void {...@@ -5,6 +5,8 @@ fn foo() callconv(.Inline) void {
5 @setAlignStack(16);5 @setAlignStack(16);
6}6}
77
8// @setAlignStack in inline function8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:5:5: error: @setAlignStack in inline function12// tmp.zig:5:5: error: @setAlignStack in inline function
test/compile_errors/stage1/obj/setAlignStack_in_naked_function.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() callconv(.Naked) void {...@@ -2,6 +2,8 @@ export fn entry() callconv(.Naked) void {
2 @setAlignStack(16);2 @setAlignStack(16);
3}3}
44
5// @setAlignStack in naked function5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:5: error: @setAlignStack in naked function9// tmp.zig:2:5: error: @setAlignStack in naked function
test/compile_errors/stage1/obj/setAlignStack_outside_function.zig+3-1
...@@ -2,6 +2,8 @@ comptime {...@@ -2,6 +2,8 @@ comptime {
2 @setAlignStack(16);2 @setAlignStack(16);
3}3}
44
5// @setAlignStack outside function5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:5: error: @setAlignStack outside function9// tmp.zig:2:5: error: @setAlignStack outside function
test/compile_errors/stage1/obj/setAlignStack_set_twice.zig+3-1
...@@ -3,7 +3,9 @@ export fn entry() void {...@@ -3,7 +3,9 @@ export fn entry() void {
3 @setAlignStack(16);3 @setAlignStack(16);
4}4}
55
6// @setAlignStack set twice6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: alignstack set twice10// tmp.zig:3:5: error: alignstack set twice
9// tmp.zig:2:5: note: first set here11// tmp.zig:2:5: note: first set here
test/compile_errors/stage1/obj/setAlignStack_too_big.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() void {...@@ -2,6 +2,8 @@ export fn entry() void {
2 @setAlignStack(511 + 1);2 @setAlignStack(511 + 1);
3}3}
44
5// @setAlignStack too big5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 2569// tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256
test/compile_errors/stage1/obj/setFloatMode_twice_for_same_scope.zig+3-1
...@@ -3,7 +3,9 @@ export fn foo() void {...@@ -3,7 +3,9 @@ export fn foo() void {
3 @setFloatMode(@import("std").builtin.FloatMode.Optimized);3 @setFloatMode(@import("std").builtin.FloatMode.Optimized);
4}4}
55
6// @setFloatMode twice for same scope6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: float mode set twice for same scope10// tmp.zig:3:5: error: float mode set twice for same scope
9// tmp.zig:2:5: note: first set here11// tmp.zig:2:5: note: first set here
test/compile_errors/stage1/obj/setRuntimeSafety_twice_for_same_scope.zig+3-1
...@@ -3,7 +3,9 @@ export fn foo() void {...@@ -3,7 +3,9 @@ export fn foo() void {
3 @setRuntimeSafety(false);3 @setRuntimeSafety(false);
4}4}
55
6// @setRuntimeSafety twice for same scope6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: runtime safety set twice for same scope10// tmp.zig:3:5: error: runtime safety set twice for same scope
9// tmp.zig:2:5: note: first set here11// tmp.zig:2:5: note: first set here
test/compile_errors/stage1/obj/setting_a_section_on_a_local_variable.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() i32 {...@@ -3,6 +3,8 @@ export fn entry() i32 {
3 return foo;3 return foo;
4}4}
55
6// setting a section on a local variable6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:30: error: cannot set section of local variable 'foo'10// tmp.zig:2:30: error: cannot set section of local variable 'foo'
test/compile_errors/stage1/obj/shift_amount_has_to_be_an_integer_type.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = x;3 _ = x;
4}4}
55
6// shift amount has to be an integer type6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8'10// tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8'
test/compile_errors/stage1/obj/shift_by_negative_comptime_integer.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a;3 _ = a;
4}4}
55
6// shift by negative comptime integer6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:18: error: shift by negative value -110// tmp.zig:2:18: error: shift by negative value -1
test/compile_errors/stage1/obj/shift_left_assign_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 a >>= 2;3 a >>= 2;
4}4}
55
6// shift left assign on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/shift_left_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a << 2;3 _ = a << 2;
4}4}
55
6// shift left on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/shift_right_assign_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 a >>= 2;3 a >>= 2;
4}4}
55
6// shift right assign on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/shift_right_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a >> 2;3 _ = a >> 2;
4}4}
55
6// shift right on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/shifting_RHS_is_log2_of_LHS_int_bit_width.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry(x: u8, y: u8) u8 {...@@ -2,6 +2,8 @@ export fn entry(x: u8, y: u8) u8 {
2 return x << y;2 return x << y;
3}3}
44
5// shifting RHS is log2 of LHS int bit width5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:17: error: expected type 'u3', found 'u8'9// tmp.zig:2:17: error: expected type 'u3', found 'u8'
test/compile_errors/stage1/obj/shifting_without_int_type_or_comptime_known.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry(x: u8) u8 {...@@ -2,6 +2,8 @@ export fn entry(x: u8) u8 {
2 return 0x11 << x;2 return 0x11 << x;
3}3}
44
5// shifting without int type or comptime known5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known9// tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known
test/compile_errors/stage1/obj/shlExact_shifts_out_1_bits.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = x;3 _ = x;
4}4}
55
6// @shlExact shifts out 1 bits6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:15: error: operation caused overflow10// tmp.zig:2:15: error: operation caused overflow
test/compile_errors/stage1/obj/shrExact_shifts_out_1_bits.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = x;3 _ = x;
4}4}
55
6// @shrExact shifts out 1 bits6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:15: error: exact shift shifted out 1 bits10// tmp.zig:2:15: error: exact shift shifted out 1 bits
test/compile_errors/stage1/obj/signed_integer_division.zig+3-1
...@@ -2,6 +2,8 @@ export fn foo(a: i32, b: i32) i32 {...@@ -2,6 +2,8 @@ export fn foo(a: i32, b: i32) i32 {
2 return a / b;2 return a / b;
3}3}
44
5// signed integer division5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact9// tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact
test/compile_errors/stage1/obj/signed_integer_remainder_division.zig+3-1
...@@ -2,6 +2,8 @@ export fn foo(a: i32, b: i32) i32 {...@@ -2,6 +2,8 @@ export fn foo(a: i32, b: i32) i32 {
2 return a % b;2 return a % b;
3}3}
44
5// signed integer remainder division5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod9// tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod
test/compile_errors/stage1/obj/sizeOf_bad_type.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() usize {...@@ -2,6 +2,8 @@ export fn entry() usize {
2 return @sizeOf(@TypeOf(null));2 return @sizeOf(@TypeOf(null));
3}3}
44
5// @sizeOf bad type5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:20: error: no size available for type '@Type(.Null)'9// tmp.zig:2:20: error: no size available for type '@Type(.Null)'
test/compile_errors/stage1/obj/slice_cannot_have_its_bytes_reinterpreted.zig+3-1
...@@ -4,6 +4,8 @@ export fn foo() void {...@@ -4,6 +4,8 @@ export fn foo() void {
4 _ = value;4 _ = value;
5}5}
66
7// slice cannot have its bytes reinterpreted7// error
8// backend=stage1
9// target=native
8//10//
9// :3:52: error: slice '[]const u8' cannot have its bytes reinterpreted11// :3:52: error: slice '[]const u8' cannot have its bytes reinterpreted
test/compile_errors/stage1/obj/slice_passed_as_array_init_type.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = x;3 _ = x;
4}4}
55
6// slice passed as array init type6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'10// tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'
test/compile_errors/stage1/obj/slice_passed_as_array_init_type_with_elems.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = x;3 _ = x;
4}4}
55
6// slice passed as array init type with elems6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'10// tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'
test/compile_errors/stage1/obj/slice_sentinel_mismatch-1.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = y;3 _ = y;
4}4}
55
6// slice sentinel mismatch - 16// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'10// tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'
test/compile_errors/stage1/obj/slice_sentinel_mismatch-2.zig+3-1
...@@ -4,7 +4,9 @@ fn foo() [:0]u8 {...@@ -4,7 +4,9 @@ fn foo() [:0]u8 {
4}4}
5comptime { _ = foo; }5comptime { _ = foo; }
66
7// slice sentinel mismatch - 27// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:12: error: expected type '[:0]u8', found '[]u8'11// tmp.zig:3:12: error: expected type '[:0]u8', found '[]u8'
10// tmp.zig:3:12: note: destination pointer requires a terminating '0' sentinel12// tmp.zig:3:12: note: destination pointer requires a terminating '0' sentinel
test/compile_errors/stage1/obj/slicing_of_global_undefined_pointer.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = buf[0..1];3 _ = buf[0..1];
4}4}
55
6// slicing of global undefined pointer6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:12: error: non-zero length slice of undefined pointer10// tmp.zig:3:12: error: non-zero length slice of undefined pointer
test/compile_errors/stage1/obj/slicing_single-item_pointer.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry(ptr: *i32) void {...@@ -3,6 +3,8 @@ export fn entry(ptr: *i32) void {
3 _ = slice;3 _ = slice;
4}4}
55
6// slicing single-item pointer6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:22: error: slice of single-item pointer10// tmp.zig:2:22: error: slice of single-item pointer
test/compile_errors/stage1/obj/specify_enum_tag_type_that_is_too_small.zig+3-1
...@@ -11,6 +11,8 @@ export fn entry() void {...@@ -11,6 +11,8 @@ export fn entry() void {
11 _ = x;11 _ = x;
12}12}
1313
14// specify enum tag type that is too small14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'18// tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'
test/compile_errors/stage1/obj/specify_non-integer_enum_tag_type.zig+3-1
...@@ -9,6 +9,8 @@ export fn entry() void {...@@ -9,6 +9,8 @@ export fn entry() void {
9 _ = x;9 _ = x;
10}10}
1111
12// specify non-integer enum tag type12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:1:21: error: expected integer, found 'f32'16// tmp.zig:1:21: error: expected integer, found 'f32'
test/compile_errors/stage1/obj/src_outside_function.zig+3-1
...@@ -2,6 +2,8 @@ comptime {...@@ -2,6 +2,8 @@ comptime {
2 @src();2 @src();
3}3}
44
5// @src outside function5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:5: error: @src outside function9// tmp.zig:2:5: error: @src outside function
test/compile_errors/stage1/obj/std.fmt_error_for_unused_arguments.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() void {...@@ -2,6 +2,8 @@ export fn entry() void {
2 @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15});2 @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15});
3}3}
44
5// std.fmt error for unused arguments5// error
6// backend=stage1
7// target=native
6//8//
7// ?:?:?: error: 10 unused arguments in '{d} {d} {d} {d} {d}'9// ?:?:?: error: 10 unused arguments in '{d} {d} {d} {d} {d}'
test/compile_errors/stage1/obj/store_vector_pointer_with_unknown_runtime_index.zig+3-1
...@@ -9,6 +9,8 @@ fn storev(ptr: anytype, val: i32) void {...@@ -9,6 +9,8 @@ fn storev(ptr: anytype, val: i32) void {
9 ptr.* = val;9 ptr.* = val;
10}10}
1111
12// store vector pointer with unknown runtime index12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i3216// tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32
test/compile_errors/stage1/obj/storing_runtime_value_in_compile_time_variable_then_using_it.zig+3-1
...@@ -42,6 +42,8 @@ export fn entry() void {...@@ -42,6 +42,8 @@ export fn entry() void {
42 }42 }
43}43}
4444
45// storing runtime value in compile time variable then using it45// error
46// backend=stage1
47// target=native
46//48//
47// tmp.zig:38:29: error: cannot store runtime value in compile time variable49// tmp.zig:38:29: error: cannot store runtime value in compile time variable
test/compile_errors/stage1/obj/struct_depends_on_itself_via_optional_field.zig+3-1
...@@ -10,7 +10,9 @@ export fn entry() void {...@@ -10,7 +10,9 @@ export fn entry() void {
10 _ = obj;10 _ = obj;
11}11}
1212
13// struct depends on itself via optional field13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:1:17: error: struct 'LhsExpr' depends on itself17// tmp.zig:1:17: error: struct 'LhsExpr' depends on itself
16// tmp.zig:5:5: note: while checking this field18// tmp.zig:5:5: note: while checking this field
test/compile_errors/stage1/obj/struct_field_missing_type.zig+3-1
...@@ -6,6 +6,8 @@ export fn entry() void {...@@ -6,6 +6,8 @@ export fn entry() void {
6 _ = a;6 _ = a;
7}7}
88
9// struct field missing type9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:2:5: error: struct field missing type13// tmp.zig:2:5: error: struct field missing type
test/compile_errors/stage1/obj/struct_init_syntax_for_array.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = foo;3 _ = foo;
4}4}
55
6// struct init syntax for array6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:1:13: error: initializing array with struct syntax10// tmp.zig:1:13: error: initializing array with struct syntax
test/compile_errors/stage1/obj/struct_with_declarations_unavailable_for_reify_type.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() void {...@@ -2,6 +2,8 @@ export fn entry() void {
2 _ = @Type(@typeInfo(struct { const foo = 1; }));2 _ = @Type(@typeInfo(struct { const foo = 1; }));
3}3}
44
5// struct with declarations unavailable for @Type5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:15: error: Type.Struct.decls must be empty for @Type9// tmp.zig:2:15: error: Type.Struct.decls must be empty for @Type
test/compile_errors/stage1/obj/struct_with_invalid_field.zig+3-1
...@@ -23,6 +23,8 @@ export fn entry() void {...@@ -23,6 +23,8 @@ export fn entry() void {
23 _ = a;23 _ = a;
24}24}
2525
26// struct with invalid field26// error
27// backend=stage1
28// target=native
27//29//
28// tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'30// tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'
test/compile_errors/stage1/obj/sub_assign_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 a -= a;3 a -= a;
4}4}
55
6// sub assign on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/sub_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a - a;3 _ = a - a;
4}4}
55
6// sub on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/sub_overflow_in_function_evaluation.zig+3-1
...@@ -5,6 +5,8 @@ fn sub(a: u16, b: u16) u16 {...@@ -5,6 +5,8 @@ fn sub(a: u16, b: u16) u16 {
55
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
77
8// sub overflow in function evaluation8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:3:14: error: operation caused overflow12// tmp.zig:3:14: error: operation caused overflow
test/compile_errors/stage1/obj/sub_wrap_assign_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 a -%= a;3 a -%= a;
4}4}
55
6// sub wrap assign on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: use of undefined value here causes undefined behavior10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/sub_wrap_on_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = a -% a;3 _ = a -% a;
4}4}
55
6// sub wrap on undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:9: error: use of undefined value here causes undefined behavior10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/suspend_inside_suspend_block.zig+3-1
...@@ -8,7 +8,9 @@ fn foo() void {...@@ -8,7 +8,9 @@ fn foo() void {
8 }8 }
9}9}
1010
11// suspend inside suspend block11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:6:9: error: cannot suspend inside suspend block15// tmp.zig:6:9: error: cannot suspend inside suspend block
14// tmp.zig:5:5: note: other suspend block here16// tmp.zig:5:5: note: other suspend block here
test/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong.zig+3-1
...@@ -16,7 +16,9 @@ fn f(n: Number) i32 {...@@ -16,7 +16,9 @@ fn f(n: Number) i32 {
1616
17export fn entry() usize { return @sizeOf(@TypeOf(f)); }17export fn entry() usize { return @sizeOf(@TypeOf(f)); }
1818
19// switch expression - duplicate enumeration prong19// error
20// backend=stage1
21// target=native
20//22//
21// tmp.zig:13:15: error: duplicate switch value23// tmp.zig:13:15: error: duplicate switch value
22// tmp.zig:10:15: note: other value here24// tmp.zig:10:15: note: other value here
test/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong_when_else_present.zig+3-1
...@@ -17,7 +17,9 @@ fn f(n: Number) i32 {...@@ -17,7 +17,9 @@ fn f(n: Number) i32 {
1717
18export fn entry() usize { return @sizeOf(@TypeOf(f)); }18export fn entry() usize { return @sizeOf(@TypeOf(f)); }
1919
20// switch expression - duplicate enumeration prong when else present20// error
21// backend=stage1
22// target=native
21//23//
22// tmp.zig:13:15: error: duplicate switch value24// tmp.zig:13:15: error: duplicate switch value
23// tmp.zig:10:15: note: other value here25// tmp.zig:10:15: note: other value here
test/compile_errors/stage1/obj/switch_expression-duplicate_or_overlapping_integer_value.zig+3-1
...@@ -8,7 +8,9 @@ fn foo(x: u8) u8 {...@@ -8,7 +8,9 @@ fn foo(x: u8) u8 {
8}8}
9export fn entry() usize { return @sizeOf(@TypeOf(foo)); }9export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1010
11// switch expression - duplicate or overlapping integer value11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:6:9: error: duplicate switch value15// tmp.zig:6:9: error: duplicate switch value
14// tmp.zig:5:14: note: previous value here16// tmp.zig:5:14: note: previous value here
test/compile_errors/stage1/obj/switch_expression-duplicate_type.zig+3-1
...@@ -9,7 +9,9 @@ fn foo(comptime T: type, x: T) u8 {...@@ -9,7 +9,9 @@ fn foo(comptime T: type, x: T) u8 {
9}9}
10export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }10export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
1111
12// switch expression - duplicate type12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:6:9: error: duplicate switch value16// tmp.zig:6:9: error: duplicate switch value
15// tmp.zig:4:9: note: previous value here17// tmp.zig:4:9: note: previous value here
test/compile_errors/stage1/obj/switch_expression-duplicate_type_struct_alias.zig+3-1
...@@ -13,7 +13,9 @@ fn foo(comptime T: type, x: T) u8 {...@@ -13,7 +13,9 @@ fn foo(comptime T: type, x: T) u8 {
13}13}
14export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }14export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
1515
16// switch expression - duplicate type (struct alias)16// error
17// backend=stage1
18// target=native
17//19//
18// tmp.zig:10:9: error: duplicate switch value20// tmp.zig:10:9: error: duplicate switch value
19// tmp.zig:8:9: note: previous value here21// tmp.zig:8:9: note: previous value here
test/compile_errors/stage1/obj/switch_expression-missing_enumeration_prong.zig+3-1
...@@ -14,6 +14,8 @@ fn f(n: Number) i32 {...@@ -14,6 +14,8 @@ fn f(n: Number) i32 {
1414
15export fn entry() usize { return @sizeOf(@TypeOf(f)); }15export fn entry() usize { return @sizeOf(@TypeOf(f)); }
1616
17// switch expression - missing enumeration prong17// error
18// backend=stage1
19// target=native
18//20//
19// tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch21// tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch
test/compile_errors/stage1/obj/switch_expression-multiple_else_prongs.zig+3-1
...@@ -9,6 +9,8 @@ export fn entry() void {...@@ -9,6 +9,8 @@ export fn entry() void {
9 f(1234);9 f(1234);
10}10}
1111
12// switch expression - multiple else prongs12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:5:9: error: multiple else prongs in switch expression16// tmp.zig:5:9: error: multiple else prongs in switch expression
test/compile_errors/stage1/obj/switch_expression-non_exhaustive_integer_prongs.zig+3-1
...@@ -5,6 +5,8 @@ fn foo(x: u8) void {...@@ -5,6 +5,8 @@ fn foo(x: u8) void {
5}5}
6export fn entry() usize { return @sizeOf(@TypeOf(foo)); }6export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
77
8// switch expression - non exhaustive integer prongs8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:2:5: error: switch must handle all possibilities12// tmp.zig:2:5: error: switch must handle all possibilities
test/compile_errors/stage1/obj/switch_expression-switch_on_pointer_type_with_no_else.zig+3-1
...@@ -6,6 +6,8 @@ fn foo(x: *u8) void {...@@ -6,6 +6,8 @@ fn foo(x: *u8) void {
6const y: u8 = 100;6const y: u8 = 100;
7export fn entry() usize { return @sizeOf(@TypeOf(foo)); }7export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
88
9// switch expression - switch on pointer type with no else9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:2:5: error: else prong required when switching on type '*u8'13// tmp.zig:2:5: error: else prong required when switching on type '*u8'
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_bool.zig+3-1
...@@ -7,6 +7,8 @@ fn foo(x: bool) void {...@@ -7,6 +7,8 @@ fn foo(x: bool) void {
7}7}
8export fn entry() usize { return @sizeOf(@TypeOf(foo)); }8export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
99
10// switch expression - unreachable else prong (bool)10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:5:9: error: unreachable else prong, all cases already handled14// tmp.zig:5:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_enum.zig+3-1
...@@ -17,6 +17,8 @@ fn foo(x: u8) void {...@@ -17,6 +17,8 @@ fn foo(x: u8) void {
1717
18export fn entry() usize { return @sizeOf(@TypeOf(foo)); }18export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1919
20// switch expression - unreachable else prong (enum)20// error
21// backend=stage1
22// target=native
21//23//
22// tmp.zig:14:9: error: unreachable else prong, all cases already handled24// tmp.zig:14:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_i8.zig+3-1
...@@ -10,6 +10,8 @@ fn foo(x: i8) void {...@@ -10,6 +10,8 @@ fn foo(x: i8) void {
10}10}
11export fn entry() usize { return @sizeOf(@TypeOf(foo)); }11export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1212
13// switch expression - unreachable else prong (range i8)13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:8:9: error: unreachable else prong, all cases already handled17// tmp.zig:8:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_u8.zig+3-1
...@@ -10,6 +10,8 @@ fn foo(x: u8) void {...@@ -10,6 +10,8 @@ fn foo(x: u8) void {
10}10}
11export fn entry() usize { return @sizeOf(@TypeOf(foo)); }11export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1212
13// switch expression - unreachable else prong (range u8)13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:8:9: error: unreachable else prong, all cases already handled17// tmp.zig:8:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u1.zig+3-1
...@@ -7,6 +7,8 @@ fn foo(x: u1) void {...@@ -7,6 +7,8 @@ fn foo(x: u1) void {
7}7}
8export fn entry() usize { return @sizeOf(@TypeOf(foo)); }8export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
99
10// switch expression - unreachable else prong (u1)10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:5:9: error: unreachable else prong, all cases already handled14// tmp.zig:5:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u2.zig+3-1
...@@ -9,6 +9,8 @@ fn foo(x: u2) void {...@@ -9,6 +9,8 @@ fn foo(x: u2) void {
9}9}
10export fn entry() usize { return @sizeOf(@TypeOf(foo)); }10export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
1111
12// switch expression - unreachable else prong (u2)12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:7:9: error: unreachable else prong, all cases already handled16// tmp.zig:7:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_on_enum_with_1_field_with_no_prongs.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 switch (f) {}5 switch (f) {}
6}6}
77
8// switch on enum with 1 field with no prongs8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch12// tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch
test/compile_errors/stage1/obj/switch_on_union_with_no_attached_enum.zig+3-1
...@@ -14,7 +14,9 @@ fn foo(a: *const Payload) void {...@@ -14,7 +14,9 @@ fn foo(a: *const Payload) void {
14 }14 }
15}15}
1616
17// switch on union with no attached enum17// error
18// backend=stage1
19// target=native
18//20//
19// tmp.zig:11:14: error: switch on union which has no attached enum21// tmp.zig:11:14: error: switch on union which has no attached enum
20// tmp.zig:1:17: note: consider 'union(enum)' here22// tmp.zig:1:17: note: consider 'union(enum)' here
test/compile_errors/stage1/obj/switch_with_invalid_expression_parameter.zig+3-1
...@@ -10,6 +10,8 @@ fn Test(comptime T: type) void {...@@ -10,6 +10,8 @@ fn Test(comptime T: type) void {
10 _ = x;10 _ = x;
11}11}
1212
13// switch with invalid expression parameter13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:7:17: error: switch on type 'type' provides no expression parameter17// tmp.zig:7:17: error: switch on type 'type' provides no expression parameter
test/compile_errors/stage1/obj/switch_with_overlapping_case_ranges.zig+3-1
...@@ -6,6 +6,8 @@ export fn entry() void {...@@ -6,6 +6,8 @@ export fn entry() void {
6 }6 }
7}7}
88
9// switch with overlapping case ranges9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:5:9: error: duplicate switch value13// tmp.zig:5:9: error: duplicate switch value
test/compile_errors/stage1/obj/tagName_used_on_union_with_no_associated_enum_tag.zig+3-1
...@@ -8,7 +8,9 @@ export fn entry() void {...@@ -8,7 +8,9 @@ export fn entry() void {
8 _ = tagName;8 _ = tagName;
9}9}
1010
11// @tagName used on union with no associated enum tag11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:7:19: error: union has no associated enum15// tmp.zig:7:19: error: union has no associated enum
14// tmp.zig:1:18: note: declared here16// tmp.zig:1:18: note: declared here
test/compile_errors/stage1/obj/take_slice_of_invalid_dereference.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = x;3 _ = x;
4}4}
55
6// take slice of invalid dereference6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'10// tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'
test/compile_errors/stage1/obj/taking_bit_offset_of_void_field_in_struct.zig+3-1
...@@ -6,6 +6,8 @@ export fn foo() void {...@@ -6,6 +6,8 @@ export fn foo() void {
6 _ = fieldOffset;6 _ = fieldOffset;
7}7}
88
9// taking bit offset of void field in struct9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset13// tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset
test/compile_errors/stage1/obj/taking_byte_offset_of_void_field_in_struct.zig+3-1
...@@ -6,6 +6,8 @@ export fn foo() void {...@@ -6,6 +6,8 @@ export fn foo() void {
6 _ = fieldOffset;6 _ = fieldOffset;
7}7}
88
9// taking byte offset of void field in struct9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset13// tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset
test/compile_errors/stage1/obj/threadlocal_qualifier_on_const.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() i32 {...@@ -3,6 +3,8 @@ export fn entry() i32 {
3 return x;3 return x;
4}4}
55
6// threadlocal qualifier on const6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:1:1: error: threadlocal variable cannot be constant10// tmp.zig:1:1: error: threadlocal variable cannot be constant
test/compile_errors/stage1/obj/top_level_decl_dependency_loop.zig+3-1
...@@ -5,6 +5,8 @@ export fn entry() void {...@@ -5,6 +5,8 @@ export fn entry() void {
5 _ = c;5 _ = c;
6}6}
77
8// top level decl dependency loop8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:2:19: error: dependency loop detected12// tmp.zig:2:19: error: dependency loop detected
test/compile_errors/stage1/obj/truncate_sign_mismatch.zig+3-1
...@@ -15,7 +15,9 @@ export fn entry4() u8 {...@@ -15,7 +15,9 @@ export fn entry4() u8 {
15 return @truncate(u8, x);15 return @truncate(u8, x);
16}16}
1717
18// truncate sign mismatch18// error
19// backend=stage1
20// target=native
19//21//
20// tmp.zig:3:26: error: expected signed integer type, found 'u32'22// tmp.zig:3:26: error: expected signed integer type, found 'u32'
21// tmp.zig:7:26: error: expected unsigned integer type, found 'i32'23// tmp.zig:7:26: error: expected unsigned integer type, found 'i32'
test/compile_errors/stage1/obj/truncate_undefined_value.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = z;3 _ = z;
4}4}
55
6// @truncate undefined value6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:27: error: use of undefined value here causes undefined behavior10// tmp.zig:2:27: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/try_in_function_with_non_error_return_type.zig+3-1
...@@ -3,6 +3,8 @@ export fn f() void {...@@ -3,6 +3,8 @@ export fn f() void {
3}3}
4fn something() anyerror!void { }4fn something() anyerror!void { }
55
6// try in function with non error return type6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:5: error: expected type 'void', found 'anyerror'10// tmp.zig:2:5: error: expected type 'void', found 'anyerror'
test/compile_errors/stage1/obj/type_checking_function_pointers.zig+3-1
...@@ -6,6 +6,8 @@ export fn entry() void {...@@ -6,6 +6,8 @@ export fn entry() void {
6 a(c);6 a(c);
7}7}
88
9// type checking function pointers9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'13// tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'
test/compile_errors/stage1/obj/type_variables_must_be_constant.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() foo {...@@ -3,6 +3,8 @@ export fn entry() foo {
3 return 1;3 return 1;
4}4}
55
6// type variables must be constant6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:1:1: error: variable of type 'type' must be constant10// tmp.zig:1:1: error: variable of type 'type' must be constant
test/compile_errors/stage1/obj/undeclared_identifier.zig+3-1
...@@ -4,6 +4,8 @@ export fn a() void {...@@ -4,6 +4,8 @@ export fn a() void {
4 c;4 c;
5}5}
66
7// undeclared identifier7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:5: error: use of undeclared identifier 'b'11// tmp.zig:3:5: error: use of undeclared identifier 'b'
test/compile_errors/stage1/obj/undeclared_identifier_error_should_mark_fn_as_impure.zig+3-1
...@@ -5,6 +5,8 @@ fn test_a_thing() void {...@@ -5,6 +5,8 @@ fn test_a_thing() void {
5 bad_fn_call();5 bad_fn_call();
6}6}
77
8// undeclared identifier error should mark fn as impure8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'12// tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'
test/compile_errors/stage1/obj/undeclared_identifier_in_unanalyzed_branch.zig+3-1
...@@ -4,6 +4,8 @@ export fn a() void {...@@ -4,6 +4,8 @@ export fn a() void {
4 }4 }
5}5}
66
7// undeclared identifier in unanalyzed branch7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:9: error: use of undeclared identifier 'lol_this_doesnt_exist'11// tmp.zig:3:9: error: use of undeclared identifier 'lol_this_doesnt_exist'
test/compile_errors/stage1/obj/undefined_as_field_type_is_rejected.zig+3-1
...@@ -6,6 +6,8 @@ export fn entry1() void {...@@ -6,6 +6,8 @@ export fn entry1() void {
6 _ = foo;6 _ = foo;
7}7}
88
9// undefined as field type is rejected9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:2:8: error: use of undefined value here causes undefined behavior13// tmp.zig:2:8: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/undefined_function_call.zig+3-1
...@@ -2,6 +2,8 @@ export fn a() void {...@@ -2,6 +2,8 @@ export fn a() void {
2 b();2 b();
3}3}
44
5// undefined function call5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:5: error: use of undeclared identifier 'b'9// tmp.zig:2:5: error: use of undeclared identifier 'b'
test/compile_errors/stage1/obj/underscore_is_not_a_declarable_symbol.zig+3-1
...@@ -3,6 +3,8 @@ export fn f1() usize {...@@ -3,6 +3,8 @@ export fn f1() usize {
3 return _;3 return _;
4}4}
55
6// `_` is not a declarable symbol6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:9: error: '_' used as an identifier without @"_" syntax10// tmp.zig:2:9: error: '_' used as an identifier without @"_" syntax
test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_for.zig+3-1
...@@ -6,6 +6,8 @@ export fn returns() void {...@@ -6,6 +6,8 @@ export fn returns() void {
6 }6 }
7}7}
88
9// `_` should not be usable inside for9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:4:20: error: '_' used as an identifier without @"_" syntax13// tmp.zig:4:20: error: '_' used as an identifier without @"_" syntax
test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while.zig+3-1
...@@ -9,6 +9,8 @@ fn optionalReturn() ?u32 {...@@ -9,6 +9,8 @@ fn optionalReturn() ?u32 {
9 return 1;9 return 1;
10}10}
1111
12// `_` should not be usable inside while12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:4:20: error: '_' used as an identifier without @"_" syntax16// tmp.zig:4:20: error: '_' used as an identifier without @"_" syntax
test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while_else.zig+3-1
...@@ -11,6 +11,8 @@ fn optionalReturnError() !?u32 {...@@ -11,6 +11,8 @@ fn optionalReturnError() !?u32 {
11 return error.optionalReturnError;11 return error.optionalReturnError;
12}12}
1313
14// `_` should not be usable inside while else14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:6:17: error: '_' used as an identifier without @"_" syntax18// tmp.zig:6:17: error: '_' used as an identifier without @"_" syntax
test/compile_errors/stage1/obj/union_auto-enum_value_already_taken.zig+3-1
...@@ -10,7 +10,9 @@ export fn entry() void {...@@ -10,7 +10,9 @@ export fn entry() void {
10 _ = x;10 _ = x;
11}11}
1212
13// union auto-enum value already taken13// error
14// backend=stage1
15// target=native
14//16//
15// tmp.zig:6:9: error: enum tag value 60 already taken17// tmp.zig:6:9: error: enum tag value 60 already taken
16// tmp.zig:4:9: note: other occurrence here18// tmp.zig:4:9: note: other occurrence here
test/compile_errors/stage1/obj/union_enum_field_does_not_match_enum.zig+3-1
...@@ -14,7 +14,9 @@ export fn entry() void {...@@ -14,7 +14,9 @@ export fn entry() void {
14 _ = a;14 _ = a;
15}15}
1616
17// union enum field does not match enum17// error
18// backend=stage1
19// target=native
18//20//
19// tmp.zig:10:5: error: enum field not found: 'D'21// tmp.zig:10:5: error: enum field not found: 'D'
20// tmp.zig:1:16: note: enum declared here22// tmp.zig:1:16: note: enum declared here
test/compile_errors/stage1/obj/union_fields_with_value_assignments.zig+3-1
...@@ -6,7 +6,9 @@ export fn entry() void {...@@ -6,7 +6,9 @@ export fn entry() void {
6 _ = x;6 _ = x;
7}7}
88
9// union fields with value assignments9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:1:24: error: explicitly valued tagged union missing integer tag type13// tmp.zig:1:24: error: explicitly valued tagged union missing integer tag type
12// tmp.zig:2:14: note: tag value specified here14// tmp.zig:2:14: note: tag value specified here
test/compile_errors/stage1/obj/union_with_0_fields.zig+3-1
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1const Foo = union {};1const Foo = union {};
22
3// union with 0 fields3// error
4// backend=stage1
5// target=native
4//6//
5// tmp.zig:1:13: error: union declarations must have at least one tag7// tmp.zig:1:13: error: union declarations must have at least one tag
test/compile_errors/stage1/obj/union_with_specified_enum_omits_field.zig+3-1
...@@ -11,7 +11,9 @@ export fn entry() usize {...@@ -11,7 +11,9 @@ export fn entry() usize {
11 return @sizeOf(Payload);11 return @sizeOf(Payload);
12}12}
1313
14// union with specified enum omits field14// error
15// backend=stage1
16// target=native
15//17//
16// tmp.zig:6:17: error: enum field missing: 'C'18// tmp.zig:6:17: error: enum field missing: 'C'
17// tmp.zig:4:5: note: declared here19// tmp.zig:4:5: note: declared here
test/compile_errors/stage1/obj/union_with_too_small_explicit_signed_tag_type.zig+3-1
...@@ -8,7 +8,9 @@ export fn entry() void {...@@ -8,7 +8,9 @@ export fn entry() void {
8 _ = U{ .D = 1 };8 _ = U{ .D = 1 };
9}9}
1010
11// union with too small explicit signed tag type11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:1:22: error: specified integer tag type cannot represent every field15// tmp.zig:1:22: error: specified integer tag type cannot represent every field
14// tmp.zig:1:22: note: type i2 cannot fit values in range 0...316// tmp.zig:1:22: note: type i2 cannot fit values in range 0...3
test/compile_errors/stage1/obj/union_with_too_small_explicit_unsigned_tag_type.zig+3-1
...@@ -9,7 +9,9 @@ export fn entry() void {...@@ -9,7 +9,9 @@ export fn entry() void {
9 _ = U{ .E = 1 };9 _ = U{ .E = 1 };
10}10}
1111
12// union with too small explicit unsigned tag type12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:1:22: error: specified integer tag type cannot represent every field16// tmp.zig:1:22: error: specified integer tag type cannot represent every field
15// tmp.zig:1:22: note: type u2 cannot fit values in range 0...417// tmp.zig:1:22: note: type u2 cannot fit values in range 0...4
test/compile_errors/stage1/obj/unknown_length_pointer_to_opaque.zig+3-1
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1export const T = [*]opaque {};1export const T = [*]opaque {};
22
3// unknown length pointer to opaque3// error
4// backend=stage1
5// target=native
4//6//
5// tmp.zig:1:21: error: unknown-length pointer to opaque7// tmp.zig:1:21: error: unknown-length pointer to opaque
test/compile_errors/stage1/obj/unreachable_code-double_break.zig+3-1
...@@ -4,7 +4,9 @@ export fn a() void {...@@ -4,7 +4,9 @@ export fn a() void {
4 };4 };
5}5}
66
7// unreachable code - double break7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:9: error: unreachable code11// tmp.zig:3:9: error: unreachable code
10// tmp.zig:3:20: note: control flow is diverted here12// tmp.zig:3:20: note: control flow is diverted here
test/compile_errors/stage1/obj/unreachable_code-nested_returns.zig+3-1
...@@ -2,7 +2,9 @@ export fn a() i32 {...@@ -2,7 +2,9 @@ export fn a() i32 {
2 return return 1;2 return return 1;
3}3}
44
5// unreachable code - nested returns5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:5: error: unreachable code9// tmp.zig:2:5: error: unreachable code
8// tmp.zig:2:12: note: control flow is diverted here10// tmp.zig:2:12: note: control flow is diverted here
test/compile_errors/stage1/obj/unreachable_code.zig+3-1
...@@ -5,7 +5,9 @@ export fn a() void {...@@ -5,7 +5,9 @@ export fn a() void {
55
6fn b() void {}6fn b() void {}
77
8// unreachable code8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:3:6: error: unreachable code12// tmp.zig:3:6: error: unreachable code
11// tmp.zig:2:5: note: control flow is diverted here13// tmp.zig:2:5: note: control flow is diverted here
test/compile_errors/stage1/obj/unreachable_executed_at_comptime.zig+3-1
...@@ -8,7 +8,9 @@ export fn entry() void {...@@ -8,7 +8,9 @@ export fn entry() void {
8 _ = foo(-42);8 _ = foo(-42);
9}9}
1010
11// unreachable executed at comptime11// error
12// backend=stage1
13// target=native
12//14//
13// tmp.zig:4:9: error: reached unreachable code15// tmp.zig:4:9: error: reached unreachable code
14// tmp.zig:8:12: note: called from here16// tmp.zig:8:12: note: called from here
test/compile_errors/stage1/obj/unreachable_parameter.zig+3-1
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1fn f(a: noreturn) void { _ = a; }1fn f(a: noreturn) void { _ = a; }
2export fn entry() void { f(); }2export fn entry() void { f(); }
33
4// unreachable parameter4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:1:9: error: parameter of type 'noreturn' not allowed8// tmp.zig:1:9: error: parameter of type 'noreturn' not allowed
test/compile_errors/stage1/obj/unreachable_variable.zig+3-1
...@@ -3,6 +3,8 @@ export fn f() void {...@@ -3,6 +3,8 @@ export fn f() void {
3 _ = a;3 _ = a;
4}4}
55
6// unreachable variable6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:25: error: expected type 'noreturn', found 'void'10// tmp.zig:2:25: error: expected type 'noreturn', found 'void'
test/compile_errors/stage1/obj/unreachable_with_return.zig+3-1
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1fn a() noreturn {return;}1fn a() noreturn {return;}
2export fn entry() void { a(); }2export fn entry() void { a(); }
33
4// unreachable with return4// error
5// backend=stage1
6// target=native
5//7//
6// tmp.zig:1:18: error: expected type 'noreturn', found 'void'8// tmp.zig:1:18: error: expected type 'noreturn', found 'void'
test/compile_errors/stage1/obj/unsupported_modifier_at_start_of_asm_output_constraint.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo() void {...@@ -3,6 +3,8 @@ export fn foo() void {
3 asm volatile ("" : [baz]"+r"(bar) : : "");3 asm volatile ("" : [baz]"+r"(bar) : : "");
4}4}
55
6// unsupported modifier at start of asm output constraint6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:5: error: invalid modifier starting output constraint for 'baz': '+', only '=' is supported. Compiler TODO: see https://github.com/ziglang/zig/issues/21510// tmp.zig:3:5: error: invalid modifier starting output constraint for 'baz': '+', only '=' is supported. Compiler TODO: see https://github.com/ziglang/zig/issues/215
test/compile_errors/stage1/obj/unused_variable_error_on_errdefer.zig+3-1
...@@ -6,6 +6,8 @@ export fn entry() void {...@@ -6,6 +6,8 @@ export fn entry() void {
6 foo() catch unreachable;6 foo() catch unreachable;
7}7}
88
9// unused variable error on errdefer9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:2:15: error: unused variable: 'a'13// tmp.zig:2:15: error: unused variable: 'a'
test/compile_errors/stage1/obj/use_anyopaque_as_return_type_of_fn_ptr.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = a;3 _ = a;
4}4}
55
6// use anyopaque as return type of fn ptr6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:20: error: return type cannot be opaque10// tmp.zig:2:20: error: return type cannot be opaque
test/compile_errors/stage1/obj/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig+3-1
...@@ -7,6 +7,8 @@ export fn entry() void {...@@ -7,6 +7,8 @@ export fn entry() void {
7 _ = y;7 _ = y;
8}8}
99
10// use implicit casts to assign null to non-nullable pointer10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:4:23: error: expected type '*?*i32', found '**i32'14// tmp.zig:4:23: error: expected type '*?*i32', found '**i32'
test/compile_errors/stage1/obj/use_invalid_number_literal_as_array_index.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 _ = arr;4 _ = arr;
5}5}
66
7// use invalid number literal as array index7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:1:1: error: unable to infer variable type11// tmp.zig:1:1: error: unable to infer variable type
test/compile_errors/stage1/obj/use_of_comptime-known_undefined_function_value.zig+3-1
...@@ -6,6 +6,8 @@ export fn entry() void {...@@ -6,6 +6,8 @@ export fn entry() void {
6 command.exec();6 command.exec();
7}7}
88
9// use of comptime-known undefined function value9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:6:12: error: use of undefined value here causes undefined behavior13// tmp.zig:6:12: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/use_of_undeclared_identifier.zig+3-1
...@@ -2,6 +2,8 @@ export fn f() void {...@@ -2,6 +2,8 @@ export fn f() void {
2 b = 3;2 b = 3;
3}3}
44
5// use of undeclared identifier5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:5: error: use of undeclared identifier 'b'9// tmp.zig:2:5: error: use of undeclared identifier 'b'
test/compile_errors/stage1/obj/using_an_unknown_len_ptr_type_instead_of_array.zig+3-1
...@@ -6,6 +6,8 @@ comptime {...@@ -6,6 +6,8 @@ comptime {
6 _ = resolutions;6 _ = resolutions;
7}7}
88
9// using an unknown len ptr type instead of array9// error
10// backend=stage1
11// target=native
10//12//
11// tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'13// tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'
test/compile_errors/stage1/obj/using_invalid_types_in_function_call_raises_an_error.zig+3-1
...@@ -4,6 +4,8 @@ export fn entry() void {...@@ -4,6 +4,8 @@ export fn entry() void {
4 func(MenuEffect.ThisDoesNotExist);4 func(MenuEffect.ThisDoesNotExist);
5}5}
66
7// using invalid types in function call raises an error7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:1:20: error: enum declarations must have at least one tag11// tmp.zig:1:20: error: enum declarations must have at least one tag
test/compile_errors/stage1/obj/usingnamespace_with_wrong_type.zig+3-1
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1usingnamespace void;1usingnamespace void;
22
3// usingnamespace with wrong type3// error
4// backend=stage1
5// target=native
4//6//
5// tmp.zig:1:1: error: expected struct, enum, or union; found 'void'7// tmp.zig:1:1: error: expected struct, enum, or union; found 'void'
test/compile_errors/stage1/obj/variable_has_wrong_type.zig+3-1
...@@ -3,6 +3,8 @@ export fn f() i32 {...@@ -3,6 +3,8 @@ export fn f() i32 {
3 return a;3 return a;
4}4}
55
6// variable has wrong type6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'10// tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'
test/compile_errors/stage1/obj/variable_in_inline_assembly_template_cannot_be_found.zig created+12
...@@ -0,0 +1,12 @@
1export fn entry() void {
2 var sp = asm volatile ("mov %[foo], sp"
3 : [bar] "=r" (-> usize),
4 );
5 _ = sp;
6}
7
8// error
9// backend=stage1
10// target=x86_64-linux-gnu
11//
12// tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs
test/compile_errors/stage1/obj/variable_initialization_compile_error_then_referenced.zig+3-1
...@@ -12,6 +12,8 @@ export fn entry() void {...@@ -12,6 +12,8 @@ export fn entry() void {
12 _ = S;12 _ = S;
13}13}
1414
15// variable initialization compile error then referenced15// error
16// backend=stage1
17// target=native
16//18//
17// tmp.zig:2:12: error: use of undeclared identifier 'T'19// tmp.zig:2:12: error: use of undeclared identifier 'T'
test/compile_errors/stage1/obj/variable_with_type_noreturn.zig+3-1
...@@ -2,7 +2,9 @@ export fn entry9() void {...@@ -2,7 +2,9 @@ export fn entry9() void {
2 var z: noreturn = return;2 var z: noreturn = return;
3}3}
44
5// variable with type 'noreturn'5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:5: error: unreachable code9// tmp.zig:2:5: error: unreachable code
8// tmp.zig:2:23: note: control flow is diverted here10// tmp.zig:2:23: note: control flow is diverted here
test/compile_errors/stage1/obj/vector_index_out_of_bounds.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 _ = x;3 _ = x;
4}4}
55
6// vector index out of bounds6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:62: error: index 3 outside vector of size 310// tmp.zig:2:62: error: index 3 outside vector of size 3
test/compile_errors/stage1/obj/volatile_on_global_assembly.zig+3-1
...@@ -2,6 +2,8 @@ comptime {...@@ -2,6 +2,8 @@ comptime {
2 asm volatile ("");2 asm volatile ("");
3}3}
44
5// volatile on global assembly5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:9: error: volatile is meaningless on global assembly9// tmp.zig:2:9: error: volatile is meaningless on global assembly
test/compile_errors/stage1/obj/wasmMemoryGrow_is_a_compile_error_in_non-Wasm_targets.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo() void {...@@ -3,6 +3,8 @@ export fn foo() void {
3 return;3 return;
4}4}
55
6// wasmMemoryGrow is a compile error in non-Wasm targets6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only10// tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only
test/compile_errors/stage1/obj/wasmMemorySize_is_a_compile_error_in_non-Wasm_targets.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo() void {...@@ -3,6 +3,8 @@ export fn foo() void {
3 return;3 return;
4}4}
55
6// wasmMemorySize is a compile error in non-Wasm targets6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only10// tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only
test/compile_errors/stage1/obj/while_expected_bool_got_error_union.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo() void {...@@ -3,6 +3,8 @@ export fn foo() void {
3}3}
4fn bar() anyerror!i32 { return 1; }4fn bar() anyerror!i32 { return 1; }
55
6// while expected bool, got error union6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'10// tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'
test/compile_errors/stage1/obj/while_expected_bool_got_optional.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo() void {...@@ -3,6 +3,8 @@ export fn foo() void {
3}3}
4fn bar() ?i32 { return 1; }4fn bar() ?i32 { return 1; }
55
6// while expected bool, got optional6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:15: error: expected type 'bool', found '?i32'10// tmp.zig:2:15: error: expected type 'bool', found '?i32'
test/compile_errors/stage1/obj/while_expected_error_union_got_bool.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo() void {...@@ -3,6 +3,8 @@ export fn foo() void {
3}3}
4fn bar() bool { return true; }4fn bar() bool { return true; }
55
6// while expected error union, got bool6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:15: error: expected error union type, found 'bool'10// tmp.zig:2:15: error: expected error union type, found 'bool'
test/compile_errors/stage1/obj/while_expected_error_union_got_optional.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo() void {...@@ -3,6 +3,8 @@ export fn foo() void {
3}3}
4fn bar() ?i32 { return 1; }4fn bar() ?i32 { return 1; }
55
6// while expected error union, got optional6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:15: error: expected error union type, found '?i32'10// tmp.zig:2:15: error: expected error union type, found '?i32'
test/compile_errors/stage1/obj/while_expected_optional_got_bool.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo() void {...@@ -3,6 +3,8 @@ export fn foo() void {
3}3}
4fn bar() bool { return true; }4fn bar() bool { return true; }
55
6// while expected optional, got bool6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:15: error: expected optional type, found 'bool'10// tmp.zig:2:15: error: expected optional type, found 'bool'
test/compile_errors/stage1/obj/while_expected_optional_got_error_union.zig+3-1
...@@ -3,6 +3,8 @@ export fn foo() void {...@@ -3,6 +3,8 @@ export fn foo() void {
3}3}
4fn bar() anyerror!i32 { return 1; }4fn bar() anyerror!i32 { return 1; }
55
6// while expected optional, got error union6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'10// tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'
test/compile_errors/stage1/obj/while_loop_body_expression_ignored.zig+3-1
...@@ -13,7 +13,9 @@ export fn f3() void {...@@ -13,7 +13,9 @@ export fn f3() void {
13 while (x) |_| returns() else |_| unreachable;13 while (x) |_| returns() else |_| unreachable;
14}14}
1515
16// while loop body expression ignored16// error
17// backend=stage1
18// target=native
17//19//
18// tmp.zig:5:25: error: expression value is ignored20// tmp.zig:5:25: error: expression value is ignored
19// tmp.zig:9:26: error: expression value is ignored21// tmp.zig:9:26: error: expression value is ignored
test/compile_errors/stage1/obj/write_to_const_global_variable.zig+3-1
...@@ -4,6 +4,8 @@ fn f() void {...@@ -4,6 +4,8 @@ fn f() void {
4}4}
5export fn entry() void { f(); }5export fn entry() void { f(); }
66
7// write to const global variable7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:3:9: error: cannot assign to constant11// tmp.zig:3:9: error: cannot assign to constant
test/compile_errors/stage1/obj/wrong_frame_type_used_for_async_call.zig+3-1
...@@ -9,6 +9,8 @@ fn bar() void {...@@ -9,6 +9,8 @@ fn bar() void {
9 suspend {}9 suspend {}
10}10}
1111
12// wrong frame type used for async call12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'16// tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'
test/compile_errors/stage1/obj/wrong_function_type.zig+3-1
...@@ -4,6 +4,8 @@ fn b() i32 {return 1;}...@@ -4,6 +4,8 @@ fn b() i32 {return 1;}
4fn c() i32 {return 2;}4fn c() i32 {return 2;}
5export fn entry() usize { return @sizeOf(@TypeOf(fns)); }5export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
66
7// wrong function type7// error
8// backend=stage1
9// target=native
8//10//
9// tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'11// tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'
test/compile_errors/stage1/obj/wrong_initializer_for_union_payload_of_type_type.zig+3-1
...@@ -9,6 +9,8 @@ export fn entry() void {...@@ -9,6 +9,8 @@ export fn entry() void {
9 v.u.A = U{ .A = i32 };9 v.u.A = U{ .A = i32 };
10}10}
1111
12// wrong initializer for union payload of type 'type'12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:9:8: error: use of undefined value here causes undefined behavior16// tmp.zig:9:8: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/wrong_number_of_arguments.zig+3-1
...@@ -3,6 +3,8 @@ export fn a() void {...@@ -3,6 +3,8 @@ export fn a() void {
3}3}
4fn c(d: i32, e: i32, f: i32) void { _ = d; _ = e; _ = f; }4fn c(d: i32, e: i32, f: i32) void { _ = d; _ = e; _ = f; }
55
6// wrong number of arguments6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:6: error: expected 3 argument(s), found 110// tmp.zig:2:6: error: expected 3 argument(s), found 1
test/compile_errors/stage1/obj/wrong_number_of_arguments_for_method_fn_call.zig+3-1
...@@ -7,6 +7,8 @@ fn f(foo: *const Foo) void {...@@ -7,6 +7,8 @@ fn f(foo: *const Foo) void {
7}7}
8export fn entry() usize { return @sizeOf(@TypeOf(f)); }8export fn entry() usize { return @sizeOf(@TypeOf(f)); }
99
10// wrong number of arguments for method fn call10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:6:15: error: expected 2 argument(s), found 314// tmp.zig:6:15: error: expected 2 argument(s), found 3
test/compile_errors/stage1/obj/wrong_panic_signature_generic_function.zig+3-1
...@@ -4,7 +4,9 @@ pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace)...@@ -4,7 +4,9 @@ pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace)
4}4}
5const builtin = @import("std").builtin;5const builtin = @import("std").builtin;
66
7// wrong panic signature, generic function7// error
8// backend=stage1
9// target=native
8//10//
9// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,anytype) anytype'11// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,anytype) anytype'
10// note: only one of the functions is generic12// note: only one of the functions is generic
test/compile_errors/stage1/obj/wrong_panic_signature_runtime_function.zig+3-1
...@@ -3,6 +3,8 @@ test "" {}...@@ -3,6 +3,8 @@ test "" {}
3pub fn panic() void {}3pub fn panic() void {}
44
55
6// wrong panic signature, runtime function6// error
7// backend=stage1
8// target=native
7//9//
8// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'10// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'
test/compile_errors/stage1/obj/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig+3-1
...@@ -5,6 +5,8 @@ export fn foo() void {...@@ -5,6 +5,8 @@ export fn foo() void {
5 bar(@ptrCast(*anyopaque, &x));5 bar(@ptrCast(*anyopaque, &x));
6}6}
77
8// wrong pointer coerced to pointer to opaque {}8// error
9// backend=stage1
10// target=native
9//11//
10// tmp.zig:5:9: error: expected type '*Derp', found '*anyopaque'12// tmp.zig:5:9: error: expected type '*Derp', found '*anyopaque'
test/compile_errors/stage1/obj/wrong_return_type_for_main.zig+3-1
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1pub fn main() f32 { }1pub fn main() f32 { }
22
3// wrong return type for main3// error
4// backend=stage1
5// target=native
4//6//
5// error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'7// error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'
test/compile_errors/stage1/obj/wrong_size_to_an_array_literal.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 _ = array;3 _ = array;
4}4}
55
6// wrong size to an array literal6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:2:31: error: index 2 outside array of size 210// tmp.zig:2:31: error: index 2 outside array of size 2
test/compile_errors/stage1/obj/wrong_type_for_argument_tuple_to_asyncCall.zig+3-1
...@@ -7,6 +7,8 @@ fn foo() i32 {...@@ -7,6 +7,8 @@ fn foo() i32 {
7 return 0;7 return 0;
8}8}
99
10// wrong type for argument tuple to @asyncCall10// error
11// backend=stage1
12// target=native
11//13//
12// tmp.zig:3:33: error: expected tuple or struct, found 'void'14// tmp.zig:3:33: error: expected tuple or struct, found 'void'
test/compile_errors/stage1/obj/wrong_type_for_reify_type.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() void {...@@ -2,6 +2,8 @@ export fn entry() void {
2 _ = @Type(0);2 _ = @Type(0);
3}3}
44
5// wrong type for @Type5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:15: error: expected type 'std.builtin.Type', found 'comptime_int'9// tmp.zig:2:15: error: expected type 'std.builtin.Type', found 'comptime_int'
test/compile_errors/stage1/obj/wrong_type_for_result_ptr_to_asyncCall.zig+3-1
...@@ -9,6 +9,8 @@ fn foo() i32 {...@@ -9,6 +9,8 @@ fn foo() i32 {
9 return 1234;9 return 1234;
10}10}
1111
12// wrong type for result ptr to @asyncCall12// error
13// backend=stage1
14// target=native
13//15//
14// tmp.zig:6:37: error: expected type '*i32', found 'bool'16// tmp.zig:6:37: error: expected type '*i32', found 'bool'
test/compile_errors/stage1/obj/wrong_type_passed_to_panic.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 @panic(e);3 @panic(e);
4}4}
55
6// wrong type passed to @panic6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'10// tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'
test/compile_errors/stage1/obj/wrong_type_to_hasField.zig+3-1
...@@ -2,6 +2,8 @@ export fn entry() bool {...@@ -2,6 +2,8 @@ export fn entry() bool {
2 return @hasField(i32, "hi");2 return @hasField(i32, "hi");
3}3}
44
5// wrong type to @hasField5// error
6// backend=stage1
7// target=native
6//8//
7// tmp.zig:2:22: error: type 'i32' does not support @hasField9// tmp.zig:2:22: error: type 'i32' does not support @hasField
test/compile_errors/stage1/obj/wrong_types_given_to_atomic_order_args_in_cmpxchg.zig+3-1
...@@ -3,6 +3,8 @@ export fn entry() void {...@@ -3,6 +3,8 @@ export fn entry() void {
3 while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {}3 while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {}
4}4}
55
6// wrong types given to atomic order args in cmpxchg6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'10// tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'
test/compile_errors/stage1/obj/wrong_types_given_to_export.zig+3-1
...@@ -3,6 +3,8 @@ comptime {...@@ -3,6 +3,8 @@ comptime {
3 @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) });3 @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) });
4}4}
55
6// wrong types given to @export6// error
7// backend=stage1
8// target=native
7//9//
8// tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'10// tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'
test/compile_errors/stage1/test/access_invalid_typeInfo_decl.zig+4-1
...@@ -3,6 +3,9 @@ test "Crash" {...@@ -3,6 +3,9 @@ test "Crash" {
3 _ = @typeInfo(@This()).Struct.decls[0];3 _ = @typeInfo(@This()).Struct.decls[0];
4}4}
55
6// access invalid @typeInfo decl6// error
7// backend=stage1
8// target=native
9// is_test=1
7//10//
8// tmp.zig:1:11: error: use of undeclared identifier 'B'11// tmp.zig:1:11: error: use of undeclared identifier 'B'
test/compile_errors/stage1/test/alignCast_of_zero_sized_types.zig+4-1
...@@ -17,7 +17,10 @@ export fn qux() void {...@@ -17,7 +17,10 @@ export fn qux() void {
17 _ = @alignCast(2, a);17 _ = @alignCast(2, a);
18}18}
1919
20// @alignCast of zero sized types20// error
21// backend=stage1
22// target=native
23// is_test=1
21//24//
22// tmp.zig:3:23: error: cannot adjust alignment of zero sized type '*void'25// tmp.zig:3:23: error: cannot adjust alignment of zero sized type '*void'
23// tmp.zig:7:23: error: cannot adjust alignment of zero sized type '?*void'26// tmp.zig:7:23: error: cannot adjust alignment of zero sized type '?*void'
test/compile_errors/stage1/test/bad_splat_type.zig+4-1
...@@ -4,6 +4,9 @@ export fn entry() void {...@@ -4,6 +4,9 @@ export fn entry() void {
4 _ = v;4 _ = v;
5}5}
66
7// bad @splat type7// error
8// backend=stage1
9// target=native
10// is_test=1
8//11//
9// tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid12// tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid
test/compile_errors/stage1/test/binary_OR_operator_on_error_sets.zig+4-1
...@@ -5,6 +5,9 @@ export fn entry() void {...@@ -5,6 +5,9 @@ export fn entry() void {
5 _ = x;5 _ = x;
6}6}
77
8// binary OR operator on error sets8// error
9// backend=stage1
10// target=native
11// is_test=1
9//12//
10// tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'13// tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'
test/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-always_inline.zig+4-1
...@@ -3,6 +3,9 @@ pub export fn entry() void {...@@ -3,6 +3,9 @@ pub export fn entry() void {
3 @call(.{ .modifier = .always_inline }, call_me, .{});3 @call(.{ .modifier = .always_inline }, call_me, .{});
4}4}
55
6// @call rejects non comptime-known fn - always_inline6// error
7// backend=stage1
8// target=native
9// is_test=1
7//10//
8// tmp.zig:3:5: error: the specified modifier requires a comptime-known function11// tmp.zig:3:5: error: the specified modifier requires a comptime-known function
test/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-compile_time.zig+4-1
...@@ -3,6 +3,9 @@ pub export fn entry() void {...@@ -3,6 +3,9 @@ pub export fn entry() void {
3 @call(.{ .modifier = .compile_time }, call_me, .{});3 @call(.{ .modifier = .compile_time }, call_me, .{});
4}4}
55
6// @call rejects non comptime-known fn - compile_time6// error
7// backend=stage1
8// target=native
9// is_test=1
7//10//
8// tmp.zig:3:5: error: the specified modifier requires a comptime-known function11// tmp.zig:3:5: error: the specified modifier requires a comptime-known function
test/compile_errors/stage1/test/cast_between_optional_T_where_T_is_not_a_pointer.zig+4-1
...@@ -6,7 +6,10 @@ export fn entry() void {...@@ -6,7 +6,10 @@ export fn entry() void {
6 a = b;6 a = b;
7}7}
88
9// cast between ?T where T is not a pointer9// error
10// backend=stage1
11// target=native
12// is_test=1
10//13//
11// tmp.zig:6:9: error: expected type '?fn(i8) void', found '?fn(u64) void'14// tmp.zig:6:9: error: expected type '?fn(i8) void', found '?fn(u64) void'
12// tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void'15// tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void'
test/compile_errors/stage1/test/combination_of_nosuspend_and_async.zig+4-1
...@@ -7,7 +7,10 @@ export fn entry() void {...@@ -7,7 +7,10 @@ export fn entry() void {
7}7}
8fn foo() void {}8fn foo() void {}
99
10// combination of nosuspend and async10// error
11// backend=stage1
12// target=native
13// is_test=1
11//14//
12// tmp.zig:4:9: error: suspend inside nosuspend block15// tmp.zig:4:9: error: suspend inside nosuspend block
13// tmp.zig:2:5: note: nosuspend block here16// tmp.zig:2:5: note: nosuspend block here
test/compile_errors/stage1/test/comparison_of_non-tagged_union_and_enum_literal.zig+4-1
...@@ -5,7 +5,10 @@ export fn entry() void {...@@ -5,7 +5,10 @@ export fn entry() void {
5 _ = ok;5 _ = ok;
6}6}
77
8// comparison of non-tagged union and enum literal8// error
9// backend=stage1
10// target=native
11// is_test=1
9//12//
10// tmp.zig:4:16: error: comparison of union and enum literal is only valid for tagged union types13// tmp.zig:4:16: error: comparison of union and enum literal is only valid for tagged union types
11// tmp.zig:2:15: note: type U is not a tagged union14// tmp.zig:2:15: note: type U is not a tagged union
test/compile_errors/stage1/test/comptime_vector_overflow_shows_the_index.zig+4-1
...@@ -5,7 +5,10 @@ comptime {...@@ -5,7 +5,10 @@ comptime {
5 _ = x;5 _ = x;
6}6}
77
8// comptime vector overflow shows the index8// error
9// backend=stage1
10// target=native
11// is_test=1
9//12//
10// tmp.zig:4:15: error: operation caused overflow13// tmp.zig:4:15: error: operation caused overflow
11// tmp.zig:4:15: note: when computing vector element at index 214// tmp.zig:4:15: note: when computing vector element at index 2
test/compile_errors/stage1/test/duplicate_field_in_anonymous_struct_literal.zig+4-1
...@@ -10,7 +10,10 @@ export fn entry() void {...@@ -10,7 +10,10 @@ export fn entry() void {
10 _ = anon;10 _ = anon;
11}11}
1212
13// duplicate field in anonymous struct literal13// error
14// backend=stage1
15// target=native
16// is_test=1
14//17//
15// tmp.zig:7:13: error: duplicate field18// tmp.zig:7:13: error: duplicate field
16// tmp.zig:4:13: note: other field here19// tmp.zig:4:13: note: other field here
test/compile_errors/stage1/test/error_in_struct_initializer_doesnt_crash_the_compiler.zig+4-1
...@@ -7,6 +7,9 @@ pub export fn entry() void {...@@ -7,6 +7,9 @@ pub export fn entry() void {
7 _ = a;7 _ = a;
8}8}
99
10// error in struct initializer doesn't crash the compiler10// error
11// backend=stage1
12// target=native
13// is_test=1
11//14//
12// tmp.zig:4:9: error: duplicate struct field: 'e'15// tmp.zig:4:9: error: duplicate struct field: 'e'
test/compile_errors/stage1/test/errors_in_for_loop_bodies_are_propagated.zig+4-1
...@@ -3,6 +3,9 @@ pub export fn entry() void {...@@ -3,6 +3,9 @@ pub export fn entry() void {
3 for (arr) |bits| _ = @popCount(bits);3 for (arr) |bits| _ = @popCount(bits);
4}4}
55
6// errors in for loop bodies are propagated6// error
7// backend=stage1
8// target=native
9// is_test=1
7//10//
8// tmp.zig:3:26: error: expected 2 arguments, found 111// tmp.zig:3:26: error: expected 2 arguments, found 1
test/compile_errors/stage1/test/export_with_empty_name_string.zig+4-1
...@@ -3,6 +3,9 @@ comptime {...@@ -3,6 +3,9 @@ comptime {
3 @export(entry, .{ .name = "" });3 @export(entry, .{ .name = "" });
4}4}
55
6// @export with empty name string6// error
7// backend=stage1
8// target=native
9// is_test=1
7//10//
8// tmp.zig:3:5: error: exported symbol name cannot be empty11// tmp.zig:3:5: error: exported symbol name cannot be empty
test/compile_errors/stage1/test/helpful_return_type_error_message.zig+4-1
...@@ -15,7 +15,10 @@ export fn quux() u32 {...@@ -15,7 +15,10 @@ export fn quux() u32 {
15 buf = bar();15 buf = bar();
16}16}
1717
18// helpful return type error message18// error
19// backend=stage1
20// target=native
21// is_test=1
19//22//
20// tmp.zig:2:17: error: expected type 'u32', found 'error{Ohno}'23// tmp.zig:2:17: error: expected type 'u32', found 'error{Ohno}'
21// tmp.zig:1:17: note: function cannot return an error24// tmp.zig:1:17: note: function cannot return an error
test/compile_errors/stage1/test/int-float_conversion_to_comptime_int-float.zig+4-1
...@@ -7,7 +7,10 @@ export fn bar() void {...@@ -7,7 +7,10 @@ export fn bar() void {
7 _ = @intToFloat(comptime_float, a);7 _ = @intToFloat(comptime_float, a);
8}8}
99
10// int/float conversion to comptime_int/float10// error
11// backend=stage1
12// target=native
13// is_test=1
11//14//
12// tmp.zig:3:35: error: unable to evaluate constant expression15// tmp.zig:3:35: error: unable to evaluate constant expression
13// tmp.zig:7:37: error: unable to evaluate constant expression16// tmp.zig:7:37: error: unable to evaluate constant expression
test/compile_errors/stage1/test/invalid_assignments.zig+4-1
...@@ -10,7 +10,10 @@ export fn entry4() void {...@@ -10,7 +10,10 @@ export fn entry4() void {
10 2 + 2 = 3;10 2 + 2 = 3;
11}11}
1212
13// invalid assignments13// error
14// backend=stage1
15// target=native
16// is_test=1
14//17//
15// tmp.zig:3:6: error: invalid left-hand side to assignment18// tmp.zig:3:6: error: invalid left-hand side to assignment
16// tmp.zig:7:7: error: invalid left-hand side to assignment19// tmp.zig:7:7: error: invalid left-hand side to assignment
test/compile_errors/stage1/test/invalid_float_casts.zig+4-1
...@@ -15,7 +15,10 @@ export fn qux() void {...@@ -15,7 +15,10 @@ export fn qux() void {
15 _ = @floatCast(f32, a);15 _ = @floatCast(f32, a);
16}16}
1717
18// invalid float casts18// error
19// backend=stage1
20// target=native
21// is_test=1
19//22//
20// tmp.zig:3:36: error: unable to evaluate constant expression23// tmp.zig:3:36: error: unable to evaluate constant expression
21// tmp.zig:7:21: error: expected integer type, found 'f32'24// tmp.zig:7:21: error: expected integer type, found 'f32'
test/compile_errors/stage1/test/invalid_int_casts.zig+4-1
...@@ -15,7 +15,10 @@ export fn qux() void {...@@ -15,7 +15,10 @@ export fn qux() void {
15 _ = @intCast(u32, a);15 _ = @intCast(u32, a);
16}16}
1717
18// invalid int casts18// error
19// backend=stage1
20// target=native
21// is_test=1
19//22//
20// tmp.zig:3:32: error: unable to evaluate constant expression23// tmp.zig:3:32: error: unable to evaluate constant expression
21// tmp.zig:7:21: error: expected float type, found 'u32'24// tmp.zig:7:21: error: expected float type, found 'u32'
test/compile_errors/stage1/test/invalid_non-exhaustive_enum_to_union.zig+4-1
...@@ -18,7 +18,10 @@ export fn bar() void {...@@ -18,7 +18,10 @@ export fn bar() void {
18 _ = u;18 _ = u;
19}19}
2020
21// invalid non-exhaustive enum to union21// error
22// backend=stage1
23// target=native
24// is_test=1
22//25//
23// tmp.zig:12:16: error: runtime cast to union 'U' from non-exhaustive enum26// tmp.zig:12:16: error: runtime cast to union 'U' from non-exhaustive enum
24// tmp.zig:17:16: error: no tag by value 1527// tmp.zig:17:16: error: no tag by value 15
test/compile_errors/stage1/test/invalid_pointer_with_reify_type.zig+4-1
...@@ -11,6 +11,9 @@ export fn entry() void {...@@ -11,6 +11,9 @@ export fn entry() void {
11 }});11 }});
12}12}
1313
14// invalid pointer with @Type14// error
15// backend=stage1
16// target=native
17// is_test=1
15//18//
16// tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers19// tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers
test/compile_errors/stage1/test/nested_vectors.zig+4-1
...@@ -5,6 +5,9 @@ export fn entry() void {...@@ -5,6 +5,9 @@ export fn entry() void {
5 _ = v;5 _ = v;
6}6}
77
8// nested vectors8// error
9// backend=stage1
10// target=native
11// is_test=1
9//12//
10// tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid13// tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid
test/compile_errors/stage1/test/non-exhaustive_enum_marker_assigned_a_value.zig+4-1
...@@ -10,7 +10,10 @@ const B = enum {...@@ -10,7 +10,10 @@ const B = enum {
10};10};
11comptime { _ = A; _ = B; }11comptime { _ = A; _ = B; }
1212
13// non-exhaustive enum marker assigned a value13// error
14// backend=stage1
15// target=native
16// is_test=1
14//17//
15// tmp.zig:4:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value18// tmp.zig:4:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value
16// tmp.zig:6:11: error: non-exhaustive enum missing integer tag type19// tmp.zig:6:11: error: non-exhaustive enum missing integer tag type
test/compile_errors/stage1/test/non-exhaustive_enums.zig+4-1
...@@ -13,7 +13,10 @@ pub export fn entry() void {...@@ -13,7 +13,10 @@ pub export fn entry() void {
13 _ = C;13 _ = C;
14}14}
1515
16// non-exhaustive enums16// error
17// backend=stage1
18// target=native
19// is_test=1
17//20//
18// tmp.zig:3:5: error: '_' field of non-exhaustive enum must be last21// tmp.zig:3:5: error: '_' field of non-exhaustive enum must be last
19// tmp.zig:6:11: error: non-exhaustive enum specifies every value22// tmp.zig:6:11: error: non-exhaustive enum specifies every value
test/compile_errors/stage1/test/not_an_enum_type.zig+4-1
...@@ -12,6 +12,9 @@ const Error = union(enum) {...@@ -12,6 +12,9 @@ const Error = union(enum) {
12const InvalidToken = struct {};12const InvalidToken = struct {};
13const ExpectedVarDeclOrFn = struct {};13const ExpectedVarDeclOrFn = struct {};
1414
15// not an enum type15// error
16// backend=stage1
17// target=native
18// is_test=1
16//19//
17// tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'20// tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'
test/compile_errors/stage1/test/packed_struct_with_fields_of_not_allowed_types.zig+4-1
...@@ -59,7 +59,10 @@ const Enum = enum {...@@ -59,7 +59,10 @@ const Enum = enum {
59 B,59 B,
60};60};
6161
62// packed struct with fields of not allowed types62// error
63// backend=stage1
64// target=native
65// is_test=1
63//66//
64// tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation67// tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation
65// tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits (must be padded from 48 to 64 bits)68// tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits (must be padded from 48 to 64 bits)
test/compile_errors/stage1/test/ptrToInt_with_pointer_to_zero-sized_type.zig+4-1
...@@ -4,6 +4,9 @@ export fn entry() void {...@@ -4,6 +4,9 @@ export fn entry() void {
4 _ = x;4 _ = x;
5}5}
66
7// @ptrToInt with pointer to zero-sized type7// error
8// backend=stage1
9// target=native
10// is_test=1
8//11//
9// tmp.zig:3:23: error: pointer to size 0 type has no address12// tmp.zig:3:23: error: pointer to size 0 type has no address
test/compile_errors/stage1/test/reassign_to_array_parameter.zig+4-1
...@@ -5,6 +5,9 @@ export fn entry() void {...@@ -5,6 +5,9 @@ export fn entry() void {
5 reassign(.{1, 2, 3});5 reassign(.{1, 2, 3});
6}6}
77
8// reassign to array parameter8// error
9// backend=stage1
10// target=native
11// is_test=1
9//12//
10// tmp.zig:2:15: error: cannot assign to constant13// tmp.zig:2:15: error: cannot assign to constant
test/compile_errors/stage1/test/reassign_to_slice_parameter.zig+4-1
...@@ -5,6 +5,9 @@ export fn entry() void {...@@ -5,6 +5,9 @@ export fn entry() void {
5 reassign("foo");5 reassign("foo");
6}6}
77
8// reassign to slice parameter8// error
9// backend=stage1
10// target=native
11// is_test=1
9//12//
10// tmp.zig:2:10: error: cannot assign to constant13// tmp.zig:2:10: error: cannot assign to constant
test/compile_errors/stage1/test/reassign_to_struct_parameter.zig+4-1
...@@ -8,6 +8,9 @@ export fn entry() void {...@@ -8,6 +8,9 @@ export fn entry() void {
8 reassign(S{.x = 3});8 reassign(S{.x = 3});
9}9}
1010
11// reassign to struct parameter11// error
12// backend=stage1
13// target=native
14// is_test=1
12//15//
13// tmp.zig:5:10: error: cannot assign to constant16// tmp.zig:5:10: error: cannot assign to constant
test/compile_errors/stage1/test/reference_to_const_data.zig+4-1
...@@ -19,7 +19,10 @@ export fn qux() void {...@@ -19,7 +19,10 @@ export fn qux() void {
19 ptr.x = 2;19 ptr.x = 2;
20}20}
2121
22// reference to const data22// error
23// backend=stage1
24// target=native
25// is_test=1
23//26//
24// tmp.zig:3:14: error: cannot assign to constant27// tmp.zig:3:14: error: cannot assign to constant
25// tmp.zig:7:13: error: cannot assign to constant28// tmp.zig:7:13: error: cannot assign to constant
test/compile_errors/stage1/test/reify_typeOf_with_incompatible_arguments.zig+4-1
...@@ -4,6 +4,9 @@ export fn entry() void {...@@ -4,6 +4,9 @@ export fn entry() void {
4 _ = @TypeOf(var_1, var_2);4 _ = @TypeOf(var_1, var_2);
5}5}
66
7// @TypeOf with incompatible arguments7// error
8// backend=stage1
9// target=native
10// is_test=1
8//11//
9// tmp.zig:4:9: error: incompatible types: 'f32' and 'u32'12// tmp.zig:4:9: error: incompatible types: 'f32' and 'u32'
test/compile_errors/stage1/test/reify_typeOf_with_no_arguments.zig+4-1
...@@ -2,6 +2,9 @@ export fn entry() void {...@@ -2,6 +2,9 @@ export fn entry() void {
2 _ = @TypeOf();2 _ = @TypeOf();
3}3}
44
5// @TypeOf with no arguments5// error
6// backend=stage1
7// target=native
8// is_test=1
6//9//
7// tmp.zig:2:9: error: expected at least 1 argument, found 010// tmp.zig:2:9: error: expected at least 1 argument, found 0
test/compile_errors/stage1/test/reject_extern_function_definitions_with_body.zig+4-1
...@@ -2,6 +2,9 @@ extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 {...@@ -2,6 +2,9 @@ extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 {
2 return a + b;2 return a + b;
3}3}
44
5// reject extern function definitions with body5// error
6// backend=stage1
7// target=native
8// is_test=1
6//9//
7// tmp.zig:1:1: error: extern functions have no body10// tmp.zig:1:1: error: extern functions have no body
test/compile_errors/stage1/test/reject_extern_variables_with_initializers.zig+4-1
...@@ -1,5 +1,8 @@...@@ -1,5 +1,8 @@
1extern var foo: int = 2;1extern var foo: int = 2;
22
3// reject extern variables with initializers3// error
4// backend=stage1
5// target=native
6// is_test=1
4//7//
5// tmp.zig:1:23: error: extern variables have no initializers8// tmp.zig:1:23: error: extern variables have no initializers
test/compile_errors/stage1/test/repeated_invalid_field_access_to_generic_function_returning_type_crashes_compiler_2655.zig+4-1
...@@ -6,6 +6,9 @@ test "1" {...@@ -6,6 +6,9 @@ test "1" {
6 _ = A().a;6 _ = A().a;
7}7}
88
9// repeated invalid field access to generic function returning type crashes compiler. #26559// error
10// backend=stage1
11// target=native
12// is_test=1
10//13//
11// tmp.zig:2:12: error: use of undeclared identifier 'Q'14// tmp.zig:2:12: error: use of undeclared identifier 'Q'
test/compile_errors/stage1/test/return_invalid_type_from_test.zig+4-1
...@@ -1,5 +1,8 @@...@@ -1,5 +1,8 @@
1test "example" { return 1; }1test "example" { return 1; }
22
3// return invalid type from test3// error
4// backend=stage1
5// target=native
6// is_test=1
4//7//
5// tmp.zig:1:25: error: expected type 'void', found 'comptime_int'8// tmp.zig:1:25: error: expected type 'void', found 'comptime_int'
test/compile_errors/stage1/test/shift_on_type_with_non-power-of-two_size.zig+4-1
...@@ -23,7 +23,10 @@ export fn entry() void {...@@ -23,7 +23,10 @@ export fn entry() void {
23 S.d();23 S.d();
24}24}
2525
26// shift on type with non-power-of-two size26// error
27// backend=stage1
28// target=native
29// is_test=1
27//30//
28// tmp.zig:5:19: error: RHS of shift is too large for LHS type31// tmp.zig:5:19: error: RHS of shift is too large for LHS type
29// tmp.zig:9:19: error: RHS of shift is too large for LHS type32// tmp.zig:9:19: error: RHS of shift is too large for LHS type
test/compile_errors/stage1/test/shuffle_with_selected_index_past_first_vector_length.zig+4-1
...@@ -5,7 +5,10 @@ export fn entry() void {...@@ -5,7 +5,10 @@ export fn entry() void {
5 _ = z;5 _ = z;
6}6}
77
8// @shuffle with selected index past first vector length8// error
9// backend=stage1
10// target=native
11// is_test=1
9//12//
10// tmp.zig:4:39: error: mask index '4' has out-of-bounds selection13// tmp.zig:4:39: error: mask index '4' has out-of-bounds selection
11// tmp.zig:4:27: note: selected index '7' out of bounds of @Vector(4, u32)14// tmp.zig:4:27: note: selected index '7' out of bounds of @Vector(4, u32)
test/compile_errors/stage1/test/switch_ranges_endpoints_are_validated.zig+4-1
...@@ -7,7 +7,10 @@ pub export fn entry() void {...@@ -7,7 +7,10 @@ pub export fn entry() void {
7 }7 }
8}8}
99
10// switch ranges endpoints are validated10// error
11// backend=stage1
12// target=native
13// is_test=1
11//14//
12// tmp.zig:4:9: error: range start value is greater than the end value15// tmp.zig:4:9: error: range start value is greater than the end value
13// tmp.zig:5:9: error: range start value is greater than the end value16// tmp.zig:5:9: error: range start value is greater than the end value
test/compile_errors/stage1/test/switching_with_exhaustive_enum_has___prong_.zig+4-1
...@@ -11,6 +11,9 @@ pub export fn entry() void {...@@ -11,6 +11,9 @@ pub export fn entry() void {
11 }11 }
12}12}
1313
14// switching with exhaustive enum has '_' prong 14// error
15// backend=stage1
16// target=native
17// is_test=1
15//18//
16// tmp.zig:7:5: error: switch on exhaustive enum has `_` prong19// tmp.zig:7:5: error: switch on exhaustive enum has `_` prong
test/compile_errors/stage1/test/switching_with_non-exhaustive_enums.zig+4-1
...@@ -25,7 +25,10 @@ pub export fn entry() void {...@@ -25,7 +25,10 @@ pub export fn entry() void {
25 }25 }
26}26}
2727
28// switching with non-exhaustive enums28// error
29// backend=stage1
30// target=native
31// is_test=1
29//32//
30// tmp.zig:12:5: error: enumeration value 'E.b' not handled in switch33// tmp.zig:12:5: error: enumeration value 'E.b' not handled in switch
31// tmp.zig:16:5: error: switch on non-exhaustive enum must include `else` or `_` prong34// tmp.zig:16:5: error: switch on non-exhaustive enum must include `else` or `_` prong
test/compile_errors/stage1/test/tagName_on_invalid_value_of_non-exhaustive_enum.zig+4-1
...@@ -3,6 +3,9 @@ test "enum" {...@@ -3,6 +3,9 @@ test "enum" {
3 _ = @tagName(@intToEnum(E, 5));3 _ = @tagName(@intToEnum(E, 5));
4}4}
55
6// @tagName on invalid value of non-exhaustive enum6// error
7// backend=stage1
8// target=native
9// is_test=1
7//10//
8// tmp.zig:3:18: error: no tag by value 511// tmp.zig:3:18: error: no tag by value 5
test/compile_errors/stage1/test/type_mismatch_in_C_prototype_with_varargs.zig+4-1
...@@ -6,6 +6,9 @@ export fn main() void {...@@ -6,6 +6,9 @@ export fn main() void {
6 _ = x;6 _ = x;
7}7}
88
9// type mismatch in C prototype with varargs9// error
10// backend=stage1
11// target=native
12// is_test=1
10//13//
11// tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'14// tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'
test/compile_errors/stage1/test/type_mismatch_with_tuple_concatenation.zig+4-1
...@@ -3,6 +3,9 @@ export fn entry() void {...@@ -3,6 +3,9 @@ export fn entry() void {
3 x = x ++ .{ 1, 2, 3 };3 x = x ++ .{ 1, 2, 3 };
4}4}
55
6// type mismatch with tuple concatenation6// error
7// backend=stage1
8// target=native
9// is_test=1
7//10//
8// tmp.zig:3:11: error: expected type 'struct:2:14', found 'struct:3:11'11// tmp.zig:3:11: error: expected type 'struct:2:14', found 'struct:3:11'
test/compile_errors/stage2/constant_inside_comptime_function_has_compile_error.zig+2-1
...@@ -14,7 +14,8 @@ export fn entry() void {...@@ -14,7 +14,8 @@ export fn entry() void {
14 _ = allocator;14 _ = allocator;
15}15}
1616
17// constant inside comptime function has compile error17// error
18// target=native
18//19//
19// :4:5: error: unreachable code20// :4:5: error: unreachable code
20// :4:25: note: control flow is diverted here21// :4:25: note: control flow is diverted here
test/compile_errors/stage2/duplicate-unused_labels.zig+2-1
...@@ -17,7 +17,8 @@ comptime {...@@ -17,7 +17,8 @@ comptime {
17 blk: for(@as([0]void, undefined)) |_| {}17 blk: for(@as([0]void, undefined)) |_| {}
18}18}
1919
20// duplicate/unused labels20// error
21// target=native
21//22//
22// :2:12: error: redefinition of label 'blk'23// :2:12: error: redefinition of label 'blk'
23// :2:5: note: previous definition here24// :2:5: note: previous definition here
test/compile_errors/stage2/embed_outside_package.zig+2-1
...@@ -2,6 +2,7 @@ export fn a() usize {...@@ -2,6 +2,7 @@ export fn a() usize {
2 return @embedFile("/root/foo").len;2 return @embedFile("/root/foo").len;
3}3}
44
5// embed outside package5// error
6// target=native
6//7//
7//:2:23: error: embed of file outside package path: '/root/foo'8//:2:23: error: embed of file outside package path: '/root/foo'
test/compile_errors/stage2/import_outside_package.zig+2-1
...@@ -2,6 +2,7 @@ export fn a() usize {...@@ -2,6 +2,7 @@ export fn a() usize {
2 return @import("../../above.zig").len;2 return @import("../../above.zig").len;
3}3}
44
5// import outside package5// error
6// target=native
6//7//
7// :2:20: error: import of file outside package path: '../../above.zig'8// :2:20: error: import of file outside package path: '../../above.zig'
test/compile_errors/stage2/out_of_bounds_index.zig+2-1
...@@ -20,7 +20,8 @@ comptime {...@@ -20,7 +20,8 @@ comptime {
20 _ = slice;20 _ = slice;
21}21}
2222
23// out of bounds indexing23// error
24// target=native
24//25//
25// :4:26: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)26// :4:26: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)
26// :9:22: error: end index 6 out of bounds for array of length 4 +1 (sentinel)27// :9:22: error: end index 6 out of bounds for array of length 4 +1 (sentinel)
test/compile_errors/stage2/slice_of_null_pointer.zig+2-1
...@@ -5,6 +5,7 @@ comptime {...@@ -5,6 +5,7 @@ comptime {
5 _ = y;5 _ = y;
6}6}
77
8// slice of null C pointer8// error
9// target=native
9//10//
10// :4:14: error: slice of null pointer11// :4:14: error: slice of null pointer
test/compile_errors/stage2/struct_duplicate_field_name.zig+2-1
...@@ -8,7 +8,8 @@ export fn entry() void {...@@ -8,7 +8,8 @@ export fn entry() void {
8 _ = s;8 _ = s;
9}9}
1010
11// duplicate struct field name11// error
12// target=native
12//13//
13// :3:5: error: duplicate struct field: 'foo'14// :3:5: error: duplicate struct field: 'foo'
14// :2:5: note: other field here15// :2:5: note: other field here
test/compile_errors/stage2/union_access_of_inactive_field.zig+3-2
...@@ -3,12 +3,13 @@ const U = union {...@@ -3,12 +3,13 @@ const U = union {
3 b: u64,3 b: u64,
4};4};
5comptime {5comptime {
6 var u: U = .{.a = {}};6 var u: U = .{ .a = {} };
7 const v = u.b;7 const v = u.b;
8 _ = v;8 _ = v;
9}9}
1010
11// access of inactive union field11// error
12// target=native
12//13//
13// :7:16: error: access of union field 'b' while field 'a' is active14// :7:16: error: access of union field 'b' while field 'a' is active
14// :1:11: note: union declared here15// :1:11: note: union declared here
test/compile_errors/stage2/union_duplicate_enum_field.zig+3-2
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1const E = enum {a, b};1const E = enum { a, b };
2const U = union(E) {2const U = union(E) {
3 a: u32,3 a: u32,
4 a: u32,4 a: u32,
...@@ -9,7 +9,8 @@ export fn foo() void {...@@ -9,7 +9,8 @@ export fn foo() void {
9 _ = u;9 _ = u;
10}10}
1111
12// union with enum and duplicate fields12// error
13// target=native
13//14//
14// :4:5: error: duplicate union field: 'a'15// :4:5: error: duplicate union field: 'a'
15// :3:5: note: other field here16// :3:5: note: other field here
test/compile_errors/stage2/union_duplicate_field_definition.zig+2-1
...@@ -8,7 +8,8 @@ export fn entry() void {...@@ -8,7 +8,8 @@ export fn entry() void {
8 _ = u;8 _ = u;
9}9}
1010
11// duplicate union field name11// error
12// target=native
12//13//
13// :3:5: error: duplicate union field: 'foo'14// :3:5: error: duplicate union field: 'foo'
14// :2:5: note: other field here15// :2:5: note: other field here
test/compile_errors/stage2/union_enum_field_missing.zig+2-1
...@@ -13,7 +13,8 @@ export fn entry() usize {...@@ -13,7 +13,8 @@ export fn entry() usize {
13 return @sizeOf(U);13 return @sizeOf(U);
14}14}
1515
16// enum field missing in union16// error
17// target=native
17//18//
18// :7:1: error: enum field(s) missing in union19// :7:1: error: enum field(s) missing in union
19// :4:5: note: field 'c' missing, declared here20// :4:5: note: field 'c' missing, declared here
test/compile_errors/stage2/union_extra_field.zig+2-1
...@@ -13,7 +13,8 @@ export fn entry() usize {...@@ -13,7 +13,8 @@ export fn entry() usize {
13 return @sizeOf(U);13 return @sizeOf(U);
14}14}
1515
16// union extra field16// error
17// target=native
17//18//
18// :6:1: error: enum 'tmp.E' has no field named 'd'19// :6:1: error: enum 'tmp.E' has no field named 'd'
19// :1:11: note: enum declared here20// :1:11: note: enum declared here
test/compile_errors/stage2/union_runtime_coercion_from_enum.zig+2-1
...@@ -14,7 +14,8 @@ export fn doTheTest() u64 {...@@ -14,7 +14,8 @@ export fn doTheTest() u64 {
14 return u.b;14 return u.b;
15}15}
1616
17// runtime coercion from enum to union17// error
18// target=native
18//19//
19// :13:19: error: runtime coercion from enum 'tmp.E' to union 'tmp.U' which has non-void fields20// :13:19: error: runtime coercion from enum 'tmp.E' to union 'tmp.U' which has non-void fields
20// :6:5: note: field 'a' has type 'u32'21// :6:5: note: field 'a' has type 'u32'
test/incremental/aarch64-linux/conditional_branches.0.zig created+26
...@@ -0,0 +1,26 @@
1pub fn main() void {
2 foo(123);
3}
4
5fn foo(x: u64) void {
6 if (x > 42) {
7 print();
8 }
9}
10
11fn print() void {
12 asm volatile ("svc #0"
13 :
14 : [number] "{x8}" (64),
15 [arg1] "{x0}" (1),
16 [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
17 [arg3] "{x2}" ("Hello, World!\n".len),
18 : "memory", "cc"
19 );
20}
21
22// run
23// target=aarch64-linux
24//
25// Hello, World!
26//
test/incremental/aarch64-linux/conditional_branches.1.zig created+25
...@@ -0,0 +1,25 @@
1pub fn main() void {
2 foo(true);
3}
4
5fn foo(x: bool) void {
6 if (x) {
7 print();
8 }
9}
10
11fn print() void {
12 asm volatile ("svc #0"
13 :
14 : [number] "{x8}" (64),
15 [arg1] "{x0}" (1),
16 [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
17 [arg3] "{x2}" ("Hello, World!\n".len),
18 : "memory", "cc"
19 );
20}
21
22// run
23//
24// Hello, World!
25//
test/incremental/aarch64-linux/hello_world_with_updates.0.zig created+31
...@@ -0,0 +1,31 @@
1pub export fn _start() noreturn {
2 print();
3 exit(0);
4}
5
6fn print() void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{x8}" (64),
10 [arg1] "{x0}" (1),
11 [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
12 [arg3] "{x2}" ("Hello, World!\n".len),
13 : "memory", "cc"
14 );
15}
16
17fn exit(ret: usize) noreturn {
18 asm volatile ("svc #0"
19 :
20 : [number] "{x8}" (93),
21 [arg1] "{x0}" (ret),
22 : "memory", "cc"
23 );
24 unreachable;
25}
26
27// run
28// target=aarch64-linux
29//
30// Hello, World!
31//
test/incremental/aarch64-linux/hello_world_with_updates.1.zig created+36
...@@ -0,0 +1,36 @@
1pub export fn _start() noreturn {
2 print();
3 print();
4 print();
5 print();
6 exit(0);
7}
8
9fn print() void {
10 asm volatile ("svc #0"
11 :
12 : [number] "{x8}" (64),
13 [arg1] "{x0}" (1),
14 [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
15 [arg3] "{x2}" ("Hello, World!\n".len),
16 : "memory", "cc"
17 );
18}
19
20fn exit(ret: usize) noreturn {
21 asm volatile ("svc #0"
22 :
23 : [number] "{x8}" (93),
24 [arg1] "{x0}" (ret),
25 : "memory", "cc"
26 );
27 unreachable;
28}
29
30// run
31//
32// Hello, World!
33// Hello, World!
34// Hello, World!
35// Hello, World!
36//
test/incremental/aarch64-linux/hello_world_with_updates.2.zig created+21
...@@ -0,0 +1,21 @@
1pub fn main() void {
2 print();
3 print();
4}
5
6fn print() void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{x8}" (64),
10 [arg1] "{x0}" (1),
11 [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
12 [arg3] "{x2}" ("Hello, World!\n".len),
13 : "memory", "cc"
14 );
15}
16
17// run
18//
19// Hello, World!
20// Hello, World!
21//
test/incremental/aarch64-macos/hello_world_with_updates.0.zig created+5
...@@ -0,0 +1,5 @@
1// error
2// output_mode=Exe
3// target=aarch64-macos
4//
5// :109:9: error: struct 'tmp.tmp' has no member named 'main'
test/incremental/aarch64-macos/hello_world_with_updates.1.zig created+5
...@@ -0,0 +1,5 @@
1pub export fn main() noreturn {}
2
3// error
4//
5// :1:32: error: expected noreturn, found void
test/incremental/aarch64-macos/hello_world_with_updates.2.zig created+19
...@@ -0,0 +1,19 @@
1extern "c" fn write(usize, usize, usize) usize;
2extern "c" fn exit(usize) noreturn;
3
4pub export fn main() noreturn {
5 print();
6
7 exit(0);
8}
9
10fn print() void {
11 const msg = @ptrToInt("Hello, World!\n");
12 const len = 14;
13 _ = write(1, msg, len);
14}
15
16// run
17//
18// Hello, World!
19//
test/incremental/aarch64-macos/hello_world_with_updates.3.zig created+16
...@@ -0,0 +1,16 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 print();
5}
6
7fn print() void {
8 const msg = @ptrToInt("Hello, World!\n");
9 const len = 14;
10 _ = write(1, msg, len);
11}
12
13// run
14//
15// Hello, World!
16//
test/incremental/aarch64-macos/hello_world_with_updates.4.zig created+22
...@@ -0,0 +1,22 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 print();
5 print();
6 print();
7 print();
8}
9
10fn print() void {
11 const msg = @ptrToInt("Hello, World!\n");
12 const len = 14;
13 _ = write(1, msg, len);
14}
15
16// run
17//
18// Hello, World!
19// Hello, World!
20// Hello, World!
21// Hello, World!
22//
test/incremental/aarch64-macos/hello_world_with_updates.5.zig created+16
...@@ -0,0 +1,16 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 print();
5}
6
7fn print() void {
8 const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
9 const len = 104;
10 _ = write(1, msg, len);
11}
12
13// run
14//
15// What is up? This is a longer message that will force the data to be relocated in virtual address space.
16//
test/incremental/aarch64-macos/hello_world_with_updates.6.zig created+18
...@@ -0,0 +1,18 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 print();
5 print();
6}
7
8fn print() void {
9 const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
10 const len = 104;
11 _ = write(1, msg, len);
12}
13
14// run
15//
16// What is up? This is a longer message that will force the data to be relocated in virtual address space.
17// What is up? This is a longer message that will force the data to be relocated in virtual address space.
18//
test/incremental/adding_numbers_at_runtime_and_comptime.0.zig created+10
...@@ -0,0 +1,10 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 if (a + b != 7) unreachable;
7}
8
9// run
10//
test/incremental/adding_numbers_at_runtime_and_comptime.1.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() void {
2 if (x - 7 != 0) unreachable;
3}
4
5fn add(a: u32, b: u32) u32 {
6 return a + b;
7}
8
9const x = add(3, 4);
10
11// run
12//
test/incremental/adding_numbers_at_runtime_and_comptime.2.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() void {
2 var x: usize = 3;
3 const y = add(1, 2, x);
4 if (y - 6 != 0) unreachable;
5}
6
7inline fn add(a: usize, b: usize, c: usize) usize {
8 return a + b + c;
9}
10
11// run
12//
test/incremental/ambiguous_reference.zig created+13
...@@ -0,0 +1,13 @@
1const T = struct {
2 const T = struct {
3 fn f() void {
4 _ = T;
5 }
6 };
7};
8
9// error
10//
11// :4:17: error: ambiguous reference
12// :2:5: note: declared here
13// :1:1: note: also declared here
test/incremental/arm-linux/arithmetic_operations.0.zig created+21
...@@ -0,0 +1,21 @@
1pub fn main() void {
2 print(2, 4);
3 print(1, 7);
4}
5
6fn print(a: u32, b: u32) void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg3] "{r2}" (a + b),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("123456789")),
13 : "memory"
14 );
15 return;
16}
17
18// run
19// target=arm-linux
20//
21// 12345612345678
test/incremental/arm-linux/arithmetic_operations.1.zig created+20
...@@ -0,0 +1,20 @@
1pub fn main() void {
2 print(10, 5);
3 print(4, 3);
4}
5
6fn print(a: u32, b: u32) void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg3] "{r2}" (a - b),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("123456789")),
13 : "memory"
14 );
15 return;
16}
17
18// run
19//
20// 123451
test/incremental/arm-linux/arithmetic_operations.2.zig created+20
...@@ -0,0 +1,20 @@
1pub fn main() void {
2 print(8, 9);
3 print(3, 7);
4}
5
6fn print(a: u32, b: u32) void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg3] "{r2}" (a & b),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("123456789")),
13 : "memory"
14 );
15 return;
16}
17
18// run
19//
20// 12345678123
test/incremental/arm-linux/arithmetic_operations.3.zig created+20
...@@ -0,0 +1,20 @@
1pub fn main() void {
2 print(4, 2);
3 print(3, 7);
4}
5
6fn print(a: u32, b: u32) void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg3] "{r2}" (a | b),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("123456789")),
13 : "memory"
14 );
15 return;
16}
17
18// run
19//
20// 1234561234567
test/incremental/arm-linux/arithmetic_operations.4.zig created+20
...@@ -0,0 +1,20 @@
1pub fn main() void {
2 print(42, 42);
3 print(3, 5);
4}
5
6fn print(a: u32, b: u32) void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg3] "{r2}" (a ^ b),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("123456789")),
13 : "memory"
14 );
15 return;
16}
17
18// run
19//
20// 123456
test/incremental/arm-linux/arithmetic_operations.5.zig created+15
...@@ -0,0 +1,15 @@
1pub fn main() void {
2 var x: u32 = 1;
3 assert(x << 1 == 2);
4
5 x <<= 1;
6 assert(x << 2 == 8);
7 assert(x << 3 == 16);
8}
9
10pub fn assert(ok: bool) void {
11 if (!ok) unreachable; // assertion failure
12}
13
14// run
15//
test/incremental/arm-linux/arithmetic_operations.6.zig created+21
...@@ -0,0 +1,21 @@
1pub fn main() void {
2 var a: u32 = 1024;
3 assert(a >> 1 == 512);
4
5 a >>= 1;
6 assert(a >> 2 == 128);
7 assert(a >> 3 == 64);
8 assert(a >> 4 == 32);
9 assert(a >> 5 == 16);
10 assert(a >> 6 == 8);
11 assert(a >> 7 == 4);
12 assert(a >> 8 == 2);
13 assert(a >> 9 == 1);
14}
15
16pub fn assert(ok: bool) void {
17 if (!ok) unreachable; // assertion failure
18}
19
20// run
21//
test/incremental/arm-linux/errors.0.zig created+21
...@@ -0,0 +1,21 @@
1pub fn main() void {
2 foo() catch print();
3}
4
5fn foo() anyerror!void {}
6
7fn print() void {
8 asm volatile ("svc #0"
9 :
10 : [number] "{r7}" (4),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
13 [arg3] "{r2}" ("Hello, World!\n".len),
14 : "memory"
15 );
16 return;
17}
18
19// run
20// target=arm-linux
21//
test/incremental/arm-linux/errors.1.zig created+24
...@@ -0,0 +1,24 @@
1pub fn main() void {
2 foo() catch print();
3}
4
5fn foo() anyerror!void {
6 return error.Test;
7}
8
9fn print() void {
10 asm volatile ("svc #0"
11 :
12 : [number] "{r7}" (4),
13 [arg1] "{r0}" (1),
14 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
15 [arg3] "{r2}" ("Hello, World!\n".len),
16 : "memory"
17 );
18 return;
19}
20
21// run
22//
23// Hello, World!
24//
test/incremental/arm-linux/errors.2.zig created+27
...@@ -0,0 +1,27 @@
1pub fn main() void {
2 foo() catch |err| {
3 assert(err == error.Foo);
4 assert(err != error.Bar);
5 assert(err != error.Baz);
6 };
7 bar() catch |err| {
8 assert(err != error.Foo);
9 assert(err == error.Bar);
10 assert(err != error.Baz);
11 };
12}
13
14fn assert(ok: bool) void {
15 if (!ok) unreachable;
16}
17
18fn foo() anyerror!void {
19 return error.Foo;
20}
21
22fn bar() anyerror!void {
23 return error.Bar;
24}
25
26// run
27//
test/incremental/arm-linux/errors.3.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() void {
2 foo() catch unreachable;
3}
4
5fn foo() anyerror!void {
6 try bar();
7}
8
9fn bar() anyerror!void {}
10
11// run
12//
test/incremental/arm-linux/function_pointers.zig created+44
...@@ -0,0 +1,44 @@
1const PrintFn = *const fn () void;
2
3pub fn main() void {
4 var printFn: PrintFn = stopSayingThat;
5 var i: u32 = 0;
6 while (i < 4) : (i += 1) printFn();
7
8 printFn = moveEveryZig;
9 printFn();
10}
11
12fn stopSayingThat() void {
13 asm volatile ("svc #0"
14 :
15 : [number] "{r7}" (4),
16 [arg1] "{r0}" (1),
17 [arg2] "{r1}" (@ptrToInt("Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n")),
18 [arg3] "{r2}" ("Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n".len),
19 : "memory"
20 );
21 return;
22}
23
24fn moveEveryZig() void {
25 asm volatile ("svc #0"
26 :
27 : [number] "{r7}" (4),
28 [arg1] "{r0}" (1),
29 [arg2] "{r1}" (@ptrToInt("All your codebase are belong to us\n")),
30 [arg3] "{r2}" ("All your codebase are belong to us\n".len),
31 : "memory"
32 );
33 return;
34}
35
36// run
37// target=arm-linux
38//
39// Hello, my name is Inigo Montoya; you killed my father, prepare to die.
40// Hello, my name is Inigo Montoya; you killed my father, prepare to die.
41// Hello, my name is Inigo Montoya; you killed my father, prepare to die.
42// Hello, my name is Inigo Montoya; you killed my father, prepare to die.
43// All your codebase are belong to us
44//
test/incremental/arm-linux/hello_world_with_updates.0.zig created+32
...@@ -0,0 +1,32 @@
1pub export fn _start() noreturn {
2 print();
3 exit();
4}
5
6fn print() void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg1] "{r0}" (1),
11 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
12 [arg3] "{r2}" (14),
13 : "memory"
14 );
15 return;
16}
17
18fn exit() noreturn {
19 asm volatile ("svc #0"
20 :
21 : [number] "{r7}" (1),
22 [arg1] "{r0}" (0),
23 : "memory"
24 );
25 unreachable;
26}
27
28// run
29// target=arm-linux
30//
31// Hello, World!
32//
test/incremental/arm-linux/hello_world_with_updates.1.zig created+37
...@@ -0,0 +1,37 @@
1pub export fn _start() noreturn {
2 print();
3 print();
4 print();
5 print();
6 exit();
7}
8
9fn print() void {
10 asm volatile ("svc #0"
11 :
12 : [number] "{r7}" (4),
13 [arg1] "{r0}" (1),
14 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
15 [arg3] "{r2}" (14),
16 : "memory"
17 );
18 return;
19}
20
21fn exit() noreturn {
22 asm volatile ("svc #0"
23 :
24 : [number] "{r7}" (1),
25 [arg1] "{r0}" (0),
26 : "memory"
27 );
28 unreachable;
29}
30
31// run
32//
33// Hello, World!
34// Hello, World!
35// Hello, World!
36// Hello, World!
37//
test/incremental/arm-linux/hello_world_with_updates.2.zig created+22
...@@ -0,0 +1,22 @@
1pub fn main() void {
2 print();
3 print();
4}
5
6fn print() void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg1] "{r0}" (1),
11 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
12 [arg3] "{r2}" (14),
13 : "memory"
14 );
15 return;
16}
17
18// run
19//
20// Hello, World!
21// Hello, World!
22//
test/incremental/arm-linux/parameters_and_return_values.0.zig created+28
...@@ -0,0 +1,28 @@
1pub fn main() void {
2 print(id(14));
3}
4
5fn id(x: u32) u32 {
6 return x;
7}
8
9// TODO: The parameters to the asm statement in print() had to
10// be in a specific order because otherwise the write to r0
11// would overwrite the len parameter which resides in r0
12fn print(len: u32) void {
13 asm volatile ("svc #0"
14 :
15 : [number] "{r7}" (4),
16 [arg3] "{r2}" (len),
17 [arg1] "{r0}" (1),
18 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
19 : "memory"
20 );
21 return;
22}
23
24// run
25// target=arm-linux
26//
27// Hello, World!
28//
test/incremental/arm-linux/parameters_and_return_values.1.zig created+14
...@@ -0,0 +1,14 @@
1pub fn main() void {
2 assert(add(1, 2, 3, 4, 5, 6) == 21);
3}
4
5fn add(a: u32, b: u32, c: u32, d: u32, e: u32, f: u32) u32 {
6 return a + b + c + d + e + f;
7}
8
9pub fn assert(ok: bool) void {
10 if (!ok) unreachable; // assertion failure
11}
12
13// run
14//
test/incremental/arm-linux/print_u32s.zig created+40
...@@ -0,0 +1,40 @@
1pub fn main() void {
2 printNumberHex(0x00000000);
3 printNumberHex(0xaaaaaaaa);
4 printNumberHex(0xdeadbeef);
5 printNumberHex(0x31415926);
6}
7
8fn printNumberHex(x: u32) void {
9 var i: u5 = 28;
10 while (true) : (i -= 4) {
11 const digit = (x >> i) & 0xf;
12 asm volatile ("svc #0"
13 :
14 : [number] "{r7}" (4),
15 [arg1] "{r0}" (1),
16 [arg2] "{r1}" (@ptrToInt("0123456789abcdef") + digit),
17 [arg3] "{r2}" (1),
18 : "memory"
19 );
20
21 if (i == 0) break;
22 }
23 asm volatile ("svc #0"
24 :
25 : [number] "{r7}" (4),
26 [arg1] "{r0}" (1),
27 [arg2] "{r1}" (@ptrToInt("\n")),
28 [arg3] "{r2}" (1),
29 : "memory"
30 );
31}
32
33// run
34// target=arm-linux
35//
36// 00000000
37// aaaaaaaa
38// deadbeef
39// 31415926
40//
test/incremental/arm-linux/spilling_registers.0.zig created+38
...@@ -0,0 +1,38 @@
1pub fn main() void {
2 assert(add(3, 4) == 791);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 const f = d + e; // 24
11 const g = e + f; // 38
12 const h = f + g; // 62
13 const i = g + h; // 100
14 const j = i + d; // 110
15 const k = i + j; // 210
16 const l = k + c; // 217
17 const m = l + d; // 227
18 const n = m + e; // 241
19 const o = n + f; // 265
20 const p = o + g; // 303
21 const q = p + h; // 365
22 const r = q + i; // 465
23 const s = r + j; // 575
24 const t = s + k; // 785
25 break :blk t;
26 };
27 const y = x + a; // 788
28 const z = y + a; // 791
29 return z;
30}
31
32fn assert(ok: bool) void {
33 if (!ok) unreachable;
34}
35
36// run
37// target=arm-linux
38//
test/incremental/arm-linux/spilling_registers.1.zig created+37
...@@ -0,0 +1,37 @@
1pub fn main() void {
2 assert(addMul(3, 4) == 357747496);
3}
4
5fn addMul(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 const f = d + e; // 24
11 const g = e + f; // 38
12 const h = f + g; // 62
13 const i = g + h; // 100
14 const j = i + d; // 110
15 const k = i + j; // 210
16 const l = k + c; // 217
17 const m = l * d; // 2170
18 const n = m + e; // 2184
19 const o = n * f; // 52416
20 const p = o + g; // 52454
21 const q = p * h; // 3252148
22 const r = q + i; // 3252248
23 const s = r * j; // 357747280
24 const t = s + k; // 357747490
25 break :blk t;
26 };
27 const y = x + a; // 357747493
28 const z = y + a; // 357747496
29 return z;
30}
31
32fn assert(ok: bool) void {
33 if (!ok) unreachable;
34}
35
36// run
37//
test/incremental/bad_inferred_variable_type.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 var x = null;
3 _ = x;
4}
5
6// error
7// output_mode=Exe
8//
9// :2:9: error: variable of type '@TypeOf(null)' must be const or comptime
test/incremental/binary_operands.0.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 var i: u8 = 5;
3 i += 20;
4 if (i != 25) unreachable;
5}
6
7// run
8// target=wasm32-wasi
9//
test/incremental/binary_operands.1.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() void {
2 var i: i32 = 2147483647;
3 if (i +% 1 != -2147483648) unreachable;
4 return;
5}
6
7// run
8//
test/incremental/binary_operands.10.zig created+13
...@@ -0,0 +1,13 @@
1pub fn main() void {
2 var i: u32 = 5;
3 i *= 7;
4 var result: u32 = foo(i, 10);
5 if (result != 350) unreachable;
6 return;
7}
8fn foo(x: u32, y: u32) u32 {
9 return x * y;
10}
11
12// run
13//
test/incremental/binary_operands.11.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 var i: i32 = 2147483647;
3 const result = i *% 2;
4 if (result != -2) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.12.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() void {
2 var i: u3 = 3;
3 if (i *% 3 != 1) unreachable;
4 return;
5}
6
7// run
8//
test/incremental/binary_operands.13.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() void {
2 var i: i4 = 3;
3 if (i *% 3 != 1) unreachable;
4 return;
5}
6
7// run
8//
test/incremental/binary_operands.14.zig created+13
...@@ -0,0 +1,13 @@
1pub fn main() void {
2 var i: u32 = 352;
3 i /= 7; // i = 50
4 var result: u32 = foo(i, 7);
5 if (result != 7) unreachable;
6 return;
7}
8fn foo(x: u32, y: u32) u32 {
9 return x / y;
10}
11
12// run
13//
test/incremental/binary_operands.15.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 i &= 6;
4 return i - 4;
5}
6
7// run
8//
test/incremental/binary_operands.16.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 i |= 6;
4 return i - 7;
5}
6
7// run
8//
test/incremental/binary_operands.17.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 i ^= 6;
4 return i - 3;
5}
6
7// run
8//
test/incremental/binary_operands.18.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = false;
3 b = b or false;
4 if (b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.19.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = true;
3 b = b or false;
4 if (!b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.2.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() void {
2 var i: i4 = 7;
3 if (i +% 1 != 0) unreachable;
4 return;
5}
6
7// run
8//
test/incremental/binary_operands.20.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = false;
3 b = b or true;
4 if (!b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.21.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = true;
3 b = b or true;
4 if (!b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.22.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = false;
3 b = b and false;
4 if (b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.23.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = true;
3 b = b and false;
4 if (b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.24.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = false;
3 b = b and true;
4 if (b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.25.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = true;
3 b = b and true;
4 if (!b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.3.zig created+7
...@@ -0,0 +1,7 @@
1pub fn main() u8 {
2 var i: u8 = 255;
3 return i +% 1;
4}
5
6// run
7//
test/incremental/binary_operands.4.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 i += 20;
4 var result: u8 = foo(i, 10);
5 return result - 35;
6}
7fn foo(x: u8, y: u8) u8 {
8 return x + y;
9}
10
11// run
12//
test/incremental/binary_operands.5.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() u8 {
2 var i: u8 = 20;
3 i -= 5;
4 return i - 15;
5}
6
7// run
8//
test/incremental/binary_operands.6.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() void {
2 var i: i32 = -2147483648;
3 if (i -% 1 != 2147483647) unreachable;
4 return;
5}
6
7// run
8//
test/incremental/binary_operands.7.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() void {
2 var i: i7 = -64;
3 if (i -% 1 != 63) unreachable;
4 return;
5}
6
7// run
8//
test/incremental/binary_operands.8.zig created+7
...@@ -0,0 +1,7 @@
1pub fn main() void {
2 var i: u4 = 0;
3 if (i -% 1 != 15) unreachable;
4}
5
6// run
7//
test/incremental/binary_operands.9.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 i -= 3;
4 var result: u8 = foo(i, 10);
5 return result - 8;
6}
7fn foo(x: u8, y: u8) u8 {
8 return y - x;
9}
10
11// run
12//
test/incremental/break_continue.0.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 while (true) {
3 break;
4 }
5}
6
7// run
8// target=x86_64-linux,x86_64-macos,aarch64-linux,aarch64-macos
9//
test/incremental/break_continue.1.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() void {
2 foo: while (true) {
3 break :foo;
4 }
5}
6
7// run
8//
test/incremental/break_continue.2.zig created+10
...@@ -0,0 +1,10 @@
1pub fn main() void {
2 var i: u64 = 0;
3 while (true) : (i += 1) {
4 if (i == 4) return;
5 continue;
6 }
7}
8
9// run
10//
test/incremental/break_continue.3.zig created+10
...@@ -0,0 +1,10 @@
1pub fn main() void {
2 var i: u64 = 0;
3 foo: while (true) : (i += 1) {
4 if (i == 4) return;
5 continue :foo;
6 }
7}
8
9// run
10//
test/incremental/catch_at_comptime.0.zig created+11
...@@ -0,0 +1,11 @@
1pub fn main() void {
2 const i: anyerror!u64 = 0;
3 const caught = i catch 5;
4 assert(caught == 0);
5}
6fn assert(b: bool) void {
7 if (!b) unreachable;
8}
9
10// run
11//
test/incremental/catch_at_comptime.1.zig created+11
...@@ -0,0 +1,11 @@
1pub fn main() void {
2 const i: anyerror!u64 = error.B;
3 const caught = i catch 5;
4 assert(caught == 5);
5}
6fn assert(b: bool) void {
7 if (!b) unreachable;
8}
9
10// run
11//
test/incremental/catch_at_comptime.2.zig created+11
...@@ -0,0 +1,11 @@
1pub fn main() void {
2 const a: anyerror!comptime_int = 42;
3 const b: *const comptime_int = &(a catch unreachable);
4 assert(b.* == 42);
5}
6fn assert(b: bool) void {
7 if (!b) unreachable; // assertion failure
8}
9
10// run
11//
test/incremental/catch_at_comptime.3.zig created+10
...@@ -0,0 +1,10 @@
1pub fn main() void {
2 const a: anyerror!u32 = error.B;
3 _ = &(a catch |err| assert(err == error.B));
4}
5fn assert(b: bool) void {
6 if (!b) unreachable;
7}
8
9// run
10//
test/incremental/catch_at_comptime.4.zig created+10
...@@ -0,0 +1,10 @@
1pub fn main() void {
2 const a: anyerror!u32 = error.Bar;
3 a catch |err| assert(err == error.Bar);
4}
5fn assert(b: bool) void {
6 if (!b) unreachable;
7}
8
9// run
10//
test/incremental/compile_error.zig created+7
...@@ -0,0 +1,7 @@
1export fn foo() void {
2 @compileError("this is an error");
3}
4
5// error
6//
7// :2:5: error: this is an error
test/incremental/compile_error_in_inline_fn_call_fixed.0.zig created+16
...@@ -0,0 +1,16 @@
1pub fn main() void {
2 var x: usize = 3;
3 const y = add(10, 2, x);
4 if (y - 6 != 0) unreachable;
5}
6
7inline fn add(a: usize, b: usize, c: usize) usize {
8 if (a == 10) @compileError("bad");
9 return a + b + c;
10}
11
12// error
13// output_mode=Exe
14//
15// :8:18: error: bad
16// :3:18: note: called from here
test/incremental/compile_error_in_inline_fn_call_fixed.1.zig created+13
...@@ -0,0 +1,13 @@
1pub fn main() void {
2 var x: usize = 3;
3 const y = add(1, 2, x);
4 if (y - 6 != 0) unreachable;
5}
6
7inline fn add(a: usize, b: usize, c: usize) usize {
8 if (a == 10) @compileError("bad");
9 return a + b + c;
10}
11
12// run
13//
test/incremental/compile_log.0.zig created+17
...@@ -0,0 +1,17 @@
1export fn _start() noreturn {
2 const b = true;
3 var f: u32 = 1;
4 @compileLog(b, 20, f, x);
5 @compileLog(1000);
6 var bruh: usize = true;
7 _ = bruh;
8 unreachable;
9}
10export fn other() void {
11 @compileLog(1234);
12}
13fn x() void {}
14
15// error
16//
17// :6:23: error: expected usize, found bool
test/incremental/compile_log.1.zig created+16
...@@ -0,0 +1,16 @@
1export fn _start() noreturn {
2 const b = true;
3 var f: u32 = 1;
4 @compileLog(b, 20, f, x);
5 @compileLog(1000);
6 unreachable;
7}
8export fn other() void {
9 @compileLog(1234);
10}
11fn x() void {}
12
13// error
14//
15// :9:5: error: found compile log statement
16// :4:5: note: also here
test/incremental/double_ampersand.0.zig created+6
...@@ -0,0 +1,6 @@
1pub const a = if (true && false) 1 else 2;
2
3// error
4// output_mode=Exe
5//
6// :1:24: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND
test/incremental/double_ampersand.1.zig created+11
...@@ -0,0 +1,11 @@
1pub fn main() void {
2 const a = true;
3 const b = false;
4 _ = a & &b;
5}
6
7// error
8//
9// :4:11: error: incompatible types: 'bool' and '*const bool'
10// :4:9: note: type 'bool' here
11// :4:13: note: type '*const bool' here
test/incremental/double_ampersand.2.zig created+7
...@@ -0,0 +1,7 @@
1pub fn main() void {
2 const b: u8 = 1;
3 _ = &&b;
4}
5
6// run
7//
test/incremental/enum_values.0.zig created+18
...@@ -0,0 +1,18 @@
1const Number = enum { One, Two, Three };
2
3pub fn main() void {
4 var number1 = Number.One;
5 var number2: Number = .Two;
6 if (false) {
7 number1;
8 number2;
9 }
10 const number3 = @intToEnum(Number, 2);
11 if (@enumToInt(number3) != 2) {
12 unreachable;
13 }
14 return;
15}
16
17// run
18//
test/incremental/enum_values.1.zig created+22
...@@ -0,0 +1,22 @@
1const Number = enum { One, Two, Three };
2
3pub fn main() void {
4 var number1 = Number.One;
5 var number2: Number = .Two;
6 const number3 = @intToEnum(Number, 2);
7 assert(number1 != number2);
8 assert(number2 != number3);
9 assert(@enumToInt(number1) == 0);
10 assert(@enumToInt(number2) == 1);
11 assert(@enumToInt(number3) == 2);
12 var x: Number = .Two;
13 assert(number2 == x);
14
15 return;
16}
17fn assert(val: bool) void {
18 if (!val) unreachable;
19}
20
21// run
22//
test/incremental/extern_variable_has_no_type.0.zig created+9
...@@ -0,0 +1,9 @@
1comptime {
2 const x = foo + foo;
3 _ = x;
4}
5extern var foo: i32;
6
7// error
8//
9// :2:15: error: unable to resolve comptime value
test/incremental/extern_variable_has_no_type.1.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() void {
2 _ = foo;
3}
4extern var foo;
5
6// error
7//
8// :4:8: error: unable to infer variable type
test/incremental/function_calls.0.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() void {
2 foo();
3 bar();
4}
5fn foo() void {
6 bar();
7 bar();
8}
9fn bar() void {}
10
11// run
12//
test/incremental/function_calls.1.zig created+15
...@@ -0,0 +1,15 @@
1pub fn main() void {
2 bar();
3 foo();
4 foo();
5 bar();
6 foo();
7 bar();
8}
9fn foo() void {
10 bar();
11}
12fn bar() void {}
13
14// run
15//
test/incremental/function_calls.2.zig created+14
...@@ -0,0 +1,14 @@
1pub fn main() void {
2 bar();
3 foo();
4 return;
5}
6fn foo() void {
7 bar();
8 bar();
9 bar();
10}
11fn bar() void {}
12
13// run
14//
test/incremental/function_calls.3.zig created+10
...@@ -0,0 +1,10 @@
1pub fn main() void {
2 foo(10, 20);
3}
4fn foo(x: u8, y: u8) void {
5 _ = x;
6 _ = y;
7}
8
9// run
10//
test/incremental/function_redeclaration.zig created+14
...@@ -0,0 +1,14 @@
1// dummy comment
2fn entry() void {}
3fn entry() void {}
4
5fn foo() void {
6 var foo = 1234;
7}
8
9// error
10//
11// :3:1: error: redeclaration of 'entry'
12// :2:1: note: other declaration here
13// :6:9: error: local shadows declaration of 'foo'
14// :5:1: note: declared here
test/incremental/global_variable_redeclaration.zig created+8
...@@ -0,0 +1,8 @@
1// dummy comment
2var foo = false;
3var foo = true;
4
5// error
6//
7// :3:1: error: redeclaration of 'foo'
8// :2:1: note: other declaration here
test/incremental/inner_func_accessing_outer_var.zig created+15
...@@ -0,0 +1,15 @@
1pub fn f() void {
2 var bar: bool = true;
3 const S = struct {
4 fn baz() bool {
5 return bar;
6 }
7 };
8 _ = S;
9}
10
11// error
12//
13// :5:20: error: mutable 'bar' not accessible from here
14// :2:9: note: declared mutable here
15// :3:15: note: crosses namespace boundary here
test/incremental/int_to_ptr.0.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() void {
2 _ = @intToPtr(*u8, 0);
3}
4
5// error
6// output_mode=Exe
7//
8// :2:24: error: pointer type '*u8' does not allow address zero
test/incremental/int_to_ptr.1.zig created+7
...@@ -0,0 +1,7 @@
1pub fn main() void {
2 _ = @intToPtr(*u32, 2);
3}
4
5// error
6//
7// :2:25: error: pointer type '*u32' requires aligned address
test/incremental/large_add_function.zig created+38
...@@ -0,0 +1,38 @@
1pub fn main() void {
2 assert(add(3, 4) == 791);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 const f = d + e; // 24
11 const g = e + f; // 38
12 const h = f + g; // 62
13 const i = g + h; // 100
14 const j = i + d; // 110
15 const k = i + j; // 210
16 const l = k + c; // 217
17 const m = l + d; // 227
18 const n = m + e; // 241
19 const o = n + f; // 265
20 const p = o + g; // 303
21 const q = p + h; // 365
22 const r = q + i; // 465
23 const s = r + j; // 575
24 const t = s + k; // 785
25 break :blk t;
26 };
27 const y = x + a; // 788
28 const z = y + a; // 791
29 return z;
30}
31
32fn assert(ok: bool) void {
33 if (!ok) unreachable;
34}
35
36// run
37// target=aarch64-linux,aarch64-macos
38//
test/incremental/llvm/address_space_pointer_access_chaining_pointer_to_optional_array.zig created+12
...@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.gs) ?[1]i32) *addrspace(.gs) i32 {
2 return &a.*.?[0];
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=llvm
11// target=x86_64-linux,x86_64-macos
12//
test/incremental/llvm/address_spaces_pointer_access_chaining_array_pointer.zig created+12
...@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.gs) [1]i32) *addrspace(.gs) i32 {
2 return &a[0];
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/incremental/llvm/address_spaces_pointer_access_chaining_complex.zig created+13
...@@ -0,0 +1,13 @@
1const A = struct { a: ?[1]i32 };
2fn entry(a: *addrspace(.gs) [1]A) *addrspace(.gs) i32 {
3 return &a[0].a.?[0];
4}
5pub fn main() void {
6 _ = entry;
7}
8
9// error
10// output_mode=Exe
11// backend=llvm
12// target=x86_64-linux,x86_64-macos
13//
test/incremental/llvm/address_spaces_pointer_access_chaining_struct_pointer.zig created+13
...@@ -0,0 +1,13 @@
1const A = struct { a: i32 };
2fn entry(a: *addrspace(.gs) A) *addrspace(.gs) i32 {
3 return &a.a;
4}
5pub fn main() void {
6 _ = entry;
7}
8
9// error
10// output_mode=Exe
11// backend=stage2,llvm
12// target=x86_64-linux,x86_64-macos
13//
test/incremental/llvm/any_typed_null_to_any_typed_optional.zig created+11
...@@ -0,0 +1,11 @@
1pub fn main() void {
2 var a: ?*anyopaque = undefined;
3 a = @as(?usize, null);
4}
5
6// error
7// output_mode=Exe
8// backend=stage2,llvm
9// target=x86_64-linux,x86_64-macos
10//
11// :3:21: error: expected *anyopaque, found ?usize
test/incremental/llvm/blocks.zig created+22
...@@ -0,0 +1,22 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5fn foo(ok: bool) i32 {
6 const val: i32 = blk: {
7 var x: i32 = 1;
8 if (!ok) break :blk x + 9;
9 break :blk x + 19;
10 };
11 return val + 10;
12}
13
14pub fn main() void {
15 assert(foo(false) == 20);
16 assert(foo(true) == 30);
17}
18
19// run
20// backend=stage2,llvm
21// target=x86_64-linux,x86_64-macos
22//
test/incremental/llvm/dereferencing_though_multiple_pointers_with_address_spaces.zig created+12
...@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.fs) *addrspace(.gs) *i32) *i32 {
2 return a.*.*;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/incremental/llvm/f_segment_address_space_reading_and_writing.zig created+48
...@@ -0,0 +1,48 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5fn setFs(value: c_ulong) void {
6 asm volatile (
7 \\syscall
8 :
9 : [number] "{rax}" (158),
10 [code] "{rdi}" (0x1002),
11 [val] "{rsi}" (value),
12 : "rcx", "r11", "memory"
13 );
14}
15
16fn getFs() c_ulong {
17 var result: c_ulong = undefined;
18 asm volatile (
19 \\syscall
20 :
21 : [number] "{rax}" (158),
22 [code] "{rdi}" (0x1003),
23 [ptr] "{rsi}" (@ptrToInt(&result)),
24 : "rcx", "r11", "memory"
25 );
26 return result;
27}
28
29var test_value: u64 = 12345;
30
31pub fn main() void {
32 const orig_fs = getFs();
33
34 setFs(@ptrToInt(&test_value));
35 assert(getFs() == @ptrToInt(&test_value));
36
37 var test_ptr = @intToPtr(*allowzero addrspace(.fs) u64, 0);
38 assert(test_ptr.* == 12345);
39 test_ptr.* = 98765;
40 assert(test_value == 98765);
41
42 setFs(orig_fs);
43}
44
45// run
46// backend=llvm
47// target=x86_64-linux
48//
test/incremental/llvm/for_loop.zig created+16
...@@ -0,0 +1,16 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5pub fn main() void {
6 var x: u32 = 0;
7 for ("hello") |_| {
8 x += 1;
9 }
10 assert("hello".len == x);
11}
12
13// run
14// backend=stage2,llvm
15// target=x86_64-linux,x86_64-macos
16//
test/incremental/llvm/hello_world.zig created+12
...@@ -0,0 +1,12 @@
1extern fn puts(s: [*:0]const u8) c_int;
2
3pub fn main() void {
4 _ = puts("hello world!");
5}
6
7// run
8// backend=llvm
9// target=x86_64-linux,x86_64-macos
10//
11// hello world!
12//
test/incremental/llvm/invalid_address_space_coercion.zig created+13
...@@ -0,0 +1,13 @@
1fn entry(a: *addrspace(.gs) i32) *i32 {
2 return a;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
13// :2:12: error: expected *i32, found *addrspace(.gs) i32
test/incremental/llvm/invalid_pointer_keeps_address_space_when_taking_address_of_dereference.zig created+13
...@@ -0,0 +1,13 @@
1fn entry(a: *addrspace(.gs) i32) *i32 {
2 return &a.*;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
13// :2:12: error: expected *i32, found *addrspace(.gs) i32
test/incremental/llvm/nested_blocks.zig created+24
...@@ -0,0 +1,24 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5fn foo(ok: bool) i32 {
6 var val: i32 = blk: {
7 const val2: i32 = another: {
8 if (!ok) break :blk 10;
9 break :another 10;
10 };
11 break :blk val2 + 10;
12 };
13 return val;
14}
15
16pub fn main() void {
17 assert(foo(false) == 10);
18 assert(foo(true) == 20);
19}
20
21// run
22// backend=stage2, llvm
23// target=x86_64-linux,x86_64-macos
24//
test/incremental/llvm/optionals.zig created+45
...@@ -0,0 +1,45 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5pub fn main() void {
6 var opt_val: ?i32 = 10;
7 var null_val: ?i32 = null;
8
9 var val1: i32 = opt_val.?;
10 const val1_1: i32 = opt_val.?;
11 var ptr_val1 = &(opt_val.?);
12 const ptr_val1_1 = &(opt_val.?);
13
14 var val2: i32 = null_val orelse 20;
15 const val2_2: i32 = null_val orelse 20;
16
17 var value: i32 = 20;
18 var ptr_val2 = &(null_val orelse value);
19
20 const val3 = opt_val orelse 30;
21 var val3_var = opt_val orelse 30;
22
23 assert(val1 == 10);
24 assert(val1_1 == 10);
25 assert(ptr_val1.* == 10);
26 assert(ptr_val1_1.* == 10);
27
28 assert(val2 == 20);
29 assert(val2_2 == 20);
30 assert(ptr_val2.* == 20);
31
32 assert(val3 == 10);
33 assert(val3_var == 10);
34
35 (null_val orelse val2) = 1234;
36 assert(val2 == 1234);
37
38 (opt_val orelse val2) = 5678;
39 assert(opt_val.? == 5678);
40}
41
42// run
43// backend=llvm
44// target=x86_64-linux,x86_64-macos
45//
test/incremental/llvm/pointer_keeps_address_space.zig created+12
...@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.gs) i32) *addrspace(.gs) i32 {
2 return a;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/incremental/llvm/pointer_keeps_address_space_when_taking_address_of_dereference.zig created+12
...@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.gs) i32) *addrspace(.gs) i32 {
2 return &a.*;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/incremental/llvm/pointer_to_explicit_generic_address_space_coerces_to_implicit_pointer.zig created+12
...@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.generic) i32) *i32 {
2 return a;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/incremental/llvm/pointer_with_different_address_spaces.zig created+13
...@@ -0,0 +1,13 @@
1fn entry(a: *addrspace(.gs) i32) *addrspace(.fs) i32 {
2 return a;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
13// :2:12: error: expected *addrspace(.fs) i32, found *addrspace(.gs) i32
test/incremental/llvm/pointers_with_different_address_spaces.zig created+13
...@@ -0,0 +1,13 @@
1fn entry(a: ?*addrspace(.gs) i32) *i32 {
2 return a.?;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
13// :2:13: error: expected *i32, found *addrspace(.gs) i32
test/incremental/llvm/rem.zig created+15
...@@ -0,0 +1,15 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4fn rem(lhs: i32, rhs: i32, expected: i32) bool {
5 return @rem(lhs, rhs) == expected;
6}
7pub fn main() void {
8 assert(rem(-5, 3, -2));
9 assert(rem(5, 3, 2));
10}
11
12// run
13// backend=stage2,llvm
14// target=x86_64-linux,x86_64-macos
15//
test/incremental/llvm/shift_right_plus_left.0.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() void {
2 var i: u32 = 16;
3 assert(i >> 1, 8);
4}
5fn assert(a: u32, b: u32) void {
6 if (a != b) unreachable;
7}
8
9// run
10// backend=llvm
11// target=x86_64-linux,x86_64-macos
12//
test/incremental/llvm/shift_right_plus_left.1.zig created+10
...@@ -0,0 +1,10 @@
1pub fn main() void {
2 var i: u32 = 16;
3 assert(i << 1, 32);
4}
5fn assert(a: u32, b: u32) void {
6 if (a != b) unreachable;
7}
8
9// run
10//
test/incremental/llvm/simple_addition_and_subtraction.zig created+20
...@@ -0,0 +1,20 @@
1fn add(a: i32, b: i32) i32 {
2 return a + b;
3}
4
5pub fn main() void {
6 var a: i32 = -5;
7 const x = add(a, 7);
8 var y = add(2, 0);
9 y -= x;
10 assert(y == 0);
11}
12
13fn assert(ok: bool) void {
14 if (!ok) unreachable;
15}
16
17// run
18// backend=stage2,llvm
19// target=x86_64-linux,x86_64-macos
20//
test/incremental/llvm/simple_if_statement.zig created+16
...@@ -0,0 +1,16 @@
1fn add(a: i32, b: i32) i32 {
2 return a + b;
3}
4
5fn assert(ok: bool) void {
6 if (!ok) unreachable;
7}
8
9pub fn main() void {
10 assert(add(1, 2) == 3);
11}
12
13// run
14// backend=stage2,llvm
15// target=x86_64-linux,x86_64-macos
16//
test/incremental/llvm/while_loops.zig created+18
...@@ -0,0 +1,18 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5pub fn main() void {
6 var sum: u32 = 0;
7 var i: u32 = 0;
8 while (i < 5) : (i += 1) {
9 sum += i;
10 }
11 assert(sum == 10);
12 assert(i == 5);
13}
14
15// run
16// backend=stage2,llvm
17// target=x86_64-linux,x86_64-macos
18//
test/incremental/lower_unnamed_consts_structs.0.zig created+25
...@@ -0,0 +1,25 @@
1const Foo = struct {
2 a: u8,
3 b: u32,
4
5 fn first(self: *Foo) u8 {
6 return self.a;
7 }
8
9 fn second(self: *Foo) u32 {
10 return self.b;
11 }
12};
13
14pub fn main() void {
15 var foo = Foo{ .a = 1, .b = 5 };
16 assert(foo.first() == 1);
17 assert(foo.second() == 5);
18}
19
20fn assert(ok: bool) void {
21 if (!ok) unreachable;
22}
23
24// run
25//
test/incremental/lower_unnamed_consts_structs.1.zig created+35
...@@ -0,0 +1,35 @@
1const Foo = struct {
2 a: u8,
3 b: u32,
4
5 fn first(self: *Foo) u8 {
6 return self.a;
7 }
8
9 fn second(self: *Foo) u32 {
10 return self.b;
11 }
12};
13
14pub fn main() void {
15 var foo = Foo{ .a = 1, .b = 5 };
16 assert(foo.first() == 1);
17 assert(foo.second() == 5);
18
19 foo.a = 10;
20 foo.b = 255;
21
22 assert(foo.first() == 10);
23 assert(foo.second() == 255);
24
25 var foo2 = Foo{ .a = 15, .b = 255 };
26 assert(foo2.first() == 15);
27 assert(foo2.second() == 255);
28}
29
30fn assert(ok: bool) void {
31 if (!ok) unreachable;
32}
33
34// run
35//
test/incremental/lower_unnamed_consts_structs.2.zig created+25
...@@ -0,0 +1,25 @@
1const Foo = struct {
2 a: u8,
3 b: u32,
4
5 fn first(self: *Foo) u8 {
6 return self.a;
7 }
8
9 fn second(self: *Foo) u32 {
10 return self.b;
11 }
12};
13
14pub fn main() void {
15 var foo2 = Foo{ .a = 15, .b = 255 };
16 assert(foo2.first() == 15);
17 assert(foo2.second() == 255);
18}
19
20fn assert(ok: bool) void {
21 if (!ok) unreachable;
22}
23
24// run
25//
test/incremental/merge_error_sets.0.zig created+18
...@@ -0,0 +1,18 @@
1pub fn main() void {
2 const E = error{ A, B, D } || error{ A, B, C };
3 E.A catch {};
4 E.B catch {};
5 E.C catch {};
6 E.D catch {};
7 const E2 = error{ X, Y } || @TypeOf(error.Z);
8 E2.X catch {};
9 E2.Y catch {};
10 E2.Z catch {};
11 assert(anyerror || error{Z} == anyerror);
12}
13fn assert(b: bool) void {
14 if (!b) unreachable;
15}
16
17// run
18//
test/incremental/merge_error_sets.1.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 const z = true || false;
3 _ = z;
4}
5
6// error
7//
8// :2:15: error: expected error set type, found 'bool'
9// :2:20: note: '||' merges error sets; 'or' performs boolean OR
test/incremental/multiplying_numbers_at_runtime_and_comptime.0.zig created+11
...@@ -0,0 +1,11 @@
1pub fn main() void {
2 mul(3, 4);
3}
4
5fn mul(a: u32, b: u32) void {
6 if (a * b != 12) unreachable;
7}
8
9// run
10// target=x86_64-linux,x86_64-macos
11//
test/incremental/multiplying_numbers_at_runtime_and_comptime.1.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() void {
2 if (x - 12 != 0) unreachable;
3}
4
5fn mul(a: u32, b: u32) u32 {
6 return a * b;
7}
8
9const x = mul(3, 4);
10
11// run
12//
test/incremental/multiplying_numbers_at_runtime_and_comptime.2.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() void {
2 var x: usize = 5;
3 const y = mul(2, 3, x);
4 if (y - 30 != 0) unreachable;
5}
6
7inline fn mul(a: usize, b: usize, c: usize) usize {
8 return a * b * c;
9}
10
11// run
12//
test/incremental/non_leaf_functions.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() void {
2 foo();
3}
4
5fn foo() void {
6 bar();
7}
8
9fn bar() void {}
10
11// run
12//
test/incremental/optional_payload.0.zig created+19
...@@ -0,0 +1,19 @@
1pub fn main() void {
2 var x: u32 = undefined;
3 const maybe_x = byPtr(&x);
4 assert(maybe_x != null);
5 maybe_x.?.* = 123;
6 assert(x == 123);
7}
8
9fn byPtr(x: *u32) ?*u32 {
10 return x;
11}
12
13fn assert(ok: bool) void {
14 if (!ok) unreachable;
15}
16
17// run
18// target=x86_64-linux,x86_64-macos
19//
test/incremental/optional_payload.1.zig created+17
...@@ -0,0 +1,17 @@
1pub fn main() void {
2 var x: u32 = undefined;
3 const maybe_x = byPtr(&x);
4 assert(maybe_x == null);
5}
6
7fn byPtr(x: *u32) ?*u32 {
8 _ = x;
9 return null;
10}
11
12fn assert(ok: bool) void {
13 if (!ok) unreachable;
14}
15
16// run
17//
test/incremental/optional_payload.2.zig created+18
...@@ -0,0 +1,18 @@
1pub fn main() void {
2 var x: u8 = undefined;
3 const maybe_x = byPtr(&x);
4 assert(maybe_x != null);
5 maybe_x.?.* = 255;
6 assert(x == 255);
7}
8
9fn byPtr(x: *u8) ?*u8 {
10 return x;
11}
12
13fn assert(ok: bool) void {
14 if (!ok) unreachable;
15}
16
17// run
18//
test/incremental/optional_payload.3.zig created+18
...@@ -0,0 +1,18 @@
1pub fn main() void {
2 var x: i8 = undefined;
3 const maybe_x = byPtr(&x);
4 assert(maybe_x != null);
5 maybe_x.?.* = -1;
6 assert(x == -1);
7}
8
9fn byPtr(x: *i8) ?*i8 {
10 return x;
11}
12
13fn assert(ok: bool) void {
14 if (!ok) unreachable;
15}
16
17// run
18//
test/incremental/orelse_at_comptime.0.zig created+11
...@@ -0,0 +1,11 @@
1pub fn main() void {
2 const i: ?u64 = 0;
3 const result = i orelse 5;
4 assert(result == 0);
5}
6fn assert(b: bool) void {
7 if (!b) unreachable;
8}
9
10// run
11//
test/incremental/orelse_at_comptime.1.zig created+11
...@@ -0,0 +1,11 @@
1pub fn main() void {
2 const i: ?u64 = null;
3 const result = i orelse 5;
4 assert(result == 5);
5}
6fn assert(b: bool) void {
7 if (!b) unreachable;
8}
9
10// run
11//
test/incremental/passing_u0_to_function.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 doNothing(0);
3}
4fn doNothing(arg: u0) void {
5 _ = arg;
6}
7
8// run
9//
test/incremental/plan9/exit.zig created+5
...@@ -0,0 +1,5 @@
1pub fn main() void {}
2
3// run
4// target=x86_64-plan9,aarch64-plan9
5//
test/incremental/plan9/hello_world_with_updates.0.zig created+28
...@@ -0,0 +1,28 @@
1pub fn main() void {
2 const str = "Hello World!\n";
3 asm volatile (
4 \\push $0
5 \\push %%r10
6 \\push %%r11
7 \\push $1
8 \\push $0
9 \\syscall
10 \\pop %%r11
11 \\pop %%r11
12 \\pop %%r11
13 \\pop %%r11
14 \\pop %%r11
15 :
16 // pwrite
17 : [syscall_number] "{rbp}" (51),
18 [hey] "{r11}" (@ptrToInt(str)),
19 [strlen] "{r10}" (str.len),
20 : "rcx", "rbp", "r11", "memory"
21 );
22}
23
24// run
25// target=x86_64-plan9
26//
27// Hello World
28//
test/incremental/plan9/hello_world_with_updates.1.zig created+10
...@@ -0,0 +1,10 @@
1const std = @import("std");
2pub fn main() void {
3 const str = "Hello World!\n";
4 _ = std.os.plan9.pwrite(1, str, str.len, 0);
5}
6
7// run
8//
9// Hello World
10//
test/incremental/recursive_fibonacci.zig created+24
...@@ -0,0 +1,24 @@
1pub fn main() void {
2 assert(fib(0) == 0);
3 assert(fib(1) == 1);
4 assert(fib(2) == 1);
5 assert(fib(3) == 2);
6 assert(fib(10) == 55);
7 assert(fib(20) == 6765);
8}
9
10fn fib(n: u32) u32 {
11 if (n < 2) {
12 return n;
13 } else {
14 return fib(n - 2) + fib(n - 1);
15 }
16}
17
18fn assert(ok: bool) void {
19 if (!ok) unreachable;
20}
21
22// run
23// target=arm-linux,x86_64-linux,x86_64-macos,wasm32-wasi
24//
test/incremental/recursive_inline_function.0.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() void {
2 const y = fibonacci(7);
3 if (y - 21 != 0) unreachable;
4}
5
6inline fn fibonacci(n: usize) usize {
7 if (n <= 2) return n;
8 return fibonacci(n - 2) + fibonacci(n - 1);
9}
10
11// run
12//
test/incremental/recursive_inline_function.1.zig created+16
...@@ -0,0 +1,16 @@
1// This additionally tests that the compile error reports the correct source location.
2// Without storing source locations relative to the owner decl, the compile error
3// here would be off by 2 bytes (from the "7" -> "999").
4pub fn main() void {
5 const y = fibonacci(999);
6 if (y - 21 != 0) unreachable;
7}
8
9inline fn fibonacci(n: usize) usize {
10 if (n <= 2) return n;
11 return fibonacci(n - 2) + fibonacci(n - 1);
12}
13
14// error
15//
16// :11:21: error: evaluation exceeded 1000 backwards branches
test/incremental/redundant_comptime.0.zig created+7
...@@ -0,0 +1,7 @@
1pub fn main() void {
2 var a: comptime u32 = 0;
3}
4
5// error
6//
7// :2:12: error: redundant comptime keyword in already comptime scope
test/incremental/redundant_comptime.1.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 comptime {
3 var a: u32 = comptime 0;
4 }
5}
6
7// error
8//
9// :3:22: error: redundant comptime keyword in already comptime scope
test/incremental/returns_in_try.zig created+16
...@@ -0,0 +1,16 @@
1pub fn main() !void {
2 try a();
3 try b();
4}
5
6pub fn a() !void {
7 defer try b();
8}
9pub fn b() !void {
10 defer return a();
11}
12
13// error
14//
15// :7:11: error: 'try' not allowed inside defer expression
16// :10:11: error: cannot return from defer expression
test/incremental/riscv64-linux/hello_world_with_updates.0.zig created+21
...@@ -0,0 +1,21 @@
1pub fn main() void {
2 print();
3}
4
5fn print() void {
6 asm volatile ("ecall"
7 :
8 : [number] "{a7}" (64),
9 [arg1] "{a0}" (1),
10 [arg2] "{a1}" (@ptrToInt("Hello, World!\n")),
11 [arg3] "{a2}" ("Hello, World!\n".len),
12 : "rcx", "r11", "memory"
13 );
14 return;
15}
16
17// run
18// target=riscv64-linux
19//
20// Hello, World!
21//
test/incremental/riscv64-linux/hello_world_with_updates.1.zig created+27
...@@ -0,0 +1,27 @@
1pub fn main() void {
2 print();
3 print();
4 print();
5 print();
6}
7
8fn print() void {
9 asm volatile ("ecall"
10 :
11 : [number] "{a7}" (64),
12 [arg1] "{a0}" (1),
13 [arg2] "{a1}" (@ptrToInt("Hello, World!\n")),
14 [arg3] "{a2}" ("Hello, World!\n".len),
15 : "rcx", "r11", "memory"
16 );
17 return;
18}
19
20// run
21// target=riscv64-linux
22//
23// Hello, World!
24// Hello, World!
25// Hello, World!
26// Hello, World!
27//
test/incremental/runtime_bitwise_and.zig created+16
...@@ -0,0 +1,16 @@
1pub fn main() void {
2 var i: u32 = 10;
3 var j: u32 = 11;
4 assert(i & 1 == 0);
5 assert(j & 1 == 1);
6 var m1: u32 = 0b1111;
7 var m2: u32 = 0b0000;
8 assert(m1 & 0b1010 == 0b1010);
9 assert(m2 & 0b1010 == 0b0000);
10}
11fn assert(b: bool) void {
12 if (!b) unreachable;
13}
14
15// run
16//
test/incremental/runtime_bitwise_or.zig created+16
...@@ -0,0 +1,16 @@
1pub fn main() void {
2 var i: u32 = 10;
3 var j: u32 = 11;
4 assert(i | 1 == 11);
5 assert(j | 1 == 11);
6 var m1: u32 = 0b1111;
7 var m2: u32 = 0b0000;
8 assert(m1 | 0b1010 == 0b1111);
9 assert(m2 | 0b1010 == 0b1010);
10}
11fn assert(b: bool) void {
12 if (!b) unreachable;
13}
14
15// run
16//
test/incremental/save_function_return_values_in_callee_preserved_register.zig created+22
...@@ -0,0 +1,22 @@
1pub fn main() void {
2 assert(foo() == 43);
3}
4
5fn foo() u32 {
6 return bar() + baz(42);
7}
8
9fn bar() u32 {
10 return 1;
11}
12
13fn baz(x: u32) u32 {
14 return x;
15}
16
17fn assert(ok: bool) void {
18 if (!ok) unreachable;
19}
20
21// run
22//
test/incremental/setting_an_address_space_on_a_local_variable.zig created+8
...@@ -0,0 +1,8 @@
1export fn entry() i32 {
2 var foo: i32 addrspace(".general") = 1234;
3 return foo;
4}
5
6// error
7//
8// :2:28: error: cannot set address space of local variable 'foo'
test/incremental/sparcv9-linux/hello_world.zig created+27
...@@ -0,0 +1,27 @@
1const msg = "Hello, World!\n";
2
3pub export fn _start() noreturn {
4 asm volatile ("ta 0x6d"
5 :
6 : [number] "{g1}" (4),
7 [arg1] "{o0}" (1),
8 [arg2] "{o1}" (@ptrToInt(msg)),
9 [arg3] "{o2}" (msg.len),
10 : "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7", "memory"
11 );
12
13 asm volatile ("ta 0x6d"
14 :
15 : [number] "{g1}" (1),
16 [arg1] "{o0}" (0),
17 : "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7", "memory"
18 );
19
20 unreachable;
21}
22
23// run
24// target=sparcv9-linux
25//
26// Hello, World!
27//
test/incremental/try_in_comptime_in_struct_in_test.zig created+13
...@@ -0,0 +1,13 @@
1test "@unionInit on union w/ tag but no fields" {
2 const S = struct {
3 comptime {
4 try expect(false);
5 }
6 };
7 _ = S;
8}
9
10// error
11// is_test=1
12//
13// :4:13: error: 'try' outside function scope
test/incremental/type_of.0.zig created+13
...@@ -0,0 +1,13 @@
1pub fn main() void {
2 var x: usize = 0;
3 _ = x;
4 const z = @TypeOf(x, @as(u128, 5));
5 assert(z == u128);
6}
7
8pub fn assert(ok: bool) void {
9 if (!ok) unreachable; // assertion failure
10}
11
12// run
13//
test/incremental/type_of.1.zig created+11
...@@ -0,0 +1,11 @@
1pub fn main() void {
2 const z = @TypeOf(true);
3 assert(z == bool);
4}
5
6pub fn assert(ok: bool) void {
7 if (!ok) unreachable; // assertion failure
8}
9
10// run
11//
test/incremental/type_of.2.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 _ = @TypeOf(true, 1);
3}
4
5// error
6//
7// :2:9: error: incompatible types: 'bool' and 'comptime_int'
8// :2:17: note: type 'bool' here
9// :2:23: note: type 'comptime_int' here
test/incremental/unused_labels.0.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 foo: {}
3}
4
5// error
6// output_mode=Exe
7//
8// :2:5: error: unused block label
test/incremental/unused_labels.1.zig created+7
...@@ -0,0 +1,7 @@
1comptime {
2 foo: while (true) {}
3}
4
5// error
6//
7// :2:5: error: unused while loop label
test/incremental/unused_labels.2.zig created+7
...@@ -0,0 +1,7 @@
1comptime {
2 foo: for ("foo") |_| {}
3}
4
5// error
6//
7// :2:5: error: unused for loop label
test/incremental/unused_labels.3.zig created+8
...@@ -0,0 +1,8 @@
1comptime {
2 blk: {blk: {}}
3}
4
5// error
6//
7// :2:11: error: redefinition of label 'blk'
8// :2:5: note: previous definition here
test/incremental/unused_vars.zig created+7
...@@ -0,0 +1,7 @@
1pub fn main() void {
2 const x = 1;
3}
4
5// error
6//
7// :2:11: error: unused local constant
test/incremental/variable_shadowing.0.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 var i: u32 = 10;
3 var i: u32 = 10;
4}
5
6// error
7//
8// :3:9: error: redeclaration of local variable 'i'
9// :2:9: note: previous declaration here
test/incremental/variable_shadowing.1.zig created+9
...@@ -0,0 +1,9 @@
1var testing: i64 = 10;
2pub fn main() void {
3 var testing: i64 = 20;
4}
5
6// error
7//
8// :3:9: error: local shadows declaration of 'testing'
9// :1:1: note: declared here
test/incremental/variable_shadowing.2.zig created+13
...@@ -0,0 +1,13 @@
1fn a() type {
2 return struct {
3 pub fn b() void {
4 const c = 6;
5 const c = 69;
6 }
7 };
8}
9
10// error
11//
12// :5:19: error: redeclaration of local constant 'c'
13// :4:19: note: previous declaration here
test/incremental/variable_shadowing.3.zig created+10
...@@ -0,0 +1,10 @@
1pub fn main() void {
2 var i = 0;
3 for ("n") |_, i| {
4 }
5}
6
7// error
8//
9// :3:19: error: redeclaration of local variable 'i'
10// :2:9: note: previous declaration here
test/incremental/variable_shadowing.4.zig created+10
...@@ -0,0 +1,10 @@
1pub fn main() void {
2 var i = 0;
3 for ("n") |i| {
4 }
5}
6
7// error
8//
9// :3:16: error: redeclaration of local variable 'i'
10// :2:9: note: previous declaration here
test/incremental/variable_shadowing.5.zig created+10
...@@ -0,0 +1,10 @@
1pub fn main() void {
2 var i = 0;
3 while ("n") |i| {
4 }
5}
6
7// error
8//
9// :3:18: error: redeclaration of local variable 'i'
10// :2:9: note: previous declaration here
test/incremental/variable_shadowing.6.zig created+13
...@@ -0,0 +1,13 @@
1pub fn main() void {
2 var i = 0;
3 while ("n") |bruh| {
4 _ = bruh;
5 } else |i| {
6
7 }
8}
9
10// error
11//
12// :5:13: error: redeclaration of local variable 'i'
13// :2:9: note: previous declaration here
test/incremental/variable_shadowing.7.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 var i = 0;
3 if (true) |i| {}
4}
5
6// error
7//
8// :3:16: error: redeclaration of local variable 'i'
9// :2:9: note: previous declaration here
test/incremental/variable_shadowing.8.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 var i = 0;
3 if (true) |i| {} else |e| {}
4}
5
6// error
7//
8// :3:16: error: redeclaration of local variable 'i'
9// :2:9: note: previous declaration here
test/incremental/variable_shadowing.9.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 var i = 0;
3 if (true) |_| {} else |i| {}
4}
5
6// error
7//
8// :3:28: error: redeclaration of local variable 'i'
9// :2:9: note: previous declaration here
test/incremental/wasm-wasi/conditions.0.zig created+11
...@@ -0,0 +1,11 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 if (i > @as(u8, 4)) {
4 i += 10;
5 }
6 return i - 15;
7}
8
9// run
10// target=wasm32-wasi
11//
test/incremental/wasm-wasi/conditions.1.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 if (i < @as(u8, 4)) {
4 i += 10;
5 } else {
6 i = 2;
7 }
8 return i - 2;
9}
10
11// run
12//
test/incremental/wasm-wasi/conditions.2.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 if (i < @as(u8, 4)) {
4 i += 10;
5 } else if (i == @as(u8, 5)) {
6 i = 20;
7 }
8 return i - 20;
9}
10
11// run
12//
test/incremental/wasm-wasi/conditions.3.zig created+16
...@@ -0,0 +1,16 @@
1pub fn main() u8 {
2 var i: u8 = 11;
3 if (i < @as(u8, 4)) {
4 i += 10;
5 } else {
6 if (i > @as(u8, 10)) {
7 i += 20;
8 } else {
9 i = 20;
10 }
11 }
12 return i - 31;
13}
14
15// run
16//
test/incremental/wasm-wasi/conditions.4.zig created+15
...@@ -0,0 +1,15 @@
1pub fn main() void {
2 assert(foo(true) != @as(i32, 30));
3}
4
5fn assert(ok: bool) void {
6 if (!ok) unreachable;
7}
8
9fn foo(ok: bool) i32 {
10 const x = if (ok) @as(i32, 20) else @as(i32, 10);
11 return x;
12}
13
14// run
15//
test/incremental/wasm-wasi/conditions.5.zig created+20
...@@ -0,0 +1,20 @@
1pub fn main() void {
2 assert(foo(false) == @as(i32, 20));
3 assert(foo(true) == @as(i32, 30));
4}
5
6fn assert(ok: bool) void {
7 if (!ok) unreachable;
8}
9
10fn foo(ok: bool) i32 {
11 const val: i32 = blk: {
12 var x: i32 = 1;
13 if (!ok) break :blk x + @as(i32, 9);
14 break :blk x + @as(i32, 19);
15 };
16 return val + 10;
17}
18
19// run
20//
test/incremental/wasm-wasi/error_unions.0.zig created+15
...@@ -0,0 +1,15 @@
1pub fn main() void {
2 var e1 = error.Foo;
3 var e2 = error.Bar;
4 assert(e1 != e2);
5 assert(e1 == error.Foo);
6 assert(e2 == error.Bar);
7}
8
9fn assert(b: bool) void {
10 if (!b) unreachable;
11}
12
13// run
14// target=wasm32-wasi
15//
test/incremental/wasm-wasi/error_unions.1.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() u8 {
2 var e: anyerror!u8 = 5;
3 const i = e catch 10;
4 return i - 5;
5}
6
7// run
8//
test/incremental/wasm-wasi/error_unions.2.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() u8 {
2 var e: anyerror!u8 = error.Foo;
3 const i = e catch 10;
4 return i - 10;
5}
6
7// run
8//
test/incremental/wasm-wasi/error_unions.3.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var e = foo();
3 const i = e catch 69;
4 return i - 5;
5}
6
7fn foo() anyerror!u8 {
8 return 5;
9}
10
11// run
12//
test/incremental/wasm-wasi/error_unions.4.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var e = foo();
3 const i = e catch 69;
4 return i - 69;
5}
6
7fn foo() anyerror!u8 {
8 return error.Bruh;
9}
10
11// run
12//
test/incremental/wasm-wasi/error_unions.5.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var e = foo();
3 const i = e catch 42;
4 return i - 42;
5}
6
7fn foo() anyerror!u8 {
8 return error.Dab;
9}
10
11// run
12//
test/incremental/wasm-wasi/locals.0.zig created+14
...@@ -0,0 +1,14 @@
1pub fn main() void {
2 var i: u8 = 5;
3 var y: f32 = 42.0;
4 var x: u8 = 10;
5 if (false) {
6 y;
7 x;
8 }
9 if (i != 5) unreachable;
10}
11
12// run
13// target=wasm32-wasi
14//
test/incremental/wasm-wasi/locals.1.zig created+17
...@@ -0,0 +1,17 @@
1pub fn main() void {
2 var i: u8 = 5;
3 var y: f32 = 42.0;
4 _ = y;
5 var x: u8 = 10;
6 foo(i, x);
7 i = x;
8 if (i != 10) unreachable;
9}
10fn foo(x: u8, y: u8) void {
11 _ = y;
12 var i: u8 = 10;
13 i = x;
14}
15
16// run
17//
test/incremental/wasm-wasi/optionals.0.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var x: ?u8 = 5;
3 var y: u8 = 0;
4 if (x) |val| {
5 y = val;
6 }
7 return y - 5;
8}
9
10// run
11// target=wasm32-wasi
12//
test/incremental/wasm-wasi/optionals.1.zig created+11
...@@ -0,0 +1,11 @@
1pub fn main() u8 {
2 var x: ?u8 = null;
3 var y: u8 = 0;
4 if (x) |val| {
5 y = val;
6 }
7 return y;
8}
9
10// run
11//
test/incremental/wasm-wasi/optionals.2.zig created+7
...@@ -0,0 +1,7 @@
1pub fn main() u8 {
2 var x: ?u8 = 5;
3 return x.? - 5;
4}
5
6// run
7//
test/incremental/wasm-wasi/optionals.3.zig created+8
...@@ -0,0 +1,8 @@
1pub fn main() u8 {
2 var x: u8 = 5;
3 var y: ?u8 = x;
4 return y.? - 5;
5}
6
7// run
8//
test/incremental/wasm-wasi/optionals.4.zig created+13
...@@ -0,0 +1,13 @@
1pub fn main() u8 {
2 var val: ?u8 = 5;
3 while (val) |*v| {
4 v.* -= 1;
5 if (v.* == 2) {
6 val = null;
7 }
8 }
9 return 0;
10}
11
12// run
13//
test/incremental/wasm-wasi/pointers.0.zig created+14
...@@ -0,0 +1,14 @@
1pub fn main() u8 {
2 var x: u8 = 0;
3
4 foo(&x);
5 return x - 2;
6}
7
8fn foo(x: *u8) void {
9 x.* = 2;
10}
11
12// run
13// target=wasm32-wasi
14//
test/incremental/wasm-wasi/pointers.1.zig created+18
...@@ -0,0 +1,18 @@
1pub fn main() u8 {
2 var x: u8 = 0;
3
4 foo(&x);
5 bar(&x);
6 return x - 4;
7}
8
9fn foo(x: *u8) void {
10 x.* = 2;
11}
12
13fn bar(x: *u8) void {
14 x.* += 2;
15}
16
17// run
18//
test/incremental/wasm-wasi/structs.0.zig created+10
...@@ -0,0 +1,10 @@
1const Example = struct { x: u8 };
2
3pub fn main() u8 {
4 var example: Example = .{ .x = 5 };
5 return example.x - 5;
6}
7
8// run
9// target=wasm32-wasi
10//
test/incremental/wasm-wasi/structs.1.zig created+10
...@@ -0,0 +1,10 @@
1const Example = struct { x: u8 };
2
3pub fn main() u8 {
4 var example: Example = .{ .x = 5 };
5 example.x = 10;
6 return example.x - 10;
7}
8
9// run
10//
test/incremental/wasm-wasi/structs.2.zig created+9
...@@ -0,0 +1,9 @@
1const Example = struct { x: u8, y: u8 };
2
3pub fn main() u8 {
4 var example: Example = .{ .x = 5, .y = 10 };
5 return example.y + example.x - 15;
6}
7
8// run
9//
test/incremental/wasm-wasi/structs.3.zig created+12
...@@ -0,0 +1,12 @@
1const Example = struct { x: u8, y: u8 };
2
3pub fn main() u8 {
4 var example: Example = .{ .x = 5, .y = 10 };
5 var example2: Example = .{ .x = 10, .y = 20 };
6
7 example = example2;
8 return example.y + example.x - 30;
9}
10
11// run
12//
test/incremental/wasm-wasi/structs.4.zig created+11
...@@ -0,0 +1,11 @@
1const Example = struct { x: u8, y: u8 };
2
3pub fn main() u8 {
4 var example: Example = .{ .x = 5, .y = 10 };
5
6 example = .{ .x = 10, .y = 20 };
7 return example.y + example.x - 30;
8}
9
10// run
11//
test/incremental/wasm-wasi/switch.0.zig created+15
...@@ -0,0 +1,15 @@
1pub fn main() u8 {
2 var val: u8 = 1;
3 var a: u8 = switch (val) {
4 0, 1 => 2,
5 2 => 3,
6 3 => 4,
7 else => 5,
8 };
9
10 return a - 2;
11}
12
13// run
14// target=wasm32-wasi
15//
test/incremental/wasm-wasi/switch.1.zig created+14
...@@ -0,0 +1,14 @@
1pub fn main() u8 {
2 var val: u8 = 2;
3 var a: u8 = switch (val) {
4 0, 1 => 2,
5 2 => 3,
6 3 => 4,
7 else => 5,
8 };
9
10 return a - 3;
11}
12
13// run
14//
test/incremental/wasm-wasi/switch.2.zig created+14
...@@ -0,0 +1,14 @@
1pub fn main() u8 {
2 var val: u8 = 10;
3 var a: u8 = switch (val) {
4 0, 1 => 2,
5 2 => 3,
6 3 => 4,
7 else => 5,
8 };
9
10 return a - 5;
11}
12
13// run
14//
test/incremental/wasm-wasi/switch.3.zig created+15
...@@ -0,0 +1,15 @@
1const MyEnum = enum { One, Two, Three };
2
3pub fn main() u8 {
4 var val: MyEnum = .Two;
5 var a: u8 = switch (val) {
6 .One => 1,
7 .Two => 2,
8 .Three => 3,
9 };
10
11 return a - 2;
12}
13
14// run
15//
test/incremental/wasm-wasi/while_loops.0.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var i: u8 = 0;
3 while (i < @as(u8, 5)) {
4 i += 1;
5 }
6
7 return i - 5;
8}
9
10// run
11// target=wasm32-wasi
12//
test/incremental/wasm-wasi/while_loops.1.zig created+11
...@@ -0,0 +1,11 @@
1pub fn main() u8 {
2 var i: u8 = 0;
3 while (i < @as(u8, 10)) {
4 var x: u8 = 1;
5 i += x;
6 }
7 return i - 10;
8}
9
10// run
11//
test/incremental/wasm-wasi/while_loops.2.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var i: u8 = 0;
3 while (i < @as(u8, 10)) {
4 var x: u8 = 1;
5 i += x;
6 if (i == @as(u8, 5)) break;
7 }
8 return i - 5;
9}
10
11// run
12//
test/incremental/x86_64-linux/assert_function.0.zig created+15
...@@ -0,0 +1,15 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 assert(a + b == 7);
7}
8
9pub fn assert(ok: bool) void {
10 if (!ok) unreachable; // assertion failure
11}
12
13// run
14// target=x86_64-linux
15//
test/incremental/x86_64-linux/assert_function.1.zig created+17
...@@ -0,0 +1,17 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 assert(e == 14);
10}
11
12pub fn assert(ok: bool) void {
13 if (!ok) unreachable; // assertion failure
14}
15
16// run
17//
test/incremental/x86_64-linux/assert_function.10.zig created+27
...@@ -0,0 +1,27 @@
1pub fn main() void {
2 assert(add(3, 4) == 116);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 const f = d + e; // 24
11 const g = e + f; // 38
12 const h = f + g; // 62
13 const i = g + h; // 100
14 const j = i + d; // 110
15 break :blk j;
16 };
17 const y = x + a; // 113
18 const z = y + a; // 116
19 return z;
20}
21
22pub fn assert(ok: bool) void {
23 if (!ok) unreachable; // assertion failure
24}
25
26// run
27//
test/incremental/x86_64-linux/assert_function.11.zig created+66
...@@ -0,0 +1,66 @@
1pub fn main() void {
2 assert(add(3, 4) == 1221);
3 assert(mul(3, 4) == 21609);
4}
5
6fn add(a: u32, b: u32) u32 {
7 const x: u32 = blk: {
8 const c = a + b; // 7
9 const d = a + c; // 10
10 const e = d + b; // 14
11 const f = d + e; // 24
12 const g = e + f; // 38
13 const h = f + g; // 62
14 const i = g + h; // 100
15 const j = i + d; // 110
16 const k = i + j; // 210
17 const l = j + k; // 320
18 const m = l + c; // 327
19 const n = m + d; // 337
20 const o = n + e; // 351
21 const p = o + f; // 375
22 const q = p + g; // 413
23 const r = q + h; // 475
24 const s = r + i; // 575
25 const t = s + j; // 685
26 const u = t + k; // 895
27 const v = u + l; // 1215
28 break :blk v;
29 };
30 const y = x + a; // 1218
31 const z = y + a; // 1221
32 return z;
33}
34
35fn mul(a: u32, b: u32) u32 {
36 const x: u32 = blk: {
37 const c = a * a * a * a; // 81
38 const d = a * a * a * b; // 108
39 const e = a * a * b * a; // 108
40 const f = a * a * b * b; // 144
41 const g = a * b * a * a; // 108
42 const h = a * b * a * b; // 144
43 const i = a * b * b * a; // 144
44 const j = a * b * b * b; // 192
45 const k = b * a * a * a; // 108
46 const l = b * a * a * b; // 144
47 const m = b * a * b * a; // 144
48 const n = b * a * b * b; // 192
49 const o = b * b * a * a; // 144
50 const p = b * b * a * b; // 192
51 const q = b * b * b * a; // 192
52 const r = b * b * b * b; // 256
53 const s = c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r; // 2401
54 break :blk s;
55 };
56 const y = x * a; // 7203
57 const z = y * a; // 21609
58 return z;
59}
60
61pub fn assert(ok: bool) void {
62 if (!ok) unreachable; // assertion failure
63}
64
65// run
66//
test/incremental/x86_64-linux/assert_function.12.zig created+47
...@@ -0,0 +1,47 @@
1pub fn main() void {
2 assert(add(3, 4) == 791);
3 assert(add(4, 3) == 79);
4}
5
6fn add(a: u32, b: u32) u32 {
7 const x: u32 = if (a < b) blk: {
8 const c = a + b; // 7
9 const d = a + c; // 10
10 const e = d + b; // 14
11 const f = d + e; // 24
12 const g = e + f; // 38
13 const h = f + g; // 62
14 const i = g + h; // 100
15 const j = i + d; // 110
16 const k = i + j; // 210
17 const l = k + c; // 217
18 const m = l + d; // 227
19 const n = m + e; // 241
20 const o = n + f; // 265
21 const p = o + g; // 303
22 const q = p + h; // 365
23 const r = q + i; // 465
24 const s = r + j; // 575
25 const t = s + k; // 785
26 break :blk t;
27 } else blk: {
28 const t = b + b + a; // 10
29 const c = a + t; // 14
30 const d = c + t; // 24
31 const e = d + t; // 34
32 const f = e + t; // 44
33 const g = f + t; // 54
34 const h = c + g; // 68
35 break :blk h + b; // 71
36 };
37 const y = x + a; // 788, 75
38 const z = y + a; // 791, 79
39 return z;
40}
41
42pub fn assert(ok: bool) void {
43 if (!ok) unreachable; // assertion failure
44}
45
46// run
47//
test/incremental/x86_64-linux/assert_function.13.zig created+19
...@@ -0,0 +1,19 @@
1pub fn main() void {
2 const ignore =
3 \\ cool thx
4 \\
5 ;
6 _ = ignore;
7 add('ぁ', '\x03');
8}
9
10fn add(a: u32, b: u32) void {
11 assert(a + b == 12356);
12}
13
14pub fn assert(ok: bool) void {
15 if (!ok) unreachable; // assertion failure
16}
17
18// run
19//
test/incremental/x86_64-linux/assert_function.14.zig created+17
...@@ -0,0 +1,17 @@
1pub fn main() void {
2 add(aa, bb);
3}
4
5const aa = 'ぁ';
6const bb = '\x03';
7
8fn add(a: u32, b: u32) void {
9 assert(a + b == 12356);
10}
11
12pub fn assert(ok: bool) void {
13 if (!ok) unreachable; // assertion failure
14}
15
16// run
17//
test/incremental/x86_64-linux/assert_function.15.zig created+10
...@@ -0,0 +1,10 @@
1pub fn main() void {
2 assert("hello"[0] == 'h');
3}
4
5pub fn assert(ok: bool) void {
6 if (!ok) unreachable; // assertion failure
7}
8
9// run
10//
test/incremental/x86_64-linux/assert_function.16.zig created+11
...@@ -0,0 +1,11 @@
1const hello = "hello".*;
2pub fn main() void {
3 assert(hello[1] == 'e');
4}
5
6pub fn assert(ok: bool) void {
7 if (!ok) unreachable; // assertion failure
8}
9
10// run
11//
test/incremental/x86_64-linux/assert_function.17.zig created+11
...@@ -0,0 +1,11 @@
1pub fn main() void {
2 var i: u64 = 0xFFEEDDCCBBAA9988;
3 assert(i == 0xFFEEDDCCBBAA9988);
4}
5
6pub fn assert(ok: bool) void {
7 if (!ok) unreachable; // assertion failure
8}
9
10// run
11//
test/incremental/x86_64-linux/assert_function.18.zig created+35
...@@ -0,0 +1,35 @@
1const builtin = @import("builtin");
2
3extern "c" fn write(usize, usize, usize) usize;
4
5pub fn main() void {
6 for ("hello") |_| print();
7}
8
9fn print() void {
10 switch (builtin.os.tag) {
11 .linux => {
12 asm volatile ("syscall"
13 :
14 : [number] "{rax}" (1),
15 [arg1] "{rdi}" (1),
16 [arg2] "{rsi}" (@ptrToInt("hello\n")),
17 [arg3] "{rdx}" (6),
18 : "rcx", "r11", "memory"
19 );
20 },
21 .macos => {
22 _ = write(1, @ptrToInt("hello\n"), 6);
23 },
24 else => unreachable,
25 }
26}
27
28// run
29//
30// hello
31// hello
32// hello
33// hello
34// hello
35//
test/incremental/x86_64-linux/assert_function.2.zig created+21
...@@ -0,0 +1,21 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 const f = d + e; // 24
10 const g = e + f; // 38
11 const h = f + g; // 62
12 const i = g + h; // 100
13 assert(i == 100);
14}
15
16pub fn assert(ok: bool) void {
17 if (!ok) unreachable; // assertion failure
18}
19
20// run
21//
test/incremental/x86_64-linux/assert_function.3.zig created+22
...@@ -0,0 +1,22 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 const f = d + e; // 24
10 const g = e + f; // 38
11 const h = f + g; // 62
12 const i = g + h; // 100
13 const j = i + d; // 110
14 assert(j == 110);
15}
16
17pub fn assert(ok: bool) void {
18 if (!ok) unreachable; // assertion failure
19}
20
21// run
22//
test/incremental/x86_64-linux/assert_function.4.zig created+15
...@@ -0,0 +1,15 @@
1pub fn main() void {
2 assert(add(3, 4) == 7);
3 assert(add(20, 10) == 30);
4}
5
6fn add(a: u32, b: u32) u32 {
7 return a + b;
8}
9
10pub fn assert(ok: bool) void {
11 if (!ok) unreachable; // assertion failure
12}
13
14// run
15//
test/incremental/x86_64-linux/assert_function.5.zig created+19
...@@ -0,0 +1,19 @@
1pub fn main() void {
2 assert(add(3, 4) == 7);
3 assert(add(20, 10) == 30);
4}
5
6fn add(a: u32, b: u32) u32 {
7 var x: u32 = undefined;
8 x = 0;
9 x += a;
10 x += b;
11 return x;
12}
13
14pub fn assert(ok: bool) void {
15 if (!ok) unreachable; // assertion failure
16}
17
18// run
19//
test/incremental/x86_64-linux/assert_function.6.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 const a: u32 = 2;
3 const b: ?u32 = a;
4 const c = b.?;
5 if (c != 2) unreachable;
6}
7
8// run
9//
test/incremental/x86_64-linux/assert_function.7.zig created+28
...@@ -0,0 +1,28 @@
1pub fn main() void {
2 var i: u32 = 0;
3 while (i < 4) : (i += 1) print();
4 assert(i == 4);
5}
6
7fn print() void {
8 asm volatile ("syscall"
9 :
10 : [number] "{rax}" (1),
11 [arg1] "{rdi}" (1),
12 [arg2] "{rsi}" (@ptrToInt("hello\n")),
13 [arg3] "{rdx}" (6),
14 : "rcx", "r11", "memory"
15 );
16}
17
18pub fn assert(ok: bool) void {
19 if (!ok) unreachable; // assertion failure
20}
21
22// run
23//
24// hello
25// hello
26// hello
27// hello
28//
test/incremental/x86_64-linux/assert_function.8.zig created+24
...@@ -0,0 +1,24 @@
1pub fn main() void {
2 var i: u32 = 0;
3 inline while (i < 4) : (i += 1) print();
4 assert(i == 4);
5}
6
7fn print() void {
8 asm volatile ("syscall"
9 :
10 : [number] "{rax}" (1),
11 [arg1] "{rdi}" (1),
12 [arg2] "{rsi}" (@ptrToInt("hello\n")),
13 [arg3] "{rdx}" (6),
14 : "rcx", "r11", "memory"
15 );
16}
17
18pub fn assert(ok: bool) void {
19 if (!ok) unreachable; // assertion failure
20}
21
22// error
23//
24// :3:21: error: unable to resolve comptime value
test/incremental/x86_64-linux/assert_function.9.zig created+22
...@@ -0,0 +1,22 @@
1pub fn main() void {
2 assert(add(3, 4) == 20);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 break :blk e;
11 };
12 const y = x + a; // 17
13 const z = y + a; // 20
14 return z;
15}
16
17pub fn assert(ok: bool) void {
18 if (!ok) unreachable; // assertion failure
19}
20
21// run
22//
test/incremental/x86_64-linux/comptime_var.0.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() void {
2 var a: u32 = 0;
3 comptime var b: u32 = 0;
4 if (a == 0) b = 3;
5}
6
7// error
8// output_mode=Exe
9// target=x86_64-linux
10//
11// :4:21: error: store to comptime variable depends on runtime condition
12// :4:11: note: runtime condition here
test/incremental/x86_64-linux/comptime_var.1.zig created+13
...@@ -0,0 +1,13 @@
1pub fn main() void {
2 var a: u32 = 0;
3 comptime var b: u32 = 0;
4 switch (a) {
5 0 => {},
6 else => b = 3,
7 }
8}
9
10// error
11//
12// :6:21: error: store to comptime variable depends on runtime condition
13// :4:13: note: runtime condition here
test/incremental/x86_64-linux/comptime_var.2.zig created+22
...@@ -0,0 +1,22 @@
1pub fn main() void {
2 comptime var len: u32 = 5;
3 print(len);
4 len += 9;
5 print(len);
6}
7
8fn print(len: usize) void {
9 asm volatile ("syscall"
10 :
11 : [number] "{rax}" (1),
12 [arg1] "{rdi}" (1),
13 [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
14 [arg3] "{rdx}" (len),
15 : "rcx", "r11", "memory"
16 );
17}
18
19// run
20//
21// HelloHello, World!
22//
test/incremental/x86_64-linux/comptime_var.3.zig created+10
...@@ -0,0 +1,10 @@
1comptime {
2 var x: i32 = 1;
3 x += 1;
4 if (x != 1) unreachable;
5}
6pub fn main() void {}
7
8// error
9//
10// :4:17: error: unable to resolve comptime value
test/incremental/x86_64-linux/comptime_var.4.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 comptime var i: u64 = 0;
3 while (i < 5) : (i += 1) {}
4}
5
6// error
7//
8// :3:24: error: cannot store to comptime variable in non-inline loop
9// :3:5: note: non-inline loop here
test/incremental/x86_64-linux/comptime_var.5.zig created+15
...@@ -0,0 +1,15 @@
1pub fn main() void {
2 var a: u32 = 0;
3 if (a == 0) {
4 comptime var b: u32 = 0;
5 b = 1;
6 }
7}
8comptime {
9 var x: i32 = 1;
10 x += 1;
11 if (x != 2) unreachable;
12}
13
14// run
15//
test/incremental/x86_64-linux/comptime_var.6.zig created+20
...@@ -0,0 +1,20 @@
1pub fn main() void {
2 comptime var i: u64 = 2;
3 inline while (i < 6) : (i += 1) {
4 print(i);
5 }
6}
7fn print(len: usize) void {
8 asm volatile ("syscall"
9 :
10 : [number] "{rax}" (1),
11 [arg1] "{rdi}" (1),
12 [arg2] "{rsi}" (@ptrToInt("Hello")),
13 [arg3] "{rdx}" (len),
14 : "rcx", "r11", "memory"
15 );
16}
17
18// run
19//
20// HeHelHellHello
test/incremental/x86_64-linux/hello_world_with_updates.0.zig created+5
...@@ -0,0 +1,5 @@
1// error
2// output_mode=Exe
3// target=x86_64-linux
4//
5// :109:9: error: struct 'tmp.tmp' has no member named 'main'
test/incremental/x86_64-linux/hello_world_with_updates.1.zig created+5
...@@ -0,0 +1,5 @@
1pub export fn _start() noreturn {}
2
3// error
4//
5// :1:34: error: expected noreturn, found void
test/incremental/x86_64-linux/hello_world_with_updates.2.zig created+32
...@@ -0,0 +1,32 @@
1pub export fn _start() noreturn {
2 print();
3
4 exit();
5}
6
7fn print() void {
8 asm volatile ("syscall"
9 :
10 : [number] "{rax}" (1),
11 [arg1] "{rdi}" (1),
12 [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
13 [arg3] "{rdx}" (14),
14 : "rcx", "r11", "memory"
15 );
16 return;
17}
18
19fn exit() noreturn {
20 asm volatile ("syscall"
21 :
22 : [number] "{rax}" (231),
23 [arg1] "{rdi}" (0),
24 : "rcx", "r11", "memory"
25 );
26 unreachable;
27}
28
29// run
30//
31// Hello, World!
32//
test/incremental/x86_64-linux/hello_world_with_updates.3.zig created+20
...@@ -0,0 +1,20 @@
1pub fn main() void {
2 print();
3}
4
5fn print() void {
6 asm volatile ("syscall"
7 :
8 : [number] "{rax}" (1),
9 [arg1] "{rdi}" (1),
10 [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
11 [arg3] "{rdx}" (14),
12 : "rcx", "r11", "memory"
13 );
14 return;
15}
16
17// run
18//
19// Hello, World!
20//
test/incremental/x86_64-linux/hello_world_with_updates.4.zig created+20
...@@ -0,0 +1,20 @@
1pub fn main() void {
2 print();
3}
4
5fn print() void {
6 asm volatile ("syscall"
7 :
8 : [number] "{rax}" (1),
9 [arg1] "{rdi}" (1),
10 [arg2] "{rsi}" (@ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n")),
11 [arg3] "{rdx}" (104),
12 : "rcx", "r11", "memory"
13 );
14 return;
15}
16
17// run
18//
19// What is up? This is a longer message that will force the data to be relocated in virtual address space.
20//
test/incremental/x86_64-linux/hello_world_with_updates.5.zig created+22
...@@ -0,0 +1,22 @@
1pub fn main() void {
2 print();
3 print();
4}
5
6fn print() void {
7 asm volatile ("syscall"
8 :
9 : [number] "{rax}" (1),
10 [arg1] "{rdi}" (1),
11 [arg2] "{rsi}" (@ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n")),
12 [arg3] "{rdx}" (104),
13 : "rcx", "r11", "memory"
14 );
15 return;
16}
17
18// run
19//
20// What is up? This is a longer message that will force the data to be relocated in virtual address space.
21// What is up? This is a longer message that will force the data to be relocated in virtual address space.
22//
test/incremental/x86_64-linux/inline_assembly.0.zig created+16
...@@ -0,0 +1,16 @@
1pub fn main() void {
2 const number = 1234;
3 const x = asm volatile ("syscall"
4 : [o] "{rax}" (-> number),
5 : [number] "{rax}" (231),
6 [arg1] "{rdi}" (60),
7 : "rcx", "r11", "memory"
8 );
9 _ = x;
10}
11
12// error
13// output_mode=Exe
14// target=x86_64-linux
15//
16// :4:27: error: expected type, found comptime_int
test/incremental/x86_64-linux/inline_assembly.1.zig created+15
...@@ -0,0 +1,15 @@
1const S = struct {
2 comptime {
3 asm volatile (
4 \\zig_moment:
5 \\syscall
6 );
7 }
8};
9pub fn main() void {
10 _ = S;
11}
12
13// error
14//
15// :3:13: error: volatile is meaningless on global assembly
test/incremental/x86_64-linux/inline_assembly.2.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() void {
2 var bruh: u32 = 1;
3 asm (""
4 :
5 : [bruh] "{rax}" (4)
6 : "memory"
7 );
8}
9
10// error
11//
12// :3:5: error: assembly expression with no output must be marked volatile
test/incremental/x86_64-linux/inline_assembly.3.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() void {}
2comptime {
3 asm (""
4 :
5 : [bruh] "{rax}" (4)
6 : "memory"
7 );
8}
9
10// error
11//
12// :3:5: error: global assembly cannot have inputs, outputs, or clobbers
test/incremental/x86_64-linux/only_1_function_and_it_gets_updated.0.zig created+13
...@@ -0,0 +1,13 @@
1pub export fn _start() noreturn {
2 asm volatile ("syscall"
3 :
4 : [number] "{rax}" (60), // exit
5 [arg1] "{rdi}" (0),
6 : "rcx", "r11", "memory"
7 );
8 unreachable;
9}
10
11// run
12// target=x86_64-linux
13//
test/incremental/x86_64-linux/only_1_function_and_it_gets_updated.1.zig created+12
...@@ -0,0 +1,12 @@
1pub export fn _start() noreturn {
2 asm volatile ("syscall"
3 :
4 : [number] "{rax}" (231), // exit_group
5 [arg1] "{rdi}" (0),
6 : "rcx", "r11", "memory"
7 );
8 unreachable;
9}
10
11// run
12//
test/incremental/x86_64-macos/assert_function.0.zig created+15
...@@ -0,0 +1,15 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 assert(a + b == 7);
7}
8
9pub fn assert(ok: bool) void {
10 if (!ok) unreachable; // assertion failure
11}
12
13// run
14// target=x86_64-macos
15//
test/incremental/x86_64-macos/assert_function.1.zig created+17
...@@ -0,0 +1,17 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 assert(e == 14);
10}
11
12pub fn assert(ok: bool) void {
13 if (!ok) unreachable; // assertion failure
14}
15
16// run
17//
test/incremental/x86_64-macos/assert_function.10.zig created+27
...@@ -0,0 +1,27 @@
1pub fn main() void {
2 assert(add(3, 4) == 116);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 const f = d + e; // 24
11 const g = e + f; // 38
12 const h = f + g; // 62
13 const i = g + h; // 100
14 const j = i + d; // 110
15 break :blk j;
16 };
17 const y = x + a; // 113
18 const z = y + a; // 116
19 return z;
20}
21
22pub fn assert(ok: bool) void {
23 if (!ok) unreachable; // assertion failure
24}
25
26// run
27//
test/incremental/x86_64-macos/assert_function.11.zig created+66
...@@ -0,0 +1,66 @@
1pub fn main() void {
2 assert(add(3, 4) == 1221);
3 assert(mul(3, 4) == 21609);
4}
5
6fn add(a: u32, b: u32) u32 {
7 const x: u32 = blk: {
8 const c = a + b; // 7
9 const d = a + c; // 10
10 const e = d + b; // 14
11 const f = d + e; // 24
12 const g = e + f; // 38
13 const h = f + g; // 62
14 const i = g + h; // 100
15 const j = i + d; // 110
16 const k = i + j; // 210
17 const l = j + k; // 320
18 const m = l + c; // 327
19 const n = m + d; // 337
20 const o = n + e; // 351
21 const p = o + f; // 375
22 const q = p + g; // 413
23 const r = q + h; // 475
24 const s = r + i; // 575
25 const t = s + j; // 685
26 const u = t + k; // 895
27 const v = u + l; // 1215
28 break :blk v;
29 };
30 const y = x + a; // 1218
31 const z = y + a; // 1221
32 return z;
33}
34
35fn mul(a: u32, b: u32) u32 {
36 const x: u32 = blk: {
37 const c = a * a * a * a; // 81
38 const d = a * a * a * b; // 108
39 const e = a * a * b * a; // 108
40 const f = a * a * b * b; // 144
41 const g = a * b * a * a; // 108
42 const h = a * b * a * b; // 144
43 const i = a * b * b * a; // 144
44 const j = a * b * b * b; // 192
45 const k = b * a * a * a; // 108
46 const l = b * a * a * b; // 144
47 const m = b * a * b * a; // 144
48 const n = b * a * b * b; // 192
49 const o = b * b * a * a; // 144
50 const p = b * b * a * b; // 192
51 const q = b * b * b * a; // 192
52 const r = b * b * b * b; // 256
53 const s = c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r; // 2401
54 break :blk s;
55 };
56 const y = x * a; // 7203
57 const z = y * a; // 21609
58 return z;
59}
60
61pub fn assert(ok: bool) void {
62 if (!ok) unreachable; // assertion failure
63}
64
65// run
66//
test/incremental/x86_64-macos/assert_function.12.zig created+47
...@@ -0,0 +1,47 @@
1pub fn main() void {
2 assert(add(3, 4) == 791);
3 assert(add(4, 3) == 79);
4}
5
6fn add(a: u32, b: u32) u32 {
7 const x: u32 = if (a < b) blk: {
8 const c = a + b; // 7
9 const d = a + c; // 10
10 const e = d + b; // 14
11 const f = d + e; // 24
12 const g = e + f; // 38
13 const h = f + g; // 62
14 const i = g + h; // 100
15 const j = i + d; // 110
16 const k = i + j; // 210
17 const l = k + c; // 217
18 const m = l + d; // 227
19 const n = m + e; // 241
20 const o = n + f; // 265
21 const p = o + g; // 303
22 const q = p + h; // 365
23 const r = q + i; // 465
24 const s = r + j; // 575
25 const t = s + k; // 785
26 break :blk t;
27 } else blk: {
28 const t = b + b + a; // 10
29 const c = a + t; // 14
30 const d = c + t; // 24
31 const e = d + t; // 34
32 const f = e + t; // 44
33 const g = f + t; // 54
34 const h = c + g; // 68
35 break :blk h + b; // 71
36 };
37 const y = x + a; // 788, 75
38 const z = y + a; // 791, 79
39 return z;
40}
41
42pub fn assert(ok: bool) void {
43 if (!ok) unreachable; // assertion failure
44}
45
46// run
47//
test/incremental/x86_64-macos/assert_function.13.zig created+19
...@@ -0,0 +1,19 @@
1pub fn main() void {
2 const ignore =
3 \\ cool thx
4 \\
5 ;
6 _ = ignore;
7 add('ぁ', '\x03');
8}
9
10fn add(a: u32, b: u32) void {
11 assert(a + b == 12356);
12}
13
14pub fn assert(ok: bool) void {
15 if (!ok) unreachable; // assertion failure
16}
17
18// run
19//
test/incremental/x86_64-macos/assert_function.14.zig created+17
...@@ -0,0 +1,17 @@
1pub fn main() void {
2 add(aa, bb);
3}
4
5const aa = 'ぁ';
6const bb = '\x03';
7
8fn add(a: u32, b: u32) void {
9 assert(a + b == 12356);
10}
11
12pub fn assert(ok: bool) void {
13 if (!ok) unreachable; // assertion failure
14}
15
16// run
17//
test/incremental/x86_64-macos/assert_function.15.zig created+10
...@@ -0,0 +1,10 @@
1pub fn main() void {
2 assert("hello"[0] == 'h');
3}
4
5pub fn assert(ok: bool) void {
6 if (!ok) unreachable; // assertion failure
7}
8
9// run
10//
test/incremental/x86_64-macos/assert_function.16.zig created+11
...@@ -0,0 +1,11 @@
1const hello = "hello".*;
2pub fn main() void {
3 assert(hello[1] == 'e');
4}
5
6pub fn assert(ok: bool) void {
7 if (!ok) unreachable; // assertion failure
8}
9
10// run
11//
test/incremental/x86_64-macos/assert_function.17.zig created+11
...@@ -0,0 +1,11 @@
1pub fn main() void {
2 var i: u64 = 0xFFEEDDCCBBAA9988;
3 assert(i == 0xFFEEDDCCBBAA9988);
4}
5
6pub fn assert(ok: bool) void {
7 if (!ok) unreachable; // assertion failure
8}
9
10// run
11//
test/incremental/x86_64-macos/assert_function.18.zig created+35
...@@ -0,0 +1,35 @@
1const builtin = @import("builtin");
2
3extern "c" fn write(usize, usize, usize) usize;
4
5pub fn main() void {
6 for ("hello") |_| print();
7}
8
9fn print() void {
10 switch (builtin.os.tag) {
11 .linux => {
12 asm volatile ("syscall"
13 :
14 : [number] "{rax}" (1),
15 [arg1] "{rdi}" (1),
16 [arg2] "{rsi}" (@ptrToInt("hello\n")),
17 [arg3] "{rdx}" (6),
18 : "rcx", "r11", "memory"
19 );
20 },
21 .macos => {
22 _ = write(1, @ptrToInt("hello\n"), 6);
23 },
24 else => unreachable,
25 }
26}
27
28// run
29//
30// hello
31// hello
32// hello
33// hello
34// hello
35//
test/incremental/x86_64-macos/assert_function.2.zig created+21
...@@ -0,0 +1,21 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 const f = d + e; // 24
10 const g = e + f; // 38
11 const h = f + g; // 62
12 const i = g + h; // 100
13 assert(i == 100);
14}
15
16pub fn assert(ok: bool) void {
17 if (!ok) unreachable; // assertion failure
18}
19
20// run
21//
test/incremental/x86_64-macos/assert_function.3.zig created+22
...@@ -0,0 +1,22 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 const f = d + e; // 24
10 const g = e + f; // 38
11 const h = f + g; // 62
12 const i = g + h; // 100
13 const j = i + d; // 110
14 assert(j == 110);
15}
16
17pub fn assert(ok: bool) void {
18 if (!ok) unreachable; // assertion failure
19}
20
21// run
22//
test/incremental/x86_64-macos/assert_function.4.zig created+15
...@@ -0,0 +1,15 @@
1pub fn main() void {
2 assert(add(3, 4) == 7);
3 assert(add(20, 10) == 30);
4}
5
6fn add(a: u32, b: u32) u32 {
7 return a + b;
8}
9
10pub fn assert(ok: bool) void {
11 if (!ok) unreachable; // assertion failure
12}
13
14// run
15//
test/incremental/x86_64-macos/assert_function.5.zig created+19
...@@ -0,0 +1,19 @@
1pub fn main() void {
2 assert(add(3, 4) == 7);
3 assert(add(20, 10) == 30);
4}
5
6fn add(a: u32, b: u32) u32 {
7 var x: u32 = undefined;
8 x = 0;
9 x += a;
10 x += b;
11 return x;
12}
13
14pub fn assert(ok: bool) void {
15 if (!ok) unreachable; // assertion failure
16}
17
18// run
19//
test/incremental/x86_64-macos/assert_function.6.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 const a: u32 = 2;
3 const b: ?u32 = a;
4 const c = b.?;
5 if (c != 2) unreachable;
6}
7
8// run
9//
test/incremental/x86_64-macos/assert_function.7.zig created+23
...@@ -0,0 +1,23 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 var i: u32 = 0;
5 while (i < 4) : (i += 1) print();
6 assert(i == 4);
7}
8
9fn print() void {
10 _ = write(1, @ptrToInt("hello\n"), 6);
11}
12
13pub fn assert(ok: bool) void {
14 if (!ok) unreachable; // assertion failure
15}
16
17// run
18//
19// hello
20// hello
21// hello
22// hello
23//
test/incremental/x86_64-macos/assert_function.8.zig created+19
...@@ -0,0 +1,19 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 var i: u32 = 0;
5 inline while (i < 4) : (i += 1) print();
6 assert(i == 4);
7}
8
9fn print() void {
10 _ = write(1, @ptrToInt("hello\n"), 6);
11}
12
13pub fn assert(ok: bool) void {
14 if (!ok) unreachable; // assertion failure
15}
16
17// error
18//
19// :5:21: error: unable to resolve comptime value
test/incremental/x86_64-macos/assert_function.9.zig created+22
...@@ -0,0 +1,22 @@
1pub fn main() void {
2 assert(add(3, 4) == 20);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 break :blk e;
11 };
12 const y = x + a; // 17
13 const z = y + a; // 20
14 return z;
15}
16
17pub fn assert(ok: bool) void {
18 if (!ok) unreachable; // assertion failure
19}
20
21// run
22//
test/incremental/x86_64-macos/comptime_var.0.zig created+12
...@@ -0,0 +1,12 @@
1pub fn main() void {
2 var a: u32 = 0;
3 comptime var b: u32 = 0;
4 if (a == 0) b = 3;
5}
6
7// error
8// output_mode=Exe
9// target=x86_64-macos
10//
11// :4:21: error: store to comptime variable depends on runtime condition
12// :4:11: note: runtime condition here
test/incremental/x86_64-macos/comptime_var.1.zig created+13
...@@ -0,0 +1,13 @@
1pub fn main() void {
2 var a: u32 = 0;
3 comptime var b: u32 = 0;
4 switch (a) {
5 0 => {},
6 else => b = 3,
7 }
8}
9
10// error
11//
12// :6:21: error: store to comptime variable depends on runtime condition
13// :4:13: note: runtime condition here
test/incremental/x86_64-macos/comptime_var.2.zig created+17
...@@ -0,0 +1,17 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 comptime var len: u32 = 5;
5 print(len);
6 len += 9;
7 print(len);
8}
9
10fn print(len: usize) void {
11 _ = write(1, @ptrToInt("Hello, World!\n"), len);
12}
13
14// run
15//
16// HelloHello, World!
17//
test/incremental/x86_64-macos/comptime_var.3.zig created+10
...@@ -0,0 +1,10 @@
1comptime {
2 var x: i32 = 1;
3 x += 1;
4 if (x != 1) unreachable;
5}
6pub fn main() void {}
7
8// error
9//
10// :4:17: error: unable to resolve comptime value
test/incremental/x86_64-macos/comptime_var.4.zig created+9
...@@ -0,0 +1,9 @@
1pub fn main() void {
2 comptime var i: u64 = 0;
3 while (i < 5) : (i += 1) {}
4}
5
6// error
7//
8// :3:24: error: cannot store to comptime variable in non-inline loop
9// :3:5: note: non-inline loop here
test/incremental/x86_64-macos/comptime_var.5.zig created+15
...@@ -0,0 +1,15 @@
1pub fn main() void {
2 var a: u32 = 0;
3 if (a == 0) {
4 comptime var b: u32 = 0;
5 b = 1;
6 }
7}
8comptime {
9 var x: i32 = 1;
10 x += 1;
11 if (x != 2) unreachable;
12}
13
14// run
15//
test/incremental/x86_64-macos/comptime_var.6.zig created+15
...@@ -0,0 +1,15 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 comptime var i: u64 = 2;
5 inline while (i < 6) : (i += 1) {
6 print(i);
7 }
8}
9fn print(len: usize) void {
10 _ = write(1, @ptrToInt("Hello"), len);
11}
12
13// run
14//
15// HeHelHellHello
test/incremental/x86_64-macos/hello_world_with_updates.0.zig created+5
...@@ -0,0 +1,5 @@
1// error
2// output_mode=Exe
3// target=x86_64-macos
4//
5// :109:9: error: struct 'tmp.tmp' has no member named 'main'
test/incremental/x86_64-macos/hello_world_with_updates.1.zig created+5
...@@ -0,0 +1,5 @@
1pub export fn main() noreturn {}
2
3// error
4//
5// :1:32: error: expected noreturn, found void
test/incremental/x86_64-macos/hello_world_with_updates.2.zig created+19
...@@ -0,0 +1,19 @@
1extern "c" fn write(usize, usize, usize) usize;
2extern "c" fn exit(usize) noreturn;
3
4pub export fn main() noreturn {
5 print();
6
7 exit(0);
8}
9
10fn print() void {
11 const msg = @ptrToInt("Hello, World!\n");
12 const len = 14;
13 _ = write(1, msg, len);
14}
15
16// run
17//
18// Hello, World!
19//
test/incremental/x86_64-macos/hello_world_with_updates.3.zig created+16
...@@ -0,0 +1,16 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 print();
5}
6
7fn print() void {
8 const msg = @ptrToInt("Hello, World!\n");
9 const len = 14;
10 _ = write(1, msg, len);
11}
12
13// run
14//
15// Hello, World!
16//
test/incremental/x86_64-macos/hello_world_with_updates.4.zig created+22
...@@ -0,0 +1,22 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 print();
5 print();
6 print();
7 print();
8}
9
10fn print() void {
11 const msg = @ptrToInt("Hello, World!\n");
12 const len = 14;
13 _ = write(1, msg, len);
14}
15
16// run
17//
18// Hello, World!
19// Hello, World!
20// Hello, World!
21// Hello, World!
22//
test/incremental/x86_64-macos/hello_world_with_updates.5.zig created+16
...@@ -0,0 +1,16 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 print();
5}
6
7fn print() void {
8 const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
9 const len = 104;
10 _ = write(1, msg, len);
11}
12
13// run
14//
15// What is up? This is a longer message that will force the data to be relocated in virtual address space.
16//
test/incremental/x86_64-macos/hello_world_with_updates.6.zig created+18
...@@ -0,0 +1,18 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 print();
5 print();
6}
7
8fn print() void {
9 const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
10 const len = 104;
11 _ = write(1, msg, len);
12}
13
14// run
15//
16// What is up? This is a longer message that will force the data to be relocated in virtual address space.
17// What is up? This is a longer message that will force the data to be relocated in virtual address space.
18//
test/stage2/aarch64.zig deleted-271
...@@ -1,271 +0,0 @@
1const std = @import("std");
2const CrossTarget = std.zig.CrossTarget;
3const TestContext = @import("../../src/test.zig").TestContext;
4
5const linux_aarch64 = CrossTarget{
6 .cpu_arch = .aarch64,
7 .os_tag = .linux,
8};
9const macos_aarch64 = CrossTarget{
10 .cpu_arch = .aarch64,
11 .os_tag = .macos,
12};
13
14pub fn addCases(ctx: *TestContext) !void {
15 // Linux tests
16 {
17 var case = ctx.exe("linux_aarch64 hello world", linux_aarch64);
18 // Regular old hello world
19 case.addCompareOutput(
20 \\pub fn main() void {
21 \\ print();
22 \\}
23 \\
24 \\fn print() void {
25 \\ asm volatile ("svc #0"
26 \\ :
27 \\ : [number] "{x8}" (64),
28 \\ [arg1] "{x0}" (1),
29 \\ [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
30 \\ [arg3] "{x2}" ("Hello, World!\n".len)
31 \\ : "memory", "cc"
32 \\ );
33 \\}
34 ,
35 "Hello, World!\n",
36 );
37 }
38
39 {
40 var case = ctx.exe("exit fn taking argument", linux_aarch64);
41
42 case.addCompareOutput(
43 \\pub export fn _start() noreturn {
44 \\ exit(0);
45 \\}
46 \\
47 \\fn exit(ret: usize) noreturn {
48 \\ asm volatile ("svc #0"
49 \\ :
50 \\ : [number] "{x8}" (93),
51 \\ [arg1] "{x0}" (ret)
52 \\ : "memory", "cc"
53 \\ );
54 \\ unreachable;
55 \\}
56 ,
57 "",
58 );
59 }
60
61 {
62 var case = ctx.exe("conditional branches", linux_aarch64);
63
64 case.addCompareOutput(
65 \\pub fn main() void {
66 \\ foo(123);
67 \\}
68 \\
69 \\fn foo(x: u64) void {
70 \\ if (x > 42) {
71 \\ print();
72 \\ }
73 \\}
74 \\
75 \\fn print() void {
76 \\ asm volatile ("svc #0"
77 \\ :
78 \\ : [number] "{x8}" (64),
79 \\ [arg1] "{x0}" (1),
80 \\ [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
81 \\ [arg3] "{x2}" ("Hello, World!\n".len),
82 \\ : "memory", "cc"
83 \\ );
84 \\}
85 ,
86 "Hello, World!\n",
87 );
88
89 case.addCompareOutput(
90 \\pub fn main() void {
91 \\ foo(true);
92 \\}
93 \\
94 \\fn foo(x: bool) void {
95 \\ if (x) {
96 \\ print();
97 \\ }
98 \\}
99 \\
100 \\fn print() void {
101 \\ asm volatile ("svc #0"
102 \\ :
103 \\ : [number] "{x8}" (64),
104 \\ [arg1] "{x0}" (1),
105 \\ [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
106 \\ [arg3] "{x2}" ("Hello, World!\n".len),
107 \\ : "memory", "cc"
108 \\ );
109 \\}
110 ,
111 "Hello, World!\n",
112 );
113 }
114
115 {
116 var case = ctx.exe("large add function", linux_aarch64);
117
118 case.addCompareOutput(
119 \\pub fn main() void {
120 \\ assert(add(3, 4) == 791);
121 \\}
122 \\
123 \\fn add(a: u32, b: u32) u32 {
124 \\ const x: u32 = blk: {
125 \\ const c = a + b; // 7
126 \\ const d = a + c; // 10
127 \\ const e = d + b; // 14
128 \\ const f = d + e; // 24
129 \\ const g = e + f; // 38
130 \\ const h = f + g; // 62
131 \\ const i = g + h; // 100
132 \\ const j = i + d; // 110
133 \\ const k = i + j; // 210
134 \\ const l = k + c; // 217
135 \\ const m = l + d; // 227
136 \\ const n = m + e; // 241
137 \\ const o = n + f; // 265
138 \\ const p = o + g; // 303
139 \\ const q = p + h; // 365
140 \\ const r = q + i; // 465
141 \\ const s = r + j; // 575
142 \\ const t = s + k; // 785
143 \\ break :blk t;
144 \\ };
145 \\ const y = x + a; // 788
146 \\ const z = y + a; // 791
147 \\ return z;
148 \\}
149 \\
150 \\fn assert(ok: bool) void {
151 \\ if (!ok) unreachable;
152 \\}
153 ,
154 "",
155 );
156 }
157
158 // macOS tests
159 {
160 var case = ctx.exe("hello world with updates", macos_aarch64);
161 case.addError("", &[_][]const u8{
162 ":109:9: error: struct 'tmp.tmp' has no member named 'main'",
163 });
164
165 // Incorrect return type
166 case.addError(
167 \\pub export fn main() noreturn {
168 \\}
169 , &[_][]const u8{
170 ":2:1: error: expected noreturn, found void",
171 });
172
173 // Regular old hello world
174 case.addCompareOutput(
175 \\extern "c" fn write(usize, usize, usize) usize;
176 \\extern "c" fn exit(usize) noreturn;
177 \\
178 \\pub export fn main() noreturn {
179 \\ print();
180 \\
181 \\ exit(0);
182 \\}
183 \\
184 \\fn print() void {
185 \\ const msg = @ptrToInt("Hello, World!\n");
186 \\ const len = 14;
187 \\ _ = write(1, msg, len);
188 \\}
189 ,
190 "Hello, World!\n",
191 );
192
193 // Now using start.zig without an explicit extern exit fn
194 case.addCompareOutput(
195 \\extern "c" fn write(usize, usize, usize) usize;
196 \\
197 \\pub fn main() void {
198 \\ print();
199 \\}
200 \\
201 \\fn print() void {
202 \\ const msg = @ptrToInt("Hello, World!\n");
203 \\ const len = 14;
204 \\ _ = write(1, msg, len);
205 \\}
206 ,
207 "Hello, World!\n",
208 );
209
210 // Print it 4 times and force growth and realloc.
211 case.addCompareOutput(
212 \\extern "c" fn write(usize, usize, usize) usize;
213 \\
214 \\pub fn main() void {
215 \\ print();
216 \\ print();
217 \\ print();
218 \\ print();
219 \\}
220 \\
221 \\fn print() void {
222 \\ const msg = @ptrToInt("Hello, World!\n");
223 \\ const len = 14;
224 \\ _ = write(1, msg, len);
225 \\}
226 ,
227 \\Hello, World!
228 \\Hello, World!
229 \\Hello, World!
230 \\Hello, World!
231 \\
232 );
233
234 // Print it once, and change the message.
235 case.addCompareOutput(
236 \\extern "c" fn write(usize, usize, usize) usize;
237 \\
238 \\pub fn main() void {
239 \\ print();
240 \\}
241 \\
242 \\fn print() void {
243 \\ const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
244 \\ const len = 104;
245 \\ _ = write(1, msg, len);
246 \\}
247 ,
248 "What is up? This is a longer message that will force the data to be relocated in virtual address space.\n",
249 );
250
251 // Now we print it twice.
252 case.addCompareOutput(
253 \\extern "c" fn write(usize, usize, usize) usize;
254 \\
255 \\pub fn main() void {
256 \\ print();
257 \\ print();
258 \\}
259 \\
260 \\fn print() void {
261 \\ const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
262 \\ const len = 104;
263 \\ _ = write(1, msg, len);
264 \\}
265 ,
266 \\What is up? This is a longer message that will force the data to be relocated in virtual address space.
267 \\What is up? This is a longer message that will force the data to be relocated in virtual address space.
268 \\
269 );
270 }
271}
test/stage2/arm.zig deleted-798
...@@ -1,798 +0,0 @@
1const std = @import("std");
2const TestContext = @import("../../src/test.zig").TestContext;
3
4const linux_arm = std.zig.CrossTarget{
5 .cpu_arch = .arm,
6 .os_tag = .linux,
7};
8
9pub fn addCases(ctx: *TestContext) !void {
10 {
11 var case = ctx.exe("linux_arm hello world", linux_arm);
12 // Hello world using _start and inline asm.
13 case.addCompareOutput(
14 \\pub export fn _start() noreturn {
15 \\ print();
16 \\ exit();
17 \\}
18 \\
19 \\fn print() void {
20 \\ asm volatile ("svc #0"
21 \\ :
22 \\ : [number] "{r7}" (4),
23 \\ [arg1] "{r0}" (1),
24 \\ [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
25 \\ [arg3] "{r2}" (14)
26 \\ : "memory"
27 \\ );
28 \\ return;
29 \\}
30 \\
31 \\fn exit() noreturn {
32 \\ asm volatile ("svc #0"
33 \\ :
34 \\ : [number] "{r7}" (1),
35 \\ [arg1] "{r0}" (0)
36 \\ : "memory"
37 \\ );
38 \\ unreachable;
39 \\}
40 ,
41 "Hello, World!\n",
42 );
43 }
44
45 {
46 var case = ctx.exe("parameters and return values", linux_arm);
47 // Testing simple parameters and return values
48 //
49 // TODO: The parameters to the asm statement in print() had to
50 // be in a specific order because otherwise the write to r0
51 // would overwrite the len parameter which resides in r0
52 case.addCompareOutput(
53 \\pub fn main() void {
54 \\ print(id(14));
55 \\}
56 \\
57 \\fn id(x: u32) u32 {
58 \\ return x;
59 \\}
60 \\
61 \\fn print(len: u32) void {
62 \\ asm volatile ("svc #0"
63 \\ :
64 \\ : [number] "{r7}" (4),
65 \\ [arg3] "{r2}" (len),
66 \\ [arg1] "{r0}" (1),
67 \\ [arg2] "{r1}" (@ptrToInt("Hello, World!\n"))
68 \\ : "memory"
69 \\ );
70 \\ return;
71 \\}
72 ,
73 "Hello, World!\n",
74 );
75
76 case.addCompareOutput(
77 \\pub fn main() void {
78 \\ assert(add(1, 2, 3, 4, 5, 6) == 21);
79 \\}
80 \\
81 \\fn add(a: u32, b: u32, c: u32, d: u32, e: u32, f: u32) u32 {
82 \\ return a + b + c + d + e + f;
83 \\}
84 \\
85 \\pub fn assert(ok: bool) void {
86 \\ if (!ok) unreachable; // assertion failure
87 \\}
88 ,
89 "",
90 );
91 }
92
93 {
94 var case = ctx.exe("non-leaf functions", linux_arm);
95 // Testing non-leaf functions
96 case.addCompareOutput(
97 \\pub fn main() void {
98 \\ foo();
99 \\}
100 \\
101 \\fn foo() void {
102 \\ bar();
103 \\}
104 \\
105 \\fn bar() void {}
106 ,
107 "",
108 );
109 }
110
111 {
112 var case = ctx.exe("arithmetic operations", linux_arm);
113
114 // Add two numbers
115 case.addCompareOutput(
116 \\pub fn main() void {
117 \\ print(2, 4);
118 \\ print(1, 7);
119 \\}
120 \\
121 \\fn print(a: u32, b: u32) void {
122 \\ asm volatile ("svc #0"
123 \\ :
124 \\ : [number] "{r7}" (4),
125 \\ [arg3] "{r2}" (a + b),
126 \\ [arg1] "{r0}" (1),
127 \\ [arg2] "{r1}" (@ptrToInt("123456789"))
128 \\ : "memory"
129 \\ );
130 \\ return;
131 \\}
132 ,
133 "12345612345678",
134 );
135
136 // Subtract two numbers
137 case.addCompareOutput(
138 \\pub fn main() void {
139 \\ print(10, 5);
140 \\ print(4, 3);
141 \\}
142 \\
143 \\fn print(a: u32, b: u32) void {
144 \\ asm volatile ("svc #0"
145 \\ :
146 \\ : [number] "{r7}" (4),
147 \\ [arg3] "{r2}" (a - b),
148 \\ [arg1] "{r0}" (1),
149 \\ [arg2] "{r1}" (@ptrToInt("123456789"))
150 \\ : "memory"
151 \\ );
152 \\ return;
153 \\}
154 ,
155 "123451",
156 );
157
158 // Bitwise And
159 case.addCompareOutput(
160 \\pub fn main() void {
161 \\ print(8, 9);
162 \\ print(3, 7);
163 \\}
164 \\
165 \\fn print(a: u32, b: u32) void {
166 \\ asm volatile ("svc #0"
167 \\ :
168 \\ : [number] "{r7}" (4),
169 \\ [arg3] "{r2}" (a & b),
170 \\ [arg1] "{r0}" (1),
171 \\ [arg2] "{r1}" (@ptrToInt("123456789"))
172 \\ : "memory"
173 \\ );
174 \\ return;
175 \\}
176 ,
177 "12345678123",
178 );
179
180 // Bitwise Or
181 case.addCompareOutput(
182 \\pub fn main() void {
183 \\ print(4, 2);
184 \\ print(3, 7);
185 \\}
186 \\
187 \\fn print(a: u32, b: u32) void {
188 \\ asm volatile ("svc #0"
189 \\ :
190 \\ : [number] "{r7}" (4),
191 \\ [arg3] "{r2}" (a | b),
192 \\ [arg1] "{r0}" (1),
193 \\ [arg2] "{r1}" (@ptrToInt("123456789"))
194 \\ : "memory"
195 \\ );
196 \\ return;
197 \\}
198 ,
199 "1234561234567",
200 );
201
202 // Bitwise Xor
203 case.addCompareOutput(
204 \\pub fn main() void {
205 \\ print(42, 42);
206 \\ print(3, 5);
207 \\}
208 \\
209 \\fn print(a: u32, b: u32) void {
210 \\ asm volatile ("svc #0"
211 \\ :
212 \\ : [number] "{r7}" (4),
213 \\ [arg3] "{r2}" (a ^ b),
214 \\ [arg1] "{r0}" (1),
215 \\ [arg2] "{r1}" (@ptrToInt("123456789"))
216 \\ : "memory"
217 \\ );
218 \\ return;
219 \\}
220 ,
221 "123456",
222 );
223
224 // Bit Shift Left
225 case.addCompareOutput(
226 \\pub fn main() void {
227 \\ var x: u32 = 1;
228 \\ assert(x << 1 == 2);
229 \\
230 \\ x <<= 1;
231 \\ assert(x << 2 == 8);
232 \\ assert(x << 3 == 16);
233 \\}
234 \\
235 \\pub fn assert(ok: bool) void {
236 \\ if (!ok) unreachable; // assertion failure
237 \\}
238 ,
239 "",
240 );
241
242 // Bit Shift Right
243 case.addCompareOutput(
244 \\pub fn main() void {
245 \\ var a: u32 = 1024;
246 \\ assert(a >> 1 == 512);
247 \\
248 \\ a >>= 1;
249 \\ assert(a >> 2 == 128);
250 \\ assert(a >> 3 == 64);
251 \\ assert(a >> 4 == 32);
252 \\ assert(a >> 5 == 16);
253 \\ assert(a >> 6 == 8);
254 \\ assert(a >> 7 == 4);
255 \\ assert(a >> 8 == 2);
256 \\ assert(a >> 9 == 1);
257 \\}
258 \\
259 \\pub fn assert(ok: bool) void {
260 \\ if (!ok) unreachable; // assertion failure
261 \\}
262 ,
263 "",
264 );
265 }
266
267 {
268 var case = ctx.exe("if statements", linux_arm);
269 // Simple if statement in assert
270 case.addCompareOutput(
271 \\pub fn main() void {
272 \\ var x: u32 = 123;
273 \\ var y: u32 = 42;
274 \\ assert(x > y);
275 \\}
276 \\
277 \\fn assert(ok: bool) void {
278 \\ if (!ok) unreachable;
279 \\}
280 ,
281 "",
282 );
283 }
284
285 {
286 var case = ctx.exe("while loops", linux_arm);
287 // Simple while loop with assert
288 case.addCompareOutput(
289 \\pub fn main() void {
290 \\ var x: u32 = 2020;
291 \\ var i: u32 = 0;
292 \\ while (x > 0) {
293 \\ x -= 2;
294 \\ i += 1;
295 \\ }
296 \\ assert(i == 1010);
297 \\}
298 \\
299 \\fn assert(ok: bool) void {
300 \\ if (!ok) unreachable;
301 \\}
302 ,
303 "",
304 );
305 }
306
307 {
308 var case = ctx.exe("integer multiplication", linux_arm);
309 // Simple u32 integer multiplication
310 case.addCompareOutput(
311 \\pub fn main() void {
312 \\ assert(mul(1, 1) == 1);
313 \\ assert(mul(42, 1) == 42);
314 \\ assert(mul(1, 42) == 42);
315 \\ assert(mul(123, 42) == 5166);
316 \\}
317 \\
318 \\fn mul(x: u32, y: u32) u32 {
319 \\ return x * y;
320 \\}
321 \\
322 \\fn assert(ok: bool) void {
323 \\ if (!ok) unreachable;
324 \\}
325 ,
326 "",
327 );
328 }
329
330 {
331 var case = ctx.exe("save function return values in callee preserved register", linux_arm);
332 // Here, it is necessary to save the result of bar() into a
333 // callee preserved register, otherwise it will be overwritten
334 // by the first parameter to baz.
335 case.addCompareOutput(
336 \\pub fn main() void {
337 \\ assert(foo() == 43);
338 \\}
339 \\
340 \\fn foo() u32 {
341 \\ return bar() + baz(42);
342 \\}
343 \\
344 \\fn bar() u32 {
345 \\ return 1;
346 \\}
347 \\
348 \\fn baz(x: u32) u32 {
349 \\ return x;
350 \\}
351 \\
352 \\fn assert(ok: bool) void {
353 \\ if (!ok) unreachable;
354 \\}
355 ,
356 "",
357 );
358 }
359
360 {
361 var case = ctx.exe("enums", linux_arm);
362 case.addCompareOutput(
363 \\const Number = enum { one, two, three };
364 \\
365 \\pub fn main() void {
366 \\ var x: Number = .one;
367 \\ var y = Number.two;
368 \\ var z = @intToEnum(Number, 2);
369 \\ assert(@enumToInt(x) == 0);
370 \\ assert(@enumToInt(y) == 1);
371 \\ assert(@enumToInt(z) == 2);
372 \\}
373 \\
374 \\fn assert(ok: bool) void {
375 \\ if (!ok) unreachable; // assertion failure
376 \\}
377 ,
378 "",
379 );
380
381 case.addCompareOutput(
382 \\const Number = enum { one, two, three };
383 \\
384 \\pub fn main() void {
385 \\ var x: Number = .one;
386 \\ var y = Number.two;
387 \\ assert(@enumToInt(x) < @enumToInt(y));
388 \\}
389 \\
390 \\fn assert(ok: bool) void {
391 \\ if (!ok) unreachable; // assertion failure
392 \\}
393 ,
394 "",
395 );
396 }
397
398 {
399 var case = ctx.exe("recursive fibonacci", linux_arm);
400 case.addCompareOutput(
401 \\pub fn main() void {
402 \\ assert(fib(0) == 0);
403 \\ assert(fib(1) == 1);
404 \\ assert(fib(2) == 1);
405 \\ assert(fib(3) == 2);
406 \\ assert(fib(10) == 55);
407 \\ assert(fib(20) == 6765);
408 \\}
409 \\
410 \\fn fib(n: u32) u32 {
411 \\ if (n < 2) {
412 \\ return n;
413 \\ } else {
414 \\ return fib(n - 2) + fib(n - 1);
415 \\ }
416 \\}
417 \\
418 \\fn assert(ok: bool) void {
419 \\ if (!ok) unreachable;
420 \\}
421 ,
422 "",
423 );
424 }
425
426 {
427 var case = ctx.exe("spilling registers", linux_arm);
428 case.addCompareOutput(
429 \\pub fn main() void {
430 \\ assert(add(3, 4) == 791);
431 \\}
432 \\
433 \\fn add(a: u32, b: u32) u32 {
434 \\ const x: u32 = blk: {
435 \\ const c = a + b; // 7
436 \\ const d = a + c; // 10
437 \\ const e = d + b; // 14
438 \\ const f = d + e; // 24
439 \\ const g = e + f; // 38
440 \\ const h = f + g; // 62
441 \\ const i = g + h; // 100
442 \\ const j = i + d; // 110
443 \\ const k = i + j; // 210
444 \\ const l = k + c; // 217
445 \\ const m = l + d; // 227
446 \\ const n = m + e; // 241
447 \\ const o = n + f; // 265
448 \\ const p = o + g; // 303
449 \\ const q = p + h; // 365
450 \\ const r = q + i; // 465
451 \\ const s = r + j; // 575
452 \\ const t = s + k; // 785
453 \\ break :blk t;
454 \\ };
455 \\ const y = x + a; // 788
456 \\ const z = y + a; // 791
457 \\ return z;
458 \\}
459 \\
460 \\fn assert(ok: bool) void {
461 \\ if (!ok) unreachable;
462 \\}
463 ,
464 "",
465 );
466
467 case.addCompareOutput(
468 \\pub fn main() void {
469 \\ assert(addMul(3, 4) == 357747496);
470 \\}
471 \\
472 \\fn addMul(a: u32, b: u32) u32 {
473 \\ const x: u32 = blk: {
474 \\ const c = a + b; // 7
475 \\ const d = a + c; // 10
476 \\ const e = d + b; // 14
477 \\ const f = d + e; // 24
478 \\ const g = e + f; // 38
479 \\ const h = f + g; // 62
480 \\ const i = g + h; // 100
481 \\ const j = i + d; // 110
482 \\ const k = i + j; // 210
483 \\ const l = k + c; // 217
484 \\ const m = l * d; // 2170
485 \\ const n = m + e; // 2184
486 \\ const o = n * f; // 52416
487 \\ const p = o + g; // 52454
488 \\ const q = p * h; // 3252148
489 \\ const r = q + i; // 3252248
490 \\ const s = r * j; // 357747280
491 \\ const t = s + k; // 357747490
492 \\ break :blk t;
493 \\ };
494 \\ const y = x + a; // 357747493
495 \\ const z = y + a; // 357747496
496 \\ return z;
497 \\}
498 \\
499 \\fn assert(ok: bool) void {
500 \\ if (!ok) unreachable;
501 \\}
502 ,
503 "",
504 );
505 }
506
507 {
508 var case = ctx.exe("print u32s", linux_arm);
509 case.addCompareOutput(
510 \\pub fn main() void {
511 \\ printNumberHex(0x00000000);
512 \\ printNumberHex(0xaaaaaaaa);
513 \\ printNumberHex(0xdeadbeef);
514 \\ printNumberHex(0x31415926);
515 \\}
516 \\
517 \\fn printNumberHex(x: u32) void {
518 \\ var i: u5 = 28;
519 \\ while (true) : (i -= 4) {
520 \\ const digit = (x >> i) & 0xf;
521 \\ asm volatile ("svc #0"
522 \\ :
523 \\ : [number] "{r7}" (4),
524 \\ [arg1] "{r0}" (1),
525 \\ [arg2] "{r1}" (@ptrToInt("0123456789abcdef") + digit),
526 \\ [arg3] "{r2}" (1)
527 \\ : "memory"
528 \\ );
529 \\
530 \\ if (i == 0) break;
531 \\ }
532 \\ asm volatile ("svc #0"
533 \\ :
534 \\ : [number] "{r7}" (4),
535 \\ [arg1] "{r0}" (1),
536 \\ [arg2] "{r1}" (@ptrToInt("\n")),
537 \\ [arg3] "{r2}" (1)
538 \\ : "memory"
539 \\ );
540 \\}
541 ,
542 \\00000000
543 \\aaaaaaaa
544 \\deadbeef
545 \\31415926
546 \\
547 ,
548 );
549 }
550
551 {
552 var case = ctx.exe("save compare flags", linux_arm);
553 case.addCompareOutput(
554 \\pub fn main() void {
555 \\ foo(2, 1);
556 \\}
557 \\
558 \\fn foo(x: u32, y: u32) void {
559 \\ const b = x > y;
560 \\ assert(b);
561 \\ assert(b);
562 \\}
563 \\
564 \\pub fn assert(ok: bool) void {
565 \\ if (!ok) unreachable; // assertion failure
566 \\}
567 ,
568 "",
569 );
570 }
571
572 {
573 var case = ctx.exe("optionals", linux_arm);
574 case.addCompareOutput(
575 \\var x: u32 = 42;
576 \\
577 \\pub fn main() void {
578 \\ var p: ?*u32 = null;
579 \\ assert(p == null);
580 \\ p = &x;
581 \\ assert(p != null);
582 \\}
583 \\
584 \\fn assert(ok: bool) void {
585 \\ if (!ok) unreachable;
586 \\}
587 ,
588 "",
589 );
590 }
591
592 {
593 var case = ctx.exe("errors", linux_arm);
594 case.addCompareOutput(
595 \\pub fn main() void {
596 \\ foo() catch print();
597 \\}
598 \\
599 \\fn foo() anyerror!void {}
600 \\
601 \\fn print() void {
602 \\ asm volatile ("svc #0"
603 \\ :
604 \\ : [number] "{r7}" (4),
605 \\ [arg1] "{r0}" (1),
606 \\ [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
607 \\ [arg3] "{r2}" ("Hello, World!\n".len),
608 \\ : "memory"
609 \\ );
610 \\ return;
611 \\}
612 ,
613 "",
614 );
615
616 case.addCompareOutput(
617 \\pub fn main() void {
618 \\ foo() catch print();
619 \\}
620 \\
621 \\fn foo() anyerror!void {
622 \\ return error.Test;
623 \\}
624 \\
625 \\fn print() void {
626 \\ asm volatile ("svc #0"
627 \\ :
628 \\ : [number] "{r7}" (4),
629 \\ [arg1] "{r0}" (1),
630 \\ [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
631 \\ [arg3] "{r2}" ("Hello, World!\n".len),
632 \\ : "memory"
633 \\ );
634 \\ return;
635 \\}
636 ,
637 "Hello, World!\n",
638 );
639
640 case.addCompareOutput(
641 \\pub fn main() void {
642 \\ foo() catch |err| {
643 \\ assert(err == error.Foo);
644 \\ assert(err != error.Bar);
645 \\ assert(err != error.Baz);
646 \\ };
647 \\ bar() catch |err| {
648 \\ assert(err != error.Foo);
649 \\ assert(err == error.Bar);
650 \\ assert(err != error.Baz);
651 \\ };
652 \\}
653 \\
654 \\fn assert(ok: bool) void {
655 \\ if (!ok) unreachable;
656 \\}
657 \\
658 \\fn foo() anyerror!void {
659 \\ return error.Foo;
660 \\}
661 \\
662 \\fn bar() anyerror!void {
663 \\ return error.Bar;
664 \\}
665 ,
666 "",
667 );
668
669 case.addCompareOutput(
670 \\pub fn main() void {
671 \\ foo() catch unreachable;
672 \\}
673 \\
674 \\fn foo() anyerror!void {
675 \\ try bar();
676 \\}
677 \\
678 \\fn bar() anyerror!void {}
679 ,
680 "",
681 );
682 }
683
684 {
685 var case = ctx.exe("slices", linux_arm);
686 case.addCompareOutput(
687 \\var array = [_]u32{ 0, 42, 123, 69 };
688 \\var s: []const u32 = &array;
689 \\
690 \\pub fn main() void {
691 \\ assert(s[0] == 0);
692 \\ assert(s[1] == 42);
693 \\ assert(s[2] == 123);
694 \\ assert(s[3] == 69);
695 \\}
696 \\
697 \\fn assert(ok: bool) void {
698 \\ if (!ok) unreachable;
699 \\}
700 ,
701 "",
702 );
703 }
704
705 {
706 var case = ctx.exe("structs", linux_arm);
707 case.addCompareOutput(
708 \\var array = [_]SomeStruct{
709 \\ .{ .a = 0, .b = 42, .c = 69 },
710 \\ .{ .a = 1, .b = 2, .c = 3 },
711 \\ .{ .a = 123, .b = 456, .c = 789 },
712 \\};
713 \\var s: []const SomeStruct = &array;
714 \\
715 \\var some_struct: SomeStruct = .{
716 \\ .a = 0,
717 \\ .b = 42,
718 \\ .c = 69,
719 \\};
720 \\
721 \\const SomeStruct = struct {
722 \\ a: u32,
723 \\ b: u32,
724 \\ c: u32,
725 \\};
726 \\
727 \\pub fn main() void {
728 \\ assert(some_struct.a == 0);
729 \\ assert(some_struct.b == 42);
730 \\ assert(some_struct.c == 69);
731 \\
732 \\ assert(s[0].a == 0);
733 \\ assert(s[0].b == 42);
734 \\ assert(s[0].c == 69);
735 \\ assert(s[1].a == 1);
736 \\ assert(s[1].b == 2);
737 \\ assert(s[1].c == 3);
738 \\ assert(s[2].a == 123);
739 \\ assert(s[2].b == 456);
740 \\ assert(s[2].c == 789);
741 \\}
742 \\
743 \\fn assert(ok: bool) void {
744 \\ if (!ok) unreachable;
745 \\}
746 ,
747 "",
748 );
749 }
750
751 {
752 var case = ctx.exe("function pointers", linux_arm);
753 case.addCompareOutput(
754 \\const PrintFn = *const fn () void;
755 \\
756 \\pub fn main() void {
757 \\ var printFn: PrintFn = stopSayingThat;
758 \\ var i: u32 = 0;
759 \\ while (i < 4) : (i += 1) printFn();
760 \\
761 \\ printFn = moveEveryZig;
762 \\ printFn();
763 \\}
764 \\
765 \\fn stopSayingThat() void {
766 \\ asm volatile ("svc #0"
767 \\ :
768 \\ : [number] "{r7}" (4),
769 \\ [arg1] "{r0}" (1),
770 \\ [arg2] "{r1}" (@ptrToInt("Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n")),
771 \\ [arg3] "{r2}" ("Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n".len),
772 \\ : "memory"
773 \\ );
774 \\ return;
775 \\}
776 \\
777 \\fn moveEveryZig() void {
778 \\ asm volatile ("svc #0"
779 \\ :
780 \\ : [number] "{r7}" (4),
781 \\ [arg1] "{r0}" (1),
782 \\ [arg2] "{r1}" (@ptrToInt("All your codebase are belong to us\n")),
783 \\ [arg3] "{r2}" ("All your codebase are belong to us\n".len),
784 \\ : "memory"
785 \\ );
786 \\ return;
787 \\}
788 ,
789 \\Hello, my name is Inigo Montoya; you killed my father, prepare to die.
790 \\Hello, my name is Inigo Montoya; you killed my father, prepare to die.
791 \\Hello, my name is Inigo Montoya; you killed my father, prepare to die.
792 \\Hello, my name is Inigo Montoya; you killed my father, prepare to die.
793 \\All your codebase are belong to us
794 \\
795 ,
796 );
797 }
798}
test/stage2/llvm.zig deleted-438
...@@ -1,438 +0,0 @@
1const std = @import("std");
2const TestContext = @import("../../src/test.zig").TestContext;
3const build_options = @import("build_options");
4
5// These tests should work with all platforms, but we're using linux_x64 for
6// now for consistency. Will be expanded eventually.
7const linux_x64 = std.zig.CrossTarget{
8 .cpu_arch = .x86_64,
9 .os_tag = .linux,
10};
11
12pub fn addCases(ctx: *TestContext) !void {
13 {
14 var case = ctx.exeUsingLlvmBackend("simple addition and subtraction", linux_x64);
15
16 case.addCompareOutput(
17 \\fn add(a: i32, b: i32) i32 {
18 \\ return a + b;
19 \\}
20 \\
21 \\pub export fn main() c_int {
22 \\ var a: i32 = -5;
23 \\ const x = add(a, 7);
24 \\ var y = add(2, 0);
25 \\ y -= x;
26 \\ return y;
27 \\}
28 , "");
29 }
30
31 {
32 var case = ctx.exeUsingLlvmBackend("shift right + left", linux_x64);
33
34 case.addCompareOutput(
35 \\pub export fn main() c_int {
36 \\ var i: u32 = 16;
37 \\ assert(i >> 1, 8);
38 \\ return 0;
39 \\}
40 \\fn assert(a: u32, b: u32) void {
41 \\ if (a != b) unreachable;
42 \\}
43 , "");
44 case.addCompareOutput(
45 \\pub export fn main() c_int {
46 \\ var i: u32 = 16;
47 \\ assert(i << 1, 32);
48 \\ return 0;
49 \\}
50 \\fn assert(a: u32, b: u32) void {
51 \\ if (a != b) unreachable;
52 \\}
53 , "");
54 }
55
56 {
57 var case = ctx.exeUsingLlvmBackend("llvm hello world", linux_x64);
58
59 case.addCompareOutput(
60 \\extern fn puts(s: [*:0]const u8) c_int;
61 \\
62 \\pub export fn main() c_int {
63 \\ _ = puts("hello world!");
64 \\ return 0;
65 \\}
66 , "hello world!" ++ std.cstr.line_sep);
67 }
68
69 {
70 var case = ctx.exeUsingLlvmBackend("simple if statement", linux_x64);
71
72 case.addCompareOutput(
73 \\fn add(a: i32, b: i32) i32 {
74 \\ return a + b;
75 \\}
76 \\
77 \\fn assert(ok: bool) void {
78 \\ if (!ok) unreachable;
79 \\}
80 \\
81 \\pub export fn main() c_int {
82 \\ assert(add(1,2) == 3);
83 \\ return 0;
84 \\}
85 , "");
86 }
87
88 {
89 var case = ctx.exeUsingLlvmBackend("blocks", linux_x64);
90
91 case.addCompareOutput(
92 \\fn assert(ok: bool) void {
93 \\ if (!ok) unreachable;
94 \\}
95 \\
96 \\fn foo(ok: bool) i32 {
97 \\ const val: i32 = blk: {
98 \\ var x: i32 = 1;
99 \\ if (!ok) break :blk x + 9;
100 \\ break :blk x + 19;
101 \\ };
102 \\ return val + 10;
103 \\}
104 \\
105 \\pub export fn main() c_int {
106 \\ assert(foo(false) == 20);
107 \\ assert(foo(true) == 30);
108 \\ return 0;
109 \\}
110 , "");
111 }
112
113 {
114 var case = ctx.exeUsingLlvmBackend("nested blocks", linux_x64);
115
116 case.addCompareOutput(
117 \\fn assert(ok: bool) void {
118 \\ if (!ok) unreachable;
119 \\}
120 \\
121 \\fn foo(ok: bool) i32 {
122 \\ var val: i32 = blk: {
123 \\ const val2: i32 = another: {
124 \\ if (!ok) break :blk 10;
125 \\ break :another 10;
126 \\ };
127 \\ break :blk val2 + 10;
128 \\ };
129 \\ return val;
130 \\}
131 \\
132 \\pub export fn main() c_int {
133 \\ assert(foo(false) == 10);
134 \\ assert(foo(true) == 20);
135 \\ return 0;
136 \\}
137 , "");
138 }
139
140 {
141 var case = ctx.exeUsingLlvmBackend("while loops", linux_x64);
142
143 case.addCompareOutput(
144 \\fn assert(ok: bool) void {
145 \\ if (!ok) unreachable;
146 \\}
147 \\
148 \\pub export fn main() c_int {
149 \\ var sum: u32 = 0;
150 \\ var i: u32 = 0;
151 \\ while (i < 5) : (i += 1) {
152 \\ sum += i;
153 \\ }
154 \\ assert(sum == 10);
155 \\ assert(i == 5);
156 \\ return 0;
157 \\}
158 , "");
159 }
160
161 {
162 var case = ctx.exeUsingLlvmBackend("optionals", linux_x64);
163
164 case.addCompareOutput(
165 \\fn assert(ok: bool) void {
166 \\ if (!ok) unreachable;
167 \\}
168 \\
169 \\pub export fn main() c_int {
170 \\ var opt_val: ?i32 = 10;
171 \\ var null_val: ?i32 = null;
172 \\
173 \\ var val1: i32 = opt_val.?;
174 \\ const val1_1: i32 = opt_val.?;
175 \\ var ptr_val1 = &(opt_val.?);
176 \\ const ptr_val1_1 = &(opt_val.?);
177 \\
178 \\ var val2: i32 = null_val orelse 20;
179 \\ const val2_2: i32 = null_val orelse 20;
180 \\
181 \\ var value: i32 = 20;
182 \\ var ptr_val2 = &(null_val orelse value);
183 \\
184 \\ const val3 = opt_val orelse 30;
185 \\ var val3_var = opt_val orelse 30;
186 \\
187 \\ assert(val1 == 10);
188 \\ assert(val1_1 == 10);
189 \\ assert(ptr_val1.* == 10);
190 \\ assert(ptr_val1_1.* == 10);
191 \\
192 \\ assert(val2 == 20);
193 \\ assert(val2_2 == 20);
194 \\ assert(ptr_val2.* == 20);
195 \\
196 \\ assert(val3 == 10);
197 \\ assert(val3_var == 10);
198 \\
199 \\ (null_val orelse val2) = 1234;
200 \\ assert(val2 == 1234);
201 \\
202 \\ (opt_val orelse val2) = 5678;
203 \\ assert(opt_val.? == 5678);
204 \\
205 \\ return 0;
206 \\}
207 , "");
208 }
209
210 {
211 var case = ctx.exeUsingLlvmBackend("for loop", linux_x64);
212
213 case.addCompareOutput(
214 \\fn assert(ok: bool) void {
215 \\ if (!ok) unreachable;
216 \\}
217 \\
218 \\pub export fn main() c_int {
219 \\ var x: u32 = 0;
220 \\ for ("hello") |_| {
221 \\ x += 1;
222 \\ }
223 \\ assert("hello".len == x);
224 \\ return 0;
225 \\}
226 , "");
227 }
228
229 {
230 var case = ctx.exeUsingLlvmBackend("@rem", linux_x64);
231 case.addCompareOutput(
232 \\fn assert(ok: bool) void {
233 \\ if (!ok) unreachable;
234 \\}
235 \\fn rem(lhs: i32, rhs: i32, expected: i32) bool {
236 \\ return @rem(lhs, rhs) == expected;
237 \\}
238 \\pub export fn main() c_int {
239 \\ assert(rem(-5, 3, -2));
240 \\ assert(rem(5, 3, 2));
241 \\ return 0;
242 \\}
243 , "");
244 }
245
246 {
247 var case = ctx.exeUsingLlvmBackend("invalid address space coercion", linux_x64);
248 case.addError(
249 \\fn entry(a: *addrspace(.gs) i32) *i32 {
250 \\ return a;
251 \\}
252 \\pub export fn main() void { _ = entry; }
253 , &[_][]const u8{
254 ":2:12: error: expected *i32, found *addrspace(.gs) i32",
255 });
256 }
257
258 {
259 var case = ctx.exeUsingLlvmBackend("pointer keeps address space", linux_x64);
260 case.compiles(
261 \\fn entry(a: *addrspace(.gs) i32) *addrspace(.gs) i32 {
262 \\ return a;
263 \\}
264 \\pub export fn main() void { _ = entry; }
265 );
266 }
267
268 {
269 var case = ctx.exeUsingLlvmBackend("pointer to explicit generic address space coerces to implicit pointer", linux_x64);
270 case.compiles(
271 \\fn entry(a: *addrspace(.generic) i32) *i32 {
272 \\ return a;
273 \\}
274 \\pub export fn main() void { _ = entry; }
275 );
276 }
277
278 {
279 var case = ctx.exeUsingLlvmBackend("pointers with different address spaces", linux_x64);
280 case.addError(
281 \\fn entry(a: *addrspace(.gs) i32) *addrspace(.fs) i32 {
282 \\ return a;
283 \\}
284 \\pub export fn main() void { _ = entry; }
285 , &[_][]const u8{
286 ":2:12: error: expected *addrspace(.fs) i32, found *addrspace(.gs) i32",
287 });
288 }
289
290 {
291 var case = ctx.exeUsingLlvmBackend("pointers with different address spaces", linux_x64);
292 case.addError(
293 \\fn entry(a: ?*addrspace(.gs) i32) *i32 {
294 \\ return a.?;
295 \\}
296 \\pub export fn main() void { _ = entry; }
297 , &[_][]const u8{
298 ":2:13: error: expected *i32, found *addrspace(.gs) i32",
299 });
300 }
301
302 {
303 var case = ctx.exeUsingLlvmBackend("invalid pointer keeps address space when taking address of dereference", linux_x64);
304 case.addError(
305 \\fn entry(a: *addrspace(.gs) i32) *i32 {
306 \\ return &a.*;
307 \\}
308 \\pub export fn main() void { _ = entry; }
309 , &[_][]const u8{
310 ":2:12: error: expected *i32, found *addrspace(.gs) i32",
311 });
312 }
313
314 {
315 var case = ctx.exeUsingLlvmBackend("pointer keeps address space when taking address of dereference", linux_x64);
316 case.compiles(
317 \\fn entry(a: *addrspace(.gs) i32) *addrspace(.gs) i32 {
318 \\ return &a.*;
319 \\}
320 \\pub export fn main() void { _ = entry; }
321 );
322 }
323
324 {
325 var case = ctx.exeUsingLlvmBackend("address spaces pointer access chaining: array pointer", linux_x64);
326 case.compiles(
327 \\fn entry(a: *addrspace(.gs) [1]i32) *addrspace(.gs) i32 {
328 \\ return &a[0];
329 \\}
330 \\pub export fn main() void { _ = entry; }
331 );
332 }
333
334 {
335 var case = ctx.exeUsingLlvmBackend("address spaces pointer access chaining: pointer to optional array", linux_x64);
336 case.compiles(
337 \\fn entry(a: *addrspace(.gs) ?[1]i32) *addrspace(.gs) i32 {
338 \\ return &a.*.?[0];
339 \\}
340 \\pub export fn main() void { _ = entry; }
341 );
342 }
343
344 {
345 var case = ctx.exeUsingLlvmBackend("address spaces pointer access chaining: struct pointer", linux_x64);
346 case.compiles(
347 \\const A = struct{ a: i32 };
348 \\fn entry(a: *addrspace(.gs) A) *addrspace(.gs) i32 {
349 \\ return &a.a;
350 \\}
351 \\pub export fn main() void { _ = entry; }
352 );
353 }
354
355 {
356 var case = ctx.exeUsingLlvmBackend("address spaces pointer access chaining: complex", linux_x64);
357 case.compiles(
358 \\const A = struct{ a: ?[1]i32 };
359 \\fn entry(a: *addrspace(.gs) [1]A) *addrspace(.gs) i32 {
360 \\ return &a[0].a.?[0];
361 \\}
362 \\pub export fn main() void { _ = entry; }
363 );
364 }
365
366 {
367 var case = ctx.exeUsingLlvmBackend("dereferencing through multiple pointers with address spaces", linux_x64);
368 case.compiles(
369 \\fn entry(a: *addrspace(.fs) *addrspace(.gs) *i32) *i32 {
370 \\ return a.*.*;
371 \\}
372 \\pub export fn main() void { _ = entry; }
373 );
374 }
375
376 {
377 var case = ctx.exeUsingLlvmBackend("f segment address space reading and writing", linux_x64);
378 case.addCompareOutput(
379 \\fn assert(ok: bool) void {
380 \\ if (!ok) unreachable;
381 \\}
382 \\
383 \\fn setFs(value: c_ulong) void {
384 \\ asm volatile (
385 \\ \\syscall
386 \\ :
387 \\ : [number] "{rax}" (158),
388 \\ [code] "{rdi}" (0x1002),
389 \\ [val] "{rsi}" (value),
390 \\ : "rcx", "r11", "memory"
391 \\ );
392 \\}
393 \\
394 \\fn getFs() c_ulong {
395 \\ var result: c_ulong = undefined;
396 \\ asm volatile (
397 \\ \\syscall
398 \\ :
399 \\ : [number] "{rax}" (158),
400 \\ [code] "{rdi}" (0x1003),
401 \\ [ptr] "{rsi}" (@ptrToInt(&result)),
402 \\ : "rcx", "r11", "memory"
403 \\ );
404 \\ return result;
405 \\}
406 \\
407 \\var test_value: u64 = 12345;
408 \\
409 \\pub export fn main() c_int {
410 \\ const orig_fs = getFs();
411 \\
412 \\ setFs(@ptrToInt(&test_value));
413 \\ assert(getFs() == @ptrToInt(&test_value));
414 \\
415 \\ var test_ptr = @intToPtr(*allowzero addrspace(.fs) u64, 0);
416 \\ assert(test_ptr.* == 12345);
417 \\ test_ptr.* = 98765;
418 \\ assert(test_value == 98765);
419 \\
420 \\ setFs(orig_fs);
421 \\ return 0;
422 \\}
423 , "");
424 }
425
426 {
427 // This worked in stage1 and we expressly do not want this to work in stage2
428 var case = ctx.exeUsingLlvmBackend("any typed null to any typed optional", linux_x64);
429 case.addError(
430 \\pub export fn main() void {
431 \\ var a: ?*anyopaque = undefined;
432 \\ a = @as(?usize, null);
433 \\}
434 , &[_][]const u8{
435 ":3:21: error: expected *anyopaque, found ?usize",
436 });
437 }
438}
test/stage2/plan9.zig deleted-55
...@@ -1,55 +0,0 @@
1const std = @import("std");
2const TestContext = @import("../../src/test.zig").TestContext;
3
4pub fn addCases(ctx: *TestContext) !void {
5 const x64: std.zig.CrossTarget = .{
6 .cpu_arch = .x86_64,
7 .os_tag = .plan9,
8 };
9 const aarch64: std.zig.CrossTarget = .{
10 .cpu_arch = .aarch64,
11 .os_tag = .plan9,
12 };
13 {
14 var case = ctx.exe("plan9: exiting correctly x64", x64);
15 case.addCompareOutput("pub fn main() void {}", "");
16 }
17 {
18 var case = ctx.exe("plan9: exiting correctly arm", aarch64);
19 case.addCompareOutput("pub fn main() void {}", "");
20 }
21 {
22 var case = ctx.exe("plan9: hello world", x64);
23 case.addCompareOutput(
24 \\pub fn main() void {
25 \\ const str = "Hello World!\n";
26 \\ asm volatile (
27 \\ \\push $0
28 \\ \\push %%r10
29 \\ \\push %%r11
30 \\ \\push $1
31 \\ \\push $0
32 \\ \\syscall
33 \\ \\pop %%r11
34 \\ \\pop %%r11
35 \\ \\pop %%r11
36 \\ \\pop %%r11
37 \\ \\pop %%r11
38 \\ :
39 \\ // pwrite
40 \\ : [syscall_number] "{rbp}" (51),
41 \\ [hey] "{r11}" (@ptrToInt(str)),
42 \\ [strlen] "{r10}" (str.len)
43 \\ : "rcx", "rbp", "r11", "memory"
44 \\ );
45 \\}
46 , "Hello World\n");
47 case.addCompareOutput(
48 \\const std = @import("std");
49 \\pub fn main() void {
50 \\ const str = "Hello World!\n";
51 \\ _ = std.os.plan9.pwrite(1, str, str.len, 0);
52 \\}
53 , "Hello World\n");
54 }
55}
test/stage2/riscv64.zig deleted-33
...@@ -1,33 +0,0 @@
1const std = @import("std");
2const TestContext = @import("../../src/test.zig").TestContext;
3
4const linux_riscv64 = std.zig.CrossTarget{
5 .cpu_arch = .riscv64,
6 .os_tag = .linux,
7};
8
9pub fn addCases(ctx: *TestContext) !void {
10 {
11 var case = ctx.exe("riscv64 hello world", linux_riscv64);
12 // Regular old hello world
13 case.addCompareOutput(
14 \\pub fn main() void {
15 \\ print();
16 \\}
17 \\
18 \\fn print() void {
19 \\ asm volatile ("ecall"
20 \\ :
21 \\ : [number] "{a7}" (64),
22 \\ [arg1] "{a0}" (1),
23 \\ [arg2] "{a1}" (@ptrToInt("Hello, World!\n")),
24 \\ [arg3] "{a2}" ("Hello, World!\n".len)
25 \\ : "rcx", "r11", "memory"
26 \\ );
27 \\ return;
28 \\}
29 ,
30 "Hello, World!\n",
31 );
32 }
33}
test/stage2/sparcv9.zig deleted-39
...@@ -1,39 +0,0 @@
1const std = @import("std");
2const TestContext = @import("../../src/test.zig").TestContext;
3
4const linux_sparcv9 = std.zig.CrossTarget{
5 .cpu_arch = .sparcv9,
6 .os_tag = .linux,
7};
8
9pub fn addCases(ctx: *TestContext) !void {
10 {
11 var case = ctx.exe("sparcv9 hello world", linux_sparcv9);
12 // Regular old hello world
13 case.addCompareOutput(
14 \\const msg = "Hello, World!\n";
15 \\
16 \\pub export fn _start() noreturn {
17 \\ asm volatile ("ta 0x6d"
18 \\ :
19 \\ : [number] "{g1}" (4),
20 \\ [arg1] "{o0}" (1),
21 \\ [arg2] "{o1}" (@ptrToInt(msg)),
22 \\ [arg3] "{o2}" (msg.len)
23 \\ : "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7", "memory"
24 \\ );
25 \\
26 \\ asm volatile ("ta 0x6d"
27 \\ :
28 \\ : [number] "{g1}" (1),
29 \\ [arg1] "{o0}" (0)
30 \\ : "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7", "memory"
31 \\ );
32 \\
33 \\ unreachable;
34 \\}
35 ,
36 "Hello, World!\n",
37 );
38 }
39}
test/stage2/wasm.zig deleted-796
...@@ -1,796 +0,0 @@
1const std = @import("std");
2const TestContext = @import("../../src/test.zig").TestContext;
3
4const wasi = std.zig.CrossTarget{
5 .cpu_arch = .wasm32,
6 .os_tag = .wasi,
7};
8
9pub fn addCases(ctx: *TestContext) !void {
10 {
11 var case = ctx.exe("wasm function calls", wasi);
12
13 case.addCompareOutput(
14 \\pub fn main() void {
15 \\ foo();
16 \\ bar();
17 \\}
18 \\fn foo() void {
19 \\ bar();
20 \\ bar();
21 \\}
22 \\fn bar() void {}
23 , "");
24
25 case.addCompareOutput(
26 \\pub fn main() void {
27 \\ bar();
28 \\ foo();
29 \\ foo();
30 \\ bar();
31 \\ foo();
32 \\ bar();
33 \\}
34 \\fn foo() void {
35 \\ bar();
36 \\}
37 \\fn bar() void {}
38 , "");
39
40 case.addCompareOutput(
41 \\pub fn main() void {
42 \\ bar();
43 \\ foo();
44 \\ return;
45 \\}
46 \\fn foo() void {
47 \\ bar();
48 \\ bar();
49 \\ bar();
50 \\}
51 \\fn bar() void {}
52 ,
53 "",
54 );
55
56 case.addCompareOutput(
57 \\pub fn main() void {
58 \\ foo(10, 20);
59 \\}
60 \\fn foo(x: u8, y: u8) void { _ = x; _ = y; }
61 , "");
62 }
63
64 {
65 var case = ctx.exe("wasm locals", wasi);
66
67 case.addCompareOutput(
68 \\pub fn main() void {
69 \\ var i: u8 = 5;
70 \\ var y: f32 = 42.0;
71 \\ var x: u8 = 10;
72 \\ if (false) {
73 \\ y;
74 \\ x;
75 \\ }
76 \\ if (i != 5) unreachable;
77 \\}
78 , "");
79
80 case.addCompareOutput(
81 \\pub fn main() void {
82 \\ var i: u8 = 5;
83 \\ var y: f32 = 42.0;
84 \\ _ = y;
85 \\ var x: u8 = 10;
86 \\ foo(i, x);
87 \\ i = x;
88 \\ if (i != 10) unreachable;
89 \\}
90 \\fn foo(x: u8, y: u8) void {
91 \\ _ = y;
92 \\ var i: u8 = 10;
93 \\ i = x;
94 \\}
95 , "");
96 }
97
98 {
99 var case = ctx.exe("wasm binary operands", wasi);
100
101 case.addCompareOutput(
102 \\pub fn main() void {
103 \\ var i: u8 = 5;
104 \\ i += 20;
105 \\ if (i != 25) unreachable;
106 \\}
107 , "");
108
109 case.addCompareOutput(
110 \\pub fn main() void {
111 \\ var i: i32 = 2147483647;
112 \\ if (i +% 1 != -2147483648) unreachable;
113 \\ return;
114 \\}
115 , "");
116
117 case.addCompareOutput(
118 \\pub fn main() void {
119 \\ var i: i4 = 7;
120 \\ if (i +% 1 != 0) unreachable;
121 \\ return;
122 \\}
123 , "");
124
125 case.addCompareOutput(
126 \\pub fn main() u8 {
127 \\ var i: u8 = 255;
128 \\ return i +% 1;
129 \\}
130 , "");
131
132 case.addCompareOutput(
133 \\pub fn main() u8 {
134 \\ var i: u8 = 5;
135 \\ i += 20;
136 \\ var result: u8 = foo(i, 10);
137 \\ return result - 35;
138 \\}
139 \\fn foo(x: u8, y: u8) u8 {
140 \\ return x + y;
141 \\}
142 , "");
143
144 case.addCompareOutput(
145 \\pub fn main() u8 {
146 \\ var i: u8 = 20;
147 \\ i -= 5;
148 \\ return i - 15;
149 \\}
150 , "");
151
152 case.addCompareOutput(
153 \\pub fn main() void {
154 \\ var i: i32 = -2147483648;
155 \\ if (i -% 1 != 2147483647) unreachable;
156 \\ return;
157 \\}
158 , "");
159
160 case.addCompareOutput(
161 \\pub fn main() void {
162 \\ var i: i7 = -64;
163 \\ if (i -% 1 != 63) unreachable;
164 \\ return;
165 \\}
166 , "");
167
168 case.addCompareOutput(
169 \\pub fn main() void {
170 \\ var i: u4 = 0;
171 \\ if(i -% 1 != 15) unreachable;
172 \\}
173 , "");
174
175 case.addCompareOutput(
176 \\pub fn main() u8 {
177 \\ var i: u8 = 5;
178 \\ i -= 3;
179 \\ var result: u8 = foo(i, 10);
180 \\ return result - 8;
181 \\}
182 \\fn foo(x: u8, y: u8) u8 {
183 \\ return y - x;
184 \\}
185 , "");
186
187 case.addCompareOutput(
188 \\pub fn main() void {
189 \\ var i: u32 = 5;
190 \\ i *= 7;
191 \\ var result: u32 = foo(i, 10);
192 \\ if (result != 350) unreachable;
193 \\ return;
194 \\}
195 \\fn foo(x: u32, y: u32) u32 {
196 \\ return x * y;
197 \\}
198 , "");
199
200 case.addCompareOutput(
201 \\pub fn main() void {
202 \\ var i: i32 = 2147483647;
203 \\ const result = i *% 2;
204 \\ if (result != -2) unreachable;
205 \\ return;
206 \\}
207 , "");
208
209 case.addCompareOutput(
210 \\pub fn main() void {
211 \\ var i: u3 = 3;
212 \\ if (i *% 3 != 1) unreachable;
213 \\ return;
214 \\}
215 , "");
216
217 case.addCompareOutput(
218 \\pub fn main() void {
219 \\ var i: i4 = 3;
220 \\ if (i *% 3 != 1) unreachable;
221 \\ return;
222 \\}
223 , "");
224
225 case.addCompareOutput(
226 \\pub fn main() void {
227 \\ var i: u32 = 352;
228 \\ i /= 7; // i = 50
229 \\ var result: u32 = foo(i, 7);
230 \\ if (result != 7) unreachable;
231 \\ return;
232 \\}
233 \\fn foo(x: u32, y: u32) u32 {
234 \\ return x / y;
235 \\}
236 , "");
237
238 case.addCompareOutput(
239 \\pub fn main() u8 {
240 \\ var i: u8 = 5;
241 \\ i &= 6;
242 \\ return i - 4;
243 \\}
244 , "");
245
246 case.addCompareOutput(
247 \\pub fn main() u8 {
248 \\ var i: u8 = 5;
249 \\ i |= 6;
250 \\ return i - 7;
251 \\}
252 , "");
253
254 case.addCompareOutput(
255 \\pub fn main() u8 {
256 \\ var i: u8 = 5;
257 \\ i ^= 6;
258 \\ return i - 3;
259 \\}
260 , "");
261
262 case.addCompareOutput(
263 \\pub fn main() void {
264 \\ var b: bool = false;
265 \\ b = b or false;
266 \\ if (b) unreachable;
267 \\ return;
268 \\}
269 , "");
270
271 case.addCompareOutput(
272 \\pub fn main() void {
273 \\ var b: bool = true;
274 \\ b = b or false;
275 \\ if (!b) unreachable;
276 \\ return;
277 \\}
278 , "");
279
280 case.addCompareOutput(
281 \\pub fn main() void {
282 \\ var b: bool = false;
283 \\ b = b or true;
284 \\ if (!b) unreachable;
285 \\ return;
286 \\}
287 , "");
288
289 case.addCompareOutput(
290 \\pub fn main() void {
291 \\ var b: bool = true;
292 \\ b = b or true;
293 \\ if (!b) unreachable;
294 \\ return;
295 \\}
296 , "");
297
298 case.addCompareOutput(
299 \\pub fn main() void {
300 \\ var b: bool = false;
301 \\ b = b and false;
302 \\ if (b) unreachable;
303 \\ return;
304 \\}
305 , "");
306
307 case.addCompareOutput(
308 \\pub fn main() void {
309 \\ var b: bool = true;
310 \\ b = b and false;
311 \\ if (b) unreachable;
312 \\ return;
313 \\}
314 , "");
315
316 case.addCompareOutput(
317 \\pub fn main() void {
318 \\ var b: bool = false;
319 \\ b = b and true;
320 \\ if (b) unreachable;
321 \\ return;
322 \\}
323 , "");
324
325 case.addCompareOutput(
326 \\pub fn main() void {
327 \\ var b: bool = true;
328 \\ b = b and true;
329 \\ if (!b) unreachable;
330 \\ return;
331 \\}
332 , "");
333 }
334
335 {
336 var case = ctx.exe("wasm conditions", wasi);
337
338 case.addCompareOutput(
339 \\pub fn main() u8 {
340 \\ var i: u8 = 5;
341 \\ if (i > @as(u8, 4)) {
342 \\ i += 10;
343 \\ }
344 \\ return i - 15;
345 \\}
346 , "");
347
348 case.addCompareOutput(
349 \\pub fn main() u8 {
350 \\ var i: u8 = 5;
351 \\ if (i < @as(u8, 4)) {
352 \\ i += 10;
353 \\ } else {
354 \\ i = 2;
355 \\ }
356 \\ return i - 2;
357 \\}
358 , "");
359
360 case.addCompareOutput(
361 \\pub fn main() u8 {
362 \\ var i: u8 = 5;
363 \\ if (i < @as(u8, 4)) {
364 \\ i += 10;
365 \\ } else if(i == @as(u8, 5)) {
366 \\ i = 20;
367 \\ }
368 \\ return i - 20;
369 \\}
370 , "");
371
372 case.addCompareOutput(
373 \\pub fn main() u8 {
374 \\ var i: u8 = 11;
375 \\ if (i < @as(u8, 4)) {
376 \\ i += 10;
377 \\ } else {
378 \\ if (i > @as(u8, 10)) {
379 \\ i += 20;
380 \\ } else {
381 \\ i = 20;
382 \\ }
383 \\ }
384 \\ return i - 31;
385 \\}
386 , "");
387
388 case.addCompareOutput(
389 \\pub fn main() void {
390 \\ assert(foo(true) != @as(i32, 30));
391 \\}
392 \\
393 \\fn assert(ok: bool) void {
394 \\ if (!ok) unreachable;
395 \\}
396 \\
397 \\fn foo(ok: bool) i32 {
398 \\ const x = if(ok) @as(i32, 20) else @as(i32, 10);
399 \\ return x;
400 \\}
401 , "");
402
403 case.addCompareOutput(
404 \\pub fn main() void {
405 \\ assert(foo(false) == @as(i32, 20));
406 \\ assert(foo(true) == @as(i32, 30));
407 \\}
408 \\
409 \\fn assert(ok: bool) void {
410 \\ if (!ok) unreachable;
411 \\}
412 \\
413 \\fn foo(ok: bool) i32 {
414 \\ const val: i32 = blk: {
415 \\ var x: i32 = 1;
416 \\ if (!ok) break :blk x + @as(i32, 9);
417 \\ break :blk x + @as(i32, 19);
418 \\ };
419 \\ return val + 10;
420 \\}
421 , "");
422 }
423
424 {
425 var case = ctx.exe("wasm while loops", wasi);
426
427 case.addCompareOutput(
428 \\pub fn main() u8 {
429 \\ var i: u8 = 0;
430 \\ while(i < @as(u8, 5)){
431 \\ i += 1;
432 \\ }
433 \\
434 \\ return i - 5;
435 \\}
436 , "");
437
438 case.addCompareOutput(
439 \\pub fn main() u8 {
440 \\ var i: u8 = 0;
441 \\ while(i < @as(u8, 10)){
442 \\ var x: u8 = 1;
443 \\ i += x;
444 \\ }
445 \\ return i - 10;
446 \\}
447 , "");
448
449 case.addCompareOutput(
450 \\pub fn main() u8 {
451 \\ var i: u8 = 0;
452 \\ while(i < @as(u8, 10)){
453 \\ var x: u8 = 1;
454 \\ i += x;
455 \\ if (i == @as(u8, 5)) break;
456 \\ }
457 \\ return i - 5;
458 \\}
459 , "");
460 }
461
462 {
463 var case = ctx.exe("wasm enum values", wasi);
464
465 case.addCompareOutput(
466 \\const Number = enum { One, Two, Three };
467 \\
468 \\pub fn main() void {
469 \\ var number1 = Number.One;
470 \\ var number2: Number = .Two;
471 \\ if (false) {
472 \\ number1;
473 \\ number2;
474 \\ }
475 \\ const number3 = @intToEnum(Number, 2);
476 \\ if (@enumToInt(number3) != 2) {
477 \\ unreachable;
478 \\ }
479 \\ return;
480 \\}
481 , "");
482
483 case.addCompareOutput(
484 \\const Number = enum { One, Two, Three };
485 \\
486 \\pub fn main() void {
487 \\ var number1 = Number.One;
488 \\ var number2: Number = .Two;
489 \\ const number3 = @intToEnum(Number, 2);
490 \\ assert(number1 != number2);
491 \\ assert(number2 != number3);
492 \\ assert(@enumToInt(number1) == 0);
493 \\ assert(@enumToInt(number2) == 1);
494 \\ assert(@enumToInt(number3) == 2);
495 \\ var x: Number = .Two;
496 \\ assert(number2 == x);
497 \\
498 \\ return;
499 \\}
500 \\fn assert(val: bool) void {
501 \\ if(!val) unreachable;
502 \\}
503 , "");
504 }
505
506 {
507 var case = ctx.exe("wasm structs", wasi);
508
509 case.addCompareOutput(
510 \\const Example = struct { x: u8 };
511 \\
512 \\pub fn main() u8 {
513 \\ var example: Example = .{ .x = 5 };
514 \\ return example.x - 5;
515 \\}
516 , "");
517
518 case.addCompareOutput(
519 \\const Example = struct { x: u8 };
520 \\
521 \\pub fn main() u8 {
522 \\ var example: Example = .{ .x = 5 };
523 \\ example.x = 10;
524 \\ return example.x - 10;
525 \\}
526 , "");
527
528 case.addCompareOutput(
529 \\const Example = struct { x: u8, y: u8 };
530 \\
531 \\pub fn main() u8 {
532 \\ var example: Example = .{ .x = 5, .y = 10 };
533 \\ return example.y + example.x - 15;
534 \\}
535 , "");
536
537 case.addCompareOutput(
538 \\const Example = struct { x: u8, y: u8 };
539 \\
540 \\pub fn main() u8 {
541 \\ var example: Example = .{ .x = 5, .y = 10 };
542 \\ var example2: Example = .{ .x = 10, .y = 20 };
543 \\
544 \\ example = example2;
545 \\ return example.y + example.x - 30;
546 \\}
547 , "");
548
549 case.addCompareOutput(
550 \\const Example = struct { x: u8, y: u8 };
551 \\
552 \\pub fn main() u8 {
553 \\ var example: Example = .{ .x = 5, .y = 10 };
554 \\
555 \\ example = .{ .x = 10, .y = 20 };
556 \\ return example.y + example.x - 30;
557 \\}
558 , "");
559 }
560
561 {
562 var case = ctx.exe("wasm switch", wasi);
563
564 case.addCompareOutput(
565 \\pub fn main() u8 {
566 \\ var val: u8 = 1;
567 \\ var a: u8 = switch (val) {
568 \\ 0, 1 => 2,
569 \\ 2 => 3,
570 \\ 3 => 4,
571 \\ else => 5,
572 \\ };
573 \\
574 \\ return a - 2;
575 \\}
576 , "");
577
578 case.addCompareOutput(
579 \\pub fn main() u8 {
580 \\ var val: u8 = 2;
581 \\ var a: u8 = switch (val) {
582 \\ 0, 1 => 2,
583 \\ 2 => 3,
584 \\ 3 => 4,
585 \\ else => 5,
586 \\ };
587 \\
588 \\ return a - 3;
589 \\}
590 , "");
591
592 case.addCompareOutput(
593 \\pub fn main() u8 {
594 \\ var val: u8 = 10;
595 \\ var a: u8 = switch (val) {
596 \\ 0, 1 => 2,
597 \\ 2 => 3,
598 \\ 3 => 4,
599 \\ else => 5,
600 \\ };
601 \\
602 \\ return a - 5;
603 \\}
604 , "");
605
606 case.addCompareOutput(
607 \\const MyEnum = enum { One, Two, Three };
608 \\
609 \\pub fn main() u8 {
610 \\ var val: MyEnum = .Two;
611 \\ var a: u8 = switch (val) {
612 \\ .One => 1,
613 \\ .Two => 2,
614 \\ .Three => 3,
615 \\ };
616 \\
617 \\ return a - 2;
618 \\}
619 , "");
620 }
621
622 {
623 var case = ctx.exe("wasm error unions", wasi);
624
625 case.addCompareOutput(
626 \\pub fn main() void {
627 \\ var e1 = error.Foo;
628 \\ var e2 = error.Bar;
629 \\ assert(e1 != e2);
630 \\ assert(e1 == error.Foo);
631 \\ assert(e2 == error.Bar);
632 \\}
633 \\
634 \\fn assert(b: bool) void {
635 \\ if (!b) unreachable;
636 \\}
637 , "");
638
639 case.addCompareOutput(
640 \\pub fn main() u8 {
641 \\ var e: anyerror!u8 = 5;
642 \\ const i = e catch 10;
643 \\ return i - 5;
644 \\}
645 , "");
646
647 case.addCompareOutput(
648 \\pub fn main() u8 {
649 \\ var e: anyerror!u8 = error.Foo;
650 \\ const i = e catch 10;
651 \\ return i - 10;
652 \\}
653 , "");
654
655 case.addCompareOutput(
656 \\pub fn main() u8 {
657 \\ var e = foo();
658 \\ const i = e catch 69;
659 \\ return i - 5;
660 \\}
661 \\
662 \\fn foo() anyerror!u8 {
663 \\ return 5;
664 \\}
665 , "");
666 }
667
668 {
669 var case = ctx.exe("wasm error union part 2", wasi);
670
671 case.addCompareOutput(
672 \\pub fn main() u8 {
673 \\ var e = foo();
674 \\ const i = e catch 69;
675 \\ return i - 69;
676 \\}
677 \\
678 \\fn foo() anyerror!u8 {
679 \\ return error.Bruh;
680 \\}
681 , "");
682 case.addCompareOutput(
683 \\pub fn main() u8 {
684 \\ var e = foo();
685 \\ const i = e catch 42;
686 \\ return i - 42;
687 \\}
688 \\
689 \\fn foo() anyerror!u8 {
690 \\ return error.Dab;
691 \\}
692 , "");
693 }
694
695 {
696 var case = ctx.exe("wasm integer widening", wasi);
697
698 case.addCompareOutput(
699 \\pub fn main() void{
700 \\ var x: u8 = 5;
701 \\ var y: u64 = x;
702 \\ _ = y;
703 \\ return;
704 \\}
705 , "");
706 }
707
708 {
709 var case = ctx.exe("wasm optionals", wasi);
710
711 case.addCompareOutput(
712 \\pub fn main() u8 {
713 \\ var x: ?u8 = 5;
714 \\ var y: u8 = 0;
715 \\ if (x) |val| {
716 \\ y = val;
717 \\ }
718 \\ return y - 5;
719 \\}
720 , "");
721
722 case.addCompareOutput(
723 \\pub fn main() u8 {
724 \\ var x: ?u8 = null;
725 \\ var y: u8 = 0;
726 \\ if (x) |val| {
727 \\ y = val;
728 \\ }
729 \\ return y;
730 \\}
731 , "");
732
733 case.addCompareOutput(
734 \\pub fn main() u8 {
735 \\ var x: ?u8 = 5;
736 \\ return x.? - 5;
737 \\}
738 , "");
739
740 case.addCompareOutput(
741 \\pub fn main() u8 {
742 \\ var x: u8 = 5;
743 \\ var y: ?u8 = x;
744 \\ return y.? - 5;
745 \\}
746 , "");
747
748 case.addCompareOutput(
749 \\pub fn main() u8 {
750 \\ var val: ?u8 = 5;
751 \\ while (val) |*v| {
752 \\ v.* -= 1;
753 \\ if (v.* == 2) {
754 \\ val = null;
755 \\ }
756 \\ }
757 \\ return 0;
758 \\}
759 , "");
760 }
761
762 {
763 var case = ctx.exe("wasm pointers", wasi);
764
765 case.addCompareOutput(
766 \\pub fn main() u8 {
767 \\ var x: u8 = 0;
768 \\
769 \\ foo(&x);
770 \\ return x - 2;
771 \\}
772 \\
773 \\fn foo(x: *u8)void {
774 \\ x.* = 2;
775 \\}
776 , "");
777
778 case.addCompareOutput(
779 \\pub fn main() u8 {
780 \\ var x: u8 = 0;
781 \\
782 \\ foo(&x);
783 \\ bar(&x);
784 \\ return x - 4;
785 \\}
786 \\
787 \\fn foo(x: *u8)void {
788 \\ x.* = 2;
789 \\}
790 \\
791 \\fn bar(x: *u8) void {
792 \\ x.* += 2;
793 \\}
794 , "");
795 }
796}
test/stage2/x86_64.zig deleted-2288
...@@ -1,2288 +0,0 @@
1const std = @import("std");
2const CrossTarget = std.zig.CrossTarget;
3const TestContext = @import("../../src/test.zig").TestContext;
4
5const linux_x64 = std.zig.CrossTarget{
6 .cpu_arch = .x86_64,
7 .os_tag = .linux,
8};
9const macos_x64 = CrossTarget{
10 .cpu_arch = .x86_64,
11 .os_tag = .macos,
12};
13const all_targets: []const CrossTarget = &[_]CrossTarget{
14 linux_x64,
15 macos_x64,
16};
17
18pub fn addCases(ctx: *TestContext) !void {
19 try addLinuxTestCases(ctx);
20 try addMacOsTestCases(ctx);
21
22 // Common tests
23 for (all_targets) |target| {
24 {
25 var case = ctx.exe("adding numbers at runtime and comptime", target);
26 case.addCompareOutput(
27 \\pub fn main() void {
28 \\ add(3, 4);
29 \\}
30 \\
31 \\fn add(a: u32, b: u32) void {
32 \\ if (a + b != 7) unreachable;
33 \\}
34 ,
35 "",
36 );
37 // comptime function call
38 case.addCompareOutput(
39 \\pub fn main() void {
40 \\ if (x - 7 != 0) unreachable;
41 \\}
42 \\
43 \\fn add(a: u32, b: u32) u32 {
44 \\ return a + b;
45 \\}
46 \\
47 \\const x = add(3, 4);
48 ,
49 "",
50 );
51 // Inline function call
52 case.addCompareOutput(
53 \\pub fn main() void {
54 \\ var x: usize = 3;
55 \\ const y = add(1, 2, x);
56 \\ if (y - 6 != 0) unreachable;
57 \\}
58 \\
59 \\fn add(a: usize, b: usize, c: usize) callconv(.Inline) usize {
60 \\ return a + b + c;
61 \\}
62 ,
63 "",
64 );
65 }
66
67 {
68 var case = ctx.exe("subtracting numbers at runtime", target);
69 case.addCompareOutput(
70 \\pub fn main() void {
71 \\ sub(7, 4);
72 \\}
73 \\
74 \\fn sub(a: u32, b: u32) void {
75 \\ if (a - b != 3) unreachable;
76 \\}
77 ,
78 "",
79 );
80 }
81
82 {
83 var case = ctx.exe("unused vars", target);
84 case.addError(
85 \\pub fn main() void {
86 \\ const x = 1;
87 \\}
88 , &.{":2:11: error: unused local constant"});
89 }
90
91 {
92 var case = ctx.exe("multiplying numbers at runtime and comptime", target);
93 case.addCompareOutput(
94 \\pub fn main() void {
95 \\ mul(3, 4);
96 \\}
97 \\
98 \\fn mul(a: u32, b: u32) void {
99 \\ if (a * b != 12) unreachable;
100 \\}
101 ,
102 "",
103 );
104 // comptime function call
105 case.addCompareOutput(
106 \\pub fn main() void {
107 \\ if (x - 12 != 0) unreachable;
108 \\}
109 \\
110 \\fn mul(a: u32, b: u32) u32 {
111 \\ return a * b;
112 \\}
113 \\
114 \\const x = mul(3, 4);
115 ,
116 "",
117 );
118 // Inline function call
119 case.addCompareOutput(
120 \\pub fn main() void {
121 \\ var x: usize = 5;
122 \\ const y = mul(2, 3, x);
123 \\ if (y - 30 != 0) unreachable;
124 \\}
125 \\
126 \\fn mul(a: usize, b: usize, c: usize) callconv(.Inline) usize {
127 \\ return a * b * c;
128 \\}
129 ,
130 "",
131 );
132 }
133
134 {
135 var case = ctx.exe("assert function", target);
136 case.addCompareOutput(
137 \\pub fn main() void {
138 \\ add(3, 4);
139 \\}
140 \\
141 \\fn add(a: u32, b: u32) void {
142 \\ assert(a + b == 7);
143 \\}
144 \\
145 \\pub fn assert(ok: bool) void {
146 \\ if (!ok) unreachable; // assertion failure
147 \\}
148 ,
149 "",
150 );
151
152 // Tests copying a register. For the `c = a + b`, it has to
153 // preserve both a and b, because they are both used later.
154 case.addCompareOutput(
155 \\pub fn main() void {
156 \\ add(3, 4);
157 \\}
158 \\
159 \\fn add(a: u32, b: u32) void {
160 \\ const c = a + b; // 7
161 \\ const d = a + c; // 10
162 \\ const e = d + b; // 14
163 \\ assert(e == 14);
164 \\}
165 \\
166 \\pub fn assert(ok: bool) void {
167 \\ if (!ok) unreachable; // assertion failure
168 \\}
169 ,
170 "",
171 );
172
173 // More stress on the liveness detection.
174 case.addCompareOutput(
175 \\pub fn main() void {
176 \\ add(3, 4);
177 \\}
178 \\
179 \\fn add(a: u32, b: u32) void {
180 \\ const c = a + b; // 7
181 \\ const d = a + c; // 10
182 \\ const e = d + b; // 14
183 \\ const f = d + e; // 24
184 \\ const g = e + f; // 38
185 \\ const h = f + g; // 62
186 \\ const i = g + h; // 100
187 \\ assert(i == 100);
188 \\}
189 \\
190 \\pub fn assert(ok: bool) void {
191 \\ if (!ok) unreachable; // assertion failure
192 \\}
193 ,
194 "",
195 );
196
197 // Requires a second move. The register allocator should figure out to re-use rax.
198 case.addCompareOutput(
199 \\pub fn main() void {
200 \\ add(3, 4);
201 \\}
202 \\
203 \\fn add(a: u32, b: u32) void {
204 \\ const c = a + b; // 7
205 \\ const d = a + c; // 10
206 \\ const e = d + b; // 14
207 \\ const f = d + e; // 24
208 \\ const g = e + f; // 38
209 \\ const h = f + g; // 62
210 \\ const i = g + h; // 100
211 \\ const j = i + d; // 110
212 \\ assert(j == 110);
213 \\}
214 \\
215 \\pub fn assert(ok: bool) void {
216 \\ if (!ok) unreachable; // assertion failure
217 \\}
218 ,
219 "",
220 );
221
222 // Now we test integer return values.
223 case.addCompareOutput(
224 \\pub fn main() void {
225 \\ assert(add(3, 4) == 7);
226 \\ assert(add(20, 10) == 30);
227 \\}
228 \\
229 \\fn add(a: u32, b: u32) u32 {
230 \\ return a + b;
231 \\}
232 \\
233 \\pub fn assert(ok: bool) void {
234 \\ if (!ok) unreachable; // assertion failure
235 \\}
236 ,
237 "",
238 );
239
240 // Local mutable variables.
241 case.addCompareOutput(
242 \\pub fn main() void {
243 \\ assert(add(3, 4) == 7);
244 \\ assert(add(20, 10) == 30);
245 \\}
246 \\
247 \\fn add(a: u32, b: u32) u32 {
248 \\ var x: u32 = undefined;
249 \\ x = 0;
250 \\ x += a;
251 \\ x += b;
252 \\ return x;
253 \\}
254 \\
255 \\pub fn assert(ok: bool) void {
256 \\ if (!ok) unreachable; // assertion failure
257 \\}
258 ,
259 "",
260 );
261
262 // Optionals
263 case.addCompareOutput(
264 \\pub fn main() void {
265 \\ const a: u32 = 2;
266 \\ const b: ?u32 = a;
267 \\ const c = b.?;
268 \\ if (c != 2) unreachable;
269 \\}
270 ,
271 "",
272 );
273
274 switch (target.getOsTag()) {
275 .linux => {
276 // While loops
277 case.addCompareOutput(
278 \\pub fn main() void {
279 \\ var i: u32 = 0;
280 \\ while (i < 4) : (i += 1) print();
281 \\ assert(i == 4);
282 \\}
283 \\
284 \\fn print() void {
285 \\ asm volatile ("syscall"
286 \\ :
287 \\ : [number] "{rax}" (1),
288 \\ [arg1] "{rdi}" (1),
289 \\ [arg2] "{rsi}" (@ptrToInt("hello\n")),
290 \\ [arg3] "{rdx}" (6)
291 \\ : "rcx", "r11", "memory"
292 \\ );
293 \\ return;
294 \\}
295 \\
296 \\pub fn assert(ok: bool) void {
297 \\ if (!ok) unreachable; // assertion failure
298 \\}
299 ,
300 "hello\nhello\nhello\nhello\n",
301 );
302
303 // inline while requires the condition to be comptime known.
304 case.addError(
305 \\pub fn main() void {
306 \\ var i: u32 = 0;
307 \\ inline while (i < 4) : (i += 1) print();
308 \\ assert(i == 4);
309 \\}
310 \\
311 \\fn print() void {
312 \\ asm volatile ("syscall"
313 \\ :
314 \\ : [number] "{rax}" (1),
315 \\ [arg1] "{rdi}" (1),
316 \\ [arg2] "{rsi}" (@ptrToInt("hello\n")),
317 \\ [arg3] "{rdx}" (6)
318 \\ : "rcx", "r11", "memory"
319 \\ );
320 \\ return;
321 \\}
322 \\
323 \\pub fn assert(ok: bool) void {
324 \\ if (!ok) unreachable; // assertion failure
325 \\}
326 , &[_][]const u8{":3:21: error: unable to resolve comptime value"});
327 },
328 .macos => {
329 // While loops
330 case.addCompareOutput(
331 \\extern "c" fn write(usize, usize, usize) usize;
332 \\
333 \\pub fn main() void {
334 \\ var i: u32 = 0;
335 \\ while (i < 4) : (i += 1) print();
336 \\ assert(i == 4);
337 \\}
338 \\
339 \\fn print() void {
340 \\ _ = write(1, @ptrToInt("hello\n"), 6);
341 \\}
342 \\
343 \\pub fn assert(ok: bool) void {
344 \\ if (!ok) unreachable; // assertion failure
345 \\}
346 ,
347 "hello\nhello\nhello\nhello\n",
348 );
349
350 // inline while requires the condition to be comptime known.
351 case.addError(
352 \\extern "c" fn write(usize, usize, usize) usize;
353 \\
354 \\pub fn main() void {
355 \\ var i: u32 = 0;
356 \\ inline while (i < 4) : (i += 1) print();
357 \\ assert(i == 4);
358 \\}
359 \\
360 \\fn print() void {
361 \\ _ = write(1, @ptrToInt("hello\n"), 6);
362 \\}
363 \\
364 \\pub fn assert(ok: bool) void {
365 \\ if (!ok) unreachable; // assertion failure
366 \\}
367 , &[_][]const u8{":5:21: error: unable to resolve comptime value"});
368 },
369 else => unreachable,
370 }
371
372 // Labeled blocks (no conditional branch)
373 case.addCompareOutput(
374 \\pub fn main() void {
375 \\ assert(add(3, 4) == 20);
376 \\}
377 \\
378 \\fn add(a: u32, b: u32) u32 {
379 \\ const x: u32 = blk: {
380 \\ const c = a + b; // 7
381 \\ const d = a + c; // 10
382 \\ const e = d + b; // 14
383 \\ break :blk e;
384 \\ };
385 \\ const y = x + a; // 17
386 \\ const z = y + a; // 20
387 \\ return z;
388 \\}
389 \\
390 \\pub fn assert(ok: bool) void {
391 \\ if (!ok) unreachable; // assertion failure
392 \\}
393 ,
394 "",
395 );
396
397 // This catches a possible bug in the logic for re-using dying operands.
398 case.addCompareOutput(
399 \\pub fn main() void {
400 \\ assert(add(3, 4) == 116);
401 \\}
402 \\
403 \\fn add(a: u32, b: u32) u32 {
404 \\ const x: u32 = blk: {
405 \\ const c = a + b; // 7
406 \\ const d = a + c; // 10
407 \\ const e = d + b; // 14
408 \\ const f = d + e; // 24
409 \\ const g = e + f; // 38
410 \\ const h = f + g; // 62
411 \\ const i = g + h; // 100
412 \\ const j = i + d; // 110
413 \\ break :blk j;
414 \\ };
415 \\ const y = x + a; // 113
416 \\ const z = y + a; // 116
417 \\ return z;
418 \\}
419 \\
420 \\pub fn assert(ok: bool) void {
421 \\ if (!ok) unreachable; // assertion failure
422 \\}
423 ,
424 "",
425 );
426
427 // Spilling registers to the stack.
428 case.addCompareOutput(
429 \\pub fn main() void {
430 \\ assert(add(3, 4) == 1221);
431 \\ assert(mul(3, 4) == 21609);
432 \\}
433 \\
434 \\fn add(a: u32, b: u32) u32 {
435 \\ const x: u32 = blk: {
436 \\ const c = a + b; // 7
437 \\ const d = a + c; // 10
438 \\ const e = d + b; // 14
439 \\ const f = d + e; // 24
440 \\ const g = e + f; // 38
441 \\ const h = f + g; // 62
442 \\ const i = g + h; // 100
443 \\ const j = i + d; // 110
444 \\ const k = i + j; // 210
445 \\ const l = j + k; // 320
446 \\ const m = l + c; // 327
447 \\ const n = m + d; // 337
448 \\ const o = n + e; // 351
449 \\ const p = o + f; // 375
450 \\ const q = p + g; // 413
451 \\ const r = q + h; // 475
452 \\ const s = r + i; // 575
453 \\ const t = s + j; // 685
454 \\ const u = t + k; // 895
455 \\ const v = u + l; // 1215
456 \\ break :blk v;
457 \\ };
458 \\ const y = x + a; // 1218
459 \\ const z = y + a; // 1221
460 \\ return z;
461 \\}
462 \\
463 \\fn mul(a: u32, b: u32) u32 {
464 \\ const x: u32 = blk: {
465 \\ const c = a * a * a * a; // 81
466 \\ const d = a * a * a * b; // 108
467 \\ const e = a * a * b * a; // 108
468 \\ const f = a * a * b * b; // 144
469 \\ const g = a * b * a * a; // 108
470 \\ const h = a * b * a * b; // 144
471 \\ const i = a * b * b * a; // 144
472 \\ const j = a * b * b * b; // 192
473 \\ const k = b * a * a * a; // 108
474 \\ const l = b * a * a * b; // 144
475 \\ const m = b * a * b * a; // 144
476 \\ const n = b * a * b * b; // 192
477 \\ const o = b * b * a * a; // 144
478 \\ const p = b * b * a * b; // 192
479 \\ const q = b * b * b * a; // 192
480 \\ const r = b * b * b * b; // 256
481 \\ const s = c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r; // 2401
482 \\ break :blk s;
483 \\ };
484 \\ const y = x * a; // 7203
485 \\ const z = y * a; // 21609
486 \\ return z;
487 \\}
488 \\
489 \\pub fn assert(ok: bool) void {
490 \\ if (!ok) unreachable; // assertion failure
491 \\}
492 ,
493 "",
494 );
495
496 // Reusing the registers of dead operands playing nicely with conditional branching.
497 case.addCompareOutput(
498 \\pub fn main() void {
499 \\ assert(add(3, 4) == 791);
500 \\ assert(add(4, 3) == 79);
501 \\}
502 \\
503 \\fn add(a: u32, b: u32) u32 {
504 \\ const x: u32 = if (a < b) blk: {
505 \\ const c = a + b; // 7
506 \\ const d = a + c; // 10
507 \\ const e = d + b; // 14
508 \\ const f = d + e; // 24
509 \\ const g = e + f; // 38
510 \\ const h = f + g; // 62
511 \\ const i = g + h; // 100
512 \\ const j = i + d; // 110
513 \\ const k = i + j; // 210
514 \\ const l = k + c; // 217
515 \\ const m = l + d; // 227
516 \\ const n = m + e; // 241
517 \\ const o = n + f; // 265
518 \\ const p = o + g; // 303
519 \\ const q = p + h; // 365
520 \\ const r = q + i; // 465
521 \\ const s = r + j; // 575
522 \\ const t = s + k; // 785
523 \\ break :blk t;
524 \\ } else blk: {
525 \\ const t = b + b + a; // 10
526 \\ const c = a + t; // 14
527 \\ const d = c + t; // 24
528 \\ const e = d + t; // 34
529 \\ const f = e + t; // 44
530 \\ const g = f + t; // 54
531 \\ const h = c + g; // 68
532 \\ break :blk h + b; // 71
533 \\ };
534 \\ const y = x + a; // 788, 75
535 \\ const z = y + a; // 791, 79
536 \\ return z;
537 \\}
538 \\
539 \\pub fn assert(ok: bool) void {
540 \\ if (!ok) unreachable; // assertion failure
541 \\}
542 ,
543 "",
544 );
545
546 // Character literals and multiline strings.
547 case.addCompareOutput(
548 \\pub fn main() void {
549 \\ const ignore =
550 \\ \\ cool thx
551 \\ \\
552 \\ ;
553 \\ _ = ignore;
554 \\ add('ぁ', '\x03');
555 \\}
556 \\
557 \\fn add(a: u32, b: u32) void {
558 \\ assert(a + b == 12356);
559 \\}
560 \\
561 \\pub fn assert(ok: bool) void {
562 \\ if (!ok) unreachable; // assertion failure
563 \\}
564 ,
565 "",
566 );
567
568 // Global const.
569 case.addCompareOutput(
570 \\pub fn main() void {
571 \\ add(aa, bb);
572 \\}
573 \\
574 \\const aa = 'ぁ';
575 \\const bb = '\x03';
576 \\
577 \\fn add(a: u32, b: u32) void {
578 \\ assert(a + b == 12356);
579 \\}
580 \\
581 \\pub fn assert(ok: bool) void {
582 \\ if (!ok) unreachable; // assertion failure
583 \\}
584 ,
585 "",
586 );
587
588 // Array access.
589 case.addCompareOutput(
590 \\pub fn main() void {
591 \\ assert("hello"[0] == 'h');
592 \\}
593 \\
594 \\pub fn assert(ok: bool) void {
595 \\ if (!ok) unreachable; // assertion failure
596 \\}
597 ,
598 "",
599 );
600
601 // Array access to a global array.
602 case.addCompareOutput(
603 \\const hello = "hello".*;
604 \\pub fn main() void {
605 \\ assert(hello[1] == 'e');
606 \\}
607 \\
608 \\pub fn assert(ok: bool) void {
609 \\ if (!ok) unreachable; // assertion failure
610 \\}
611 ,
612 "",
613 );
614
615 // 64bit set stack
616 case.addCompareOutput(
617 \\pub fn main() void {
618 \\ var i: u64 = 0xFFEEDDCCBBAA9988;
619 \\ assert(i == 0xFFEEDDCCBBAA9988);
620 \\}
621 \\
622 \\pub fn assert(ok: bool) void {
623 \\ if (!ok) unreachable; // assertion failure
624 \\}
625 ,
626 "",
627 );
628
629 switch (target.getOsTag()) {
630 .linux => {
631 // Basic for loop
632 case.addCompareOutput(
633 \\pub fn main() void {
634 \\ for ("hello") |_| print();
635 \\}
636 \\
637 \\fn print() void {
638 \\ asm volatile ("syscall"
639 \\ :
640 \\ : [number] "{rax}" (1),
641 \\ [arg1] "{rdi}" (1),
642 \\ [arg2] "{rsi}" (@ptrToInt("hello\n")),
643 \\ [arg3] "{rdx}" (6)
644 \\ : "rcx", "r11", "memory"
645 \\ );
646 \\ return;
647 \\}
648 ,
649 "hello\nhello\nhello\nhello\nhello\n",
650 );
651 },
652 .macos => {
653 // Basic for loop
654 case.addCompareOutput(
655 \\extern "c" fn write(usize, usize, usize) usize;
656 \\
657 \\pub fn main() void {
658 \\ for ("hello") |_| print();
659 \\}
660 \\
661 \\fn print() void {
662 \\ _ = write(1, @ptrToInt("hello\n"), 6);
663 \\}
664 ,
665 "hello\nhello\nhello\nhello\nhello\n",
666 );
667 },
668 else => unreachable,
669 }
670 }
671
672 {
673 var case = ctx.exe("@TypeOf", target);
674 case.addCompareOutput(
675 \\pub fn main() void {
676 \\ var x: usize = 0;
677 \\ _ = x;
678 \\ const z = @TypeOf(x, @as(u128, 5));
679 \\ assert(z == u128);
680 \\}
681 \\
682 \\pub fn assert(ok: bool) void {
683 \\ if (!ok) unreachable; // assertion failure
684 \\}
685 ,
686 "",
687 );
688 case.addCompareOutput(
689 \\pub fn main() void {
690 \\ const z = @TypeOf(true);
691 \\ assert(z == bool);
692 \\}
693 \\
694 \\pub fn assert(ok: bool) void {
695 \\ if (!ok) unreachable; // assertion failure
696 \\}
697 ,
698 "",
699 );
700 case.addError(
701 \\pub fn main() void {
702 \\ _ = @TypeOf(true, 1);
703 \\}
704 , &[_][]const u8{
705 ":2:9: error: incompatible types: 'bool' and 'comptime_int'",
706 ":2:17: note: type 'bool' here",
707 ":2:23: note: type 'comptime_int' here",
708 });
709 }
710
711 {
712 var case = ctx.exe("basic import", target);
713 case.addCompareOutput(
714 \\pub fn main() void {
715 \\ @import("print.zig").print();
716 \\}
717 ,
718 "Hello, World!\n",
719 );
720 switch (target.getOsTag()) {
721 .linux => try case.files.append(.{
722 .src =
723 \\pub fn print() void {
724 \\ asm volatile ("syscall"
725 \\ :
726 \\ : [number] "{rax}" (@as(usize, 1)),
727 \\ [arg1] "{rdi}" (@as(usize, 1)),
728 \\ [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
729 \\ [arg3] "{rdx}" (@as(usize, 14))
730 \\ : "rcx", "r11", "memory"
731 \\ );
732 \\ return;
733 \\}
734 ,
735 .path = "print.zig",
736 }),
737 .macos => try case.files.append(.{
738 .src =
739 \\extern "c" fn write(usize, usize, usize) usize;
740 \\
741 \\pub fn print() void {
742 \\ _ = write(1, @ptrToInt("Hello, World!\n"), 14);
743 \\}
744 ,
745 .path = "print.zig",
746 }),
747 else => unreachable,
748 }
749 }
750
751 {
752 var case = ctx.exe("redundant comptime", target);
753 case.addError(
754 \\pub fn main() void {
755 \\ var a: comptime u32 = 0;
756 \\}
757 ,
758 &.{":2:12: error: redundant comptime keyword in already comptime scope"},
759 );
760 case.addError(
761 \\pub fn main() void {
762 \\ comptime {
763 \\ var a: u32 = comptime 0;
764 \\ }
765 \\}
766 ,
767 &.{":3:22: error: redundant comptime keyword in already comptime scope"},
768 );
769 }
770 {
771 var case = ctx.exe("try in comptime in struct in test", target);
772 case.addError(
773 \\test "@unionInit on union w/ tag but no fields" {
774 \\ const S = struct {
775 \\ comptime {
776 \\ try expect(false);
777 \\ }
778 \\ };
779 \\ _ = S;
780 \\}
781 ,
782 &.{":4:13: error: 'try' outside function scope"},
783 );
784 }
785 {
786 var case = ctx.exe("import private", target);
787 case.addError(
788 \\pub fn main() void {
789 \\ @import("print.zig").print();
790 \\}
791 ,
792 &.{
793 ":2:25: error: 'print' is not marked 'pub'",
794 "print.zig:2:1: note: declared here",
795 },
796 );
797 switch (target.getOsTag()) {
798 .linux => try case.files.append(.{
799 .src =
800 \\// dummy comment to make print be on line 2
801 \\fn print() void {
802 \\ asm volatile ("syscall"
803 \\ :
804 \\ : [number] "{rax}" (@as(usize, 1)),
805 \\ [arg1] "{rdi}" (@as(usize, 1)),
806 \\ [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
807 \\ [arg3] "{rdx}" (@as(usize, 14))
808 \\ : "rcx", "r11", "memory"
809 \\ );
810 \\ return;
811 \\}
812 ,
813 .path = "print.zig",
814 }),
815 .macos => try case.files.append(.{
816 .src =
817 \\extern "c" fn write(usize, usize, usize) usize;
818 \\fn print() void {
819 \\ _ = write(1, @ptrToInt("Hello, World!\n"), 14);
820 \\}
821 ,
822 .path = "print.zig",
823 }),
824 else => unreachable,
825 }
826 }
827
828 ctx.compileError("function redeclaration", target,
829 \\// dummy comment
830 \\fn entry() void {}
831 \\fn entry() void {}
832 \\
833 \\fn foo() void {
834 \\ var foo = 1234;
835 \\}
836 , &[_][]const u8{
837 ":3:1: error: redeclaration of 'entry'",
838 ":2:1: note: other declaration here",
839 ":6:9: error: local shadows declaration of 'foo'",
840 ":5:1: note: declared here",
841 });
842
843 ctx.compileError("returns in try", target,
844 \\pub fn main() !void {
845 \\ try a();
846 \\ try b();
847 \\}
848 \\
849 \\pub fn a() !void {
850 \\ defer try b();
851 \\}
852 \\pub fn b() !void {
853 \\ defer return a();
854 \\}
855 , &[_][]const u8{
856 ":7:8: error: 'try' not allowed inside defer expression",
857 ":10:8: error: cannot return from defer expression",
858 });
859
860 ctx.compileError("ambiguous references", target,
861 \\const T = struct {
862 \\ const T = struct {
863 \\ fn f() void {
864 \\ _ = T;
865 \\ }
866 \\ };
867 \\};
868 , &.{
869 ":4:17: error: ambiguous reference",
870 ":2:5: note: declared here",
871 ":1:1: note: also declared here",
872 });
873
874 ctx.compileError("inner func accessing outer var", target,
875 \\pub fn f() void {
876 \\ var bar: bool = true;
877 \\ const S = struct {
878 \\ fn baz() bool {
879 \\ return bar;
880 \\ }
881 \\ };
882 \\ _ = S;
883 \\}
884 , &.{
885 ":5:20: error: mutable 'bar' not accessible from here",
886 ":2:9: note: declared mutable here",
887 ":3:15: note: crosses namespace boundary here",
888 });
889
890 ctx.compileError("global variable redeclaration", target,
891 \\// dummy comment
892 \\var foo = false;
893 \\var foo = true;
894 , &[_][]const u8{
895 ":3:1: error: redeclaration of 'foo'",
896 ":2:1: note: other declaration here",
897 });
898
899 ctx.compileError("compileError", target,
900 \\export fn foo() void {
901 \\ @compileError("this is an error");
902 \\}
903 , &[_][]const u8{":2:3: error: this is an error"});
904
905 {
906 var case = ctx.exe("intToPtr", target);
907 case.addError(
908 \\pub fn main() void {
909 \\ _ = @intToPtr(*u8, 0);
910 \\}
911 , &[_][]const u8{
912 ":2:24: error: pointer type '*u8' does not allow address zero",
913 });
914 case.addError(
915 \\pub fn main() void {
916 \\ _ = @intToPtr(*u32, 2);
917 \\}
918 , &[_][]const u8{
919 ":2:25: error: pointer type '*u32' requires aligned address",
920 });
921 }
922
923 {
924 var case = ctx.obj("variable shadowing", target);
925 case.addError(
926 \\pub fn main() void {
927 \\ var i: u32 = 10;
928 \\ var i: u32 = 10;
929 \\}
930 , &[_][]const u8{
931 ":3:9: error: redeclaration of local variable 'i'",
932 ":2:9: note: previous declaration here",
933 });
934 case.addError(
935 \\var testing: i64 = 10;
936 \\pub fn main() void {
937 \\ var testing: i64 = 20;
938 \\}
939 , &[_][]const u8{
940 ":3:9: error: local shadows declaration of 'testing'",
941 ":1:1: note: declared here",
942 });
943 case.addError(
944 \\fn a() type {
945 \\ return struct {
946 \\ pub fn b() void {
947 \\ const c = 6;
948 \\ const c = 69;
949 \\ }
950 \\ };
951 \\}
952 , &[_][]const u8{
953 ":5:19: error: redeclaration of local constant 'c'",
954 ":4:19: note: previous declaration here",
955 });
956 case.addError(
957 \\pub fn main() void {
958 \\ var i = 0;
959 \\ for ("n") |_, i| {
960 \\ }
961 \\}
962 , &[_][]const u8{
963 ":3:19: error: redeclaration of local variable 'i'",
964 ":2:9: note: previous declaration here",
965 });
966 case.addError(
967 \\pub fn main() void {
968 \\ var i = 0;
969 \\ for ("n") |i| {
970 \\ }
971 \\}
972 , &[_][]const u8{
973 ":3:16: error: redeclaration of local variable 'i'",
974 ":2:9: note: previous declaration here",
975 });
976 case.addError(
977 \\pub fn main() void {
978 \\ var i = 0;
979 \\ while ("n") |i| {
980 \\ }
981 \\}
982 , &[_][]const u8{
983 ":3:18: error: redeclaration of local variable 'i'",
984 ":2:9: note: previous declaration here",
985 });
986 case.addError(
987 \\pub fn main() void {
988 \\ var i = 0;
989 \\ while ("n") |bruh| {
990 \\ _ = bruh;
991 \\ } else |i| {
992 \\
993 \\ }
994 \\}
995 , &[_][]const u8{
996 ":5:13: error: redeclaration of local variable 'i'",
997 ":2:9: note: previous declaration here",
998 });
999 case.addError(
1000 \\pub fn main() void {
1001 \\ var i = 0;
1002 \\ if (true) |i| {}
1003 \\}
1004 , &[_][]const u8{
1005 ":3:16: error: redeclaration of local variable 'i'",
1006 ":2:9: note: previous declaration here",
1007 });
1008 case.addError(
1009 \\pub fn main() void {
1010 \\ var i = 0;
1011 \\ if (true) |i| {} else |e| {}
1012 \\}
1013 , &[_][]const u8{
1014 ":3:16: error: redeclaration of local variable 'i'",
1015 ":2:9: note: previous declaration here",
1016 });
1017 case.addError(
1018 \\pub fn main() void {
1019 \\ var i = 0;
1020 \\ if (true) |_| {} else |i| {}
1021 \\}
1022 , &[_][]const u8{
1023 ":3:28: error: redeclaration of local variable 'i'",
1024 ":2:9: note: previous declaration here",
1025 });
1026 }
1027
1028 {
1029 // TODO make the test harness support checking the compile log output too
1030 var case = ctx.obj("@compileLog", target);
1031 // The other compile error prevents emission of a "found compile log" statement.
1032 case.addError(
1033 \\export fn _start() noreturn {
1034 \\ const b = true;
1035 \\ var f: u32 = 1;
1036 \\ @compileLog(b, 20, f, x);
1037 \\ @compileLog(1000);
1038 \\ var bruh: usize = true;
1039 \\ _ = bruh;
1040 \\ unreachable;
1041 \\}
1042 \\export fn other() void {
1043 \\ @compileLog(1234);
1044 \\}
1045 \\fn x() void {}
1046 , &[_][]const u8{
1047 ":6:23: error: expected usize, found bool",
1048 });
1049
1050 // Now only compile log statements remain. One per Decl.
1051 case.addError(
1052 \\export fn _start() noreturn {
1053 \\ const b = true;
1054 \\ var f: u32 = 1;
1055 \\ @compileLog(b, 20, f, x);
1056 \\ @compileLog(1000);
1057 \\ unreachable;
1058 \\}
1059 \\export fn other() void {
1060 \\ @compileLog(1234);
1061 \\}
1062 \\fn x() void {}
1063 , &[_][]const u8{
1064 ":9:5: error: found compile log statement",
1065 ":4:5: note: also here",
1066 });
1067 }
1068
1069 {
1070 var case = ctx.obj("extern variable has no type", target);
1071 case.addError(
1072 \\comptime {
1073 \\ const x = foo + foo;
1074 \\ _ = x;
1075 \\}
1076 \\extern var foo: i32;
1077 , &[_][]const u8{":2:15: error: unable to resolve comptime value"});
1078 case.addError(
1079 \\export fn entry() void {
1080 \\ _ = foo;
1081 \\}
1082 \\extern var foo;
1083 , &[_][]const u8{":4:8: error: unable to infer variable type"});
1084 }
1085
1086 {
1087 var case = ctx.exe("break/continue", target);
1088
1089 // Break out of loop
1090 case.addCompareOutput(
1091 \\pub fn main() void {
1092 \\ while (true) {
1093 \\ break;
1094 \\ }
1095 \\}
1096 ,
1097 "",
1098 );
1099 case.addCompareOutput(
1100 \\pub fn main() void {
1101 \\ foo: while (true) {
1102 \\ break :foo;
1103 \\ }
1104 \\}
1105 ,
1106 "",
1107 );
1108
1109 // Continue in loop
1110 case.addCompareOutput(
1111 \\pub fn main() void {
1112 \\ var i: u64 = 0;
1113 \\ while (true) : (i+=1) {
1114 \\ if (i == 4) return;
1115 \\ continue;
1116 \\ }
1117 \\}
1118 ,
1119 "",
1120 );
1121 case.addCompareOutput(
1122 \\pub fn main() void {
1123 \\ var i: u64 = 0;
1124 \\ foo: while (true) : (i+=1) {
1125 \\ if (i == 4) return;
1126 \\ continue :foo;
1127 \\ }
1128 \\}
1129 ,
1130 "",
1131 );
1132 }
1133
1134 {
1135 var case = ctx.exe("unused labels", target);
1136 case.addError(
1137 \\comptime {
1138 \\ foo: {}
1139 \\}
1140 , &[_][]const u8{":2:5: error: unused block label"});
1141 case.addError(
1142 \\comptime {
1143 \\ foo: while (true) {}
1144 \\}
1145 , &[_][]const u8{":2:5: error: unused while loop label"});
1146 case.addError(
1147 \\comptime {
1148 \\ foo: for ("foo") |_| {}
1149 \\}
1150 , &[_][]const u8{":2:5: error: unused for loop label"});
1151 case.addError(
1152 \\comptime {
1153 \\ blk: {blk: {}}
1154 \\}
1155 , &[_][]const u8{
1156 ":2:11: error: redefinition of label 'blk'",
1157 ":2:5: note: previous definition here",
1158 });
1159 }
1160
1161 {
1162 var case = ctx.exe("bad inferred variable type", target);
1163 case.addError(
1164 \\pub fn main() void {
1165 \\ var x = null;
1166 \\ _ = x;
1167 \\}
1168 , &[_][]const u8{
1169 ":2:9: error: variable of type '@TypeOf(null)' must be const or comptime",
1170 });
1171 }
1172
1173 {
1174 var case = ctx.exe("compile error in inline fn call fixed", target);
1175 case.addError(
1176 \\pub fn main() void {
1177 \\ var x: usize = 3;
1178 \\ const y = add(10, 2, x);
1179 \\ if (y - 6 != 0) unreachable;
1180 \\}
1181 \\
1182 \\fn add(a: usize, b: usize, c: usize) callconv(.Inline) usize {
1183 \\ if (a == 10) @compileError("bad");
1184 \\ return a + b + c;
1185 \\}
1186 , &[_][]const u8{
1187 ":8:18: error: bad",
1188 ":3:18: note: called from here",
1189 });
1190
1191 case.addCompareOutput(
1192 \\pub fn main() void {
1193 \\ var x: usize = 3;
1194 \\ const y = add(1, 2, x);
1195 \\ if (y - 6 != 0) unreachable;
1196 \\}
1197 \\
1198 \\fn add(a: usize, b: usize, c: usize) callconv(.Inline) usize {
1199 \\ if (a == 10) @compileError("bad");
1200 \\ return a + b + c;
1201 \\}
1202 ,
1203 "",
1204 );
1205 }
1206 {
1207 var case = ctx.exe("recursive inline function", target);
1208 case.addCompareOutput(
1209 \\pub fn main() void {
1210 \\ const y = fibonacci(7);
1211 \\ if (y - 21 != 0) unreachable;
1212 \\}
1213 \\
1214 \\fn fibonacci(n: usize) callconv(.Inline) usize {
1215 \\ if (n <= 2) return n;
1216 \\ return fibonacci(n - 2) + fibonacci(n - 1);
1217 \\}
1218 ,
1219 "",
1220 );
1221 // This additionally tests that the compile error reports the correct source location.
1222 // Without storing source locations relative to the owner decl, the compile error
1223 // here would be off by 2 bytes (from the "7" -> "999").
1224 case.addError(
1225 \\pub fn main() void {
1226 \\ const y = fibonacci(999);
1227 \\ if (y - 21 != 0) unreachable;
1228 \\}
1229 \\
1230 \\fn fibonacci(n: usize) callconv(.Inline) usize {
1231 \\ if (n <= 2) return n;
1232 \\ return fibonacci(n - 2) + fibonacci(n - 1);
1233 \\}
1234 , &[_][]const u8{":8:21: error: evaluation exceeded 1000 backwards branches"});
1235 }
1236 {
1237 var case = ctx.exe("orelse at comptime", target);
1238 case.addCompareOutput(
1239 \\pub fn main() void {
1240 \\ const i: ?u64 = 0;
1241 \\ const result = i orelse 5;
1242 \\ assert(result == 0);
1243 \\}
1244 \\fn assert(b: bool) void {
1245 \\ if (!b) unreachable;
1246 \\}
1247 ,
1248 "",
1249 );
1250 case.addCompareOutput(
1251 \\pub fn main() void {
1252 \\ const i: ?u64 = null;
1253 \\ const result = i orelse 5;
1254 \\ assert(result == 5);
1255 \\}
1256 \\fn assert(b: bool) void {
1257 \\ if (!b) unreachable;
1258 \\}
1259 ,
1260 "",
1261 );
1262 }
1263
1264 {
1265 var case = ctx.exe("passing u0 to function", target);
1266 case.addCompareOutput(
1267 \\pub fn main() void {
1268 \\ doNothing(0);
1269 \\}
1270 \\fn doNothing(arg: u0) void {
1271 \\ _ = arg;
1272 \\}
1273 ,
1274 "",
1275 );
1276 }
1277
1278 {
1279 var case = ctx.exe("catch at comptime", target);
1280 case.addCompareOutput(
1281 \\pub fn main() void {
1282 \\ const i: anyerror!u64 = 0;
1283 \\ const caught = i catch 5;
1284 \\ assert(caught == 0);
1285 \\}
1286 \\fn assert(b: bool) void {
1287 \\ if (!b) unreachable;
1288 \\}
1289 ,
1290 "",
1291 );
1292
1293 case.addCompareOutput(
1294 \\pub fn main() void {
1295 \\ const i: anyerror!u64 = error.B;
1296 \\ const caught = i catch 5;
1297 \\ assert(caught == 5);
1298 \\}
1299 \\fn assert(b: bool) void {
1300 \\ if (!b) unreachable;
1301 \\}
1302 ,
1303 "",
1304 );
1305
1306 case.addCompareOutput(
1307 \\pub fn main() void {
1308 \\ const a: anyerror!comptime_int = 42;
1309 \\ const b: *const comptime_int = &(a catch unreachable);
1310 \\ assert(b.* == 42);
1311 \\}
1312 \\fn assert(b: bool) void {
1313 \\ if (!b) unreachable; // assertion failure
1314 \\}
1315 , "");
1316
1317 case.addCompareOutput(
1318 \\pub fn main() void {
1319 \\ const a: anyerror!u32 = error.B;
1320 \\ _ = &(a catch |err| assert(err == error.B));
1321 \\}
1322 \\fn assert(b: bool) void {
1323 \\ if (!b) unreachable;
1324 \\}
1325 , "");
1326
1327 case.addCompareOutput(
1328 \\pub fn main() void {
1329 \\ const a: anyerror!u32 = error.Bar;
1330 \\ a catch |err| assert(err == error.Bar);
1331 \\}
1332 \\fn assert(b: bool) void {
1333 \\ if (!b) unreachable;
1334 \\}
1335 , "");
1336 }
1337
1338 {
1339 var case = ctx.exe("runtime bitwise and", target);
1340
1341 case.addCompareOutput(
1342 \\pub fn main() void {
1343 \\ var i: u32 = 10;
1344 \\ var j: u32 = 11;
1345 \\ assert(i & 1 == 0);
1346 \\ assert(j & 1 == 1);
1347 \\ var m1: u32 = 0b1111;
1348 \\ var m2: u32 = 0b0000;
1349 \\ assert(m1 & 0b1010 == 0b1010);
1350 \\ assert(m2 & 0b1010 == 0b0000);
1351 \\}
1352 \\fn assert(b: bool) void {
1353 \\ if (!b) unreachable;
1354 \\}
1355 ,
1356 "",
1357 );
1358 }
1359
1360 {
1361 var case = ctx.exe("runtime bitwise or", target);
1362
1363 case.addCompareOutput(
1364 \\pub fn main() void {
1365 \\ var i: u32 = 10;
1366 \\ var j: u32 = 11;
1367 \\ assert(i | 1 == 11);
1368 \\ assert(j | 1 == 11);
1369 \\ var m1: u32 = 0b1111;
1370 \\ var m2: u32 = 0b0000;
1371 \\ assert(m1 | 0b1010 == 0b1111);
1372 \\ assert(m2 | 0b1010 == 0b1010);
1373 \\}
1374 \\fn assert(b: bool) void {
1375 \\ if (!b) unreachable;
1376 \\}
1377 ,
1378 "",
1379 );
1380 }
1381
1382 {
1383 var case = ctx.exe("merge error sets", target);
1384
1385 case.addCompareOutput(
1386 \\pub fn main() void {
1387 \\ const E = error{ A, B, D } || error { A, B, C };
1388 \\ E.A catch {};
1389 \\ E.B catch {};
1390 \\ E.C catch {};
1391 \\ E.D catch {};
1392 \\ const E2 = error { X, Y } || @TypeOf(error.Z);
1393 \\ E2.X catch {};
1394 \\ E2.Y catch {};
1395 \\ E2.Z catch {};
1396 \\ assert(anyerror || error { Z } == anyerror);
1397 \\}
1398 \\fn assert(b: bool) void {
1399 \\ if (!b) unreachable;
1400 \\}
1401 ,
1402 "",
1403 );
1404 case.addError(
1405 \\pub fn main() void {
1406 \\ const z = true || false;
1407 \\ _ = z;
1408 \\}
1409 , &.{
1410 ":2:15: error: expected error set type, found 'bool'",
1411 ":2:20: note: '||' merges error sets; 'or' performs boolean OR",
1412 });
1413 }
1414
1415 {
1416 var case = ctx.exe("comptime var", target);
1417
1418 case.addError(
1419 \\pub fn main() void {
1420 \\ var a: u32 = 0;
1421 \\ comptime var b: u32 = 0;
1422 \\ if (a == 0) b = 3;
1423 \\}
1424 , &.{
1425 ":4:21: error: store to comptime variable depends on runtime condition",
1426 ":4:11: note: runtime condition here",
1427 });
1428
1429 case.addError(
1430 \\pub fn main() void {
1431 \\ var a: u32 = 0;
1432 \\ comptime var b: u32 = 0;
1433 \\ switch (a) {
1434 \\ 0 => {},
1435 \\ else => b = 3,
1436 \\ }
1437 \\}
1438 , &.{
1439 ":6:21: error: store to comptime variable depends on runtime condition",
1440 ":4:13: note: runtime condition here",
1441 });
1442
1443 switch (target.getOsTag()) {
1444 .linux => case.addCompareOutput(
1445 \\pub fn main() void {
1446 \\ comptime var len: u32 = 5;
1447 \\ print(len);
1448 \\ len += 9;
1449 \\ print(len);
1450 \\}
1451 \\
1452 \\fn print(len: usize) void {
1453 \\ asm volatile ("syscall"
1454 \\ :
1455 \\ : [number] "{rax}" (1),
1456 \\ [arg1] "{rdi}" (1),
1457 \\ [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
1458 \\ [arg3] "{rdx}" (len)
1459 \\ : "rcx", "r11", "memory"
1460 \\ );
1461 \\ return;
1462 \\}
1463 , "HelloHello, World!\n"),
1464 .macos => case.addCompareOutput(
1465 \\extern "c" fn write(usize, usize, usize) usize;
1466 \\
1467 \\pub fn main() void {
1468 \\ comptime var len: u32 = 5;
1469 \\ print(len);
1470 \\ len += 9;
1471 \\ print(len);
1472 \\}
1473 \\
1474 \\fn print(len: usize) void {
1475 \\ _ = write(1, @ptrToInt("Hello, World!\n"), len);
1476 \\}
1477 , "HelloHello, World!\n"),
1478
1479 else => unreachable,
1480 }
1481
1482 case.addError(
1483 \\comptime {
1484 \\ var x: i32 = 1;
1485 \\ x += 1;
1486 \\ if (x != 1) unreachable;
1487 \\}
1488 \\pub fn main() void {}
1489 , &.{":4:17: error: unable to resolve comptime value"});
1490
1491 case.addError(
1492 \\pub fn main() void {
1493 \\ comptime var i: u64 = 0;
1494 \\ while (i < 5) : (i += 1) {}
1495 \\}
1496 , &.{
1497 ":3:24: error: cannot store to comptime variable in non-inline loop",
1498 ":3:5: note: non-inline loop here",
1499 });
1500
1501 case.addCompareOutput(
1502 \\pub fn main() void {
1503 \\ var a: u32 = 0;
1504 \\ if (a == 0) {
1505 \\ comptime var b: u32 = 0;
1506 \\ b = 1;
1507 \\ }
1508 \\}
1509 \\comptime {
1510 \\ var x: i32 = 1;
1511 \\ x += 1;
1512 \\ if (x != 2) unreachable;
1513 \\}
1514 , "");
1515
1516 switch (target.getOsTag()) {
1517 .linux => case.addCompareOutput(
1518 \\pub fn main() void {
1519 \\ comptime var i: u64 = 2;
1520 \\ inline while (i < 6) : (i+=1) {
1521 \\ print(i);
1522 \\ }
1523 \\}
1524 \\fn print(len: usize) void {
1525 \\ asm volatile ("syscall"
1526 \\ :
1527 \\ : [number] "{rax}" (1),
1528 \\ [arg1] "{rdi}" (1),
1529 \\ [arg2] "{rsi}" (@ptrToInt("Hello")),
1530 \\ [arg3] "{rdx}" (len)
1531 \\ : "rcx", "r11", "memory"
1532 \\ );
1533 \\ return;
1534 \\}
1535 , "HeHelHellHello"),
1536 .macos => case.addCompareOutput(
1537 \\extern "c" fn write(usize, usize, usize) usize;
1538 \\
1539 \\pub fn main() void {
1540 \\ comptime var i: u64 = 2;
1541 \\ inline while (i < 6) : (i+=1) {
1542 \\ print(i);
1543 \\ }
1544 \\}
1545 \\fn print(len: usize) void {
1546 \\ _ = write(1, @ptrToInt("Hello"), len);
1547 \\}
1548 , "HeHelHellHello"),
1549 else => unreachable,
1550 }
1551 }
1552
1553 {
1554 var case = ctx.exe("double ampersand", target);
1555
1556 case.addError(
1557 \\pub const a = if (true && false) 1 else 2;
1558 , &[_][]const u8{":1:24: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND"});
1559
1560 case.addError(
1561 \\pub fn main() void {
1562 \\ const a = true;
1563 \\ const b = false;
1564 \\ _ = a & &b;
1565 \\}
1566 , &[_][]const u8{
1567 ":4:11: error: incompatible types: 'bool' and '*const bool'",
1568 ":4:9: note: type 'bool' here",
1569 ":4:13: note: type '*const bool' here",
1570 });
1571
1572 case.addCompareOutput(
1573 \\pub fn main() void {
1574 \\ const b: u8 = 1;
1575 \\ _ = &&b;
1576 \\}
1577 , "");
1578 }
1579
1580 {
1581 var case = ctx.exe("setting an address space on a local variable", target);
1582 case.addError(
1583 \\export fn entry() i32 {
1584 \\ var foo: i32 addrspace(".general") = 1234;
1585 \\ return foo;
1586 \\}
1587 , &[_][]const u8{
1588 ":2:28: error: cannot set address space of local variable 'foo'",
1589 });
1590 }
1591
1592 {
1593 var case = ctx.exe("saving vars of different ABI size to stack", target);
1594
1595 case.addCompareOutput(
1596 \\pub fn main() void {
1597 \\ assert(callMe(2) == 24);
1598 \\}
1599 \\
1600 \\fn callMe(a: u8) u8 {
1601 \\ var b: u8 = a + 10;
1602 \\ const c = 2 * b;
1603 \\ return c;
1604 \\}
1605 \\
1606 \\pub fn assert(ok: bool) void {
1607 \\ if (!ok) unreachable; // assertion failure
1608 \\}
1609 ,
1610 "",
1611 );
1612
1613 case.addCompareOutput(
1614 \\pub fn main() void {
1615 \\ assert(callMe(2) == 24);
1616 \\}
1617 \\
1618 \\fn callMe(a: u16) u16 {
1619 \\ var b: u16 = a + 10;
1620 \\ const c = 2 * b;
1621 \\ return c;
1622 \\}
1623 \\
1624 \\pub fn assert(ok: bool) void {
1625 \\ if (!ok) unreachable; // assertion failure
1626 \\}
1627 ,
1628 "",
1629 );
1630
1631 case.addCompareOutput(
1632 \\pub fn main() void {
1633 \\ assert(callMe(2) == 24);
1634 \\}
1635 \\
1636 \\fn callMe(a: u32) u32 {
1637 \\ var b: u32 = a + 10;
1638 \\ const c = 2 * b;
1639 \\ return c;
1640 \\}
1641 \\
1642 \\pub fn assert(ok: bool) void {
1643 \\ if (!ok) unreachable; // assertion failure
1644 \\}
1645 ,
1646 "",
1647 );
1648 }
1649 {
1650 var case = ctx.exe("issue 7187: miscompilation with bool return type", target);
1651 case.addCompareOutput(
1652 \\pub fn main() void {
1653 \\ var x: usize = 1;
1654 \\ var y: bool = getFalse();
1655 \\ _ = y;
1656 \\
1657 \\ assert(x == 1);
1658 \\}
1659 \\
1660 \\fn getFalse() bool {
1661 \\ return false;
1662 \\}
1663 \\
1664 \\fn assert(ok: bool) void {
1665 \\ if (!ok) unreachable;
1666 \\}
1667 , "");
1668 }
1669
1670 {
1671 var case = ctx.exe("load-store via pointer deref", target);
1672 case.addCompareOutput(
1673 \\pub fn main() void {
1674 \\ var x: u32 = undefined;
1675 \\ set(&x);
1676 \\ assert(x == 123);
1677 \\}
1678 \\
1679 \\fn set(x: *u32) void {
1680 \\ x.* = 123;
1681 \\}
1682 \\
1683 \\fn assert(ok: bool) void {
1684 \\ if (!ok) unreachable;
1685 \\}
1686 , "");
1687 case.addCompareOutput(
1688 \\pub fn main() void {
1689 \\ var x: u16 = undefined;
1690 \\ set(&x);
1691 \\ assert(x == 123);
1692 \\}
1693 \\
1694 \\fn set(x: *u16) void {
1695 \\ x.* = 123;
1696 \\}
1697 \\
1698 \\fn assert(ok: bool) void {
1699 \\ if (!ok) unreachable;
1700 \\}
1701 , "");
1702 case.addCompareOutput(
1703 \\pub fn main() void {
1704 \\ var x: u8 = undefined;
1705 \\ set(&x);
1706 \\ assert(x == 123);
1707 \\}
1708 \\
1709 \\fn set(x: *u8) void {
1710 \\ x.* = 123;
1711 \\}
1712 \\
1713 \\fn assert(ok: bool) void {
1714 \\ if (!ok) unreachable;
1715 \\}
1716 , "");
1717 }
1718
1719 {
1720 var case = ctx.exe("optional payload", target);
1721 case.addCompareOutput(
1722 \\pub fn main() void {
1723 \\ var x: u32 = undefined;
1724 \\ const maybe_x = byPtr(&x);
1725 \\ assert(maybe_x != null);
1726 \\ maybe_x.?.* = 123;
1727 \\ assert(x == 123);
1728 \\}
1729 \\
1730 \\fn byPtr(x: *u32) ?*u32 {
1731 \\ return x;
1732 \\}
1733 \\
1734 \\fn assert(ok: bool) void {
1735 \\ if (!ok) unreachable;
1736 \\}
1737 , "");
1738 case.addCompareOutput(
1739 \\pub fn main() void {
1740 \\ var x: u32 = undefined;
1741 \\ const maybe_x = byPtr(&x);
1742 \\ assert(maybe_x == null);
1743 \\}
1744 \\
1745 \\fn byPtr(x: *u32) ?*u32 {
1746 \\ _ = x;
1747 \\ return null;
1748 \\}
1749 \\
1750 \\fn assert(ok: bool) void {
1751 \\ if (!ok) unreachable;
1752 \\}
1753 , "");
1754 case.addCompareOutput(
1755 \\pub fn main() void {
1756 \\ var x: u8 = undefined;
1757 \\ const maybe_x = byPtr(&x);
1758 \\ assert(maybe_x != null);
1759 \\ maybe_x.?.* = 255;
1760 \\ assert(x == 255);
1761 \\}
1762 \\
1763 \\fn byPtr(x: *u8) ?*u8 {
1764 \\ return x;
1765 \\}
1766 \\
1767 \\fn assert(ok: bool) void {
1768 \\ if (!ok) unreachable;
1769 \\}
1770 , "");
1771 case.addCompareOutput(
1772 \\pub fn main() void {
1773 \\ var x: i8 = undefined;
1774 \\ const maybe_x = byPtr(&x);
1775 \\ assert(maybe_x != null);
1776 \\ maybe_x.?.* = -1;
1777 \\ assert(x == -1);
1778 \\}
1779 \\
1780 \\fn byPtr(x: *i8) ?*i8 {
1781 \\ return x;
1782 \\}
1783 \\
1784 \\fn assert(ok: bool) void {
1785 \\ if (!ok) unreachable;
1786 \\}
1787 , "");
1788 }
1789
1790 {
1791 var case = ctx.exe("unwrap error union - simple errors", target);
1792 case.addCompareOutput(
1793 \\pub fn main() void {
1794 \\ maybeErr() catch unreachable;
1795 \\}
1796 \\
1797 \\fn maybeErr() !void {
1798 \\ return;
1799 \\}
1800 , "");
1801 case.addCompareOutput(
1802 \\pub fn main() void {
1803 \\ maybeErr() catch return;
1804 \\ unreachable;
1805 \\}
1806 \\
1807 \\fn maybeErr() !void {
1808 \\ return error.NoWay;
1809 \\}
1810 , "");
1811 }
1812
1813 {
1814 var case = ctx.exe("access slice element by index - slice_elem_val", target);
1815 case.addCompareOutput(
1816 \\var array = [_]usize{ 0, 42, 123, 34 };
1817 \\var slice: []const usize = &array;
1818 \\
1819 \\pub fn main() void {
1820 \\ assert(slice[0] == 0);
1821 \\ assert(slice[1] == 42);
1822 \\ assert(slice[2] == 123);
1823 \\ assert(slice[3] == 34);
1824 \\}
1825 \\
1826 \\fn assert(ok: bool) void {
1827 \\ if (!ok) unreachable;
1828 \\}
1829 , "");
1830 }
1831
1832 {
1833 var case = ctx.exe("lower unnamed constants - structs", target);
1834 case.addCompareOutput(
1835 \\const Foo = struct {
1836 \\ a: u8,
1837 \\ b: u32,
1838 \\
1839 \\ fn first(self: *Foo) u8 {
1840 \\ return self.a;
1841 \\ }
1842 \\
1843 \\ fn second(self: *Foo) u32 {
1844 \\ return self.b;
1845 \\ }
1846 \\};
1847 \\
1848 \\pub fn main() void {
1849 \\ var foo = Foo{ .a = 1, .b = 5 };
1850 \\ assert(foo.first() == 1);
1851 \\ assert(foo.second() == 5);
1852 \\}
1853 \\
1854 \\fn assert(ok: bool) void {
1855 \\ if (!ok) unreachable;
1856 \\}
1857 , "");
1858
1859 case.addCompareOutput(
1860 \\const Foo = struct {
1861 \\ a: u8,
1862 \\ b: u32,
1863 \\
1864 \\ fn first(self: *Foo) u8 {
1865 \\ return self.a;
1866 \\ }
1867 \\
1868 \\ fn second(self: *Foo) u32 {
1869 \\ return self.b;
1870 \\ }
1871 \\};
1872 \\
1873 \\pub fn main() void {
1874 \\ var foo = Foo{ .a = 1, .b = 5 };
1875 \\ assert(foo.first() == 1);
1876 \\ assert(foo.second() == 5);
1877 \\
1878 \\ foo.a = 10;
1879 \\ foo.b = 255;
1880 \\
1881 \\ assert(foo.first() == 10);
1882 \\ assert(foo.second() == 255);
1883 \\
1884 \\ var foo2 = Foo{ .a = 15, .b = 255 };
1885 \\ assert(foo2.first() == 15);
1886 \\ assert(foo2.second() == 255);
1887 \\}
1888 \\
1889 \\fn assert(ok: bool) void {
1890 \\ if (!ok) unreachable;
1891 \\}
1892 , "");
1893
1894 case.addCompareOutput(
1895 \\const Foo = struct {
1896 \\ a: u8,
1897 \\ b: u32,
1898 \\
1899 \\ fn first(self: *Foo) u8 {
1900 \\ return self.a;
1901 \\ }
1902 \\
1903 \\ fn second(self: *Foo) u32 {
1904 \\ return self.b;
1905 \\ }
1906 \\};
1907 \\
1908 \\pub fn main() void {
1909 \\ var foo2 = Foo{ .a = 15, .b = 255 };
1910 \\ assert(foo2.first() == 15);
1911 \\ assert(foo2.second() == 255);
1912 \\}
1913 \\
1914 \\fn assert(ok: bool) void {
1915 \\ if (!ok) unreachable;
1916 \\}
1917 , "");
1918 }
1919 }
1920}
1921
1922fn addLinuxTestCases(ctx: *TestContext) !void {
1923 // Linux tests
1924 {
1925 var case = ctx.exe("hello world with updates", linux_x64);
1926
1927 case.addError("", &[_][]const u8{
1928 ":109:9: error: struct 'tmp.tmp' has no member named 'main'",
1929 });
1930
1931 // Incorrect return type
1932 case.addError(
1933 \\pub export fn _start() noreturn {
1934 \\}
1935 , &[_][]const u8{":2:1: error: expected noreturn, found void"});
1936
1937 // Regular old hello world
1938 case.addCompareOutput(
1939 \\pub export fn _start() noreturn {
1940 \\ print();
1941 \\
1942 \\ exit();
1943 \\}
1944 \\
1945 \\fn print() void {
1946 \\ asm volatile ("syscall"
1947 \\ :
1948 \\ : [number] "{rax}" (1),
1949 \\ [arg1] "{rdi}" (1),
1950 \\ [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
1951 \\ [arg3] "{rdx}" (14)
1952 \\ : "rcx", "r11", "memory"
1953 \\ );
1954 \\ return;
1955 \\}
1956 \\
1957 \\fn exit() noreturn {
1958 \\ asm volatile ("syscall"
1959 \\ :
1960 \\ : [number] "{rax}" (231),
1961 \\ [arg1] "{rdi}" (0)
1962 \\ : "rcx", "r11", "memory"
1963 \\ );
1964 \\ unreachable;
1965 \\}
1966 ,
1967 "Hello, World!\n",
1968 );
1969
1970 // Convert to pub fn main
1971 case.addCompareOutput(
1972 \\pub fn main() void {
1973 \\ print();
1974 \\}
1975 \\
1976 \\fn print() void {
1977 \\ asm volatile ("syscall"
1978 \\ :
1979 \\ : [number] "{rax}" (1),
1980 \\ [arg1] "{rdi}" (1),
1981 \\ [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
1982 \\ [arg3] "{rdx}" (14)
1983 \\ : "rcx", "r11", "memory"
1984 \\ );
1985 \\ return;
1986 \\}
1987 ,
1988 "Hello, World!\n",
1989 );
1990
1991 // Now change the message only
1992 case.addCompareOutput(
1993 \\pub fn main() void {
1994 \\ print();
1995 \\}
1996 \\
1997 \\fn print() void {
1998 \\ asm volatile ("syscall"
1999 \\ :
2000 \\ : [number] "{rax}" (1),
2001 \\ [arg1] "{rdi}" (1),
2002 \\ [arg2] "{rsi}" (@ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n")),
2003 \\ [arg3] "{rdx}" (104)
2004 \\ : "rcx", "r11", "memory"
2005 \\ );
2006 \\ return;
2007 \\}
2008 ,
2009 "What is up? This is a longer message that will force the data to be relocated in virtual address space.\n",
2010 );
2011 // Now we print it twice.
2012 case.addCompareOutput(
2013 \\pub fn main() void {
2014 \\ print();
2015 \\ print();
2016 \\}
2017 \\
2018 \\fn print() void {
2019 \\ asm volatile ("syscall"
2020 \\ :
2021 \\ : [number] "{rax}" (1),
2022 \\ [arg1] "{rdi}" (1),
2023 \\ [arg2] "{rsi}" (@ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n")),
2024 \\ [arg3] "{rdx}" (104)
2025 \\ : "rcx", "r11", "memory"
2026 \\ );
2027 \\ return;
2028 \\}
2029 ,
2030 \\What is up? This is a longer message that will force the data to be relocated in virtual address space.
2031 \\What is up? This is a longer message that will force the data to be relocated in virtual address space.
2032 \\
2033 );
2034 }
2035
2036 {
2037 var case = ctx.exe("adding numbers at comptime", linux_x64);
2038 case.addCompareOutput(
2039 \\pub export fn _start() noreturn {
2040 \\ asm volatile ("syscall"
2041 \\ :
2042 \\ : [number] "{rax}" (1),
2043 \\ [arg1] "{rdi}" (1),
2044 \\ [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
2045 \\ [arg3] "{rdx}" (10 + 4)
2046 \\ : "rcx", "r11", "memory"
2047 \\ );
2048 \\ asm volatile ("syscall"
2049 \\ :
2050 \\ : [number] "{rax}" (@as(usize, 230) + @as(usize, 1)),
2051 \\ [arg1] "{rdi}" (0)
2052 \\ : "rcx", "r11", "memory"
2053 \\ );
2054 \\ unreachable;
2055 \\}
2056 ,
2057 "Hello, World!\n",
2058 );
2059 }
2060
2061 {
2062 var case = ctx.exe("only 1 function and it gets updated", linux_x64);
2063 case.addCompareOutput(
2064 \\pub export fn _start() noreturn {
2065 \\ asm volatile ("syscall"
2066 \\ :
2067 \\ : [number] "{rax}" (60), // exit
2068 \\ [arg1] "{rdi}" (0)
2069 \\ : "rcx", "r11", "memory"
2070 \\ );
2071 \\ unreachable;
2072 \\}
2073 ,
2074 "",
2075 );
2076 case.addCompareOutput(
2077 \\pub export fn _start() noreturn {
2078 \\ asm volatile ("syscall"
2079 \\ :
2080 \\ : [number] "{rax}" (231), // exit_group
2081 \\ [arg1] "{rdi}" (0)
2082 \\ : "rcx", "r11", "memory"
2083 \\ );
2084 \\ unreachable;
2085 \\}
2086 ,
2087 "",
2088 );
2089 }
2090 {
2091 var case = ctx.exe("inline assembly", linux_x64);
2092
2093 case.addError(
2094 \\pub fn main() void {
2095 \\ const number = 1234;
2096 \\ const x = asm volatile ("syscall"
2097 \\ : [o] "{rax}" (-> number)
2098 \\ : [number] "{rax}" (231),
2099 \\ [arg1] "{rdi}" (60)
2100 \\ : "rcx", "r11", "memory"
2101 \\ );
2102 \\ _ = x;
2103 \\}
2104 , &[_][]const u8{":4:27: error: expected type, found comptime_int"});
2105 case.addError(
2106 \\const S = struct {
2107 \\ comptime {
2108 \\ asm volatile (
2109 \\ \\zig_moment:
2110 \\ \\syscall
2111 \\ );
2112 \\ }
2113 \\};
2114 \\pub fn main() void {
2115 \\ _ = S;
2116 \\}
2117 , &.{":3:13: error: volatile is meaningless on global assembly"});
2118 case.addError(
2119 \\pub fn main() void {
2120 \\ var bruh: u32 = 1;
2121 \\ asm (""
2122 \\ :
2123 \\ : [bruh] "{rax}" (4)
2124 \\ : "memory"
2125 \\ );
2126 \\}
2127 , &.{":3:5: error: assembly expression with no output must be marked volatile"});
2128 case.addError(
2129 \\pub fn main() void {}
2130 \\comptime {
2131 \\ asm (""
2132 \\ :
2133 \\ : [bruh] "{rax}" (4)
2134 \\ : "memory"
2135 \\ );
2136 \\}
2137 , &.{":3:5: error: global assembly cannot have inputs, outputs, or clobbers"});
2138 }
2139
2140 {
2141 var case = ctx.exe("issue 10138: callee preserved regs working", linux_x64);
2142 case.addCompareOutput(
2143 \\pub fn main() void {
2144 \\ const fd = open();
2145 \\ _ = write(fd, "a", 1);
2146 \\ _ = close(fd);
2147 \\}
2148 \\
2149 \\fn open() usize {
2150 \\ return 42;
2151 \\}
2152 \\
2153 \\fn write(fd: usize, a: [*]const u8, len: usize) usize {
2154 \\ return syscall4(.WRITE, fd, @ptrToInt(a), len);
2155 \\}
2156 \\
2157 \\fn syscall4(n: enum { WRITE }, a: usize, b: usize, c: usize) usize {
2158 \\ _ = n;
2159 \\ _ = a;
2160 \\ _ = b;
2161 \\ _ = c;
2162 \\ return 23;
2163 \\}
2164 \\
2165 \\fn close(fd: usize) usize {
2166 \\ if (fd != 42)
2167 \\ unreachable;
2168 \\ return 0;
2169 \\}
2170 , "");
2171 }
2172}
2173
2174fn addMacOsTestCases(ctx: *TestContext) !void {
2175 // macOS tests
2176 {
2177 var case = ctx.exe("darwin hello world with updates", macos_x64);
2178 case.addError("", &[_][]const u8{
2179 ":109:9: error: struct 'tmp.tmp' has no member named 'main'",
2180 });
2181
2182 // Incorrect return type
2183 case.addError(
2184 \\pub export fn main() noreturn {
2185 \\}
2186 , &[_][]const u8{
2187 ":2:1: error: expected noreturn, found void",
2188 });
2189
2190 // Regular old hello world
2191 case.addCompareOutput(
2192 \\extern "c" fn write(usize, usize, usize) usize;
2193 \\extern "c" fn exit(usize) noreturn;
2194 \\
2195 \\pub export fn main() noreturn {
2196 \\ print();
2197 \\
2198 \\ exit(0);
2199 \\}
2200 \\
2201 \\fn print() void {
2202 \\ const msg = @ptrToInt("Hello, World!\n");
2203 \\ const len = 14;
2204 \\ _ = write(1, msg, len);
2205 \\}
2206 ,
2207 "Hello, World!\n",
2208 );
2209
2210 // Now using start.zig without an explicit extern exit fn
2211 case.addCompareOutput(
2212 \\extern "c" fn write(usize, usize, usize) usize;
2213 \\
2214 \\pub fn main() void {
2215 \\ print();
2216 \\}
2217 \\
2218 \\fn print() void {
2219 \\ const msg = @ptrToInt("Hello, World!\n");
2220 \\ const len = 14;
2221 \\ _ = write(1, msg, len);
2222 \\}
2223 ,
2224 "Hello, World!\n",
2225 );
2226
2227 // Print it 4 times and force growth and realloc.
2228 case.addCompareOutput(
2229 \\extern "c" fn write(usize, usize, usize) usize;
2230 \\
2231 \\pub fn main() void {
2232 \\ print();
2233 \\ print();
2234 \\ print();
2235 \\ print();
2236 \\}
2237 \\
2238 \\fn print() void {
2239 \\ const msg = @ptrToInt("Hello, World!\n");
2240 \\ const len = 14;
2241 \\ _ = write(1, msg, len);
2242 \\}
2243 ,
2244 \\Hello, World!
2245 \\Hello, World!
2246 \\Hello, World!
2247 \\Hello, World!
2248 \\
2249 );
2250
2251 // Print it once, and change the message.
2252 case.addCompareOutput(
2253 \\extern "c" fn write(usize, usize, usize) usize;
2254 \\
2255 \\pub fn main() void {
2256 \\ print();
2257 \\}
2258 \\
2259 \\fn print() void {
2260 \\ const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
2261 \\ const len = 104;
2262 \\ _ = write(1, msg, len);
2263 \\}
2264 ,
2265 "What is up? This is a longer message that will force the data to be relocated in virtual address space.\n",
2266 );
2267
2268 // Now we print it twice.
2269 case.addCompareOutput(
2270 \\extern "c" fn write(usize, usize, usize) usize;
2271 \\
2272 \\pub fn main() void {
2273 \\ print();
2274 \\ print();
2275 \\}
2276 \\
2277 \\fn print() void {
2278 \\ const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
2279 \\ const len = 104;
2280 \\ _ = write(1, msg, len);
2281 \\}
2282 ,
2283 \\What is up? This is a longer message that will force the data to be relocated in virtual address space.
2284 \\What is up? This is a longer message that will force the data to be relocated in virtual address space.
2285 \\
2286 );
2287 }
2288}