]> gcc.gnu.org Git - gcc.git/commit
libstdc++: fix memory clobbering in std::vector [PR110879]
authorVladimir Palevich <palevichva@gmail.com>
Tue, 8 Aug 2023 22:34:05 +0000 (01:34 +0300)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 1 Sep 2023 15:01:23 +0000 (16:01 +0100)
commit419c423d3aeca754e47e1ce1bf707735603a90a3
tree85566082042c25882b51e6b26feacac150da81e4
parent283994cba687e0746f9a1018bae2c41291e362ff
libstdc++: fix memory clobbering in std::vector [PR110879]

Fix ordering to prevent clobbering of class members by a call to deallocate
in _M_realloc_insert and _M_default_append.

Because of recent changes in _M_realloc_insert and _M_default_append,
calls to deallocate were ordered after assignment to class members of
std::vector (in the guard destructor), which is causing said members to
be call-clobbered.  This is preventing further optimization, the
compiler is unable to move memory read out of a hot loop in this case.

This patch reorders the call to before assignments by putting guard in
its own block. Plus a new testsuite for this case.  I'm not very happy
with the new testsuite, but I don't know how to properly test this.

PR libstdc++/110879

libstdc++-v3/ChangeLog:

* include/bits/vector.tcc (_M_realloc_insert): End guard
lifetime just before assignment to class members.
(_M_default_append): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/pr110879.C: New test.

Signed-off-by: Vladimir Palevich <palevichva@gmail.com>
gcc/testsuite/g++.dg/pr110879.C [new file with mode: 0644]
libstdc++-v3/include/bits/vector.tcc
This page took 0.069449 seconds and 6 git commands to generate.