libstdc++: Fix Wrong param type in :atomic_ref<_Tp*>::wait [PR100889]

Message ID 20210608002843.945023-1-rodgert@appliantology.com
State New
Headers show
Series
  • libstdc++: Fix Wrong param type in :atomic_ref<_Tp*>::wait [PR100889]
Related show

Commit Message

Thomas Rodgers June 8, 2021, 12:28 a.m.
This time without the repeatred [PRnnnn] in the subject line.

Fixes libstdc++/100889

libstdc++-v3/ChangeLog:

	* include/bits/atomic_base.h (atomic_ref<_Tp*>::wait):
	Change parameter type from _Tp to _Tp*.
	* testsuite/29_atomics/atomic_ref/wait_notify.cc: Extend
	coverage of types tested.
---
 libstdc++-v3/include/bits/atomic_base.h       |  2 +-
 .../29_atomics/atomic_ref/wait_notify.cc      | 38 ++++++++++++-------
 2 files changed, 26 insertions(+), 14 deletions(-)

-- 
2.26.2

Comments

Matt Jacobson via Gcc-patches June 8, 2021, 3:44 p.m. | #1
On Tue, 8 Jun 2021 at 01:29, Thomas Rodgers wrote:

> This time without the repeatred [PRnnnn] in the subject line.

>

> Fixes libstdc++/100889

>


This should be part of the ChangeLog entry instead, preceded by PR so it
updates bugzilla, i.e.



> libstdc++-v3/ChangeLog:

>


<TAB>PR libstdc++/100889


>         * include/bits/atomic_base.h (atomic_ref<_Tp*>::wait):

>         Change parameter type from _Tp to _Tp*.

>         * testsuite/29_atomics/atomic_ref/wait_notify.cc: Extend

>         coverage of types tested.

>



OK for trunk and gcc-11 with that change, thanks.
Matt Jacobson via Gcc-patches June 8, 2021, 11:03 p.m. | #2
Tested x86_64-pc-linux-gnu, committed to master, backported to
releases/gcc-11.

On Tue, Jun 8, 2021 at 8:44 AM Jonathan Wakely <jwakely@redhat.com> wrote:

> On Tue, 8 Jun 2021 at 01:29, Thomas Rodgers wrote:

>

>> This time without the repeatred [PRnnnn] in the subject line.

>>

>> Fixes libstdc++/100889

>>

>

> This should be part of the ChangeLog entry instead, preceded by PR so it

> updates bugzilla, i.e.

>

>

>

>> libstdc++-v3/ChangeLog:

>>

>

> <TAB>PR libstdc++/100889

>

>

>>         * include/bits/atomic_base.h (atomic_ref<_Tp*>::wait):

>>         Change parameter type from _Tp to _Tp*.

>>         * testsuite/29_atomics/atomic_ref/wait_notify.cc: Extend

>>         coverage of types tested.

>>

>

>

> OK for trunk and gcc-11 with that change, thanks.

>

>

>

>
Matt Jacobson via Gcc-patches June 9, 2021, 2:30 p.m. | #3
Hi,


On Wed, 9 Jun 2021 at 01:05, Thomas Rodgers via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>

> Tested x86_64-pc-linux-gnu, committed to master, backported to

> releases/gcc-11.

>

> On Tue, Jun 8, 2021 at 8:44 AM Jonathan Wakely <jwakely@redhat.com> wrote:

>

> > On Tue, 8 Jun 2021 at 01:29, Thomas Rodgers wrote:

> >

> >> This time without the repeatred [PRnnnn] in the subject line.

> >>

> >> Fixes libstdc++/100889

> >>

> >

> > This should be part of the ChangeLog entry instead, preceded by PR so it

> > updates bugzilla, i.e.

> >

> >

> >

> >> libstdc++-v3/ChangeLog:

> >>

> >

> > <TAB>PR libstdc++/100889

> >

> >

> >>         * include/bits/atomic_base.h (atomic_ref<_Tp*>::wait):

> >>         Change parameter type from _Tp to _Tp*.

> >>         * testsuite/29_atomics/atomic_ref/wait_notify.cc: Extend

> >>         coverage of types tested.

> >>

> >

> >

> > OK for trunk and gcc-11 with that change, thanks.

> >

> >


This is causing a regression on old arm targets:
--target arm-none-linux-gnueabi
RUNTESTFLAGS: -march=armv5t

