| author | |
| committer | |
| log | 77d0a9c07e8880bdb222d87ece66a7d822a76748 |
| tree | 6350459b8c3e68664e3c40056b3cab590613d5f1 |
| parent | d9c4f16e44f35f8d2b7aa39eb6a8100f2a680e1b |
| signature | Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM |
Targets such as wasm32 and wasm64 do not support setting function alignment, but align(1) is a no-op and should be accepted. Reject only alignments greater than 1 on those targets.
Update the compile-error tests and add a positive test covering align(1) on wasm.5 files changed, 19 insertions(+), 10 deletions(-)
src/Zcu/PerThread.zig+7-3| ... | ... | @@ -1866,9 +1866,13 @@ fn analyzeNavVal( |
| 1866 | 1866 | }; |
| 1867 | 1867 | |
| 1868 | 1868 | if (is_owned_fn) { |
| 1869 | // linksection etc are legal, except some targets do not support function alignment. | |
| 1870 | if (zir_decl.align_body != null and !target_util.supportsFunctionAlignment(zcu.getTarget())) { | |
| 1871 | return sema.fail(&block, align_src, "target does not support function alignment", .{}); | |
| 1869 | // linksection etc are legal, except some targets do not support function alignment | |
| 1870 | // greater than 1. `align(1)` is a no-op, so it is allowed even on those targets. | |
| 1871 | if (zir_decl.align_body != null and | |
| 1872 | modifiers.@"align" != .@"1" and | |
| 1873 | !target_util.supportsFunctionAlignment(zcu.getTarget())) | |
| 1874 | { | |
| 1875 | return sema.fail(&block, align_src, "target does not support function alignment greater than 1", .{}); | |
| 1872 | 1876 | } |
| 1873 | 1877 | } else if (nav_ty.comptimeOnly(zcu)) { |
| 1874 | 1878 | // alignment, linksection, addrspace annotations are not allowed for comptime-only types. |
test/behavior/align.zig+4-4| ... | ... | @@ -312,7 +312,7 @@ test "function alignment" { |
| 312 | 312 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 313 | 313 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 314 | 314 | |
| 315 | // function alignment is a compile error on wasm | |
| 315 | // function alignment greater than 1 is a compile error on wasm | |
| 316 | 316 | if (native_arch.isWasm()) return error.SkipZigTest; |
| 317 | 317 | |
| 318 | 318 | const S = struct { |
| ... | ... | @@ -341,7 +341,7 @@ test "implicitly decreasing fn alignment" { |
| 341 | 341 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 342 | 342 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 343 | 343 | |
| 344 | // function alignment is a compile error on wasm | |
| 344 | // function alignment greater than 1 is a compile error on wasm | |
| 345 | 345 | if (native_arch.isWasm()) return error.SkipZigTest; |
| 346 | 346 | |
| 347 | 347 | try testImplicitlyDecreaseFnAlign(alignedSmall, 1234); |
| ... | ... | @@ -364,7 +364,7 @@ test "@alignCast functions" { |
| 364 | 364 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 365 | 365 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 366 | 366 | |
| 367 | // function alignment is a compile error on wasm | |
| 367 | // function alignment greater than 1 is a compile error on wasm | |
| 368 | 368 | if (native_arch.isWasm()) return error.SkipZigTest; |
| 369 | 369 | |
| 370 | 370 | try expect(fnExpectsOnly1(simple4) == 0x19); |
| ... | ... | @@ -510,7 +510,7 @@ test "align(N) on functions" { |
| 510 | 510 | return error.SkipZigTest; |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | // function alignment is a compile error on wasm | |
| 513 | // function alignment greater than 1 is a compile error on wasm | |
| 514 | 514 | if (native_arch.isWasm()) return error.SkipZigTest; |
| 515 | 515 | if (native_arch.isThumb()) return error.SkipZigTest; |
| 516 | 516 |
test/cases/compile_errors/align_n_expr_function_pointers_is_a_compile_error.zig+2-2| ... | ... | @@ -1,8 +1,8 @@ |
| 1 | export fn foo() align(1) void { | |
| 1 | export fn foo() align(2) void { | |
| 2 | 2 | return; |
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | // error |
| 6 | 6 | // target=wasm32-freestanding-none |
| 7 | 7 | // |
| 8 | // :1:23: error: target does not support function alignment | |
| 8 | // :1:23: error: target does not support function alignment greater than 1 |
test/cases/compile_errors/function_alignment_on_unsupported_target.zig+1-1| ... | ... | @@ -3,4 +3,4 @@ export fn entry() align(64) void {} |
| 3 | 3 | // error |
| 4 | 4 | // target=nvptx-cuda,nvptx64-cuda,spirv32-opengl,spirv32-vulkan,spirv32-opencl,spirv64-opencl,spirv64-amdhsa,wasm32-freestanding,wasm64-freestanding |
| 5 | 5 | // |
| 6 | // :1:25: error: target does not support function alignment | |
| 6 | // :1:25: error: target does not support function alignment greater than 1 |
test/cases/function_alignment_one_on_virtual_target.zig created+5| ... | ... | @@ -0,0 +1,5 @@ |
| 1 | export fn foo() align(1) void {} | |
| 2 | ||
| 3 | // compile | |
| 4 | // backend=selfhosted | |
| 5 | // target=wasm32-freestanding |