Flexible array member added, zero sized structs removed.

This commit is contained in:
Christoffer Lerno
2021-12-14 18:53:23 +01:00
parent 5ddbf50e83
commit 680b077eb1
30 changed files with 252 additions and 35 deletions

View File

@@ -11,12 +11,6 @@ struct Bar
{
int y;
}
struct
{}
union
{
struct { }
}
}
bitstruct : uint
{
@@ -68,20 +62,20 @@ entry:
%8 = ashr i32 %7, 23
call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i32 %4, i32 %8)
%9 = bitcast %Foo* %f to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %9, i8* align 4 bitcast (%Foo* @.__const.8 to i8*), i32 16, i1 false)
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %9, i8* align 4 bitcast (%Foo* @.__const.5 to i8*), i32 16, i1 false)
%10 = getelementptr inbounds %Foo, %Foo* %f, i32 0, i32 0
%11 = getelementptr inbounds %anon.4, %anon.4* %10, i32 0, i32 0
%12 = getelementptr inbounds %anon.5, %anon.5* %11, i32 0, i32 0
%11 = getelementptr inbounds %anon.1, %anon.1* %10, i32 0, i32 0
%12 = getelementptr inbounds %anon.2, %anon.2* %11, i32 0, i32 0
%13 = load i32, i32* %12, align 4
%14 = getelementptr inbounds %Foo, %Foo* %f, i32 0, i32 0
%15 = getelementptr inbounds %anon.4, %anon.4* %14, i32 0, i32 1
%16 = getelementptr inbounds %anon.6, %anon.6* %15, i32 0, i32 0
%15 = getelementptr inbounds %anon.1, %anon.1* %14, i32 0, i32 1
%16 = getelementptr inbounds %anon.3, %anon.3* %15, i32 0, i32 0
%17 = load i32, i32* %16, align 4
%18 = getelementptr inbounds %Foo, %Foo* %f, i32 0, i32 0
%19 = getelementptr inbounds %anon.4, %anon.4* %18, i32 0, i32 2
%19 = getelementptr inbounds %anon.1, %anon.1* %18, i32 0, i32 2
%20 = load i32, i32* %19, align 4
%21 = getelementptr inbounds %Foo, %Foo* %f, i32 0, i32 1
%22 = load i32, i32* %21, align 4
call void (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i32 0, i32 0), i32 %13, i32 %17, i32 %20, i32 %22)
call void (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i32 0, i32 0), i32 %13, i32 %17, i32 %20, i32 %22)
ret void
}

View File

@@ -0,0 +1,7 @@
struct Foo // #error: Zero sized structs are not permitted.
{
}
union Bar // #error: Zero sized unions are not permitted.
{
}

View File

@@ -4,7 +4,9 @@ fn void test1()
}
struct Foo
{}
{
int x;
}
fn void test2()
{

View File

@@ -3,7 +3,7 @@ module mymodule;
extern fn void printf(char *, ...);
struct Foo { }
struct Foo { int y; }
int b;

View File

@@ -0,0 +1,3 @@
define Abc = int[*]; // #error: Inferred array types can only be used in declarations with initializers.
define Bcd = anyerr; // #error: 'anyerr' may not be aliased.
define Efd = variant; // #error: 'variant' may not be aliased.

View File

@@ -1,5 +1,5 @@
struct Foo
{}
{ int j; }
fn int main()
{

View File

@@ -1,6 +1,6 @@
define Callback = fn int(char c);
struct Person {}
struct Company {}
struct Person { int i; }
struct Company { int j; }
enum Status : int
{
IDLE,

View File

@@ -10,6 +10,7 @@ struct An3
struct An2
{
int z;
}
extern fn void printf(char *string);

View File

@@ -10,6 +10,7 @@ struct An3
struct An2
{
int y;
}
extern fn void printf(char* string);

View 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.

View 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
}

View File

@@ -0,0 +1,7 @@
define Foo = int[0];
struct Bar
{
Foo x; // #error: Zero length arrays are not valid members.
int b;
}

View File

@@ -0,0 +1,5 @@
union Zee
{
int z;
int[*] y; // #error: Flexible array members not allowed in unions.
}

View File

@@ -1,7 +1,5 @@
module test;
struct Empty {}
union Foo {}
union Qu
{
Qu *x;