mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Flexible array member added, zero sized structs removed.
This commit is contained in:
31
test/test_suite/struct/flex_array_struct_err.c3
Normal file
31
test/test_suite/struct/flex_array_struct_err.c3
Normal file
@@ -0,0 +1,31 @@
|
||||
struct Foo
|
||||
{
|
||||
int x;
|
||||
int[*] y; // #error: flexible array member must be the last element
|
||||
int z;
|
||||
}
|
||||
|
||||
struct Bar
|
||||
{
|
||||
int[*] y; // #error: flexible array member cannot be the only element
|
||||
}
|
||||
|
||||
struct Baz
|
||||
{
|
||||
int y;
|
||||
int[*] z;
|
||||
}
|
||||
|
||||
struct BazContainerOk
|
||||
{
|
||||
int z;
|
||||
Baz c;
|
||||
}
|
||||
|
||||
struct BazContainer
|
||||
{
|
||||
Baz c; // #error: A struct member with a flexible array must be the last element.
|
||||
int y;
|
||||
}
|
||||
|
||||
Baz[5] ab; // #error: Arrays of structs with flexible array members is not allowed.
|
||||
35
test/test_suite/struct/struct_codegen_fam.c3t
Normal file
35
test/test_suite/struct/struct_codegen_fam.c3t
Normal file
@@ -0,0 +1,35 @@
|
||||
// #target: x64-darwin
|
||||
module foo;
|
||||
|
||||
struct Bar
|
||||
{
|
||||
struct
|
||||
{
|
||||
int y;
|
||||
}
|
||||
int ufe;
|
||||
int[*] z;
|
||||
}
|
||||
|
||||
|
||||
fn void test(Bar b)
|
||||
{
|
||||
b.z[1];
|
||||
}
|
||||
|
||||
/* #expect: foo.ll
|
||||
|
||||
%Bar = type { %anon, i32, [0 x i32] }
|
||||
%anon = type { i32 }
|
||||
|
||||
define void @foo.test(%Bar* byval(%Bar) align 8 %0) #0 {
|
||||
entry:
|
||||
%b = alloca %Bar, align 4
|
||||
%1 = bitcast %Bar* %b to i8*
|
||||
%2 = bitcast %Bar* %0 to i8*
|
||||
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %1, i8* align 8 %2, i32 8, i1 false)
|
||||
%3 = getelementptr inbounds %Bar, %Bar* %b, i32 0, i32 2
|
||||
%4 = getelementptr inbounds [0 x i32], [0 x i32]* %3, i64 0, i64 1
|
||||
%5 = load i32, i32* %4, align 4
|
||||
ret void
|
||||
}
|
||||
7
test/test_suite/struct/zero_member.c3
Normal file
7
test/test_suite/struct/zero_member.c3
Normal file
@@ -0,0 +1,7 @@
|
||||
define Foo = int[0];
|
||||
|
||||
struct Bar
|
||||
{
|
||||
Foo x; // #error: Zero length arrays are not valid members.
|
||||
int b;
|
||||
}
|
||||
Reference in New Issue
Block a user