mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
fix labeled break inside comptime if inside runtime if
This commit is contained in:
parent
78eeb6e9ae
commit
6217b401f9
21
src/ir.cpp
21
src/ir.cpp
@ -10883,6 +10883,7 @@ static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *cons
|
||||
ira->instruction_index = 0;
|
||||
ira->old_irb.current_basic_block = old_bb;
|
||||
ira->const_predecessor_bb = const_predecessor_bb;
|
||||
ira->old_bb_index = old_bb->index;
|
||||
}
|
||||
|
||||
static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction, IrBasicBlock *next_bb,
|
||||
@ -10894,6 +10895,14 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction
|
||||
ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block);
|
||||
}
|
||||
|
||||
//if (ira->codegen->verbose_ir) {
|
||||
// fprintf(stderr, "suspend %s_%zu %s_%zu #%zu (%zu,%zu)\n", ira->old_irb.current_basic_block->name_hint,
|
||||
// ira->old_irb.current_basic_block->debug_id,
|
||||
// ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->name_hint,
|
||||
// ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->debug_id,
|
||||
// ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index)->debug_id,
|
||||
// ira->old_bb_index, ira->instruction_index);
|
||||
//}
|
||||
suspend_pos->basic_block_index = ira->old_bb_index;
|
||||
suspend_pos->instruction_index = ira->instruction_index;
|
||||
|
||||
@ -10914,10 +10923,19 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction
|
||||
|
||||
static IrInstruction *ira_resume(IrAnalyze *ira) {
|
||||
IrSuspendPosition pos = ira->resume_stack.pop();
|
||||
//if (ira->codegen->verbose_ir) {
|
||||
// fprintf(stderr, "resume (%zu,%zu) ", pos.basic_block_index, pos.instruction_index);
|
||||
//}
|
||||
ira->old_bb_index = pos.basic_block_index;
|
||||
ira->old_irb.current_basic_block = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index);
|
||||
ira->old_irb.current_basic_block->suspended = false;
|
||||
ira->instruction_index = pos.instruction_index;
|
||||
assert(pos.instruction_index < ira->old_irb.current_basic_block->instruction_list.length);
|
||||
//if (ira->codegen->verbose_ir) {
|
||||
// fprintf(stderr, "%s_%zu #%zu\n", ira->old_irb.current_basic_block->name_hint,
|
||||
// ira->old_irb.current_basic_block->debug_id,
|
||||
// ira->old_irb.current_basic_block->instruction_list.at(pos.instruction_index)->debug_id);
|
||||
//}
|
||||
ira->const_predecessor_bb = nullptr;
|
||||
ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->other;
|
||||
assert(ira->new_irb.current_basic_block != nullptr);
|
||||
@ -24999,6 +25017,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
|
||||
continue;
|
||||
}
|
||||
|
||||
//if (ira->codegen->verbose_ir) {
|
||||
// fprintf(stderr, "analyze #%zu\n", old_instruction->debug_id);
|
||||
//}
|
||||
IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
|
||||
if (new_instruction != nullptr) {
|
||||
ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction);
|
||||
|
||||
@ -78,19 +78,19 @@ fn posixCallMainAndExit() noreturn {
|
||||
while (envp_optional[envp_count]) |_| : (envp_count += 1) {}
|
||||
const envp = @ptrCast([*][*]u8, envp_optional)[0..envp_count];
|
||||
|
||||
//if (builtin.os == .linux) {
|
||||
// // Find the beginning of the auxiliary vector
|
||||
// const auxv = @ptrCast([*]std.elf.Auxv, envp.ptr + envp_count + 1);
|
||||
// std.os.linux.elf_aux_maybe = auxv;
|
||||
// // Initialize the TLS area
|
||||
// std.os.linux.tls.initTLS();
|
||||
if (builtin.os == .linux) {
|
||||
// Find the beginning of the auxiliary vector
|
||||
const auxv = @ptrCast([*]std.elf.Auxv, envp.ptr + envp_count + 1);
|
||||
std.os.linux.elf_aux_maybe = auxv;
|
||||
// Initialize the TLS area
|
||||
std.os.linux.tls.initTLS();
|
||||
|
||||
// if (std.os.linux.tls.tls_image) |tls_img| {
|
||||
// const tls_addr = std.os.linux.tls.allocateTLS(tls_img.alloc_size);
|
||||
// const tp = std.os.linux.tls.copyTLS(tls_addr);
|
||||
// std.os.linux.tls.setThreadPointer(tp);
|
||||
// }
|
||||
//}
|
||||
if (std.os.linux.tls.tls_image) |tls_img| {
|
||||
const tls_addr = std.os.linux.tls.allocateTLS(tls_img.alloc_size);
|
||||
const tp = std.os.linux.tls.copyTLS(tls_addr);
|
||||
std.os.linux.tls.setThreadPointer(tp);
|
||||
}
|
||||
}
|
||||
|
||||
std.os.exit(callMainWithArgs(argc, argv, envp));
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ comptime {
|
||||
_ = @import("behavior/ir_block_deps.zig");
|
||||
_ = @import("behavior/math.zig");
|
||||
_ = @import("behavior/merge_error_sets.zig");
|
||||
_ = @import("behavior/misc.zig"); // TODO
|
||||
_ = @import("behavior/misc.zig");
|
||||
_ = @import("behavior/namespace_depends_on_compile_var.zig");
|
||||
_ = @import("behavior/new_stack_call.zig");
|
||||
_ = @import("behavior/null.zig");
|
||||
|
||||
@ -52,3 +52,14 @@ test "unwrap mutable global var" {
|
||||
expect(e == error.SomeError);
|
||||
}
|
||||
}
|
||||
|
||||
test "labeled break inside comptime if inside runtime if" {
|
||||
var answer: i32 = 0;
|
||||
var c = true;
|
||||
if (c) {
|
||||
answer = if (true) blk: {
|
||||
break :blk i32(42);
|
||||
};
|
||||
}
|
||||
expect(answer == 42);
|
||||
}
|
||||
|
||||
@ -686,13 +686,13 @@ fn getNull() ?*i32 {
|
||||
return null;
|
||||
}
|
||||
|
||||
//test "thread local variable" {
|
||||
// const S = struct {
|
||||
// threadlocal var t: i32 = 1234;
|
||||
// };
|
||||
// S.t += 1;
|
||||
// expect(S.t == 1235);
|
||||
//}
|
||||
test "thread local variable" {
|
||||
const S = struct {
|
||||
threadlocal var t: i32 = 1234;
|
||||
};
|
||||
S.t += 1;
|
||||
expect(S.t == 1235);
|
||||
}
|
||||
|
||||
test "unicode escape in character literal" {
|
||||
var a: u24 = '\U01f4a9';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user