mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Bitstruct cast to other bitstruct by way of underlying type would fail #1159.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -1528,9 +1528,14 @@ 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));
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
15
test/test_suite/bitstruct/bitstruct_cast_and_back.c3
Normal file
15
test/test_suite/bitstruct/bitstruct_cast_and_back.c3
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user