aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend_expr.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-09-05 16:35:56 +0100
committergingerBill <bill@gingerbill.org>2022-09-05 16:35:56 +0100
commit4998cf80c15555849d1ad119be3b2d4ff5cd6e1f (patch)
treec1af60886348b52e7742504dcf0cc4e06c1db3f8 /src/llvm_backend_expr.cpp
parent37e23133e9877c6d30604be8d586363b3cf412ed (diff)
Fix #2017 mismatched types in binary matrix expression for `flt * (mat * vec)`
Diffstat (limited to 'src/llvm_backend_expr.cpp')
-rw-r--r--src/llvm_backend_expr.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp
index 023e7b363..7c92c517c 100644
--- a/src/llvm_backend_expr.cpp
+++ b/src/llvm_backend_expr.cpp
@@ -1,4 +1,4 @@
-lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, bool component_wise=false);
+lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, bool component_wise);
lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, Ast *left, Ast *right, Type *type) {
lbModule *m = p->module;
@@ -987,7 +987,6 @@ lbValue lb_emit_vector_mul_matrix(lbProcedure *p, lbValue lhs, lbValue rhs, Type
lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, bool component_wise) {
GB_ASSERT(is_type_matrix(lhs.type) || is_type_matrix(rhs.type));
-
if (op == Token_Mul && !component_wise) {
Type *xt = base_type(lhs.type);
Type *yt = base_type(rhs.type);
@@ -1001,8 +1000,22 @@ lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue
} else if (is_type_array_like(xt)) {
GB_ASSERT(yt->kind == Type_Matrix);
return lb_emit_vector_mul_matrix(p, lhs, rhs, type);
- }
+ } else {
+ GB_ASSERT(xt->kind == Type_Basic);
+ GB_ASSERT(yt->kind == Type_Matrix);
+ GB_ASSERT(is_type_matrix(type));
+
+ Type *array_type = alloc_type_array(yt->Matrix.elem, matrix_type_total_internal_elems(yt));
+ GB_ASSERT(type_size_of(array_type) == type_size_of(yt));
+ lbValue array_lhs = lb_emit_conv(p, lhs, array_type);
+ lbValue array_rhs = rhs;
+ array_rhs.type = array_type;
+
+ lbValue array = lb_emit_arith(p, op, array_lhs, array_rhs, array_type);
+ array.type = type;
+ return array;
+ }
} else {
if (is_type_matrix(lhs.type)) {
rhs = lb_emit_conv(p, rhs, lhs.type);
@@ -1047,7 +1060,7 @@ lbValue lb_emit_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Ty
if (is_type_array_like(lhs.type) || is_type_array_like(rhs.type)) {
return lb_emit_arith_array(p, op, lhs, rhs, type);
} else if (is_type_matrix(lhs.type) || is_type_matrix(rhs.type)) {
- return lb_emit_arith_matrix(p, op, lhs, rhs, type);
+ return lb_emit_arith_matrix(p, op, lhs, rhs, type, false);
} else if (is_type_complex(type)) {
lhs = lb_emit_conv(p, lhs, type);
rhs = lb_emit_conv(p, rhs, type);
@@ -1320,7 +1333,7 @@ lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) {
if (is_type_matrix(be->left->tav.type) || is_type_matrix(be->right->tav.type)) {
lbValue left = lb_build_expr(p, be->left);
lbValue right = lb_build_expr(p, be->right);
- return lb_emit_arith_matrix(p, be->op.kind, left, right, default_type(tv.type));
+ return lb_emit_arith_matrix(p, be->op.kind, left, right, default_type(tv.type), false);
}