From patchwork Thu Mar 7 21:00:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1909459 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=cYh7DWtg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TrMCv3Kvzz1yX4 for ; Fri, 8 Mar 2024 08:01:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 47DB53858D35 for ; Thu, 7 Mar 2024 21:01:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id DB0EE385C6EE for ; Thu, 7 Mar 2024 21:00:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB0EE385C6EE Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DB0EE385C6EE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709845236; cv=none; b=A24uwLRmrtzKAJtzzqZ6rYj3H9amFpeJIrS2J6pZOOKou77RsYnDcs2buiV6gM71HRa8XVsFJf2aolOAZhLsGllUG+9jCFRrDQsQ4yRj80Qup3PLaExp14EQq5F89tPzX6JSQYODr9okSWBB0d9W6JL7pC+rdw1JEdUHRajmsUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709845236; c=relaxed/simple; bh=RgrLE+7lXVsqI0qAC/3XF8rFrFIhzy2nuDgxTMpONCo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=oo9QiU32FC6I2GRhtA0AnaYBakU4C4XfHWDl/8WMe7RGi57rz8Dbna03mUuuJc/v0Cc71PiHfzSoIxk1fV4OPZTHwKluMo+SMrgiYvj/7NwxrL5v6/gW2iD2M0zWTBM5jdXqzRaN+0OYGe7O9w00gSIqy9Po3zkrzeqdMXtgX7s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709845233; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iVEdxaaH438g2s6oNubph8JCQ1xnK7tePEjf0yfX6d0=; b=cYh7DWtgw4Y5lNFEiYAU3BA2+K3tVaycOXFmqNhpSdyeNaFRli8gbWOyvqT+NnYuEluqDZ 3BvYg3bsbvoZhQMrj1v8VhLGYT7m9qk/yDIJYVSxuqEU4uTAjJ4XP928vBtCu1594RjIEv S9fJqkdqIOV7ZVI1wfutKMFNNT3Ej7k= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-VdCtefaEOZq6T89NWJvDyA-1; Thu, 07 Mar 2024 16:00:30 -0500 X-MC-Unique: VdCtefaEOZq6T89NWJvDyA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 215F129AC02D; Thu, 7 Mar 2024 21:00:30 +0000 (UTC) Received: from localhost (unknown [10.42.28.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3A1A1C060D6; Thu, 7 Mar 2024 21:00:29 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Do not define lock-free atomic aliases if not fully lock-free [PR114103] Date: Thu, 7 Mar 2024 21:00:16 +0000 Message-ID: <20240307210029.591657-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. -- >8 -- The whole point of these typedefs is to guarantee lock-freedom, so if the target has no such types, we shouldn't defined the typedefs at all. libstdc++-v3/ChangeLog: PR libstdc++/114103 * include/bits/version.def (atomic_lock_free_type_aliases): Add extra_cond to check for at least one always-lock-free type. * include/bits/version.h: Regenerate. * include/std/atomic (atomic_signed_lock_free) (atomic_unsigned_lock_free): Only use always-lock-free types. * src/c++20/tzdb.cc (time_zone::_Impl::RulesCounter): Don't use atomic counter if lock-free aliases aren't available. * testsuite/29_atomics/atomic/lock_free_aliases.cc: XFAIL for targets without lock-free word-size compare_exchange. --- libstdc++-v3/include/bits/version.def | 1 + libstdc++-v3/include/bits/version.h | 2 +- libstdc++-v3/include/std/atomic | 6 +++--- libstdc++-v3/src/c++20/tzdb.cc | 7 ++++++- .../testsuite/29_atomics/atomic/lock_free_aliases.cc | 1 + 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 502961eb269..d298420121b 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -739,6 +739,7 @@ ftms = { values = { v = 201907; cxxmin = 20; + extra_cond = "(__GCC_ATOMIC_INT_LOCK_FREE | __GCC_ATOMIC_LONG_LOCK_FREE | __GCC_ATOMIC_CHAR_LOCK_FREE) & 2"; }; }; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 7a6fbd35e2e..9107b45a484 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -819,7 +819,7 @@ #undef __glibcxx_want_atomic_float #if !defined(__cpp_lib_atomic_lock_free_type_aliases) -# if (__cplusplus >= 202002L) +# if (__cplusplus >= 202002L) && ((__GCC_ATOMIC_INT_LOCK_FREE | __GCC_ATOMIC_LONG_LOCK_FREE | __GCC_ATOMIC_CHAR_LOCK_FREE) & 2) # define __glibcxx_atomic_lock_free_type_aliases 201907L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_atomic_lock_free_type_aliases) # define __cpp_lib_atomic_lock_free_type_aliases 201907L diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic index 559f8370459..1462cf5ec23 100644 --- a/libstdc++-v3/include/std/atomic +++ b/libstdc++-v3/include/std/atomic @@ -1774,13 +1774,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION = atomic>; using atomic_unsigned_lock_free = atomic>; -# elif ATOMIC_INT_LOCK_FREE || !(ATOMIC_LONG_LOCK_FREE || ATOMIC_CHAR_LOCK_FREE) +# elif ATOMIC_INT_LOCK_FREE == 2 using atomic_signed_lock_free = atomic; using atomic_unsigned_lock_free = atomic; -# elif ATOMIC_LONG_LOCK_FREE +# elif ATOMIC_LONG_LOCK_FREE == 2 using atomic_signed_lock_free = atomic; using atomic_unsigned_lock_free = atomic; -# elif ATOMIC_CHAR_LOCK_FREE +# elif ATOMIC_CHAR_LOCK_FREE == 2 using atomic_signed_lock_free = atomic; using atomic_unsigned_lock_free = atomic; # else diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc index e03f4a5c32a..890a4c53e2d 100644 --- a/libstdc++-v3/src/c++20/tzdb.cc +++ b/libstdc++-v3/src/c++20/tzdb.cc @@ -651,7 +651,7 @@ namespace std::chrono template requires _Tp::is_always_lock_free struct RulesCounter<_Tp> { - atomic_signed_lock_free counter{0}; + _Tp counter{0}; void increment() @@ -703,7 +703,12 @@ namespace std::chrono }; #endif // __GTHREADS && __cpp_lib_atomic_wait +#if __cpp_lib_atomic_lock_free_type_aliases RulesCounter rules_counter; +#else + RulesCounter rules_counter; +#endif + #else // TZDB_DISABLED _Impl(weak_ptr) { } struct { diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc b/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc index 372a63129ff..489d181d136 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic/lock_free_aliases.cc @@ -1,5 +1,6 @@ // { dg-do compile { target c++20 } } // { dg-add-options no_pch } +// { dg-require-atomic-cmpxchg-word "PR libstdc++/114103" } #include