authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-18 13:37:50-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-18 13:37:50-05:00
loga76b048354e5754b18ecd83ad21cf45c5a34e276
treee00401d93ff2a1d2e189577d6573d6e5d6f22d19
parentb59841a80f564c63c667f6142832407086b67b56

IR: phi instruction handles unreachable values correctly


2 files changed, 13 insertions(+), 5 deletions(-)

src/codegen.cpp+7-3
...@@ -401,10 +401,14 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,...@@ -401,10 +401,14 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,
401}401}
402402
403static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *type) {403static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *type) {
404 if (handle_is_ptr(type)) {404 if (type_has_bits(type)) {
405 return ptr;405 if (handle_is_ptr(type)) {
406 return ptr;
407 } else {
408 return LLVMBuildLoad(g->builder, ptr, "");
409 }
406 } else {410 } else {
407 return LLVMBuildLoad(g->builder, ptr, "");411 return nullptr;
408 }412 }
409}413}
410414
src/ir.cpp+6-2
...@@ -6493,14 +6493,18 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP...@@ -6493,14 +6493,18 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
6493 if (predecessor->ref_count == 0)6493 if (predecessor->ref_count == 0)
6494 continue;6494 continue;
64956495
6496 assert(predecessor->other);
6497 new_incoming_blocks.append(predecessor->other);
64986496
6499 IrInstruction *old_value = phi_instruction->incoming_values[i];6497 IrInstruction *old_value = phi_instruction->incoming_values[i];
6500 assert(old_value);6498 assert(old_value);
6501 IrInstruction *new_value = old_value->other;6499 IrInstruction *new_value = old_value->other;
6502 if (!new_value || new_value->type_entry->id == TypeTableEntryIdInvalid)6500 if (!new_value || new_value->type_entry->id == TypeTableEntryIdInvalid)
6503 return ira->codegen->builtin_types.entry_invalid;6501 return ira->codegen->builtin_types.entry_invalid;
6502
6503 if (new_value->type_entry->id == TypeTableEntryIdUnreachable)
6504 continue;
6505
6506 assert(predecessor->other);
6507 new_incoming_blocks.append(predecessor->other);
6504 new_incoming_values.append(new_value);6508 new_incoming_values.append(new_value);
6505 }6509 }
6506 assert(new_incoming_blocks.length != 0);6510 assert(new_incoming_blocks.length != 0);