improve assembly error test coverage

This commit is contained in:
xdBronch 2025-11-13 12:18:21 -05:00 committed by Matthew Lugg
parent d07360f999
commit f6fecfdc00
3 changed files with 103 additions and 20 deletions

View File

@ -1034,7 +1034,7 @@ fn analyzeBodyRuntimeBreak(sema: *Sema, block: *Block, body: []const Zir.Inst.In
return sema.branch_hint orelse .none; 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. /// trigger comptime control flow to move above the function body.
pub fn analyzeFnBody( pub fn analyzeFnBody(
sema: *Sema, sema: *Sema,
@ -16386,18 +16386,11 @@ fn zirAsm(
} else sema.code.nullTerminatedString(extra.data.asm_source); } else sema.code.nullTerminatedString(extra.data.asm_source);
if (is_global_assembly) { if (is_global_assembly) {
if (outputs_len != 0) { assert(outputs_len == 0); // validated by AstGen
return sema.fail(block, src, "module-level assembly does not support outputs", .{}); assert(inputs_len == 0); // validated by AstGen
} assert(extra.data.clobbers == .none); // validated by AstGen
if (inputs_len != 0) { assert(!is_volatile); // validated by AstGen
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", .{});
}
try zcu.addGlobalAssembly(sema.owner, asm_source); try zcu.addGlobalAssembly(sema.owner, asm_source);
return .void_value; return .void_value;
} }

View File

@ -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

View File

@ -1,7 +0,0 @@
comptime {
asm volatile ("");
}
// error
//
// :2:9: error: volatile is meaningless on global assembly