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

via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 23 12:24:00 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)
----------------
yabinc wrote:

Changed IsFlexibleArray to FieldSize.
If you mean to use getTypeAllocSize() in DoZeroInitPadding(),
I don't know how to replace ASTContext::getTypeSizeInChars(clang::QualType T) with DataLayout::getTypeAllocSize(llvm::Type *Ty).

If you mean to always use CGM.getDataLayout().getTypeAllocSize(EltInit->getType()), there is a case when EltInit isn't avaiable (when emitting a DesignatedInitUpdateExpr with a nested InitListExpr).

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


More information about the cfe-commits mailing list