Skip to content

Commit

Permalink
Fixed branched block when all branches were void or no return
Browse files Browse the repository at this point in the history
  • Loading branch information
Ary Borenszweig committed Sep 18, 2013
1 parent 8cd7423 commit d7765e0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/crystal/codegen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ def match_any_type_id(type, type_id)
end

def new_branched_block(node)
branch = { node: node }
branch = { node: node, count: 0 }
branch[:exit_block] = new_block "exit"
if branch[:is_union] = node.type && node.type.union?
branch[:union_ptr] = alloca llvm_type(node.type)
Expand All @@ -1541,6 +1541,7 @@ def add_branched_block_value(branch, type, value)
@builder.unreachable
elsif type.equal?(@mod.void)
# Nothing to do
branch[:count] += 1
else
if branch[:is_union]
assign_to_union(branch[:union_ptr], branch[:node].type, type, value)
Expand All @@ -1550,6 +1551,7 @@ def add_branched_block_value(branch, type, value)
branch[:phi_table][@builder.insert_block] = value
end

branch[:count] += 1
@builder.br branch[:exit_block]
end
end
Expand All @@ -1561,8 +1563,11 @@ def close_branched_block(branch)
else
if branch[:is_union]
@last = branch[:union_ptr]
elsif branch[:phi_table].empty?
elsif branch[:count] == 0
@builder.unreachable
elsif branch[:phi_table].empty?
# All branches are void or no return
@last = llvm_nil
else
@last = @builder.phi llvm_type(branch[:node].type), branch[:phi_table]
end
Expand Down

0 comments on commit d7765e0

Please sign in to comment.