authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-09 16:37:35+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-15 00:48:47+03:00
log002260c27481e50c74dbb3d8998cf8c3b1c472d8
tree1dd95be36a6157e8481af89f42972832eb584b4c
parent6f6b14621d5a0935d39295d21b5ffad2197f0e2f

Sema: copy runtime_index & friends when making child blocks


2 files changed, 37 insertions(+), 0 deletions(-)

src/Sema.zig+12
...@@ -4749,6 +4749,9 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -4749,6 +4749,9 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
4749 .inlining = parent_block.inlining,4749 .inlining = parent_block.inlining,
4750 .is_comptime = parent_block.is_comptime,4750 .is_comptime = parent_block.is_comptime,
4751 .c_import_buf = &c_import_buf,4751 .c_import_buf = &c_import_buf,
4752 .runtime_cond = parent_block.runtime_cond,
4753 .runtime_loop = parent_block.runtime_loop,
4754 .runtime_index = parent_block.runtime_index,
4752 };4755 };
4753 defer child_block.instructions.deinit(sema.gpa);4756 defer child_block.instructions.deinit(sema.gpa);
47544757
...@@ -4847,6 +4850,9 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -4847,6 +4850,9 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErro
4847 .is_comptime = parent_block.is_comptime,4850 .is_comptime = parent_block.is_comptime,
4848 .want_safety = parent_block.want_safety,4851 .want_safety = parent_block.want_safety,
4849 .float_mode = parent_block.float_mode,4852 .float_mode = parent_block.float_mode,
4853 .runtime_cond = parent_block.runtime_cond,
4854 .runtime_loop = parent_block.runtime_loop,
4855 .runtime_index = parent_block.runtime_index,
4850 };4856 };
48514857
4852 defer child_block.instructions.deinit(gpa);4858 defer child_block.instructions.deinit(gpa);
...@@ -9742,6 +9748,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -9742,6 +9748,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
9742 .inlining = block.inlining,9748 .inlining = block.inlining,
9743 .is_comptime = block.is_comptime,9749 .is_comptime = block.is_comptime,
9744 .switch_else_err_ty = else_error_ty,9750 .switch_else_err_ty = else_error_ty,
9751 .runtime_cond = block.runtime_cond,
9752 .runtime_loop = block.runtime_loop,
9753 .runtime_index = block.runtime_index,
9745 };9754 };
9746 const merges = &child_block.label.?.merges;9755 const merges = &child_block.label.?.merges;
9747 defer child_block.instructions.deinit(gpa);9756 defer child_block.instructions.deinit(gpa);
...@@ -14872,6 +14881,9 @@ fn zirTypeofPeer(...@@ -14872,6 +14881,9 @@ fn zirTypeofPeer(
14872 .inlining = block.inlining,14881 .inlining = block.inlining,
14873 .is_comptime = false,14882 .is_comptime = false,
14874 .is_typeof = true,14883 .is_typeof = true,
14884 .runtime_cond = block.runtime_cond,
14885 .runtime_loop = block.runtime_loop,
14886 .runtime_index = block.runtime_index,
14875 };14887 };
14876 defer child_block.instructions.deinit(sema.gpa);14888 defer child_block.instructions.deinit(sema.gpa);
14877 // Ignore the result, we only care about the instructions in `args`.14889 // Ignore the result, we only care about the instructions in `args`.
test/cases/compile_errors/comptime_store_in_comptime_switch_in_runtime_if.zig created+25
...@@ -0,0 +1,25 @@
1fn foo() bool {
2 return false;
3}
4
5pub export fn entry() void {
6 const Widget = union(enum) { a: u0 };
7
8 comptime var a = 1;
9 const info = @typeInfo(Widget).Union;
10 inline for (info.fields) |field| {
11 if (foo()) {
12 switch (field.field_type) {
13 u0 => a = 2,
14 else => unreachable,
15 }
16 }
17 }
18}
19
20// error
21// backend=stage2
22// target=native
23//
24// :13:27: error: store to comptime variable depends on runtime condition
25// :11:16: note: runtime condition here