Commit 29815fe9de

Veikka Tuominen <git@vexu.eu>
2022-07-12 13:22:57
Sema: disallow 'align' on functions on wasm
1 parent 62120e3
src/Sema.zig
@@ -17713,6 +17713,10 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
         break :blk lib_name;
     } else null;
 
+    if ((extra.data.bits.has_align_body or extra.data.bits.has_align_ref) and sema.mod.getTarget().cpu.arch.isWasm()) {
+        return sema.fail(block, align_src, "'align' is not allowed on functions in wasm", .{});
+    }
+
     const @"align": ?u32 = if (extra.data.bits.has_align_body) blk: {
         const body_len = sema.code.extra[extra_index];
         extra_index += 1;
test/cases/compile_errors/stage1/obj/align_n_expr_function_pointers_is_a_compile_error.zig
@@ -1,9 +0,0 @@
-export fn foo() align(1) void {
-    return;
-}
-
-// error
-// backend=stage1
-// target=wasm32-freestanding-none
-//
-// tmp.zig:1:23: error: align(N) expr is not allowed on function prototypes in wasm32/wasm64
test/cases/compile_errors/stage1/obj/control_reaches_end_of_non-void_function.zig
@@ -1,8 +0,0 @@
-fn a() i32 {}
-export fn entry() void { _ = a(); }
-
-// error
-// backend=stage1
-// target=native
-//
-// tmp.zig:1:12: error: expected type 'i32', found 'void'
test/cases/compile_errors/stage1/obj/endless_loop_in_function_evaluation.zig
@@ -1,12 +0,0 @@
-const seventh_fib_number = fibonacci(7);
-fn fibonacci(x: i32) i32 {
-    return fibonacci(x - 1) + fibonacci(x - 2);
-}
-
-export fn entry() usize { return @sizeOf(@TypeOf(seventh_fib_number)); }
-
-// error
-// backend=stage1
-// target=native
-//
-// tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches
test/cases/compile_errors/stage1/obj/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig
@@ -1,14 +0,0 @@
-export fn entry() void {
-    var x: i32 = 1234;
-    var p: *i32 = &x;
-    var pp: *?*i32 = &p;
-    pp.* = null;
-    var y = p.*;
-    _ = y;
-}
-
-// error
-// backend=stage1
-// target=native
-//
-// tmp.zig:4:23: error: expected type '*?*i32', found '**i32'
test/cases/compile_errors/stage1/obj/aligned_variable_of_zero-bit_type.zig → test/cases/compile_errors/stage1/aligned_variable_of_zero-bit_type.zig
File renamed without changes
test/cases/compile_errors/stage1/obj/implicit_casting_undefined_c_pointer_to_zig_pointer.zig → test/cases/compile_errors/stage1/implicit_casting_undefined_c_pointer_to_zig_pointer.zig
File renamed without changes
test/cases/compile_errors/align_n_expr_function_pointers_is_a_compile_error.zig
@@ -0,0 +1,9 @@
+export fn foo() align(1) void {
+    return;
+}
+
+// error
+// backend=stage2
+// target=wasm32-freestanding-none
+//
+// :1:8: error: 'align' is not allowed on functions in wasm
test/cases/compile_errors/stage1/obj/array_access_of_non_array.zig → test/cases/compile_errors/array_access_of_non_array.zig
@@ -8,8 +8,8 @@ export fn g() void {
 }
 
 // error
-// backend=stage1
+// backend=stage2
 // target=native
 //
-// tmp.zig:3:8: error: array access of non-array type 'bool'
-// tmp.zig:7:12: error: array access of non-array type 'bool'
+// :3:8: error: element access of non-indexable type 'bool'
+// :7:12: error: element access of non-indexable type 'bool'
test/cases/compile_errors/stage1/obj/array_access_with_non_integer_index.zig → test/cases/compile_errors/array_access_with_non_integer_index.zig
@@ -10,8 +10,8 @@ export fn g() void {
 }
 
 // error
-// backend=stage1
+// backend=stage2
 // target=native
 //
-// tmp.zig:4:11: error: expected type 'usize', found 'bool'
-// tmp.zig:9:15: error: expected type 'usize', found 'bool'
+// :4:11: error: expected type 'usize', found 'bool'
+// :9:15: error: expected type 'usize', found 'bool'
test/cases/compile_errors/control_reaches_end_of_non-void_function.zig
@@ -0,0 +1,9 @@
+fn a() i32 {}
+export fn entry() void { _ = a(); }
+
+// error
+// backend=stage2
+// target=native
+//
+// :1:13: error: expected type 'i32', found 'void'
+// :1:8: note: function return type declared here
test/cases/compile_errors/endless_loop_in_function_evaluation.zig
@@ -0,0 +1,15 @@
+const seventh_fib_number = fibonacci(7);
+fn fibonacci(x: i32) i32 {
+    return fibonacci(x - 1) + fibonacci(x - 2);
+}
+
+export fn entry() usize { return @sizeOf(@TypeOf(&seventh_fib_number)); }
+
+// error
+// backend=stage2
+// target=native
+//
+// :3:21: error: evaluation exceeded 1000 backwards branches
+// :3:21: note: use @setEvalBranchQuota() to raise the branch limit from 1000
+// :3:21: note: called from here (999 times)
+// :1:37: note: called from here
test/cases/compile_errors/stage1/obj/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig → test/cases/compile_errors/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig
@@ -7,7 +7,7 @@ export fn entry() void {
 }
 
 // error
-// backend=stage1
+// backend=stage2
 // target=native
 //
-// tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes
+// :5:28: error: dereference of '*const i64' exceeds bounds of containing decl of type 'f32'
test/cases/compile_errors/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig
@@ -0,0 +1,16 @@
+export fn entry() void {
+    var x: i32 = 1234;
+    var p: *i32 = &x;
+    var pp: *?*i32 = &p;
+    pp.* = null;
+    var y = p.*;
+    _ = y;
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :4:22: error: expected type '*?*i32', found '**i32'
+// :4:22: note: pointer type child '*i32' cannot cast into pointer type child '?*i32'
+// :4:22: note: mutable '*i32' allows illegal null values stored to type '?*i32'