From 633fe41a2c2310d8cfab53ee9d87bb50ac4efc41 Mon Sep 17 00:00:00 2001 From: Daniele Cocca Date: Sun, 20 Mar 2022 20:50:59 +0000 Subject: Sema: allow comptime blocks for global assembly An assembly expression in a comptime block is legal Zig in the case of global assembly [^1]. Instead of unconditionally asserting that the expression lives in a runtime block, here we assert that if the expression lives in a comptime block it must be outside of function scope. [^1]: https://ziglang.org/documentation/0.9.1/#Global-Assembly --- src/Sema.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Sema.zig b/src/Sema.zig index 9fc54f805b..f13f97bbbb 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -10253,6 +10253,11 @@ fn zirAsm( const inputs_len = @truncate(u5, extended.small >> 5); const clobbers_len = @truncate(u5, extended.small >> 10); const is_volatile = @truncate(u1, extended.small >> 15) != 0; + const is_global_assembly = sema.func == null; + + if (block.is_comptime and !is_global_assembly) { + try sema.requireRuntimeBlock(block, src); + } if (extra.data.asm_source == 0) { // This can move to become an AstGen error after inline assembly improvements land @@ -10317,7 +10322,6 @@ fn zirAsm( needed_capacity += (asm_source.len + 3) / 4; const gpa = sema.gpa; - try sema.requireRuntimeBlock(block, src); try sema.air_extra.ensureUnusedCapacity(gpa, needed_capacity); const asm_air = try block.addInst(.{ .tag = .assembly, -- cgit v1.2.3