FAIL: 29_atomics/atomic_ref/wait_notify.cc (test for excess errors)
Excess errors:
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-linux-gnueabi/bin/ld:
/ccaaHfBz.o: in function `void
std::__atomic_impl::store<double>(double*,
std::remove_volatile<double>::type, std::memory_order)':
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/include/bits/atomic_base.h:971:
undefined reference to `__atomic_store_8'
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-linux-gnueabi/bin/ld:
/ccaaHfBz.o: in function `std::remove_volatile<double>::type
std::__atomic_impl::load<double>(double const*, std::memory_order)':
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/include/bits/atomic_base.h:979:
undefined reference to `__atomic_load_8'
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-linux-gnueabi/bin/ld:
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/include/bits/atomic_base.h:979:
undefined reference to `__atomic_load_8'
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-linux-gnueabi/bin/ld:
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/include/bits/atomic_base.h:979:
undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status

Can you check?

Thanks
Matt Jacobson via Gcc-patches June 9, 2021, 2:52 p.m. | #4
Pretty sure I know this is, I'll work on a fix today.

On Wed, Jun 9, 2021 at 7:30 AM Christophe Lyon <christophe.lyon@linaro.org>
wrote:

> Hi,

>

>

> On Wed, 9 Jun 2021 at 01:05, Thomas Rodgers via Gcc-patches

> <gcc-patches@gcc.gnu.org> wrote:

> >

> > Tested x86_64-pc-linux-gnu, committed to master, backported to

> > releases/gcc-11.

> >

> > On Tue, Jun 8, 2021 at 8:44 AM Jonathan Wakely <jwakely@redhat.com>

> wrote:

> >

> > > On Tue, 8 Jun 2021 at 01:29, Thomas Rodgers wrote:

> > >

> > >> This time without the repeatred [PRnnnn] in the subject line.

> > >>

> > >> Fixes libstdc++/100889

> > >>

> > >

> > > This should be part of the ChangeLog entry instead, preceded by PR so

> it

> > > updates bugzilla, i.e.

> > >

> > >

> > >

> > >> libstdc++-v3/ChangeLog:

> > >>

> > >

> > > <TAB>PR libstdc++/100889

> > >

> > >

> > >>         * include/bits/atomic_base.h (atomic_ref<_Tp*>::wait):

> > >>         Change parameter type from _Tp to _Tp*.

> > >>         * testsuite/29_atomics/atomic_ref/wait_notify.cc: Extend

> > >>         coverage of types tested.

> > >>

> > >

> > >

> > > OK for trunk and gcc-11 with that change, thanks.

> > >

> > >

>

> This is causing a regression on old arm targets:

> --target arm-none-linux-gnueabi

> RUNTESTFLAGS: -march=armv5t

>

> FAIL: 29_atomics/atomic_ref/wait_notify.cc (test for excess errors)

> Excess errors:

> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-linux-gnueabi/bin/ld:

> /ccaaHfBz.o: in function `void

> std::__atomic_impl::store<double>(double*,

> std::remove_volatile<double>::type, std::memory_order)':

>

> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/include/bits/atomic_base.h:971:

> undefined reference to `__atomic_store_8'

> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-linux-gnueabi/bin/ld:

> /ccaaHfBz.o: in function `std::remove_volatile<double>::type

> std::__atomic_impl::load<double>(double const*, std::memory_order)':

>

> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/include/bits/atomic_base.h:979:

> undefined reference to `__atomic_load_8'

> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-linux-gnueabi/bin/ld:

>

> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/include/bits/atomic_base.h:979:

> undefined reference to `__atomic_load_8'

> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-linux-gnueabi/bin/ld:

>

> /aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/include/bits/atomic_base.h:979:

> undefined reference to `__atomic_load_8'

> collect2: error: ld returned 1 exit status

>

> Can you check?

>

> Thanks

>

>
Matt Jacobson via Gcc-patches June 9, 2021, 3:11 p.m. | #5
For other tests that don't link to libatomic we use if-constexpr to
limit which types we test e.g.

--- a/libstdc++-v3/testsuite/29_atomics/atomic_ref/wait_notify.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_ref/wait_notify.cc
@@ -33,14 +33,17 @@ template<typename S>
    S aa{ va };
    S bb{ vb };
    std::atomic_ref<S> a{ aa };
-    a.wait(bb);
-    std::thread t([&]
+    if constexpr (std::atomic_ref<S>::is_always_lock_free)
      {
-       a.store(bb);
-       a.notify_one();
-      });
-    a.wait(aa);
-    t.join();
+       a.wait(bb);
+       std::thread t([&]
+         {
+           a.store(bb);
+           a.notify_one();
+         });
+       a.wait(aa);
+       t.join();
+      }
  }

int


Alternatively we could add arm*-*-* to the targets in
add_options_for_libatomic in testsuite/lib/dg-options.exp

Patch

diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 029b8ad65a9..20cf1343c58 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -1870,7 +1870,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #if __cpp_lib_atomic_wait
       _GLIBCXX_ALWAYS_INLINE void
-      wait(_Tp __old, memory_order __m = memory_order_seq_cst) const noexcept
+      wait(_Tp* __old, memory_order __m = memory_order_seq_cst) const noexcept
       { __atomic_impl::wait(_M_ptr, __old, __m); }
 
       // TODO add const volatile overload
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_ref/wait_notify.cc b/libstdc++-v3/testsuite/29_atomics/atomic_ref/wait_notify.cc
index 2fd31304222..2500dddf884 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_ref/wait_notify.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_ref/wait_notify.cc
@@ -26,22 +26,34 @@ 
 
 #include <testsuite_hooks.h>
 
+template<typename S>
+  void
+  test (S va, S vb)
+  {
+    S aa{ va };
+    S bb{ vb };
+    std::atomic_ref<S> a{ aa };
+    a.wait(bb);
+    std::thread t([&]
+      {
+        a.store(bb);
+        a.notify_one();
+      });
+    a.wait(aa);
+    t.join();
+  }
+
 int
 main ()
 {
+  test<int>(0, 42);
+  test<long>(0, 42);
+  test<unsigned>(0u, 42u);
+  test<float>(0.0f, 42.0f);
+  test<double>(0.0, 42.0);
+  test<void*>(nullptr, reinterpret_cast<void*>(42));
+
   struct S{ int i; };
-  S aa{ 0 };
-  S bb{ 42 };
-
-  std::atomic_ref<S> a{ aa };
-  VERIFY( a.load().i == aa.i );
-  a.wait(bb);
-  std::thread t([&]
-    {
-      a.store(bb);
-      a.notify_one();
-    });
-  a.wait(aa);
-  t.join();
+  test<S>(S{ 0 }, S{ 42 });
   return 0;
 }