Files
c3c/test/test_suite/struct/struct_pack_and_align.c3t

103 lines
2.2 KiB
Plaintext

module struct2;
// <{ i64, i8, [3 x i8] }>
struct Foo1 @packed @align(4)
{
long bar;
char foo;
}
$assert($sizeof(Foo1) == 12);
Foo1 foo1 = { 1, 2 };
// <{ i8, i64, [3 x i8] }>
struct Foo2 @packed @align(4)
{
char foo;
long bar;
}
$assert($sizeof(Foo2) == 12);
Foo2 foo2 = { 1, 2 };
// <{ i8, i64, [7 x i8] }>
struct Foo3 @packed @align(8)
{
char foo;
long bar;
}
Foo3 foo3 = { 1, 2 };
$assert($sizeof(Foo3) == 16);
// <{ i8, i64 }>
struct Foo4 @packed
{
char foo;
long bar;
}
$assert($sizeof(Foo4) == 9);
Foo4 foo4 = { 1, 2 };
// { i32, [12 x i8], i8, [15 x i8] }
struct Foo5
{
int bar @align(16);
ichar foo @align(16);
}
$assert($sizeof(Foo5) == 32);
Foo5 foo5 = { 1, 2 };
func int test5(ichar x)
{
Foo5 y = { .foo = x };
return y.foo + y.bar;
}
// { i32, i16, i16 }
struct Foo6 @packed
{
int a;
short b;
short c;
}
$assert($sizeof(Foo6) == 8);
Foo6 foo6 = { 1, 2, 3 };
// #expect: struct2.ll
%Foo1 = type <{ i64, i8, [3 x i8] }>
%Foo2 = type <{ i8, i64, [3 x i8] }>
%Foo3 = type <{ i8, i64, [7 x i8] }>
%Foo4 = type <{ i8, i64 }>
%Foo5 = type { i32, [12 x i8], i8, [15 x i8] }
%Foo6 = type { i32, i16, i16 }
@struct2.foo1 = global %Foo1 <{ i64 1, i8 2, [3 x i8] undef }>, align 4
@struct2.foo2 = global %Foo2 <{ i8 1, i64 2, [3 x i8] undef }>, align 4
@struct2.foo3 = global %Foo3 <{ i8 1, i64 2, [7 x i8] undef }>, align 8
@struct2.foo4 = global %Foo4 <{ i8 1, i64 2 }>, align 1
@struct2.foo5 = global %Foo5 { i32 1, [12 x i8] undef, i8 2, [15 x i8] undef }, align 16
@struct2.foo6 = global %Foo6 { i32 1, i16 2, i16 3 }, align 1
@struct2.test5
entry:
%x = alloca i8, align 1
%y = alloca %Foo5, align 16
store i8 %0, i8* %x, align 1
%1 = bitcast %Foo5* %y to i8*
call void @llvm.memset.p0i8.i64(i8* align 16 %1, i8 0, i64 32, i1 false)
%2 = getelementptr inbounds %Foo5, %Foo5* %y, i32 0, i32 2
%3 = load i8, i8* %x, align 1
store i8 %3, i8* %2, align 16
%4 = getelementptr inbounds %Foo5, %Foo5* %y, i32 0, i32 2
%5 = load i8, i8* %4, align 16
%sisiext = sext i8 %5 to i32
%6 = getelementptr inbounds %Foo5, %Foo5* %y, i32 0, i32 0
%7 = load i32, i32* %6, align 16
%add = add i32 %sisiext, %7
ret i32 %add