aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2010-01-27 15:49:00 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2010-01-27 15:49:00 +0000
commit77597d3907e17a45b0d4825edb893c23a0715181 (patch)
tree41da2c42473b85d27731c803582dd08dd982c329
parent9a78eb7197d02a89c12859159f9e0c32c740701b (diff)
downloadgcc-77597d3907e17a45b0d4825edb893c23a0715181.zip
gcc-77597d3907e17a45b0d4825edb893c23a0715181.tar.gz
gcc-77597d3907e17a45b0d4825edb893c23a0715181.tar.bz2
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
-rw-r--r--libstdc++-v3/ChangeLog7
-rw-r--r--libstdc++-v3/include/std/functional13
-rw-r--r--libstdc++-v3/include/tr1/functional13
3 files changed, 27 insertions, 6 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 4e5adf7..25cda7e 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,10 @@
+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>
* config/abi/pre/gnu.ver: Avoid time_get pattern conflicts.
diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional
index 29b19f6..c390c3b 100644
--- a/libstdc++-v3/include/std/functional
+++ b/libstdc++-v3/include/std/functional
@@ -1940,9 +1940,16 @@ namespace std
*/
void swap(function& __x)
{
- _Any_data __old_functor = _M_functor;
- _M_functor = __x._M_functor;
- __x._M_functor = __old_functor;
+ /* We cannot perform direct assignments of the _M_functor
+ parts as they are of type _Any_data and have a different
+ 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;
_M_manager = __x._M_manager;
__x._M_manager = __old_manager;
diff --git a/libstdc++-v3/include/tr1/functional b/libstdc++-v3/include/tr1/functional
index 4825509..2052f88 100644
--- a/libstdc++-v3/include/tr1/functional
+++ b/libstdc++-v3/include/tr1/functional
@@ -1904,9 +1904,16 @@ namespace tr1
*/
void swap(function& __x)
{
- _Any_data __old_functor = _M_functor;
- _M_functor = __x._M_functor;
- __x._M_functor = __old_functor;
+ /* We cannot perform direct assignments of the _M_functor
+ parts as they are of type _Any_data and have a different
+ 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;
_M_manager = __x._M_manager;
__x._M_manager = __old_manager;