[clang] [clang][CodeGen] Zero init unspecified fields in initializers in C (PR #97121)
John McCall via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 1 17:17:21 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:
> > But I assume that similar code is required in order to explicitly zero out any padding when dynamically initializing a local variable.
>
> I guess you mean variables assigned by Compound literals after variable definition. An example is in https://godbolt.org/z/caaEKnjWe.
No, I mean initializing a local aggregate with a non-constant initializer, e.g.
```
void g(char c) {
struct A a = { c, 2 };
}
```
Do we already zero the padding correctly in this case?
https://github.com/llvm/llvm-project/pull/97121
More information about the cfe-commits
mailing list