[gcc(refs/vendors/ibm/heads/gcc-9-branch)] libstdc++: Fix call to __glibcxx_rwlock_init (PR 94069)

Peter Bergner bergner@gcc.gnu.org
Thu Apr 23 20:51:23 GMT 2020


https://gcc.gnu.org/g:39bdebf3725d7681e5e9ba06e3862f8facef3572

commit 39bdebf3725d7681e5e9ba06e3862f8facef3572
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Mar 6 12:52:51 2020 +0000

    libstdc++: Fix call to __glibcxx_rwlock_init (PR 94069)
    
    When the target doesn't define PTHREAD_RWLOCK_INITIALIZER we use a
    wrapper around pthread_wrlock_init, but the wrapper only takes one
    argument and we try to call it with two.
    
    This went unnnoticed on most targets because they do define the
    PTHREAD_RWLOCK_INITIALIZER macro, but it causes a bootstrap failure on
    darwin8.
    
    Backport from mainline
    2020-03-06  Jonathan Wakely  <jwakely@redhat.com>
    
            PR libstdc++/94069
            * include/std/shared_mutex [!PTHREAD_RWLOCK_INITIALIZER]
            (__shared_mutex_pthread::__shared_mutex_pthread()): Remove incorrect
            second argument to __glibcxx_rwlock_init.
            * testsuite/30_threads/shared_timed_mutex/94069.cc: New test.

Diff:
---
 libstdc++-v3/ChangeLog                             | 11 +++++++++
 libstdc++-v3/include/std/shared_mutex              |  2 +-
 .../30_threads/shared_timed_mutex/94069.cc         | 28 ++++++++++++++++++++++
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 2f36d845098..ce96fe14640 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,14 @@
+2020-03-06  Jonathan Wakely  <jwakely@redhat.com>
+
+	Backport from mainline
+	2020-03-06  Jonathan Wakely  <jwakely@redhat.com>
+
+	PR libstdc++/94069
+	* include/std/shared_mutex [!PTHREAD_RWLOCK_INITIALIZER]
+	(__shared_mutex_pthread::__shared_mutex_pthread()): Remove incorrect
+	second argument to __glibcxx_rwlock_init.
+	* testsuite/30_threads/shared_timed_mutex/94069.cc: New test.
+
 2020-03-05  Jonathan Wakely  <jwakely@redhat.com>
 
 	Backport from mainline
diff --git a/libstdc++-v3/include/std/shared_mutex b/libstdc++-v3/include/std/shared_mutex
index be64144dfb0..cb998977741 100644
--- a/libstdc++-v3/include/std/shared_mutex
+++ b/libstdc++-v3/include/std/shared_mutex
@@ -158,7 +158,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   public:
     __shared_mutex_pthread()
     {
-      int __ret = __glibcxx_rwlock_init(&_M_rwlock, NULL);
+      int __ret = __glibcxx_rwlock_init(&_M_rwlock);
       if (__ret == ENOMEM)
 	__throw_bad_alloc();
       else if (__ret == EAGAIN)
diff --git a/libstdc++-v3/testsuite/30_threads/shared_timed_mutex/94069.cc b/libstdc++-v3/testsuite/30_threads/shared_timed_mutex/94069.cc
new file mode 100644
index 00000000000..6e5cf5f0c6e
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/shared_timed_mutex/94069.cc
@@ -0,0 +1,28 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do compile }
+// { dg-options "-pthread"  }
+// { dg-require-effective-target c++14 }
+// { dg-require-effective-target pthread }
+// { dg-require-gthreads "" }
+//
+#include <pthread.h>
+// This is probably undefined, but we do it to simulate a Pthreads target
+// that doesn't define the macro:
+#undef PTHREAD_RWLOCK_INITIALIZER
+#include <shared_mutex>


More information about the Libstdc++-cvs mailing list