libstdc++ PR54005M is_lock_free; consistently avoid referring to object

Message ID 201811112235.wABMZUrD005082@ignucius.se.axis.com
State New
Headers show
Series
  • libstdc++ PR54005M is_lock_free; consistently avoid referring to object
Related show

Commit Message

Hans-Peter Nilsson Nov. 11, 2018, 10:35 p.m.
This patch should have no visible effect.  It was approved in the BZ and
is what remains of PR54005.  _M_i is declared "alignas(_S_alignment) _Tp
_M_i;" and is_lock_free is supposed to refer to the *type* not the
specific *object*.  (Note how the actual address of the object is not
used in the __atomic_is_lock_free call.)  Better then also not refer to
the object indirectly like that, even though the alignas-declaration
*should* make it the same number.  Now I don't have to write tests to
assert that being true.

For an earlier version that also replaced __atomic_is_lock_free with
__atomic_always_lock_free I wrote some tests that are posted in the PR,
but as they aren't related to the effect of the patch anymore, it
doesn't seem useful to add them.

Belatedly committed.

	PR libstdc++-v3/54005
	* include/bits/atomic_base.h (__atomic_base<_TTp>::is_lock_free(),
	__atomic_base<_PTp*>::is_lock_free()): Call __atomic_is_lock_free
	with the type-derived _S_alignment instead of __alignof the object.
	* include/std/atomic (atomic<T>::is_lock_free()): Likewise.


brgds, H-P

Patch

Index: libstdc++-v3/include/std/atomic
===================================================================
--- libstdc++-v3/include/std/atomic	(revision 265027)
+++ libstdc++-v3/include/std/atomic	(working copy)
@@ -222,7 +222,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       {
 	// Produce a fake, minimally aligned pointer.
 	return __atomic_is_lock_free(sizeof(_M_i),
-	    reinterpret_cast<void *>(-__alignof(_M_i)));
+	    reinterpret_cast<void *>(-_S_alignment));
       }
 
       bool
@@ -230,7 +230,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       {
 	// Produce a fake, minimally aligned pointer.
 	return __atomic_is_lock_free(sizeof(_M_i),
-	    reinterpret_cast<void *>(-__alignof(_M_i)));
+	    reinterpret_cast<void *>(-_S_alignment));
       }
 
 #if __cplusplus >= 201703L
Index: libstdc++-v3/include/bits/atomic_base.h
===================================================================
--- libstdc++-v3/include/bits/atomic_base.h	(revision 265027)
+++ libstdc++-v3/include/bits/atomic_base.h	(working copy)
@@ -355,7 +355,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       {
 	// Use a fake, minimally aligned pointer.
 	return __atomic_is_lock_free(sizeof(_M_i),
-	    reinterpret_cast<void *>(-__alignof(_M_i)));
+	    reinterpret_cast<void *>(-_S_alignment));
       }
 
       bool
@@ -363,7 +363,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       {
 	// Use a fake, minimally aligned pointer.
 	return __atomic_is_lock_free(sizeof(_M_i),
-	    reinterpret_cast<void *>(-__alignof(_M_i)));
+	    reinterpret_cast<void *>(-_S_alignment));
       }
 
       _GLIBCXX_ALWAYS_INLINE void