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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Take:
void bad() {
  constexpr int x = 123;
  auto Outer = [&] [[gnu::noipa]] () {
    auto L = [=]  [[gnu::noipa]] () {
      const int *x1 = &x;
      for (int i = 0; i < *x1; ++i) { asm("":::"memory"); }
    };
    asm("":::"memory");
   L();
  };
  Outer();
}

void good() {
  constexpr int x = 123;
  auto L = [=] [[gnu::noipa]]() {
      const int *x1 = &x;
    for (int i = 0; i < *x1; ++i) {asm("":::"memory"); }    
  };
  L();
}

In the bad case, L is sizeof int and Outer is still 1. In good, it is sizeof
int.
This is for GCC and clang.

So I think GCC is just capturing and not removing constexpr after doing the
prop for constexpr. Which I think is just a missed optimization.

Reply via email to