diff --git a/resources/examples/contextfree/boolerr.c3 b/resources/examples/contextfree/boolerr.c3 index 93adb794e..81fb8a594 100644 --- a/resources/examples/contextfree/boolerr.c3 +++ b/resources/examples/contextfree/boolerr.c3 @@ -137,5 +137,5 @@ fn void main() }; dynamic_arena.reset(); } - dynamic_arena.destroy(); + dynamic_arena.free(); } diff --git a/src/compiler/enums.h b/src/compiler/enums.h index 0b385247d..8ce09ac97 100644 --- a/src/compiler/enums.h +++ b/src/compiler/enums.h @@ -83,6 +83,7 @@ typedef enum CAST_ANYPTR, CAST_APTSA, CAST_ARRVEC, + CAST_ARRBS, CAST_BOOLBOOL, CAST_BOOLFP, CAST_BOOLINT, @@ -103,6 +104,7 @@ typedef enum CAST_INTBOOL, CAST_INTENUM, CAST_INTFP, + CAST_INTBS, CAST_NUMVEC, CAST_PTRANY, CAST_PTRBOOL, diff --git a/src/compiler/expr.c b/src/compiler/expr.c index 334e06384..d7146f3eb 100644 --- a/src/compiler/expr.c +++ b/src/compiler/expr.c @@ -342,6 +342,8 @@ static inline bool expr_cast_is_constant_eval(Expr *expr, ConstantEvalKind eval_ return false; case CAST_BSINT: case CAST_BSARRY: + case CAST_INTBS: + case CAST_ARRBS: return true; case CAST_INTENUM: case CAST_ANYPTR: diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index 79a029c5d..d8fa3696b 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -1347,12 +1347,14 @@ void llvm_emit_cast(GenContext *c, CastKind cast_kind, Expr *expr, BEValue *valu llvm_value_aggregate_two(c, value, to_type, value->value, typeid.value); return; } + case CAST_ARRBS: case CAST_BSARRY: llvm_value_addr(c, value); llvm_value_bitcast(c, value, to_type); llvm_value_rvalue(c, value); return; case CAST_BSINT: + case CAST_INTBS: llvm_value_addr(c, value); llvm_value_bitcast(c, value, to_type); llvm_value_rvalue(c, value); diff --git a/src/compiler/sema_casts.c b/src/compiler/sema_casts.c index 6fd4adb48..a9b407ef1 100644 --- a/src/compiler/sema_casts.c +++ b/src/compiler/sema_casts.c @@ -1337,6 +1337,10 @@ RETRY: case TYPE_ENUM: if (is_explicit) goto CAST; goto REQUIRE_CAST; + case TYPE_BITSTRUCT: + if (type_flatten(to->decl->bitstruct.base_type->type) != type_flatten(from)) break; + if (is_explicit) goto CAST; + goto REQUIRE_CAST; case ALL_INTS: { // All explicit casts work. @@ -1850,6 +1854,7 @@ static bool cast_inner(Expr *expr, Type *from_type, Type *to, Type *to_type) if (to == type_bool) return integer_to_bool(expr, to_type); if (to->type_kind == TYPE_POINTER) return integer_to_pointer(expr, to_type); if (to->type_kind == TYPE_ENUM) return integer_to_enum(expr, to, to_type); + if (to->type_kind == TYPE_BITSTRUCT) return insert_cast(expr, CAST_INTBS, to_type); if (type_kind_is_any_vector(to->type_kind)) return integer_expand_to_vector_conversion(expr, to, to_type); break; case ALL_UNSIGNED_INTS: @@ -1859,6 +1864,7 @@ static bool cast_inner(Expr *expr, Type *from_type, Type *to, Type *to_type) if (to->type_kind == TYPE_POINTER) return integer_to_pointer(expr, to_type); if (to->type_kind == TYPE_ENUM) return integer_to_enum(expr, to, to_type); if (type_kind_is_any_vector(to->type_kind)) return integer_expand_to_vector_conversion(expr, to, to_type); + if (to->type_kind == TYPE_BITSTRUCT) return insert_cast(expr, CAST_INTBS, to_type); break; case ALL_FLOATS: if (type_is_integer(to)) return float_to_integer(expr, to, to_type); @@ -1894,11 +1900,7 @@ static bool cast_inner(Expr *expr, Type *from_type, Type *to, Type *to_type) return false; case TYPE_ARRAY: if (to->type_kind == TYPE_VECTOR) return array_to_vector(expr, to_type); - if (to->type_kind == TYPE_BITSTRUCT) - { - expr->type = to_type; - return true; - } + if (to->type_kind == TYPE_BITSTRUCT) return insert_cast(expr, CAST_ARRBS, to_type); FALLTHROUGH; case TYPE_STRUCT: case TYPE_UNION: