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

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 28 18:13:28 PDT 2024


efriedma-quic wrote:

The only place the standard requires padding to be zero-initialized is in "default initialization", which only applies to members which don't have an initializer.  So, for example, if you have `struct X { int x; char y; } z = {1};`, none of the padding is required to be initialized; the only default initialization is of "y", which doesn't have any padding.  Similarly, if you have  `union X { char x; int y; } z = {1};`, none of the padding is required to be initialized; there's no default initialization at all.  On the other hand, if you write `union X { char x; int y; } z = {};`, that padding is required to be initialized.

There's probably some argument for doing what this patch does, in addition to what the standard requires.  But to avoid any confusion, please file a separate bug for that, and make sure the comments in the patch distinguish between what the standard requires and what we actually implement.

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


More information about the cfe-commits mailing list