Commit a76b048354

Andrew Kelley <superjoe30@gmail.com>
2016-12-18 19:37:50
IR: phi instruction handles unreachable values correctly
1 parent b59841a
Changed files (2)
src/codegen.cpp
@@ -401,10 +401,14 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,
 }
 
 static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *type) {
-    if (handle_is_ptr(type)) {
-        return ptr;
+    if (type_has_bits(type)) {
+        if (handle_is_ptr(type)) {
+            return ptr;
+        } else {
+            return LLVMBuildLoad(g->builder, ptr, "");
+        }
     } else {
-        return LLVMBuildLoad(g->builder, ptr, "");
+        return nullptr;
     }
 }
 
src/ir.cpp
@@ -6493,14 +6493,18 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
         if (predecessor->ref_count == 0)
             continue;
 
-        assert(predecessor->other);
-        new_incoming_blocks.append(predecessor->other);
 
         IrInstruction *old_value = phi_instruction->incoming_values[i];
         assert(old_value);
         IrInstruction *new_value = old_value->other;
         if (!new_value || new_value->type_entry->id == TypeTableEntryIdInvalid)
             return ira->codegen->builtin_types.entry_invalid;
+
+        if (new_value->type_entry->id == TypeTableEntryIdUnreachable)
+            continue;
+
+        assert(predecessor->other);
+        new_incoming_blocks.append(predecessor->other);
         new_incoming_values.append(new_value);
     }
     assert(new_incoming_blocks.length != 0);