| author | |
| committer | |
| log | ec36ac8b21fa6c6d8514c60555aba8a96490a560 |
| tree | 2a289989d4f8573eca918e32b8cbe2ffdcc0c8dc |
| parent | e2b954c2738c683a85b864eb33530f0e3dbbc480 |
3 files changed, 45 insertions(+), 3 deletions(-)
src/AstGen.zig+11-1| ... | ... | @@ -6622,7 +6622,17 @@ fn asmExpr( |
| 6622 | 6622 | // See https://github.com/ziglang/zig/issues/215 and related issues discussing |
| 6623 | 6623 | // possible inline assembly improvements. Until then here is status quo AstGen |
| 6624 | 6624 | // for assembly syntax. It's used by std lib crypto aesni.zig. |
| 6625 | ||
| 6625 | const is_container_asm = astgen.fn_block == null; | |
| 6626 | if (is_container_asm) { | |
| 6627 | if (full.volatile_token) |t| | |
| 6628 | return astgen.failTok(t, "volatile is meaningless on global assembly", .{}); | |
| 6629 | if (full.outputs.len != 0 or full.inputs.len != 0 or full.first_clobber != null) | |
| 6630 | return astgen.failNode(node, "global assembly cannot have inputs, outputs, or clobbers", .{}); | |
| 6631 | } else { | |
| 6632 | if (full.outputs.len == 0 and full.volatile_token == null) { | |
| 6633 | return astgen.failNode(node, "assembly expression with no output must be marked volatile", .{}); | |
| 6634 | } | |
| 6635 | } | |
| 6626 | 6636 | if (full.outputs.len > 32) { |
| 6627 | 6637 | return astgen.failNode(full.outputs[32], "too many asm outputs", .{}); |
| 6628 | 6638 | } |
test/behavior/syntax.zig+1-2| ... | ... | @@ -60,8 +60,7 @@ fn asm_lists() void { |
| 60 | 60 | :[a] "x" (x),); |
| 61 | 61 | asm ("not real assembly" |
| 62 | 62 | :[a] "x" (->i32),:[a] "x" (1),); |
| 63 | asm ("still not real assembly" | |
| 63 | asm volatile ("still not real assembly" | |
| 64 | 64 | :::"a","b",); |
| 65 | 65 | } |
| 66 | 66 | } |
| 67 |
test/cases.zig+33| ... | ... | @@ -1506,6 +1506,39 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1506 | 1506 | \\ _ = x; |
| 1507 | 1507 | \\} |
| 1508 | 1508 | , &[_][]const u8{":4:27: error: expected type, found comptime_int"}); |
| 1509 | case.addError( | |
| 1510 | \\const S = struct { | |
| 1511 | \\ comptime { | |
| 1512 | \\ asm volatile ( | |
| 1513 | \\ \\zig_moment: | |
| 1514 | \\ \\syscall | |
| 1515 | \\ ); | |
| 1516 | \\ } | |
| 1517 | \\}; | |
| 1518 | \\pub fn main() void { | |
| 1519 | \\ _ = S; | |
| 1520 | \\} | |
| 1521 | , &.{":3:13: error: volatile is meaningless on global assembly"}); | |
| 1522 | case.addError( | |
| 1523 | \\pub fn main() void { | |
| 1524 | \\ var bruh: u32 = 1; | |
| 1525 | \\ asm ("" | |
| 1526 | \\ : | |
| 1527 | \\ : [bruh] "{rax}" (4) | |
| 1528 | \\ : "memory" | |
| 1529 | \\ ); | |
| 1530 | \\} | |
| 1531 | , &.{":3:5: error: assembly expression with no output must be marked volatile"}); | |
| 1532 | case.addError( | |
| 1533 | \\pub fn main() void {} | |
| 1534 | \\comptime { | |
| 1535 | \\ asm ("" | |
| 1536 | \\ : | |
| 1537 | \\ : [bruh] "{rax}" (4) | |
| 1538 | \\ : "memory" | |
| 1539 | \\ ); | |
| 1540 | \\} | |
| 1541 | , &.{":3:5: error: global assembly cannot have inputs, outputs, or clobbers"}); | |
| 1509 | 1542 | } |
| 1510 | 1543 | { |
| 1511 | 1544 | var case = ctx.exe("comptime var", linux_x64); |