Skip to content

Commit 7813c83

Browse files
committed
improve assembly error test coverage
1 parent 181b25c commit 7813c83

File tree

3 files changed

+103
-20
lines changed

3 files changed

+103
-20
lines changed

src/Sema.zig

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ fn analyzeBodyRuntimeBreak(sema: *Sema, block: *Block, body: []const Zir.Inst.In
10341034
return sema.branch_hint orelse .none;
10351035
}
10361036

1037-
/// Semantically analyze a ZIR function body. It is guranteed by AstGen that such a body cannot
1037+
/// Semantically analyze a ZIR function body. It is guaranteed by AstGen that such a body cannot
10381038
/// trigger comptime control flow to move above the function body.
10391039
pub fn analyzeFnBody(
10401040
sema: *Sema,
@@ -16386,18 +16386,11 @@ fn zirAsm(
1638616386
} else sema.code.nullTerminatedString(extra.data.asm_source);
1638716387

1638816388
if (is_global_assembly) {
16389-
if (outputs_len != 0) {
16390-
return sema.fail(block, src, "module-level assembly does not support outputs", .{});
16391-
}
16392-
if (inputs_len != 0) {
16393-
return sema.fail(block, src, "module-level assembly does not support inputs", .{});
16394-
}
16395-
if (extra.data.clobbers != .none) {
16396-
return sema.fail(block, src, "module-level assembly does not support clobbers", .{});
16397-
}
16398-
if (is_volatile) {
16399-
return sema.fail(block, src, "volatile keyword is redundant on module-level assembly", .{});
16400-
}
16389+
if (outputs_len != 0 or
16390+
inputs_len != 0 or
16391+
extra.data.clobbers != .none or
16392+
is_volatile) unreachable; // already checked by AstGen
16393+
1640116394
try zcu.addGlobalAssembly(sema.owner, asm_source);
1640216395
return .void_value;
1640316396
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
comptime {
2+
asm volatile ("");
3+
}
4+
comptime {
5+
asm (""
6+
: [_] "" (-> u8),
7+
);
8+
}
9+
comptime {
10+
asm (""
11+
:
12+
: [_] "" (0),
13+
);
14+
}
15+
comptime {
16+
asm ("" ::: .{});
17+
}
18+
export fn a() void {
19+
asm ("");
20+
}
21+
export fn b() void {
22+
asm (""
23+
: [_] "" (-> u8),
24+
[_] "" (-> u8),
25+
);
26+
}
27+
export fn c() void {
28+
var out: u8 = 0;
29+
asm (""
30+
: [_] "" (out),
31+
[_] "" (out),
32+
[_] "" (out),
33+
[_] "" (out),
34+
[_] "" (out),
35+
[_] "" (out),
36+
[_] "" (out),
37+
[_] "" (out),
38+
[_] "" (out),
39+
[_] "" (out),
40+
[_] "" (out),
41+
[_] "" (out),
42+
[_] "" (out),
43+
[_] "" (out),
44+
[_] "" (out),
45+
[_] "" (out),
46+
[_] "" (out),
47+
);
48+
}
49+
export fn d() void {
50+
asm volatile (""
51+
:
52+
: [_] "" (0),
53+
[_] "" (0),
54+
[_] "" (0),
55+
[_] "" (0),
56+
[_] "" (0),
57+
[_] "" (0),
58+
[_] "" (0),
59+
[_] "" (0),
60+
[_] "" (0),
61+
[_] "" (0),
62+
[_] "" (0),
63+
[_] "" (0),
64+
[_] "" (0),
65+
[_] "" (0),
66+
[_] "" (0),
67+
[_] "" (0),
68+
[_] "" (0),
69+
[_] "" (0),
70+
[_] "" (0),
71+
[_] "" (0),
72+
[_] "" (0),
73+
[_] "" (0),
74+
[_] "" (0),
75+
[_] "" (0),
76+
[_] "" (0),
77+
[_] "" (0),
78+
[_] "" (0),
79+
[_] "" (0),
80+
[_] "" (0),
81+
[_] "" (0),
82+
[_] "" (0),
83+
[_] "" (0),
84+
[_] "" (0),
85+
);
86+
}
87+
88+
// error
89+
//
90+
// :2:9: error: volatile is meaningless on global assembly
91+
// :5:5: error: global assembly cannot have inputs, outputs, or clobbers
92+
// :10:5: error: global assembly cannot have inputs, outputs, or clobbers
93+
// :16:5: error: global assembly cannot have inputs, outputs, or clobbers
94+
// :19:5: error: assembly expression with no output must be marked volatile
95+
// :24:12: error: inline assembly allows up to one output value
96+
// :46:12: error: too many asm outputs
97+
// :84:12: error: too many asm inputs

test/cases/compile_errors/volatile_on_global_assembly.zig

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)