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

Hubert Tong via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 16 09:49:55 PDT 2024


hubert-reinterpretcast wrote:

@AaronBallman, considering the concern of potential performance regressions ("unnecessary" initialization of automatic-storage duration objects), should it be the case that there is no option control?

It was also the case that the prior Clang behaviour (with `-ftrivial-auto-var-init=pattern` [1]: https://godbolt.org/z/x994WMT6h) had some utility for identifying potential portability issues with a program. Option control would make me much happier about this change.

[1]:
A string of `0xaa` is observed using `-ftrivial-auto-var-init=pattern` using Clang 19.1:
```c
typedef union { int x; long long y; } U;

int printf(const char *, ...);
int main(void) {
  U u = { 0 };
  typedef unsigned char *ucp;
  for (ucp p = (ucp)&u; p < (ucp)&1[&u]; ++p) {
    printf("%02x", (unsigned)*p);
  }
  printf("\n");
}
```

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


More information about the cfe-commits mailing list