Sema: disallow 'align' on functions on wasm

This commit is contained in:
Veikka Tuominen 2022-07-12 14:22:57 +03:00 committed by Andrew Kelley
parent 62120e3d0e
commit 29815fe9de
14 changed files with 61 additions and 51 deletions

View File

@ -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;

View File

@ -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

View File

@ -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'

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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'

View File

@ -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'