Updates to bitstruct

This commit is contained in:
Christoffer Lerno
2021-11-08 22:01:21 +01:00
committed by Christoffer Lerno
parent 15f902579b
commit 4662133893
12 changed files with 301 additions and 34 deletions

View File

@@ -0,0 +1,87 @@
// #target: x64-darwin
module foo;
struct Bar
{
int x;
struct
{
struct
{
int y;
}
struct
{}
union
{
struct { }
}
}
bitstruct : uint
{
int ww : 2..10;
}
}
struct Foo
{
struct
{
struct
{
int x;
}
struct
{
int y;
}
int z;
}
int w;
}
extern fn void printf(char*, ...);
fn void main()
{
Bar b = { 1, 2, -5 };
printf("%d %d\n", b.y, b.ww);
Foo f = { 5, 6, 7, 8 };
printf("%d %d %d %d\n", f.x, f.y, f.z, f.w);
}
/* #expect: foo.ll
define void @main() #0 {
entry:
%b = alloca %Bar, align 4
%f = alloca %Foo, align 4
%0 = bitcast %Bar* %b to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %0, i8* align 4 bitcast (%Bar* @.__const to i8*), i32 12, i1 false)
%1 = getelementptr inbounds %Bar, %Bar* %b, i32 0, i32 1
%2 = getelementptr inbounds %anon, %anon* %1, i32 0, i32 0
%3 = getelementptr inbounds %anon.0, %anon.0* %2, i32 0, i32 0
%4 = load i32, i32* %3, align 4
%5 = getelementptr inbounds %Bar, %Bar* %b, i32 0, i32 2
%6 = load i32, i32* %5, align 4
%7 = shl i32 %6, 21
%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)
%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
%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
%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
%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)
ret void
}