[clang] [HLSL] Enable InitList code to handle zero sized structs (PR #160355)

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 22 19:09:23 PDT 2025


================
@@ -4284,6 +4284,9 @@ bool SemaHLSL::transformInitList(const InitializedEntity &Entity,
   }
   size_t ExpectedSize = ILT.DestTypes.size();
   size_t ActualSize = ILT.ArgExprs.size();
+  if (ExpectedSize == 0 && ActualSize == 0)
----------------
shafik wrote:

So this check is a little troubling b/c we have a divide by `ExpectedSize` not to far below here and based on this condition `ExpectedSize` can be `0` and it is undefined behavior to divide by zero.

So if there are more conditions here not represented in the code we should add assertions to document the invariants. 

CC @llvm-beanz 

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


More information about the cfe-commits mailing list