| author | |
| committer | |
| log | f6fecfdc001fa2fc3ee63ca344e419825a11f094 |
| tree | 0d28849278487b0a8522326849b8cec42d6b08c7 |
| parent | d07360f99990497fdb72a888df257a94c9547b2f |
3 files changed, 103 insertions(+), 20 deletions(-)
src/Sema.zig+6-13| ... | @@ -1034,7 +1034,7 @@ fn analyzeBodyRuntimeBreak(sema: *Sema, block: *Block, body: []const Zir.Inst.In | ... | @@ -1034,7 +1034,7 @@ fn analyzeBodyRuntimeBreak(sema: *Sema, block: *Block, body: []const Zir.Inst.In |
| 1034 | return sema.branch_hint orelse .none; | 1034 | return sema.branch_hint orelse .none; |
| 1035 | } | 1035 | } |
| 1036 | 1036 | ||
| 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 |
| 1038 | /// trigger comptime control flow to move above the function body. | 1038 | /// trigger comptime control flow to move above the function body. |
| 1039 | pub fn analyzeFnBody( | 1039 | pub fn analyzeFnBody( |
| 1040 | sema: *Sema, | 1040 | sema: *Sema, |
| ... | @@ -16386,18 +16386,11 @@ fn zirAsm( | ... | @@ -16386,18 +16386,11 @@ fn zirAsm( |
| 16386 | } else sema.code.nullTerminatedString(extra.data.asm_source); | 16386 | } else sema.code.nullTerminatedString(extra.data.asm_source); |
| 16387 | 16387 | ||
| 16388 | if (is_global_assembly) { | 16388 | if (is_global_assembly) { |
| 16389 | if (outputs_len != 0) { | 16389 | assert(outputs_len == 0); // validated by AstGen |
| 16390 | return sema.fail(block, src, "module-level assembly does not support outputs", .{}); | 16390 | assert(inputs_len == 0); // validated by AstGen |
| 16391 | } | 16391 | assert(extra.data.clobbers == .none); // validated by AstGen |
| 16392 | if (inputs_len != 0) { | 16392 | assert(!is_volatile); // validated by AstGen |
| 16393 | return sema.fail(block, src, "module-level assembly does not support inputs", .{}); | 16393 | |
| 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 | } | ||
| 16401 | try zcu.addGlobalAssembly(sema.owner, asm_source); | 16394 | try zcu.addGlobalAssembly(sema.owner, asm_source); |
| 16402 | return .void_value; | 16395 | return .void_value; |
| 16403 | } | 16396 | } |
test/cases/compile_errors/astgen_assembly_errors.zig created+97| ... | @@ -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 deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | comptime { | ||
| 2 | asm volatile (""); | ||
| 3 | } | ||
| 4 | |||
| 5 | // error | ||
| 6 | // | ||
| 7 | // :2:9: error: volatile is meaningless on global assembly | ||