Bitstruct cast to other bitstruct by way of underlying type would fail #1159.

This commit is contained in:
Christoffer Lerno
2024-02-26 23:51:14 +01:00
parent bae5d9c7f8
commit 75e7176675
3 changed files with 23 additions and 2 deletions

View File

@@ -13,6 +13,7 @@
- $$memcpy_inline and $$memset_inline fixed.
- `.$Type = ...` and `.$foo = ...` now works #1156.
- `int.min` incorrect behaviour #1154.
- Bitstruct cast to other bitstruct by way of underlying type would fail #1159.
### Stdlib changes
- Added `new_aligned` and `alloc_aligned` functions to prevent accidental under-alignment when allocating simd.

View File

@@ -1528,8 +1528,13 @@ static void cast_int_arr_to_bitstruct(SemaContext *context, Expr *expr, Type *ty
{
if (expr->expr_kind == EXPR_CAST && expr->cast_expr.kind == CAST_BSINTARR)
{
expr_replace(expr, exprptr(expr->cast_expr.expr));
return;
Expr *inner = exprptr(expr->cast_expr.expr);
if (type_flatten(inner->type) == type_flatten(type))
{
expr_replace(expr, inner);
expr->type = type;
return;
}
}
insert_runtime_cast(expr, CAST_INTARRBS, type);
}

View File

@@ -0,0 +1,15 @@
// See issue #1159
bitstruct Foo : int {
bool a;
}
bitstruct Bar : int {
bool a;
bool b;
}
fn void bitstruct_cast() {
Bar bar;
Foo foo = (Foo)(int)bar;
}