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
1088310883 ira->instruction_index = 0;
1088410884 ira->old_irb.current_basic_block = old_bb;
1088510885 ira->const_predecessor_bb = const_predecessor_bb;
10886 ira->old_bb_index = old_bb->index;
1088610887}
1088710888
1088810889static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction, IrBasicBlock *next_bb,
......@@ -10894,6 +10895,14 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction
1089410895 ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block);
1089510896 }
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 //}
1089710906 suspend_pos->basic_block_index = ira->old_bb_index;
1089810907 suspend_pos->instruction_index = ira->instruction_index;
1089910908
......@@ -10914,10 +10923,19 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction
1091410923
1091510924static IrInstruction *ira_resume(IrAnalyze *ira) {
1091610925 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 //}
1091710929 ira->old_bb_index = pos.basic_block_index;
1091810930 ira->old_irb.current_basic_block = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index);
1091910931 ira->old_irb.current_basic_block->suspended = false;
1092010932 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 //}
1092110939 ira->const_predecessor_bb = nullptr;
1092210940 ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->other;
1092310941 assert(ira->new_irb.current_basic_block != nullptr);
......@@ -24999,6 +25017,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2499925017 continue;
2500025018 }
2500125019
25020 //if (ira->codegen->verbose_ir) {
25021 // fprintf(stderr, "analyze #%zu\n", old_instruction->debug_id);
25022 //}
2500225023 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
2500325024 if (new_instruction != nullptr) {
2500425025 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 {
7878 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}
7979 const envp = @ptrCast([*][*]u8, envp_optional)[0..envp_count];
8080
81 //if (builtin.os == .linux) {
82 // // Find the beginning of the auxiliary vector
83 // const auxv = @ptrCast([*]std.elf.Auxv, envp.ptr + envp_count + 1);
84 // std.os.linux.elf_aux_maybe = auxv;
85 // // Initialize the TLS area
86 // std.os.linux.tls.initTLS();
87
88 // if (std.os.linux.tls.tls_image) |tls_img| {
89 // const tls_addr = std.os.linux.tls.allocateTLS(tls_img.alloc_size);
90 // const tp = std.os.linux.tls.copyTLS(tls_addr);
91 // std.os.linux.tls.setThreadPointer(tp);
92 // }
93 //}
81 if (builtin.os == .linux) {
82 // Find the beginning of the auxiliary vector
83 const auxv = @ptrCast([*]std.elf.Auxv, envp.ptr + envp_count + 1);
84 std.os.linux.elf_aux_maybe = auxv;
85 // Initialize the TLS area
86 std.os.linux.tls.initTLS();
87
88 if (std.os.linux.tls.tls_image) |tls_img| {
89 const tls_addr = std.os.linux.tls.allocateTLS(tls_img.alloc_size);
90 const tp = std.os.linux.tls.copyTLS(tls_addr);
91 std.os.linux.tls.setThreadPointer(tp);
92 }
93 }
9494
9595 std.os.exit(callMainWithArgs(argc, argv, envp));
9696}
test/stage1/behavior.zig+1-1
......@@ -62,7 +62,7 @@ comptime {
6262 _ = @import("behavior/ir_block_deps.zig");
6363 _ = @import("behavior/math.zig");
6464 _ = @import("behavior/merge_error_sets.zig");
65 _ = @import("behavior/misc.zig"); // TODO
65 _ = @import("behavior/misc.zig");
6666 _ = @import("behavior/namespace_depends_on_compile_var.zig");
6767 _ = @import("behavior/new_stack_call.zig");
6868 _ = @import("behavior/null.zig");
test/stage1/behavior/if.zig+11
......@@ -52,3 +52,14 @@ test "unwrap mutable global var" {
5252 expect(e == error.SomeError);
5353 }
5454}
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 {
686686 return null;
687687}
688688
689//test "thread local variable" {
690// const S = struct {
691// threadlocal var t: i32 = 1234;
692// };
693// S.t += 1;
694// expect(S.t == 1235);
695//}
689test "thread local variable" {
690 const S = struct {
691 threadlocal var t: i32 = 1234;
692 };
693 S.t += 1;
694 expect(S.t == 1235);
695}
696696
697697test "unicode escape in character literal" {
698698 var a: u24 = '\U01f4a9';