Skip to content

Commit

Permalink
Merge pull request #4308 from karl-zylinski/fix-constant-array-conver…
Browse files Browse the repository at this point in the history
…sion-crash

Fix for crash when emitting a comparison between a constant array and a non-constant value.
  • Loading branch information
gingerBill committed Sep 26, 2024
2 parents 8371ef6 + 007730b commit d3bff23
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/llvm_backend_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2555,17 +2555,21 @@ gb_internal lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left

if (are_types_identical(a, b)) {
// NOTE(bill): No need for a conversion
} else if (lb_is_const(left) || lb_is_const_nil(left)) {
} else if ((lb_is_const(left) && !is_type_array(left.type)) || lb_is_const_nil(left)) {
// NOTE(karl): !is_type_array(left.type) is there to avoid lb_emit_conv
// trying to convert a constant array into a non-array. In that case we
// want the `else` branch to happen, so it can try to convert the
// non-array into an array instead.

if (lb_is_const_nil(left)) {
return lb_emit_comp_against_nil(p, op_kind, right);
}
left = lb_emit_conv(p, left, right.type);
} else if (lb_is_const(right) || lb_is_const_nil(right)) {
} else if ((lb_is_const(right) && !is_type_array(right.type)) || lb_is_const_nil(right)) {
if (lb_is_const_nil(right)) {
return lb_emit_comp_against_nil(p, op_kind, left);
}
right = lb_emit_conv(p, right, left.type);

} else {
Type *lt = left.type;
Type *rt = right.type;
Expand Down

0 comments on commit d3bff23

Please sign in to comment.