[clang] [clang][CodeGen] Zero init unspecified fields in initializers in C (PR #97121)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 17 13:13:32 PDT 2024
efriedma-quic wrote:
There are two possible alternative sequences we could generate there:
```
int test(int x, int y) {
struct S s;
__builtin_memset(&s, 0, 8);
s.x = x;
s.y = y;
f(&s);
}
int test2(int x, int y) {
struct S s;
long long dummy = (unsigned char)x;
__builtin_memcpy(&s, &dummy, 8);
s.x = x;
s.y = y;
f(&s);
}
```
Whether one of them is better might depend on the context... for test2, the zero-extend can be folded away in some cases.
I'd prefer to handle this on the LLVM side if possible (memcpyopt, or something like that); it's probably tricky to catch all the relevant cases in clang.
https://github.com/llvm/llvm-project/pull/97121
More information about the cfe-commits
mailing list