[clang] [clang][CodeGen] Zero init unspecified fields in initializers in C (PR #97121)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 18 20:19:58 PDT 2024


================
@@ -870,6 +904,15 @@ bool ConstStructBuilder::Build(const APValue &Val, const RecordDecl *RD,
     if (!EltInit)
       return false;
 
+    if (ZeroInitPadding) {
+      if (!DoZeroInitPadding(Layout, FieldNo, *Field, SizeSoFar,
+                             IsFlexibleArray, AllowOverwrite))
+        return false;
+      if (IsFlexibleArray)
----------------
efriedma-quic wrote:

I think I've figured out the way IsFlexibleArray works, but it's sort of awkward.  Do you really need to use a different codepath for flexible-array fields, vs. ordinary fields?  It seems like it would be simpler to just use getTypeAllocSize() in both cases.  And the name "IsFlexibleArray" is a bit confusing because isn't really reliably detecting flexible arrays; there are other zero-size fields.

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


More information about the cfe-commits mailing list