| author | |
| committer | |
| log | 36243567e610808834147218fa791cbaab535941 |
| tree | 7c7eca7acc54ac54ed5e3326118f0ce8cb18490d |
| parent | 7a2fde973d27c7c47dc6eba174c71ae93af29d5f |
| signature |
2 files changed, 25 insertions(+), 0 deletions(-)
src/Sema.zig+5| ... | @@ -26193,6 +26193,8 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -26193,6 +26193,8 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 26193 | } | 26193 | } |
| 26194 | 26194 | ||
| 26195 | try sema.requireRuntimeBlock(block, src, runtime_src); | 26195 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 26196 | try sema.validateRuntimeValue(block, dest_src, dest_ptr); | ||
| 26197 | try sema.validateRuntimeValue(block, src_src, src_ptr); | ||
| 26196 | 26198 | ||
| 26197 | // Aliasing safety check. | 26199 | // Aliasing safety check. |
| 26198 | if (block.wantSafety()) { | 26200 | if (block.wantSafety()) { |
| ... | @@ -26321,6 +26323,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -26321,6 +26323,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 26321 | }; | 26323 | }; |
| 26322 | 26324 | ||
| 26323 | try sema.requireRuntimeBlock(block, src, runtime_src); | 26325 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 26326 | try sema.validateRuntimeValue(block, dest_src, dest_ptr); | ||
| 26327 | try sema.validateRuntimeValue(block, value_src, elem); | ||
| 26328 | |||
| 26324 | _ = try block.addInst(.{ | 26329 | _ = try block.addInst(.{ |
| 26325 | .tag = if (block.wantSafety()) .memset_safe else .memset, | 26330 | .tag = if (block.wantSafety()) .memset_safe else .memset, |
| 26326 | .data = .{ .bin_op = .{ | 26331 | .data = .{ .bin_op = .{ |
test/cases/compile_errors/comptime_var_referenced_at_runtime.zig+20| ... | @@ -47,6 +47,22 @@ export fn qar() void { | ... | @@ -47,6 +47,22 @@ export fn qar() void { |
| 47 | _ = y; | 47 | _ = y; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | export fn bux() void { | ||
| 51 | comptime var x: [2]u32 = undefined; | ||
| 52 | x = .{ 1, 2 }; | ||
| 53 | |||
| 54 | var rt: [2]u32 = undefined; | ||
| 55 | @memcpy(&rt, &x); | ||
| 56 | } | ||
| 57 | |||
| 58 | export fn far() void { | ||
| 59 | comptime var x: u32 = 123; | ||
| 60 | |||
| 61 | var rt: [2]*u32 = undefined; | ||
| 62 | const elem: *u32 = &x; | ||
| 63 | @memset(&rt, elem); | ||
| 64 | } | ||
| 65 | |||
| 50 | // error | 66 | // error |
| 51 | // | 67 | // |
| 52 | // :5:19: error: runtime value contains reference to comptime var | 68 | // :5:19: error: runtime value contains reference to comptime var |
| ... | @@ -63,3 +79,7 @@ export fn qar() void { | ... | @@ -63,3 +79,7 @@ export fn qar() void { |
| 63 | // :41:12: note: comptime var pointers are not available at runtime | 79 | // :41:12: note: comptime var pointers are not available at runtime |
| 64 | // :46:39: error: runtime value contains reference to comptime var | 80 | // :46:39: error: runtime value contains reference to comptime var |
| 65 | // :46:39: note: comptime var pointers are not available at runtime | 81 | // :46:39: note: comptime var pointers are not available at runtime |
| 82 | // :55:18: error: runtime value contains reference to comptime var | ||
| 83 | // :55:18: note: comptime var pointers are not available at runtime | ||
| 84 | // :63:18: error: runtime value contains reference to comptime var | ||
| 85 | // :63:18: note: comptime var pointers are not available at runtime |