Zig Version
0.12.0-dev.86+197d9a9eb
Steps to Reproduce and Observed Behavior
It looks like coercion involving pointer-of-vector types doesn't have the correct alignment in its calculations. Zig normally catches potentially unsafe coercion at comptime, so it's weird that this sort of code could segfault.
test "segfaults more often than not" {
var x: [16]f32 = undefined;
var y: *[1]@Vector(16, f32) = &x;
for (y) |*v|
v.* = @splat(0);
}
test "fails at comptime, as it should" {
var x: [16]f32 = undefined;
// cast increases pointer alignment
var y: *[1]@Vector(16, f32) = @ptrCast(&x);
_ = y;
}
test "also fails at comptime since the coercion doesn't involve vectors" {
var x: u128 = 0;
var y: *align(64) u128 = &x;
_ = y;
}
Expected Behavior
All three of those tests should fail to compile because there's a potentially unsafe coercion from a less aligned type to a more aligned type.
Zig Version
0.12.0-dev.86+197d9a9eb
Steps to Reproduce and Observed Behavior
It looks like coercion involving pointer-of-vector types doesn't have the correct alignment in its calculations. Zig normally catches potentially unsafe coercion at comptime, so it's weird that this sort of code could segfault.
Expected Behavior
All three of those tests should fail to compile because there's a potentially unsafe coercion from a less aligned type to a more aligned type.