[Bug middle-end/108217] bogus -Warray-bounds with pointer to constant local

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Dec 24 20:42:12 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108217

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The problem with const is GCC does not have an idea of a store once and then
become constant.
an example of that would be:
```
void ExternFunc(const int*);

int f();

int Bad() {
  const int i = f();
  const int* pi = &i;
  ExternFunc(pi);
  return *pi;
}

int Good() {
  const int i = f();
  ExternFunc(&i);
  return i;
}
```
This is similar to LLVM/clang really because this does not come up that much.


More information about the Gcc-bugs mailing list