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

            Bug ID: 125345
           Summary: [16/17 Regression] -D_GLIBCXX_ASSERTIONS with -O2
                    leads to abort/segfault
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gnu.ojxq8 at dralias dot com
  Target Milestone: ---

Code to reproduce:

```cpp
#include <array>

struct Data {
  std::array<unsigned, 8> dst;
  std::array<unsigned, 8> src{1};
};

int main() {
  Data d;
  d.dst = d.src;
  unsigned p = d.dst.size();
  while (!d.dst[--p]) ;
  (void)__builtin_clz(d.dst[p]);
}
```

Command to reproduce:

```
# g++-15 -O2 -std=c++11 -D_GLIBCXX_ASSERTIONS ./work.cc -o ./e && ./e           
# g++-16 -O2 -std=c++11 -D_GLIBCXX_ASSERTIONS ./work.cc -o ./e && ./e
Segmentation fault (core dumped)
```

Godbolt:

https://godbolt.org/z/nMq8G78qc


While reducing the test case, I found that it sometimes goes away with -O3, but
not always. Also, when inlining the two Data fields into main directly, the
segv becomes an abort.

Reply via email to