From e8a8ac8bc129394e5754287c7280566fd7da359a Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 20 Dec 2022 03:24:24 +0100 Subject: [PATCH] Fix bit or / xor / and on bool vectors. --- src/compiler/llvm_codegen_expr.c | 5 +++++ src/compiler/sema_expr.c | 13 ++++++++++++- src/compiler/sema_initializers.c | 3 +-- src/version.h | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index 43765cee9..a51bf0b53 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -3708,6 +3708,11 @@ void llvm_emit_binary(GenContext *c, BEValue *be_value, Expr *expr, BEValue *lhs llvm_value_set_bool(be_value, val); return; } + if (lhs.kind == BE_BOOLVECTOR) + { + llvm_value_set_bool_vector(be_value, val, expr->type); + return; + } llvm_value_set(be_value, val, expr->type); } diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index df5a5a536..e4d07b298 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -179,6 +179,7 @@ void expr_insert_widening_type(Expr *expr, Type *infer_type); static Expr *expr_access_inline_member(Expr *parent, Decl *parent_decl); static inline int64_t expr_get_index_max(Expr *expr); static inline bool expr_both_any_integer_or_integer_vector(Expr *left, Expr *right); +static inline bool expr_both_any_integer_or_integer_bool_vector(Expr *left, Expr *right); static inline bool expr_both_const(Expr *left, Expr *right); static inline bool sema_identifier_find_possible_inferred(Type *to, Expr *expr); static inline bool sema_expr_analyse_enum_constant(Expr *expr, const char *name, Decl *decl); @@ -313,6 +314,16 @@ static inline bool expr_both_any_integer_or_integer_vector(Expr *left, Expr *rig return type_is_integer(flatten_left->array.base) && type_is_integer(flatten_right->array.base); } +static inline bool expr_both_any_integer_or_integer_bool_vector(Expr *left, Expr *right) +{ + Type *flatten_left = type_flatten(left->type); + Type *flatten_right = type_flatten(right->type); + if (type_is_integer(flatten_left) && type_is_integer(flatten_right)) return true; + + if (flatten_left->type_kind != TYPE_VECTOR || flatten_right->type_kind != TYPE_VECTOR) return false; + + return type_is_integer_or_bool_kind(flatten_left->array.base) && type_is_integer_or_bool_kind(flatten_right->array.base); +} static void expr_binary_unify_failability(Expr *expr, Expr *left, Expr *right) { @@ -4680,7 +4691,7 @@ static bool sema_expr_analyse_bit(SemaContext *context, Expr *expr, Expr *left, // 2. Check that both are integers or bools. bool is_bool = left->type->canonical == type_bool; - if (!is_bool && !expr_both_any_integer_or_integer_vector(left, right)) + if (!is_bool && !expr_both_any_integer_or_integer_bool_vector(left, right)) { return sema_type_error_on_binop(expr); } diff --git a/src/compiler/sema_initializers.c b/src/compiler/sema_initializers.c index 750032fc6..fd11f354e 100644 --- a/src/compiler/sema_initializers.c +++ b/src/compiler/sema_initializers.c @@ -758,10 +758,9 @@ static inline void sema_update_const_initializer_with_designator( sema_update_const_initializer_with_designator_union(const_init, curr, end, value); return; case TYPE_ARRAY: + case TYPE_VECTOR: sema_update_const_initializer_with_designator_array(const_init, curr, end, value); return; - case TYPE_VECTOR: - TODO default: UNREACHABLE } diff --git a/src/version.h b/src/version.h index 1ed2a0f87..7a3f4f553 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.3.122" \ No newline at end of file +#define COMPILER_VERSION "0.3.123" \ No newline at end of file