Files
c3c/test/test_suite/abi/small_struct_x64.c3t

74 lines
2.2 KiB
C

// #target: x64-darwin
module test;
struct Foo
{
char a;
char b;
char c;
}
fn int testing()
{
Foo y = getFoo(Foo { 4, 5, 6 });
return y.a + y.c;
}
fn Foo getFoo(Foo f)
{
return Foo { 1, 2, 3 };
}
/* #expect: test.ll
define i32 @test.testing() #0 {
entry:
%y = alloca %Foo, align 1
%literal = alloca %Foo, align 1
%tempcoerce = alloca i24, align 4
%result = alloca %Foo, align 1
%0 = getelementptr inbounds %Foo, %Foo* %literal, i32 0, i32 0
store i8 4, i8* %0, align 1
%1 = getelementptr inbounds %Foo, %Foo* %literal, i32 0, i32 1
store i8 5, i8* %1, align 1
%2 = getelementptr inbounds %Foo, %Foo* %literal, i32 0, i32 2
store i8 6, i8* %2, align 1
%3 = bitcast i24* %tempcoerce to i8*
%4 = bitcast %Foo* %literal to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %3, i8* align 1 %4, i32 3, i1 false)
%5 = load i24, i24* %tempcoerce, align 4
%6 = call i24 @test.getFoo(i24 %5)
%7 = bitcast %Foo* %result to i24*
store i24 %6, i24* %7, align 1
%8 = bitcast %Foo* %y to i8*
%9 = bitcast %Foo* %result to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 %8, i8* align 1 %9, i32 3, i1 false)
%10 = getelementptr inbounds %Foo, %Foo* %y, i32 0, i32 0
%11 = load i8, i8* %10, align 1
%uisiext = zext i8 %11 to i32
%12 = getelementptr inbounds %Foo, %Foo* %y, i32 0, i32 2
%13 = load i8, i8* %12, align 1
%uisiext1 = zext i8 %13 to i32
%add = add i32 %uisiext, %uisiext1
ret i32 %add
}
; Function Attrs: nounwind
define i24 @test.getFoo(i24 %0) #0 {
entry:
%f = alloca %Foo, align 1
%literal = alloca %Foo, align 1
%tempcoerce = alloca i24, align 4
%1 = bitcast %Foo* %f to i24*
store i24 %0, i24* %1, align 1
%2 = getelementptr inbounds %Foo, %Foo* %literal, i32 0, i32 0
store i8 1, i8* %2, align 1
%3 = getelementptr inbounds %Foo, %Foo* %literal, i32 0, i32 1
store i8 2, i8* %3, align 1
%4 = getelementptr inbounds %Foo, %Foo* %literal, i32 0, i32 2
store i8 3, i8* %4, align 1
%5 = bitcast i24* %tempcoerce to i8*
%6 = bitcast %Foo* %literal to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %5, i8* align 1 %6, i32 3, i1 false)
%7 = load i24, i24* %tempcoerce, align 4
ret i24 %7
}