[clang] [HLSL] Fix miscompile of small structs after arrays in cbuffers (PR #179768)

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 4 11:55:11 PST 2026


================
@@ -73,7 +73,7 @@ void cbstructs() {
   use(s1.a1);
   // CHECK: load <3 x i16>, ptr addrspace(2) getelementptr inbounds nuw (%B, ptr addrspace(2) @s2, i32 0, i32 1), align 2
   use(s2.b1);
-  // CHECK: load <2 x float>, ptr addrspace(2) getelementptr inbounds nuw (%C, ptr addrspace(2) @s3, i32 0, i32 1), align 8
+  // CHECK: load <2 x float>, ptr addrspace(2) getelementptr inbounds nuw (%C, ptr addrspace(2) @s3, i32 0, i32 2), align 8
----------------
bogner wrote:

We have:
```c++
struct A {
  float2 a1;
};

struct C {
  int c1;
  A c2;
};
```

So there will be 12 bytes of padding after `c1`, which is member `1` of the layout struct at `@s3`. Thus, `2` is needed to access `s3.c2`.

https://github.com/llvm/llvm-project/pull/179768


More information about the cfe-commits mailing list