Commit e80e8a8099

Andrew Kelley <superjoe30@gmail.com>
2016-11-21 19:53:08
IR: fix detection of invalid codegen
1 parent 67d5651
Changed files (3)
src/all_types.hpp
@@ -36,6 +36,7 @@ struct IrExecutable {
     ZigList<IrBasicBlock *> basic_block_list;
     size_t mem_slot_count;
     size_t next_debug_id;
+    bool invalid;
 };
 
 enum OutType {
src/analyze.cpp
@@ -838,9 +838,9 @@ static IrInstruction *analyze_const_value(CodeGen *g, BlockContext *scope, AstNo
 {
     IrExecutable ir_executable = {0};
     IrExecutable analyzed_executable = {0};
-    IrInstruction *pass1 = ir_gen(g, node, scope, &ir_executable);
+    ir_gen(g, node, scope, &ir_executable);
 
-    if (pass1->type_entry->id == TypeTableEntryIdInvalid)
+    if (ir_executable.invalid)
         return g->invalid_instruction;
 
     if (g->verbose) {
@@ -2552,8 +2552,8 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) {
             buf_sprintf("byvalue types not yet supported on extern function return values"));
     }
 
-    IrInstruction *result = ir_gen_fn(g, fn_table_entry);
-    if (result == g->invalid_instruction) {
+    ir_gen_fn(g, fn_table_entry);
+    if (fn_table_entry->ir_executable.invalid) {
         fn_proto_node->data.fn_proto.skip = true;
         fn_table_entry->anal_state = FnAnalStateSkipped;
         return;
src/ir.cpp
@@ -2058,7 +2058,7 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, AstNode *node) {
     return ir_build_phi(irb, node, 2, incoming_blocks, incoming_values);
 }
 
-static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockContext *block_context,
+static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, BlockContext *block_context,
         LValPurpose lval)
 {
     assert(block_context);
@@ -2140,6 +2140,14 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockCont
     zig_unreachable();
 }
 
+static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, BlockContext *block_context,
+        LValPurpose lval)
+{
+    IrInstruction *result = ir_gen_node_raw(irb, node, block_context, lval);
+    irb->exec->invalid = irb->exec->invalid || (result == irb->codegen->invalid_instruction);
+    return result;
+}
+
 static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, BlockContext *scope) {
     return ir_gen_node_extra(irb, node, scope, LValPurposeNone);
 }
@@ -4881,6 +4889,8 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins
 TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec,
         TypeTableEntry *expected_type, AstNode *expected_type_source_node)
 {
+    assert(!old_exec->invalid);
+
     IrAnalyze ir_analyze_data = {};
     IrAnalyze *ira = &ir_analyze_data;
     ira->codegen = codegen;