diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2024-09-26 16:40:43 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-26 16:40:43 +0100 |
| commit | d3bff23bce94c9601c851c1f39ac3b9857720522 (patch) | |
| tree | 030d875d1125c8d921b5f2a055003af45c696e8b /src/llvm_backend_expr.cpp | |
| parent | 8371ef66816c60e0a69dd52255d36a0718542f3d (diff) | |
| parent | 007730bfbcf7508552d370e8a658e14313a4694c (diff) | |
Merge pull request #4308 from karl-zylinski/fix-constant-array-conversion-crash
Fix for crash when emitting a comparison between a constant array and a non-constant value.
Diffstat (limited to 'src/llvm_backend_expr.cpp')
| -rw-r--r-- | src/llvm_backend_expr.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp index 58467db2e..608be4947 100644 --- a/src/llvm_backend_expr.cpp +++ b/src/llvm_backend_expr.cpp @@ -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; |