https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127496
Bug ID: 127496
Summary: 7 push_back in a row causes aliasing issues
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: alias, missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Blocks: 118130
Target Milestone: ---
Take:
```
#include <vector>
void g(std::vector<int>&);
void f()
{
std::vector<int> a;
a.push_back(1); //4
a.push_back(1); //8
a.push_back(1); //16
a.push_back(1);
a.push_back(1); // 32+memcpy
a.push_back(1);
a.push_back(1);
g(a);
}
```
At -O3 -fno-exceptions, we get:
```
_199 = operator new (32);
operator delete (_149, 16);
a.D.35903._M_impl.D.35200._M_start = _199;
_194 = _199 + 32;
a.D.35903._M_impl.D.35200._M_end_of_storage = _194;
_42 = _199 + 24;
a.D.35903._M_impl.D.35200._M_finish = _42;
MEM <uint128_t> [(char * {ref-all})_199] = 0x1000000010000000100000001;
MEM <unsigned long> [(int *)_199 + 16B] = 4294967297;
MEM[(int *)_199 + 24B] = 1;
_36 = _199 + 28;
a.D.35903._M_impl.D.35200._M_finish = _36;
```
Notice how there are 2 stores to _M_finish happening. I suspect this is
because we can't 100% figure out that _199 does not alias a here.
This is due to a memcpy that happened.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118130
[Bug 118130] std::vector code quality issues