[clang] [clang][CodeGen] The linux kernel expects initializers to FULLY initialize variables, structs and unions including padding (PR #97121)

John McCall via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 31 14:56:37 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.
----------------
rjmccall wrote:

Also, I think we should do this unconditionally in all language modes.  It's not like this is forbidden in C++.

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


More information about the cfe-commits mailing list