aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-12-18 13:37:50 -0500
committerAndrew Kelley <superjoe30@gmail.com>2016-12-18 13:37:50 -0500
commita76b048354e5754b18ecd83ad21cf45c5a34e276 (patch)
treee00401d93ff2a1d2e189577d6573d6e5d6f22d19 /src
parentb59841a80f564c63c667f6142832407086b67b56 (diff)
downloadzig-a76b048354e5754b18ecd83ad21cf45c5a34e276.tar.gz
zig-a76b048354e5754b18ecd83ad21cf45c5a34e276.zip
IR: phi instruction handles unreachable values correctly
Diffstat (limited to 'src')
-rw-r--r--src/codegen.cpp10
-rw-r--r--src/ir.cpp8
2 files changed, 13 insertions, 5 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 6dfa2520bc..dd734cbf63 100644
--- a/src/codegen.cpp
+++ b/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;
}
}
diff --git a/src/ir.cpp b/src/ir.cpp
index c58b91f604..b215721acb 100644
--- a/src/ir.cpp
+++ b/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);