[Bug c++/122780] Unnecessary stack allocation and copy for copy/move-assignment of trivial type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122780 --- Comment #4 from m.cencora at gmail dot com --- I see, thanks for explanation. Is there a func attribute that would say "this func doesn't use globals" which would allow for the mentioned optimization to apply?
[Bug c++/122780] Unnecessary stack allocation and copy for copy/move-assignment of trivial type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122780
--- Comment #3 from Andrew Pinski ---
Simple as:
```
struct bar a;
bar create() noexcept
{
bar t; // NVR will transform t into the copy passed in
t = a;
t.data[10]++;
t.data[20] = a.data[10];
return t;
}
void g()
{
foo_not_ok(a);
}
```
If the copy is removed in foo_not_ok, then NVR would be invalid. But the C++17
standard allows (requires?) for NVR here. So not having a copy will get the
wrong value into t.data[20].
[Bug c++/122780] Unnecessary stack allocation and copy for copy/move-assignment of trivial type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122780 Andrew Pinski changed: What|Removed |Added Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED --- Comment #2 from Andrew Pinski --- Yes this is invalid. as create can access obj_on_heap via a different way before it is finished so there needs to be a copy.
[Bug c++/122780] Unnecessary stack allocation and copy for copy/move-assignment of trivial type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122780 --- Comment #1 from Andrew Pinski --- I think this is invalid. obj_on_heap could be accessed in create is finished so there needs to copied.
