Files
c3c/test/test_suite2/struct/nested_struct_init.c3t
2022-07-10 23:29:05 +02:00

75 lines
2.6 KiB
C

// #target: macos-x64
module foo;
import libc;
struct Matrix2x2
{
union
{
struct {
float m00, m01, m10, m11;
}
float[4] m;
}
}
struct Matrix2x2_b
{
union
{
float[4] m;
struct {
float m00, m01, m10, m11;
}
}
}
fn void main()
{
Matrix2x2 m = { 1, 2, 3, 4 };
Matrix2x2_b m2 = { { 1, 2, 3, 4 } };
libc::printf("%f %f %f %f\n", m.m00, m.m[1], m.m10, m.m[3]);
}
/* #expect: foo.ll
%Matrix2x2 = type { %anon }
%anon = type { %anon.0 }
%anon.0 = type { float, float, float, float }
%Matrix2x2_b = type { %anon.1 }
%anon.1 = type { [4 x float] }
@.typeid.foo.anon = linkonce constant { i8, i64 } { i8 10, i64 4 }, align 8
@.typeid.foo.anon.1 = linkonce constant { i8, i64 } { i8 11, i64 2 }, align 8
@.typeid.foo.Matrix2x2 = linkonce constant { i8, i64 } { i8 10, i64 1 }, align 8
@.typeid.foo.anon.2 = linkonce constant { i8, i64 } { i8 10, i64 4 }, align 8
@.typeid.foo.anon.3 = linkonce constant { i8, i64 } { i8 11, i64 2 }, align 8
@.typeid.foo.Matrix2x2_b = linkonce constant { i8, i64 } { i8 10, i64 1 }, align 8
@.__const = private unnamed_addr constant %Matrix2x2 { %anon { %anon.0 { float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00 } } }, align 4
@.__const.4 = private unnamed_addr constant %Matrix2x2_b { %anon.1 { [4 x float] [float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00] } }, align 4
@.str = private unnamed_addr constant [13 x i8] c"%f %f %f %f\0A\00", align 1
; Function Attrs: nounwind
define void @foo.main() #0 {
entry:
%m = alloca %Matrix2x2, align 4
%m2 = alloca %Matrix2x2_b, align 4
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %m, ptr align 4 @.__const, i32 16, i1 false)
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %m2, ptr align 4 @.__const.4, i32 16, i1 false)
%0 = getelementptr inbounds %Matrix2x2, ptr %m, i32 0, i32 0
%1 = getelementptr inbounds %anon.0, ptr %0, i32 0, i32 0
%2 = load float, ptr %1, align 4
%fpfpext = fpext float %2 to double
%3 = getelementptr inbounds %Matrix2x2, ptr %m, i32 0, i32 0
%4 = getelementptr inbounds [4 x float], ptr %3, i64 0, i64 1
%5 = load float, ptr %4, align 4
%fpfpext1 = fpext float %5 to double
%6 = getelementptr inbounds %Matrix2x2, ptr %m, i32 0, i32 0
%7 = getelementptr inbounds %anon.0, ptr %6, i32 0, i32 2
%8 = load float, ptr %7, align 4
%fpfpext2 = fpext float %8 to double
%9 = getelementptr inbounds %Matrix2x2, ptr %m, i32 0, i32 0
%10 = getelementptr inbounds [4 x float], ptr %9, i64 0, i64 3
%11 = load float, ptr %10, align 4
%fpfpext3 = fpext float %11 to double
%12 = call i32 (ptr, ...) @printf(ptr @.str, double %fpfpext, double %fpfpext1, double %fpfpext2, double %fpfpext3)
ret void
}