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 {...@@ -36,6 +36,7 @@ struct IrExecutable {
36 ZigList<IrBasicBlock *> basic_block_list;36 ZigList<IrBasicBlock *> basic_block_list;
37 size_t mem_slot_count;37 size_t mem_slot_count;
38 size_t next_debug_id;38 size_t next_debug_id;
39 bool invalid;
39};40};
4041
41enum OutType {42enum OutType {
src/analyze.cpp+4-4
...@@ -838,9 +838,9 @@ static IrInstruction *analyze_const_value(CodeGen *g, BlockContext *scope, AstNo...@@ -838,9 +838,9 @@ static IrInstruction *analyze_const_value(CodeGen *g, BlockContext *scope, AstNo
838{838{
839 IrExecutable ir_executable = {0};839 IrExecutable ir_executable = {0};
840 IrExecutable analyzed_executable = {0};840 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)
844 return g->invalid_instruction;844 return g->invalid_instruction;
845845
846 if (g->verbose) {846 if (g->verbose) {
...@@ -2552,8 +2552,8 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {...@@ -2552,8 +2552,8 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
2552 buf_sprintf("byvalue types not yet supported on extern function return values"));2552 buf_sprintf("byvalue types not yet supported on extern function return values"));
2553 }2553 }
25542554
2555 IrInstruction *result = ir_gen_fn(g, fn_table_entry);2555 ir_gen_fn(g, fn_table_entry);
2556 if (result == g->invalid_instruction) {2556 if (fn_table_entry->ir_executable.invalid) {
2557 fn_proto_node->data.fn_proto.skip = true;2557 fn_proto_node->data.fn_proto.skip = true;
2558 fn_table_entry->anal_state = FnAnalStateSkipped;2558 fn_table_entry->anal_state = FnAnalStateSkipped;
2559 return;2559 return;
src/ir.cpp+11-1
...@@ -2058,7 +2058,7 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) {...@@ -2058,7 +2058,7 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) {
2058 return ir_build_phi(irb, node, 2, incoming_blocks, incoming_values);2058 return ir_build_phi(irb, node, 2, incoming_blocks, incoming_values);
2059}2059}
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,
2062 LValPurpose lval)2062 LValPurpose lval)
2063{2063{
2064 assert(block_context);2064 assert(block_context);
...@@ -2140,6 +2140,14 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockCont...@@ -2140,6 +2140,14 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockCont
2140 zig_unreachable();2140 zig_unreachable();
2141}2141}
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
2143static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, BlockContext *scope) {2151static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, BlockContext *scope) {
2144 return ir_gen_node_extra(irb, node, scope, LValPurposeNone);2152 return ir_gen_node_extra(irb, node, scope, LValPurposeNone);
2145}2153}
...@@ -4881,6 +4889,8 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins...@@ -4881,6 +4889,8 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins
4881TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec,4889TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec,
4882 TypeTableEntry *expected_type, AstNode *expected_type_source_node)4890 TypeTableEntry *expected_type, AstNode *expected_type_source_node)
4883{4891{
4892 assert(!old_exec->invalid);
4893
4884 IrAnalyze ir_analyze_data = {};4894 IrAnalyze ir_analyze_data = {};
4885 IrAnalyze *ira = &ir_analyze_data;4895 IrAnalyze *ira = &ir_analyze_data;
4886 ira->codegen = codegen;4896 ira->codegen = codegen;