- Add float[<3>] x = { .xy = 1.2, .z = 3.3 } swizzle initialization for vectors. #2599

This commit is contained in:
Christoffer Lerno
2025-11-26 11:31:08 +01:00
parent ab1efdda73
commit 8ec3a52ef7
9 changed files with 116 additions and 35 deletions

View File

@@ -0,0 +1,8 @@
fn int test()
{
int[<2>] v = { .xyz = 2 }; // #error: The 'z' component is not present in a vector of length 2, did you assume a longer vector?
int[<2>] v2 = { .z = 2 }; // #error: The 'z' component is not present in a vector of length 2, did you assume a longer vector?
int[<2>] v3 = { .yx = 2 }; // #error: Designated initializers using swizzling must be a contiguous range, like '.xyz = 123'
int[<3>] v4 = { .xyz = 2 };
int[<3>] v5 = { .xz = 2 }; // #error: Designated initializers using swizzling must be a contiguous range, like '.xyz = 123'
}

View File

@@ -0,0 +1,22 @@
// #target: macos-x64
module test;
import std;
fn int main()
{
int[<2>] v = { .xy = 2 };
int[<2>] v2 = { .x = 2, .y = 3 };
int[<3>] v3 = { .z = 4, .xy = 1 };
return 0;
}
/* #expect: test.ll
entry:
%v = alloca <2 x i32>, align 8
%v2 = alloca <2 x i32>, align 8
%v3 = alloca <3 x i32>, align 16
store <2 x i32>
store <2 x i32> <i32 2, i32 3>, ptr %v2, align 8
store <4 x i32> <i32 1, i32 1, i32 4, i32 undef>, ptr %v3, align 16
ret i32 0
}