1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
const std = @import("std");
const builtin = @import("builtin");
const TestContext = @import("../src/test.zig").TestContext;
pub fn addCases(ctx: *TestContext) !void {
var parent_dir = try std.fs.cwd().openDir(std.fs.path.dirname(@src().file).?, .{ .no_follow = true });
defer parent_dir.close();
var compile_errors_dir = try parent_dir.openDir("compile_errors", .{ .no_follow = true });
defer compile_errors_dir.close();
{
var stage2_dir = try compile_errors_dir.openDir("stage2", .{ .iterate = true, .no_follow = true });
defer stage2_dir.close();
const one_test_case_per_file = false;
try ctx.addErrorCasesFromDir("stage2 compile errors", stage2_dir, .stage2, .Obj, false, one_test_case_per_file);
}
{
var stage1_dir = try compile_errors_dir.openDir("stage1", .{ .no_follow = true });
defer stage1_dir.close();
{
const one_test_case_per_file = true;
var obj_dir = try stage1_dir.openDir("obj", .{ .iterate = true, .no_follow = true });
defer obj_dir.close();
try ctx.addErrorCasesFromDir("stage1", obj_dir, .stage1, .Obj, false, one_test_case_per_file);
var exe_dir = try stage1_dir.openDir("exe", .{ .iterate = true, .no_follow = true });
defer exe_dir.close();
try ctx.addErrorCasesFromDir("stage1", exe_dir, .stage1, .Exe, false, one_test_case_per_file);
var test_dir = try stage1_dir.openDir("test", .{ .iterate = true, .no_follow = true });
defer test_dir.close();
try ctx.addErrorCasesFromDir("stage1", test_dir, .stage1, .Exe, true, one_test_case_per_file);
}
}
{
const case = ctx.obj("callconv(.Interrupt) on unsupported platform", .{
.cpu_arch = .aarch64,
.os_tag = .linux,
.abi = .none,
});
case.backend = .stage1;
case.addError(
\\export fn entry() callconv(.Interrupt) void {}
, &[_][]const u8{
"tmp.zig:1:28: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64",
});
}
{
var case = ctx.obj("callconv(.Signal) on unsupported platform", .{
.cpu_arch = .x86_64,
.os_tag = .linux,
.abi = .none,
});
case.backend = .stage1;
case.addError(
\\export fn entry() callconv(.Signal) void {}
, &[_][]const u8{
"tmp.zig:1:28: error: callconv 'Signal' is only available on AVR, not x86_64",
});
}
{
const case = ctx.obj("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", .{
.cpu_arch = .x86_64,
.os_tag = .linux,
.abi = .none,
});
case.backend = .stage1;
case.addError(
\\const F1 = fn () callconv(.Stdcall) void;
\\const F2 = fn () callconv(.Fastcall) void;
\\const F3 = fn () callconv(.Thiscall) void;
\\export fn entry1() void { var a: F1 = undefined; _ = a; }
\\export fn entry2() void { var a: F2 = undefined; _ = a; }
\\export fn entry3() void { var a: F3 = undefined; _ = a; }
, &[_][]const u8{
"tmp.zig:1:27: error: callconv 'Stdcall' is only available on x86, not x86_64",
"tmp.zig:2:27: error: callconv 'Fastcall' is only available on x86, not x86_64",
"tmp.zig:3:27: error: callconv 'Thiscall' is only available on x86, not x86_64",
});
}
{
const case = ctx.obj("callconv(.Stdcall, .Fastcall, .Thiscall) on unsupported platform", .{
.cpu_arch = .x86_64,
.os_tag = .linux,
.abi = .none,
});
case.backend = .stage1;
case.addError(
\\export fn entry1() callconv(.Stdcall) void {}
\\export fn entry2() callconv(.Fastcall) void {}
\\export fn entry3() callconv(.Thiscall) void {}
, &[_][]const u8{
"tmp.zig:1:29: error: callconv 'Stdcall' is only available on x86, not x86_64",
"tmp.zig:2:29: error: callconv 'Fastcall' is only available on x86, not x86_64",
"tmp.zig:3:29: error: callconv 'Thiscall' is only available on x86, not x86_64",
});
}
{
const case = ctx.obj("callconv(.Vectorcall) on unsupported platform", .{
.cpu_arch = .x86_64,
.os_tag = .linux,
.abi = .none,
});
case.backend = .stage1;
case.addError(
\\export fn entry() callconv(.Vectorcall) void {}
, &[_][]const u8{
"tmp.zig:1:28: error: callconv 'Vectorcall' is only available on x86 and AArch64, not x86_64",
});
}
{
const case = ctx.obj("callconv(.APCS, .AAPCS, .AAPCSVFP) on unsupported platform", .{
.cpu_arch = .x86_64,
.os_tag = .linux,
.abi = .none,
});
case.backend = .stage1;
case.addError(
\\export fn entry1() callconv(.APCS) void {}
\\export fn entry2() callconv(.AAPCS) void {}
\\export fn entry3() callconv(.AAPCSVFP) void {}
, &[_][]const u8{
"tmp.zig:1:29: error: callconv 'APCS' is only available on ARM, not x86_64",
"tmp.zig:2:29: error: callconv 'AAPCS' is only available on ARM, not x86_64",
"tmp.zig:3:29: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64",
});
}
{
const case = ctx.obj("call with new stack on unsupported target", .{
.cpu_arch = .wasm32,
.os_tag = .wasi,
.abi = .none,
});
case.backend = .stage1;
case.addError(
\\var buf: [10]u8 align(16) = undefined;
\\export fn entry() void {
\\ @call(.{.stack = &buf}, foo, .{});
\\}
\\fn foo() void {}
, &[_][]const u8{
"tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack",
});
}
// Note: One of the error messages here is backwards. It would be nice to fix, but that's not
// going to stop me from merging this branch which fixes a bunch of other stuff.
ctx.objErrStage1("incompatible sentinels",
\\export fn entry1(ptr: [*:255]u8) [*:0]u8 {
\\ return ptr;
\\}
\\export fn entry2(ptr: [*]u8) [*:0]u8 {
\\ return ptr;
\\}
\\export fn entry3() void {
\\ var array: [2:0]u8 = [_:255]u8{1, 2};
\\ _ = array;
\\}
\\export fn entry4() void {
\\ var array: [2:0]u8 = [_]u8{1, 2};
\\ _ = array;
\\}
, &[_][]const u8{
"tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'",
"tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel",
"tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'",
"tmp.zig:5:12: note: destination pointer requires a terminating '0' sentinel",
"tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'",
"tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel",
"tmp.zig:12:31: error: expected type '[2:0]u8', found '[2]u8'",
"tmp.zig:12:31: note: destination array requires a terminating '0' sentinel",
});
{
const case = ctx.obj("variable in inline assembly template cannot be found", .{
.cpu_arch = .x86_64,
.os_tag = .linux,
.abi = .gnu,
});
case.backend = .stage1;
case.addError(
\\export fn entry() void {
\\ var sp = asm volatile (
\\ "mov %[foo], sp"
\\ : [bar] "=r" (-> usize)
\\ );
\\ _ = sp;
\\}
, &[_][]const u8{
"tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs",
});
}
{
const case = ctx.obj("bad alignment in @asyncCall", .{
.cpu_arch = .aarch64,
.os_tag = .linux,
.abi = .none,
});
case.backend = .stage1;
case.addError(
\\export fn entry() void {
\\ var ptr: fn () callconv(.Async) void = func;
\\ var bytes: [64]u8 = undefined;
\\ _ = @asyncCall(&bytes, {}, ptr, .{});
\\}
\\fn func() callconv(.Async) void {}
, &[_][]const u8{
"tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8'",
});
}
if (builtin.os.tag == .linux) {
ctx.testErrStage1("implicit dependency on libc",
\\extern "c" fn exit(u8) void;
\\export fn entry() void {
\\ exit(0);
\\}
, &[_][]const u8{
"tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command",
});
ctx.testErrStage1("libc headers note",
\\const c = @cImport(@cInclude("stdio.h"));
\\export fn entry() void {
\\ _ = c.printf("hello, world!\n");
\\}
, &[_][]const u8{
"tmp.zig:1:11: error: C import failed",
"tmp.zig:1:11: note: libc headers not available; compilation does not link against libc",
});
}
{
const case = ctx.obj("wrong same named struct", .{});
case.backend = .stage1;
case.addSourceFile("a.zig",
\\pub const Foo = struct {
\\ x: i32,
\\};
);
case.addSourceFile("b.zig",
\\pub const Foo = struct {
\\ z: f64,
\\};
);
case.addError(
\\const a = @import("a.zig");
\\const b = @import("b.zig");
\\
\\export fn entry() void {
\\ var a1: a.Foo = undefined;
\\ bar(&a1);
\\}
\\
\\fn bar(x: *b.Foo) void {_ = x;}
, &[_][]const u8{
"tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'",
"tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'",
"a.zig:1:17: note: a.Foo declared here",
"b.zig:1:17: note: b.Foo declared here",
});
}
{
const case = ctx.obj("multiple files with private function error", .{});
case.backend = .stage1;
case.addSourceFile("foo.zig",
\\fn privateFunction() void { }
);
case.addError(
\\const foo = @import("foo.zig",);
\\
\\export fn callPrivFunction() void {
\\ foo.privateFunction();
\\}
, &[_][]const u8{
"tmp.zig:4:8: error: 'privateFunction' is private",
"foo.zig:1:1: note: declared here",
});
}
{
const case = ctx.obj("multiple files with private member instance function (canonical invocation) error", .{});
case.backend = .stage1;
case.addSourceFile("foo.zig",
\\pub const Foo = struct {
\\ fn privateFunction(self: *Foo) void { _ = self; }
\\};
);
case.addError(
\\const Foo = @import("foo.zig",).Foo;
\\
\\export fn callPrivFunction() void {
\\ var foo = Foo{};
\\ Foo.privateFunction(foo);
\\}
, &[_][]const u8{
"tmp.zig:5:8: error: 'privateFunction' is private",
"foo.zig:2:5: note: declared here",
});
}
{
const case = ctx.obj("multiple files with private member instance function error", .{});
case.backend = .stage1;
case.addSourceFile("foo.zig",
\\pub const Foo = struct {
\\ fn privateFunction(self: *Foo) void { _ = self; }
\\};
);
case.addError(
\\const Foo = @import("foo.zig",).Foo;
\\
\\export fn callPrivFunction() void {
\\ var foo = Foo{};
\\ foo.privateFunction();
\\}
, &[_][]const u8{
"tmp.zig:5:8: error: 'privateFunction' is private",
"foo.zig:2:5: note: declared here",
});
}
{
const case = ctx.obj("export collision", .{});
case.backend = .stage1;
case.addSourceFile("foo.zig",
\\export fn bar() void {}
\\pub const baz = 1234;
);
case.addError(
\\const foo = @import("foo.zig",);
\\
\\export fn bar() usize {
\\ return foo.baz;
\\}
, &[_][]const u8{
"foo.zig:1:1: error: exported symbol collision: 'bar'",
"tmp.zig:3:1: note: other symbol here",
});
}
ctx.objErrStage1("non-printable invalid character", "\xff\xfe" ++
"fn foo() bool {\r\n" ++
" return true;\r\n" ++
"}\r\n", &[_][]const u8{
"tmp.zig:1:1: error: expected test, comptime, var decl, or container field, found 'invalid bytes'",
"tmp.zig:1:1: note: invalid byte: '\\xff'",
});
ctx.objErrStage1("non-printable invalid character with escape alternative", "fn foo() bool {\n" ++
"\treturn true;\n" ++
"}\n", &[_][]const u8{
"tmp.zig:2:1: error: invalid character: '\\t'",
});
// TODO test this in stage2, but we won't even try in stage1
//ctx.objErrStage1("inline fn calls itself indirectly",
// \\export fn foo() void {
// \\ bar();
// \\}
// \\fn bar() callconv(.Inline) void {
// \\ baz();
// \\ quux();
// \\}
// \\fn baz() callconv(.Inline) void {
// \\ bar();
// \\ quux();
// \\}
// \\extern fn quux() void;
//, &[_][]const u8{
// "tmp.zig:4:1: error: unable to inline function",
//});
//ctx.objErrStage1("save reference to inline function",
// \\export fn foo() void {
// \\ quux(@ptrToInt(bar));
// \\}
// \\fn bar() callconv(.Inline) void { }
// \\extern fn quux(usize) void;
//, &[_][]const u8{
// "tmp.zig:4:1: error: unable to inline function",
//});
{
const case = ctx.obj("align(N) expr function pointers is a compile error", .{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
.abi = .none,
});
case.backend = .stage1;
case.addError(
\\export fn foo() align(1) void {
\\ return;
\\}
, &[_][]const u8{
"tmp.zig:1:23: error: align(N) expr is not allowed on function prototypes in wasm32/wasm64",
});
}
}
|