aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacob G-W <jacoblevgw@gmail.com>2021-06-22 12:04:19 -0400
committerAndrew Kelley <andrew@ziglang.org>2021-07-08 14:33:01 -0400
commitec36ac8b21fa6c6d8514c60555aba8a96490a560 (patch)
tree2a289989d4f8573eca918e32b8cbe2ffdcc0c8dc /src
parente2b954c2738c683a85b864eb33530f0e3dbbc480 (diff)
downloadzig-ec36ac8b21fa6c6d8514c60555aba8a96490a560.tar.gz
zig-ec36ac8b21fa6c6d8514c60555aba8a96490a560.zip
stage2 astgen: provide 3 more errors for invalid inline assembly
Diffstat (limited to 'src')
-rw-r--r--src/AstGen.zig12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index a816628f66..e2cdffc014 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -6622,7 +6622,17 @@ fn asmExpr(
// See https://github.com/ziglang/zig/issues/215 and related issues discussing
// possible inline assembly improvements. Until then here is status quo AstGen
// for assembly syntax. It's used by std lib crypto aesni.zig.
-
+ const is_container_asm = astgen.fn_block == null;
+ if (is_container_asm) {
+ if (full.volatile_token) |t|
+ return astgen.failTok(t, "volatile is meaningless on global assembly", .{});
+ if (full.outputs.len != 0 or full.inputs.len != 0 or full.first_clobber != null)
+ return astgen.failNode(node, "global assembly cannot have inputs, outputs, or clobbers", .{});
+ } else {
+ if (full.outputs.len == 0 and full.volatile_token == null) {
+ return astgen.failNode(node, "assembly expression with no output must be marked volatile", .{});
+ }
+ }
if (full.outputs.len > 32) {
return astgen.failNode(full.outputs[32], "too many asm outputs", .{});
}