authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-11-21 13:53:08-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-11-21 13:53:08-05:00
loge80e8a80993734f22e9e9c1b8ba078b0b9b946c3
treee9478d4436b275a7eeed841467a50b9054ab8340
parent67d565136abd904b67792ae61f195a4054463b00

IR: fix detection of invalid codegen


3 files changed, 16 insertions(+), 5 deletions(-)

src/all_types.hpp+1
......@@ -36,6 +36,7 @@ struct IrExecutable {
3636 ZigList<IrBasicBlock *> basic_block_list;
3737 size_t mem_slot_count;
3838 size_t next_debug_id;
39 bool invalid;
3940};
4041
4142enum OutType {
src/analyze.cpp+4-4
......@@ -838,9 +838,9 @@ static IrInstruction *analyze_const_value(CodeGen *g, BlockContext *scope, AstNo
838838{
839839 IrExecutable ir_executable = {0};
840840 IrExecutable analyzed_executable = {0};
841 IrInstruction *pass1 = ir_gen(g, node, scope, &ir_executable);
841 ir_gen(g, node, scope, &ir_executable);
842842
843 if (pass1->type_entry->id == TypeTableEntryIdInvalid)
843 if (ir_executable.invalid)
844844 return g->invalid_instruction;
845845
846846 if (g->verbose) {
......@@ -2552,8 +2552,8 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
25522552 buf_sprintf("byvalue types not yet supported on extern function return values"));
25532553 }
25542554
2555 IrInstruction *result = ir_gen_fn(g, fn_table_entry);
2556 if (result == g->invalid_instruction) {
2555 ir_gen_fn(g, fn_table_entry);
2556 if (fn_table_entry->ir_executable.invalid) {
25572557 fn_proto_node->data.fn_proto.skip = true;
25582558 fn_table_entry->anal_state = FnAnalStateSkipped;
25592559 return;
src/ir.cpp+11-1
......@@ -2058,7 +2058,7 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) {
20582058 return ir_build_phi(irb, node, 2, incoming_blocks, incoming_values);
20592059}
20602060
2061static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockContext *block_context,
2061static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, BlockContext *block_context,
20622062 LValPurpose lval)
20632063{
20642064 assert(block_context);
......@@ -2140,6 +2140,14 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockCont
21402140 zig_unreachable();
21412141}
21422142
2143static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockContext *block_context,
2144 LValPurpose lval)
2145{
2146 IrInstruction *result = ir_gen_node_raw(irb, node, block_context, lval);
2147 irb->exec->invalid = irb->exec->invalid || (result == irb->codegen->invalid_instruction);
2148 return result;
2149}
2150
21432151static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, BlockContext *scope) {
21442152 return ir_gen_node_extra(irb, node, scope, LValPurposeNone);
21452153}
......@@ -4881,6 +4889,8 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins
48814889TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec,
48824890 TypeTableEntry *expected_type, AstNode *expected_type_source_node)
48834891{
4892 assert(!old_exec->invalid);
4893
48844894 IrAnalyze ir_analyze_data = {};
48854895 IrAnalyze *ira = &ir_analyze_data;
48864896 ira->codegen = codegen;