aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorMeghan Denny <hello@nektro.net>2023-12-23 03:52:49 -0800
committerAndrew Kelley <andrew@ziglang.org>2024-01-12 16:23:42 -0800
commit3d6c26525f3914a139d0843307d7052bc3841177 (patch)
treecb35357abed048541698a1b160fa7e40e02568be /src/Sema.zig
parentd8b5831dc4f0666dceef671f47d23b5447b25912 (diff)
downloadzig-3d6c26525f3914a139d0843307d7052bc3841177.tar.gz
zig-3d6c26525f3914a139d0843307d7052bc3841177.zip
sema: forbid asm output to const locals
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index b8dcd0a1a5..f66b505e5c 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -16614,6 +16614,7 @@ fn zirAsm(
const clobbers_len: u5 = @truncate(extended.small >> 10);
const is_volatile = @as(u1, @truncate(extended.small >> 15)) != 0;
const is_global_assembly = sema.func_index == .none;
+ const zir_tags = sema.code.instructions.items(.tag);
const asm_source: []const u8 = if (tmpl_is_expr) blk: {
const tmpl: Zir.Inst.Ref = @enumFromInt(@intFromEnum(extra.data.asm_source));
@@ -16674,6 +16675,13 @@ fn zirAsm(
const name = sema.code.nullTerminatedString(output.data.name);
needed_capacity += (constraint.len + name.len + (2 + 3)) / 4;
+ if (output.data.operand.toIndex()) |index| {
+ if (zir_tags[@intFromEnum(index)] == .ref) {
+ // TODO: better error location; it would be even nicer if there were notes that pointed at the output and the variable definition
+ return sema.fail(block, src, "asm cannot output to const local '{s}'", .{name});
+ }
+ }
+
outputs[out_i] = .{ .c = constraint, .n = name };
}