Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
97 changes: 97 additions & 0 deletions test/cases/compile_errors/astgen_assembly_errors.zig
Original file line number Diff line number Diff line change
@@ -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
7 changes: 0 additions & 7 deletions test/cases/compile_errors/volatile_on_global_assembly.zig

This file was deleted.