Commit f6fecfdc00
Changed files (3)
src
test
cases
src/Sema.zig
@@ -1034,7 +1034,7 @@ fn analyzeBodyRuntimeBreak(sema: *Sema, block: *Block, body: []const Zir.Inst.In
return sema.branch_hint orelse .none;
}
-/// Semantically analyze a ZIR function body. It is guranteed by AstGen that such a body cannot
+/// Semantically analyze a ZIR function body. It is guaranteed by AstGen that such a body cannot
/// trigger comptime control flow to move above the function body.
pub fn analyzeFnBody(
sema: *Sema,
@@ -16386,18 +16386,11 @@ fn zirAsm(
} else sema.code.nullTerminatedString(extra.data.asm_source);
if (is_global_assembly) {
- if (outputs_len != 0) {
- return sema.fail(block, src, "module-level assembly does not support outputs", .{});
- }
- if (inputs_len != 0) {
- return sema.fail(block, src, "module-level assembly does not support inputs", .{});
- }
- if (extra.data.clobbers != .none) {
- return sema.fail(block, src, "module-level assembly does not support clobbers", .{});
- }
- if (is_volatile) {
- return sema.fail(block, src, "volatile keyword is redundant on module-level assembly", .{});
- }
+ assert(outputs_len == 0); // validated by AstGen
+ assert(inputs_len == 0); // validated by AstGen
+ assert(extra.data.clobbers == .none); // validated by AstGen
+ assert(!is_volatile); // validated by AstGen
+
try zcu.addGlobalAssembly(sema.owner, asm_source);
return .void_value;
}
test/cases/compile_errors/astgen_assembly_errors.zig
@@ -0,0 +1,97 @@
+comptime {
+ asm volatile ("");
+}
+comptime {
+ asm (""
+ : [_] "" (-> u8),
+ );
+}
+comptime {
+ asm (""
+ :
+ : [_] "" (0),
+ );
+}
+comptime {
+ asm ("" ::: .{});
+}
+export fn a() void {
+ asm ("");
+}
+export fn b() void {
+ asm (""
+ : [_] "" (-> u8),
+ [_] "" (-> u8),
+ );
+}
+export fn c() void {
+ var out: u8 = 0;
+ asm (""
+ : [_] "" (out),
+ [_] "" (out),
+ [_] "" (out),
+ [_] "" (out),
+ [_] "" (out),
+ [_] "" (out),
+ [_] "" (out),
+ [_] "" (out),
+ [_] "" (out),
+ [_] "" (out),
+ [_] "" (out),
+ [_] "" (out),
+ [_] "" (out),
+ [_] "" (out),
+ [_] "" (out),
+ [_] "" (out),
+ [_] "" (out),
+ );
+}
+export fn d() void {
+ asm volatile (""
+ :
+ : [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ [_] "" (0),
+ );
+}
+
+// error
+//
+// :2:9: error: volatile is meaningless on global assembly
+// :5:5: error: global assembly cannot have inputs, outputs, or clobbers
+// :10:5: error: global assembly cannot have inputs, outputs, or clobbers
+// :16:5: error: global assembly cannot have inputs, outputs, or clobbers
+// :19:5: error: assembly expression with no output must be marked volatile
+// :24:12: error: inline assembly allows up to one output value
+// :46:12: error: too many asm outputs
+// :84:12: error: too many asm inputs
test/cases/compile_errors/volatile_on_global_assembly.zig
@@ -1,7 +0,0 @@
-comptime {
- asm volatile ("");
-}
-
-// error
-//
-// :2:9: error: volatile is meaningless on global assembly