Fix issues with union of const. Bump version 0.2.12

This commit is contained in:
Christoffer Lerno
2022-07-11 17:37:32 +02:00
committed by Christoffer Lerno
parent ea5d7cd2e7
commit abfccb5576
4 changed files with 248 additions and 3 deletions

View File

@@ -0,0 +1,116 @@
// #target: macos-x64
module foob;
import libc;
struct Matrix2x2
{
union
{
float[4] m;
struct {
float m00, m01, m10, m11;
}
}
}
struct Matrix2x2_b
{
union
{
struct {
float m00, m01, m10, m11;
}
float[4] m;
}
}
struct Matrix4x4 {
union {
struct {
float m00, m01, m02, m03;
float m10, m11, m12, m13;
float m20, m21, m22, m23;
float m30, m31, m32, m33;
}
float[16] m;
}
}
struct Matrix3x3 {
union {
struct {
float m00, m01, m02, m10, m11, m12, m20, m21, m22;
}
float[9] m;
}
}
fn void main()
{
Matrix3x3 x = { 1, 2, 3, 4, 5, 6, 7,8 ,9};
Matrix2x2 m = { float[4] { 1, 2, 3, 4 } };
Matrix2x2_b m2 = { 1, 2, 3, 4 };
libc::printf("%f %f %f %f\n", x.m00, x.m[1], x.m10, x.m[3]);
}
/* #expect: foob.ll
%Matrix2x2 = type { %anon.1 }
%anon.1 = type { [4 x float] }
%Matrix2x2_b = type { %anon.2 }
%anon.2 = type { %anon.3 }
%anon.3 = type { float, float, float, float }
%Matrix3x3 = type { %anon }
%anon = type { %anon.0 }
%anon.0 = type { float, float, float, float, float, float, float, float, float }
define void @foob.main() #0 {
entry:
%x = alloca %Matrix3x3, align 4
%m = alloca %Matrix2x2, align 4
%m2 = alloca %Matrix2x2_b, align 4
%0 = getelementptr inbounds %Matrix3x3, %Matrix3x3* %x, i32 0, i32 0
%1 = bitcast %anon* %0 to %anon.0*
%2 = getelementptr inbounds %anon.0, %anon.0* %1, i32 0, i32 0
store float 1.000000e+00, float* %2, align 4
%3 = getelementptr inbounds %anon.0, %anon.0* %1, i32 0, i32 1
store float 2.000000e+00, float* %3, align 4
%4 = getelementptr inbounds %anon.0, %anon.0* %1, i32 0, i32 2
store float 3.000000e+00, float* %4, align 4
%5 = getelementptr inbounds %anon.0, %anon.0* %1, i32 0, i32 3
store float 4.000000e+00, float* %5, align 4
%6 = getelementptr inbounds %anon.0, %anon.0* %1, i32 0, i32 4
store float 5.000000e+00, float* %6, align 4
%7 = getelementptr inbounds %anon.0, %anon.0* %1, i32 0, i32 5
store float 6.000000e+00, float* %7, align 4
%8 = getelementptr inbounds %anon.0, %anon.0* %1, i32 0, i32 6
store float 7.000000e+00, float* %8, align 4
%9 = getelementptr inbounds %anon.0, %anon.0* %1, i32 0, i32 7
store float 8.000000e+00, float* %9, align 4
%10 = getelementptr inbounds %anon.0, %anon.0* %1, i32 0, i32 8
store float 9.000000e+00, float* %10, align 4
%11 = bitcast %Matrix2x2* %m to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %11, i8* align 4 bitcast (%Matrix2x2* @.__const to i8*), i32 16, i1 false)
%12 = bitcast %Matrix2x2_b* %m2 to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %12, i8* align 4 bitcast (%Matrix2x2_b* @.__const.8 to i8*), i32 16, i1 false)
%13 = getelementptr inbounds %Matrix3x3, %Matrix3x3* %x, i32 0, i32 0
%14 = bitcast %anon* %13 to %anon.0*
%15 = getelementptr inbounds %anon.0, %anon.0* %14, i32 0, i32 0
%16 = load float, float* %15, align 4
%fpfpext = fpext float %16 to double
%17 = getelementptr inbounds %Matrix3x3, %Matrix3x3* %x, i32 0, i32 0
%18 = bitcast %anon* %17 to [9 x float]*
%19 = getelementptr inbounds [9 x float], [9 x float]* %18, i64 0, i64 1
%20 = load float, float* %19, align 4
%fpfpext1 = fpext float %20 to double
%21 = getelementptr inbounds %Matrix3x3, %Matrix3x3* %x, i32 0, i32 0
%22 = bitcast %anon* %21 to %anon.0*
%23 = getelementptr inbounds %anon.0, %anon.0* %22, i32 0, i32 3
%24 = load float, float* %23, align 4
%fpfpext2 = fpext float %24 to double
%25 = getelementptr inbounds %Matrix3x3, %Matrix3x3* %x, i32 0, i32 0
%26 = bitcast %anon* %25 to [9 x float]*
%27 = getelementptr inbounds [9 x float], [9 x float]* %26, i64 0, i64 3
%28 = load float, float* %27, align 4
%fpfpext3 = fpext float %28 to double
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i32 0, i32 0), double %fpfpext, double %fpfpext1, double %fpfpext2, double %fpfpext3)
ret void
}