diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-06-23 18:19:17 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-07-02 13:26:50 -0700 |
| commit | 125b85d7375b96b4847f6ead51c853cdc0567506 (patch) | |
| tree | 34a947e48f84ce6455d3ff133828a8e0e5614ce8 /src/stage1/ir.cpp | |
| parent | d84b386f6034278c8a9e8c3d2b0975ac541584aa (diff) | |
| download | zig-125b85d7375b96b4847f6ead51c853cdc0567506.tar.gz zig-125b85d7375b96b4847f6ead51c853cdc0567506.zip | |
move "unreachable code" error from stage1 to stage2
* AstGen: implement "unreachable code" error for blocks. This works at
the statement level.
* stage1: remove the "unreachable code" error implementation, which
means removing the `is_gen` field from IrInstSrc. This is one small
step towards a smaller memory footprint for stage1. The benefits
won't be realized until a future commit because this flag took
advantage of padding.
There may be a regression here with "union has no associated enum"
error, and there is a regression with the following code:
```zig
const a = noreturn;
```
A future commit will address these regressions.
Diffstat (limited to 'src/stage1/ir.cpp')
| -rw-r--r-- | src/stage1/ir.cpp | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp index 2200e8380d..0c915f5c35 100644 --- a/src/stage1/ir.cpp +++ b/src/stage1/ir.cpp @@ -5407,16 +5407,6 @@ static void ir_finish_bb(IrAnalyze *ira) { ira->new_irb.current_basic_block->debug_id); } } - ira->instruction_index += 1; - while (ira->instruction_index < ira->zir_current_basic_block->instruction_list.length) { - IrInstSrc *next_instruction = ira->zir_current_basic_block->instruction_list.at(ira->instruction_index); - if (!next_instruction->is_gen) { - ir_add_error(ira, &next_instruction->base, buf_sprintf("unreachable code")); - break; - } - ira->instruction_index += 1; - } - ir_start_next_bb(ira); } @@ -15934,7 +15924,7 @@ static IrInstGen *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstSrcPopC return ir_build_pop_count_gen(ira, &instruction->base.base, return_type, op); } -static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, bool is_gen) { +static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value) { if (type_is_invalid(value->value->type)) return ira->codegen->invalid_inst_gen; @@ -15943,7 +15933,7 @@ static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, IrInst* source_instr, IrI buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name))); return ira->codegen->invalid_inst_gen; } - if (!value->value->type->data.unionation.have_explicit_tag_type && !is_gen) { + if (!value->value->type->data.unionation.have_explicit_tag_type) { ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum")); if (value->value->type->data.unionation.decl_node != nullptr) { add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node, @@ -16906,7 +16896,7 @@ static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrc } if (target_type->id == ZigTypeIdUnion) { - target = ir_analyze_union_tag(ira, &instruction->base.base, target, instruction->base.is_gen); + target = ir_analyze_union_tag(ira, &instruction->base.base, target); if (type_is_invalid(target->value->type)) return ira->codegen->invalid_inst_gen; target_type = target->value->type; |
