# Compiler bug, access violation when passing @Vector wraped inside struct

**URL:** <https://ziggit.dev/t/compiler-bug-access-violation-when-passing-vector-wraped-inside-struct/17872>\
**Category:** Help\
**Tags:** language\
**Created:** [October 6, 2026, 6:00pm UTC](https://ziggit.dev/t/compiler-bug-access-violation-when-passing-vector-wraped-inside-struct/17872 "2026-10-06T18:00:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lassade](https://ziggit.dev/user_avatar/ziggit.dev/lassade/32/569_2.png) [@lassade](https://ziggit.dev/u/lassade)\
**Post date:** [October 6, 2026, 6:00pm UTC](https://ziggit.dev/t/compiler-bug-access-violation-when-passing-vector-wraped-inside-struct/17872/1 "2026-10-06T18:00:00Z")

</div>

I have he following structs in my math library

```zig
pub const F32x4 = @Vector(4, f32);
pub const Quat = extern struct {
  xyzw: F32x4 = .{ 0.0, 0.0, 0.0, 1.0 },
};

pub fn matRotation_1(q: Quat) Mat4 // q is passed via stack
pub fn matRotation_2(q: F32x4) Mat4 // q is passed via xmm0 as it should

pub fn matTRS_1(pos: F32x4, rot: Quat, s: F32x4) Mat4; // crashes on access violation
pub fn matTRS_2(pos: F32x4, rot: F32x4, s: F32x4) Mat4; // works fine

```

the issue is when using `matTRS_1` I get an access violation exception, no error occurs if inline the function (by copy/paste or tag with inline keyword) looking at the assembly I notice that `Quat` is passed via stack while `F32x4` is passed via xmm register not sure if this is a causing the bug or not.

In the past zig had produce invalid code with long an complex functions; I’m calling matTRS\_1 from `main` that is about 1K line function

About Quat been passed in the stack rather than xmm is that working as intended?

Edit 1:  
I found another thing: calling `Quat.mat(rot)` produces a different result that `rot.mat()` whut

```zig
pub fn trs(pos: F32x4, rot: Quat, s: F32x4) Mat4 {
  var m = Quat.mat(rot); // works fine
  var m = rot.mat(); // access violation
  inline for (0..3) |i| m.rows[i] *= @splat(s[i]);
  m.rows[3] = @shuffle(f32, pos, m.rows[3], [4]i32{ 0, 1, 2, -4 });
  return m;
}

```

---

<div class="post-metadata">

**Author:** ![elpablete](https://ziggit.dev/user_avatar/ziggit.dev/elpablete/32/7701_2.png) [@elpablete](https://ziggit.dev/u/elpablete)\
**Post date:** [October 6, 2026, 6:09pm UTC](https://ziggit.dev/t/compiler-bug-access-violation-when-passing-vector-wraped-inside-struct/17872/2 "2026-10-06T18:09:28Z")

</div>

Maybe take a look at this strategy: [@Vector abuse? - #3 by Plebosaur](https://ziggit.dev/t/vector-abuse/17854/3)

---

<div class="post-metadata">

**Author:** ![lassade](https://ziggit.dev/user_avatar/ziggit.dev/lassade/32/569_2.png) [@lassade](https://ziggit.dev/u/lassade)\
**Post date:** [October 6, 2026, 6:36pm UTC](https://ziggit.dev/t/compiler-bug-access-violation-when-passing-vector-wraped-inside-struct/17872/3 "2026-10-06T18:36:44Z")

</div>

Hum, interesting, I’m on 0.16 but I think this is related, using `Quat = struct` without `extern` didn’t made difference at frist; but it enforced me to use `.{ .xyzw = @bitCast(t.rotation) }` instead of just `@bitCast(t.rotation)` and that fixed it;

Like the post said it tries to load the quaternion from stack by using `vmovdqa` instead of `vmovdqu` but `t.rotation` is a `[4]f32` alinged to 4 instead of 16, I was getting access violation because of that;

This could have been avoided if quat had been passed by value via some xmm register 😕
