Commit 77597d39 by Richard Guenther Committed by Richard Biener

re PR libstdc++/42832 (Revisit std::function for aliasing issues and efficiency)

2010-01-27  Richard Guenther  <rguenther@suse.de>

	PR libstdc++/42832
	* include/std/functional (function<>::swap): Perform bytewise
	swap of _M_functor.
	* include/tr1/functional (function<>::swap): Likewise.

From-SVN: r156290
parent 9a78eb71
2010-01-27 Richard Guenther <rguenther@suse.de>
PR libstdc++/42832
* include/std/functional (function<>::swap): Perform bytewise
swap of _M_functor.
* include/tr1/functional (function<>::swap): Likewise.
2010-01-27 Andreas Krebbel <Andreas.Krebbel@de.ibm.com> 2010-01-27 Andreas Krebbel <Andreas.Krebbel@de.ibm.com>
* config/abi/pre/gnu.ver: Avoid time_get pattern conflicts. * config/abi/pre/gnu.ver: Avoid time_get pattern conflicts.
......
...@@ -1940,9 +1940,16 @@ namespace std ...@@ -1940,9 +1940,16 @@ namespace std
*/ */
void swap(function& __x) void swap(function& __x)
{ {
_Any_data __old_functor = _M_functor; /* We cannot perform direct assignments of the _M_functor
_M_functor = __x._M_functor; parts as they are of type _Any_data and have a different
__x._M_functor = __old_functor; dynamic type. Doing so would violate type-based aliasing
rules and lead to spurious miscompilations.
Instead perform a bytewise exchange of the memory of
both POD objects.
??? A wordwise exchange honoring alignment of _M_functor
would be more efficient. See PR42845. */
for (unsigned i = 0; i < sizeof (_M_functor._M_pod_data); ++i)
std::swap (_M_functor._M_pod_data[i], __x._M_functor._M_pod_data[i]);
_Manager_type __old_manager = _M_manager; _Manager_type __old_manager = _M_manager;
_M_manager = __x._M_manager; _M_manager = __x._M_manager;
__x._M_manager = __old_manager; __x._M_manager = __old_manager;
......
...@@ -1904,9 +1904,16 @@ namespace tr1 ...@@ -1904,9 +1904,16 @@ namespace tr1
*/ */
void swap(function& __x) void swap(function& __x)
{ {
_Any_data __old_functor = _M_functor; /* We cannot perform direct assignments of the _M_functor
_M_functor = __x._M_functor; parts as they are of type _Any_data and have a different
__x._M_functor = __old_functor; dynamic type. Doing so would violate type-based aliasing
rules and lead to spurious miscompilations.
Instead perform a bytewise exchange of the memory of
both POD objects.
??? A wordwise exchange honoring alignment of _M_functor
would be more efficient. See PR42845. */
for (unsigned i = 0; i < sizeof (_M_functor._M_pod_data); ++i)
std::swap (_M_functor._M_pod_data[i], __x._M_functor._M_pod_data[i]);
_Manager_type __old_manager = _M_manager; _Manager_type __old_manager = _M_manager;
_M_manager = __x._M_manager; _M_manager = __x._M_manager;
__x._M_manager = __old_manager; __x._M_manager = __old_manager;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment