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

via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 15 14:15:28 PDT 2024


================
@@ -361,6 +368,13 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const VarDecl &D,
     }
     return GV;
   }
+  if (!getLangOpts().CPlusPlus) {
+    // In C, when an initializer is given, the Linux kernel relies on clang to
+    // zero-initialize all members not explicitly initialized, including padding
+    // bits.
----------------
yabinc wrote:

> I don't mind staging it in over multiple commits in principle. If you'd like to switch to an implementation that adds explicit padding fields when building the original constant, you could still stage that and only add those fields in certain language modes.

Changed as suggested, adding explicit padding fields when building the original constant.

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


More information about the cfe-commits mailing list