[clang] [HLSL][Sema] Fix Struct Size Calculation containing 16/32 bit scalars (PR #128086)
Helena Kotas via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 21 09:29:23 PST 2025
================
@@ -172,6 +172,27 @@ Decl *SemaHLSL::ActOnStartBuffer(Scope *BufferScope, bool CBuffer,
return Result;
}
+static unsigned calculateLegacyCbufferFieldAlign(const ASTContext &Context,
+ QualType T) {
+ // Aggregate types are always aligned to new buffer rows
+ if (T->isAggregateType())
+ return 16;
+
+ assert(Context.getTypeSize(T) <= 64 &&
+ "Scalar bit widths larger than 64 not supported");
+
+ // 64 bit types such as double and uint64_t align to 8 bytes
+ if (Context.getTypeSize(T) == 64)
+ return 8;
+
+ // Half types align to 2 bytes only if native half is available
+ if (T->isHalfType() && Context.getLangOpts().NativeHalfType)
----------------
hekota wrote:
I was wondering the same. Doesn't `Context.getTypeSize(T)/8` give you the right alignment value without these extra checks?
https://github.com/llvm/llvm-project/pull/128086
More information about the cfe-commits
mailing list