mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Support distrinct types as the base type of bitstructs. #2218
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
- The form-feed character '\f' is no longer valid white space.
|
||||
- Show code that caused unreachable code #2207
|
||||
- Allow generics over distinct types #2216.
|
||||
- Support distrinct types as the base type of bitstructs. #2218
|
||||
|
||||
### Fixes
|
||||
- `-2147483648`, MIN literals work correctly.
|
||||
|
||||
@@ -1061,8 +1061,8 @@ static bool sema_analyse_bitstruct(SemaContext *context, Decl *decl, bool *erase
|
||||
if (*erase_decl) return true;
|
||||
DEBUG_LOG("Beginning analysis of %s.", decl->name ? decl->name : ".anon");
|
||||
if (!sema_resolve_type_info(context, decl->strukt.container_type, RESOLVE_TYPE_DEFAULT)) return false;
|
||||
Type *type = decl->strukt.container_type->type->canonical;
|
||||
Type *base_type = type->type_kind == TYPE_ARRAY ? type->array.base : type;
|
||||
Type *type = type_flatten(decl->strukt.container_type->type->canonical);
|
||||
Type *base_type = type->type_kind == TYPE_ARRAY ? type_flatten(type->array.base) : type;
|
||||
if (!type_is_integer(base_type))
|
||||
{
|
||||
SEMA_ERROR(decl->strukt.container_type, "The type of the bitstruct cannot be %s but must be an integer or an array of integers.",
|
||||
|
||||
48
test/test_suite/bitstruct/bitstruct_with_distinct.c3t
Normal file
48
test/test_suite/bitstruct/bitstruct_with_distinct.c3t
Normal file
@@ -0,0 +1,48 @@
|
||||
// #target: macos-x64
|
||||
module test;
|
||||
typedef Foo = int;
|
||||
|
||||
bitstruct Bar : Foo
|
||||
{
|
||||
bool a : 0;
|
||||
Foo x : 1..4;
|
||||
}
|
||||
|
||||
typedef Baz = char;
|
||||
|
||||
bitstruct Bar2 : Baz[3]
|
||||
{
|
||||
bool x;
|
||||
}
|
||||
|
||||
fn int main()
|
||||
{
|
||||
Bar x;
|
||||
Bar2 y;
|
||||
x.a = true;
|
||||
x.x = 100;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
define i32 @main() #0 {
|
||||
entry:
|
||||
%x = alloca i32, align 4
|
||||
%y = alloca [3 x i8], align 1
|
||||
store i32 0, ptr %x, align 4
|
||||
store i8 0, ptr %y, align 1
|
||||
%ptradd = getelementptr inbounds i8, ptr %y, i64 1
|
||||
store i8 0, ptr %ptradd, align 1
|
||||
%ptradd1 = getelementptr inbounds i8, ptr %y, i64 2
|
||||
store i8 0, ptr %ptradd1, align 1
|
||||
%0 = load i32, ptr %x, align 4
|
||||
%1 = and i32 %0, -2
|
||||
%2 = or i32 %1, 1
|
||||
store i32 %2, ptr %x, align 4
|
||||
%3 = load i32, ptr %x, align 4
|
||||
%4 = and i32 %3, -31
|
||||
%5 = or i32 %4, 8
|
||||
store i32 %5, ptr %x, align 4
|
||||
ret i32 0
|
||||
}
|
||||
Reference in New Issue
Block a user