aboutsummaryrefslogtreecommitdiff
path: root/test/cases
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-08-30 15:55:05 -0400
committerGitHub <noreply@github.com>2022-08-30 15:55:05 -0400
commitf559ea95b1c37fd6ede8fff6ffb2d74d5c2abc4e (patch)
tree6d9714e54fa2223aa6842d8d496d5f3dadd360e8 /test/cases
parent0a42602418dcaf08f13b4220b6c216356f87cbfc (diff)
parent7377dce368090e3c49a15d8996cc812adadd3d43 (diff)
downloadzig-f559ea95b1c37fd6ede8fff6ffb2d74d5c2abc4e.tar.gz
zig-f559ea95b1c37fd6ede8fff6ffb2d74d5c2abc4e.zip
Merge pull request #12686 from Vexu/stage2-fixes
Stage2 fixes
Diffstat (limited to 'test/cases')
-rw-r--r--test/cases/compile_errors/invalid_tail_call.zig12
-rw-r--r--test/cases/compile_errors/non-comptime-parameter-used-as-array-size.zig16
-rw-r--r--test/cases/compile_errors/runtime_to_comptime_num.zig31
-rw-r--r--test/cases/compile_errors/shifting_without_int_type_or_comptime_known.zig23
-rw-r--r--test/cases/compile_errors/stage1/obj/shifting_without_int_type_or_comptime_known.zig9
-rw-r--r--test/cases/taill_call_noreturn.zig18
6 files changed, 100 insertions, 9 deletions
diff --git a/test/cases/compile_errors/invalid_tail_call.zig b/test/cases/compile_errors/invalid_tail_call.zig
new file mode 100644
index 0000000000..cdeb9df930
--- /dev/null
+++ b/test/cases/compile_errors/invalid_tail_call.zig
@@ -0,0 +1,12 @@
+fn myFn(_: usize) void {
+ return;
+}
+pub export fn entry() void {
+ @call(.{ .modifier = .always_tail }, myFn, .{0});
+}
+
+// error
+// backend=llvm
+// target=native
+//
+// :5:5: error: unable to perform tail call: type of function being called 'fn(usize) void' does not match type of calling function 'fn() callconv(.C) void'
diff --git a/test/cases/compile_errors/non-comptime-parameter-used-as-array-size.zig b/test/cases/compile_errors/non-comptime-parameter-used-as-array-size.zig
new file mode 100644
index 0000000000..b5495480ed
--- /dev/null
+++ b/test/cases/compile_errors/non-comptime-parameter-used-as-array-size.zig
@@ -0,0 +1,16 @@
+export fn entry() void {
+ const llamas1 = makeLlamas(5);
+ const llamas2 = makeLlamas(5);
+ _ = llamas1;
+ _ = llamas2;
+}
+
+fn makeLlamas(count: usize) [count]u8 {
+ _ = count;
+}
+
+// error
+// target=native
+//
+// :8:30: error: unable to resolve comptime value
+// :8:30: note: array length must be comptime known
diff --git a/test/cases/compile_errors/runtime_to_comptime_num.zig b/test/cases/compile_errors/runtime_to_comptime_num.zig
new file mode 100644
index 0000000000..2275e35c43
--- /dev/null
+++ b/test/cases/compile_errors/runtime_to_comptime_num.zig
@@ -0,0 +1,31 @@
+pub export fn entry() void {
+ var a: u32 = 0;
+ _ = @as(comptime_int, a);
+}
+pub export fn entry2() void{
+ var a: u32 = 0;
+ _ = @as(comptime_float, a);
+}
+pub export fn entry3() void{
+ comptime var aa: comptime_float = 0.0;
+ var a: f32 = 4;
+ aa = a;
+}
+pub export fn entry4() void{
+ comptime var aa: comptime_int = 0.0;
+ var a: f32 = 4;
+ aa = a;
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :3:27: error: unable to resolve comptime value
+// :3:27: note: value being casted to 'comptime_int' must be comptime known
+// :7:29: error: unable to resolve comptime value
+// :7:29: note: value being casted to 'comptime_float' must be comptime known
+// :12:10: error: unable to resolve comptime value
+// :12:10: note: value being casted to 'comptime_float' must be comptime known
+// :17:10: error: unable to resolve comptime value
+// :17:10: note: value being casted to 'comptime_int' must be comptime known
diff --git a/test/cases/compile_errors/shifting_without_int_type_or_comptime_known.zig b/test/cases/compile_errors/shifting_without_int_type_or_comptime_known.zig
new file mode 100644
index 0000000000..7e68baed62
--- /dev/null
+++ b/test/cases/compile_errors/shifting_without_int_type_or_comptime_known.zig
@@ -0,0 +1,23 @@
+export fn entry(x: u8) u8 {
+ return 0x11 << x;
+}
+export fn entry1(x: u8) u8 {
+ return 0x11 >> x;
+}
+export fn entry2() void {
+ var x: u5 = 1;
+ _ = @shlExact(12345, x);
+}
+export fn entry3() void {
+ var x: u5 = 1;
+ _ = @shrExact(12345, x);
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be a comptime known
+// :5:17: error: LHS of shift must be a fixed-width integer type, or RHS must be a comptime known
+// :9:9: error: LHS of shift must be a fixed-width integer type, or RHS must be a comptime known
+// :13:9: error: LHS of shift must be a fixed-width integer type, or RHS must be a comptime known
diff --git a/test/cases/compile_errors/stage1/obj/shifting_without_int_type_or_comptime_known.zig b/test/cases/compile_errors/stage1/obj/shifting_without_int_type_or_comptime_known.zig
deleted file mode 100644
index 4d875575d0..0000000000
--- a/test/cases/compile_errors/stage1/obj/shifting_without_int_type_or_comptime_known.zig
+++ /dev/null
@@ -1,9 +0,0 @@
-export fn entry(x: u8) u8 {
- return 0x11 << x;
-}
-
-// error
-// backend=stage1
-// target=native
-//
-// tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known
diff --git a/test/cases/taill_call_noreturn.zig b/test/cases/taill_call_noreturn.zig
new file mode 100644
index 0000000000..fabb9e729b
--- /dev/null
+++ b/test/cases/taill_call_noreturn.zig
@@ -0,0 +1,18 @@
+const std = @import("std");
+const builtin = std.builtin;
+pub fn foo(message: []const u8, stack_trace: ?*builtin.StackTrace) noreturn {
+ @call(.{ .modifier = .always_tail }, bar, .{ message, stack_trace });
+}
+pub fn bar(message: []const u8, stack_trace: ?*builtin.StackTrace) noreturn {
+ _ = message;
+ _ = stack_trace;
+ std.process.exit(0);
+}
+
+pub fn main() void {
+ foo("foo", null);
+}
+
+// run
+// backend=llvm
+// target=x86_64-linux,x86_64-macos,aarch64-linux,aarch64-macos