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

--- Comment #4 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
Managed to shrink example even further. Now fails in `037t.fre1`:

```c++
struct string {
  char * _M_buf;
  // local store
  char _M_local_buf[16];

  __attribute__((noinline)) string() : _M_buf(_M_local_buf) {}

  ~string() {
    if (_M_buf != _M_local_buf)
      __builtin_trap();
  }

  string(const string &__str); // no copies
};

// main.cc

__attribute__((noinline)) static string dir_name() { return string(); }
class Importer {
  string base_path;

public:
  __attribute__((noinline)) Importer() : base_path (dir_name()) {}
};

int main() {
  Importer imp;
}
```

```
$ g++-11.0.0 -O2 -std=c++11 main.cc -o a && ./a
Illegal instruction     (core dumped) ./a
$ g++-11.0.0 --param=modref-max-depth=0 -O2 -std=c++11 main.cc -o a && ./a
<ok>
```

It feels like c++'s return-value-optimization somehow misses the PTA.

Reply via email to