[clang] [HLSL][Sema] Fix Struct Size Calculation containing 16/32 bit scalars (PR #128086)

Ashley Coleman via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 25 08:28:52 PST 2025


================
@@ -172,6 +172,23 @@ Decl *SemaHLSL::ActOnStartBuffer(Scope *BufferScope, bool CBuffer,
   return Result;
 }
 
+static unsigned calculateLegacyCbufferFieldAlign(const ASTContext &Context,
+                                                 QualType T) {
+  // Arrays and Structs are always aligned to new buffer rows
+  if (T->isArrayType() || T->isStructureType())
+    return 16;
+
+  // Vectors are aligned to the type they contain
+  if (const VectorType *VT = T->getAs<VectorType>())
+    return calculateLegacyCbufferFieldAlign(Context, VT->getElementType());
----------------
V-FEXrt wrote:

Does https://github.com/llvm/llvm-project/pull/128086/files#diff-7fa57e132f6ce9b16a443061bbb89e859e96d41d35645a64151845840c34c453R77 not do this?

Its testing that 2 `float2`s is the same alignment as 4 `float`s

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


More information about the cfe-commits mailing list