authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-19 23:39:49-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-19 23:39:49-04:00
log6217b401f94380a0a82aa979bc4ac90e7431267d
tree5ad2e27f3faec52b04e1c876d9e96a2d7fb99cd1
parent78eeb6e9aea9c280513faaa83f9df959b7ac6f59
signaturelock-open Commit is signed but in an unrecognized format.

fix labeled break inside comptime if inside runtime if


5 files changed, 53 insertions(+), 21 deletions(-)

src/ir.cpp+21
...@@ -10883,6 +10883,7 @@ static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *cons...@@ -10883,6 +10883,7 @@ static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *cons
10883 ira->instruction_index = 0;10883 ira->instruction_index = 0;
10884 ira->old_irb.current_basic_block = old_bb;10884 ira->old_irb.current_basic_block = old_bb;
10885 ira->const_predecessor_bb = const_predecessor_bb;10885 ira->const_predecessor_bb = const_predecessor_bb;
10886 ira->old_bb_index = old_bb->index;
10886}10887}
1088710888
10888static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction, IrBasicBlock *next_bb,10889static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction, IrBasicBlock *next_bb,
...@@ -10894,6 +10895,14 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction...@@ -10894,6 +10895,14 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction
10894 ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block);10895 ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block);
10895 }10896 }
1089610897
10898 //if (ira->codegen->verbose_ir) {
10899 // fprintf(stderr, "suspend %s_%zu %s_%zu #%zu (%zu,%zu)\n", ira->old_irb.current_basic_block->name_hint,
10900 // ira->old_irb.current_basic_block->debug_id,
10901 // ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->name_hint,
10902 // ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->debug_id,
10903 // ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index)->debug_id,
10904 // ira->old_bb_index, ira->instruction_index);
10905 //}
10897 suspend_pos->basic_block_index = ira->old_bb_index;10906 suspend_pos->basic_block_index = ira->old_bb_index;
10898 suspend_pos->instruction_index = ira->instruction_index;10907 suspend_pos->instruction_index = ira->instruction_index;
1089910908
...@@ -10914,10 +10923,19 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction...@@ -10914,10 +10923,19 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction
1091410923
10915static IrInstruction *ira_resume(IrAnalyze *ira) {10924static IrInstruction *ira_resume(IrAnalyze *ira) {
10916 IrSuspendPosition pos = ira->resume_stack.pop();10925 IrSuspendPosition pos = ira->resume_stack.pop();
10926 //if (ira->codegen->verbose_ir) {
10927 // fprintf(stderr, "resume (%zu,%zu) ", pos.basic_block_index, pos.instruction_index);
10928 //}
10917 ira->old_bb_index = pos.basic_block_index;10929 ira->old_bb_index = pos.basic_block_index;
10918 ira->old_irb.current_basic_block = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index);10930 ira->old_irb.current_basic_block = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index);
10919 ira->old_irb.current_basic_block->suspended = false;10931 ira->old_irb.current_basic_block->suspended = false;
10920 ira->instruction_index = pos.instruction_index;10932 ira->instruction_index = pos.instruction_index;
10933 assert(pos.instruction_index < ira->old_irb.current_basic_block->instruction_list.length);
10934 //if (ira->codegen->verbose_ir) {
10935 // fprintf(stderr, "%s_%zu #%zu\n", ira->old_irb.current_basic_block->name_hint,
10936 // ira->old_irb.current_basic_block->debug_id,
10937 // ira->old_irb.current_basic_block->instruction_list.at(pos.instruction_index)->debug_id);
10938 //}
10921 ira->const_predecessor_bb = nullptr;10939 ira->const_predecessor_bb = nullptr;
10922 ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->other;10940 ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->other;
10923 assert(ira->new_irb.current_basic_block != nullptr);10941 assert(ira->new_irb.current_basic_block != nullptr);
...@@ -24999,6 +25017,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -24999,6 +25017,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
24999 continue;25017 continue;
25000 }25018 }
2500125019
25020 //if (ira->codegen->verbose_ir) {
25021 // fprintf(stderr, "analyze #%zu\n", old_instruction->debug_id);
25022 //}
25002 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);25023 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
25003 if (new_instruction != nullptr) {25024 if (new_instruction != nullptr) {
25004 ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction);25025 ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction);
std/special/bootstrap.zig+13-13
...@@ -78,19 +78,19 @@ fn posixCallMainAndExit() noreturn {...@@ -78,19 +78,19 @@ fn posixCallMainAndExit() noreturn {
78 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}78 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}
79 const envp = @ptrCast([*][*]u8, envp_optional)[0..envp_count];79 const envp = @ptrCast([*][*]u8, envp_optional)[0..envp_count];
8080
81 //if (builtin.os == .linux) {81 if (builtin.os == .linux) {
82 // // Find the beginning of the auxiliary vector82 // Find the beginning of the auxiliary vector
83 // const auxv = @ptrCast([*]std.elf.Auxv, envp.ptr + envp_count + 1);83 const auxv = @ptrCast([*]std.elf.Auxv, envp.ptr + envp_count + 1);
84 // std.os.linux.elf_aux_maybe = auxv;84 std.os.linux.elf_aux_maybe = auxv;
85 // // Initialize the TLS area85 // Initialize the TLS area
86 // std.os.linux.tls.initTLS();86 std.os.linux.tls.initTLS();
8787
88 // if (std.os.linux.tls.tls_image) |tls_img| {88 if (std.os.linux.tls.tls_image) |tls_img| {
89 // const tls_addr = std.os.linux.tls.allocateTLS(tls_img.alloc_size);89 const tls_addr = std.os.linux.tls.allocateTLS(tls_img.alloc_size);
90 // const tp = std.os.linux.tls.copyTLS(tls_addr);90 const tp = std.os.linux.tls.copyTLS(tls_addr);
91 // std.os.linux.tls.setThreadPointer(tp);91 std.os.linux.tls.setThreadPointer(tp);
92 // }92 }
93 //}93 }
9494
95 std.os.exit(callMainWithArgs(argc, argv, envp));95 std.os.exit(callMainWithArgs(argc, argv, envp));
96}96}
test/stage1/behavior.zig+1-1
...@@ -62,7 +62,7 @@ comptime {...@@ -62,7 +62,7 @@ comptime {
62 _ = @import("behavior/ir_block_deps.zig");62 _ = @import("behavior/ir_block_deps.zig");
63 _ = @import("behavior/math.zig");63 _ = @import("behavior/math.zig");
64 _ = @import("behavior/merge_error_sets.zig");64 _ = @import("behavior/merge_error_sets.zig");
65 _ = @import("behavior/misc.zig"); // TODO65 _ = @import("behavior/misc.zig");
66 _ = @import("behavior/namespace_depends_on_compile_var.zig");66 _ = @import("behavior/namespace_depends_on_compile_var.zig");
67 _ = @import("behavior/new_stack_call.zig");67 _ = @import("behavior/new_stack_call.zig");
68 _ = @import("behavior/null.zig");68 _ = @import("behavior/null.zig");
test/stage1/behavior/if.zig+11
...@@ -52,3 +52,14 @@ test "unwrap mutable global var" {...@@ -52,3 +52,14 @@ test "unwrap mutable global var" {
52 expect(e == error.SomeError);52 expect(e == error.SomeError);
53 }53 }
54}54}
55
56test "labeled break inside comptime if inside runtime if" {
57 var answer: i32 = 0;
58 var c = true;
59 if (c) {
60 answer = if (true) blk: {
61 break :blk i32(42);
62 };
63 }
64 expect(answer == 42);
65}
test/stage1/behavior/misc.zig+7-7
...@@ -686,13 +686,13 @@ fn getNull() ?*i32 {...@@ -686,13 +686,13 @@ fn getNull() ?*i32 {
686 return null;686 return null;
687}687}
688688
689//test "thread local variable" {689test "thread local variable" {
690// const S = struct {690 const S = struct {
691// threadlocal var t: i32 = 1234;691 threadlocal var t: i32 = 1234;
692// };692 };
693// S.t += 1;693 S.t += 1;
694// expect(S.t == 1235);694 expect(S.t == 1235);
695//}695}
696696
697test "unicode escape in character literal" {697test "unicode escape in character literal" {
698 var a: u24 = '\U01f4a9';698 var a: u24 = '\U01f4a9';