From patchwork Wed May 15 09:19:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1935404 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=XIVoM078; 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 4VfSP373nqz1ymf for ; Wed, 15 May 2024 19:20:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2DE1C384AB64 for ; Wed, 15 May 2024 09:20:06 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id DA1E1384AB54 for ; Wed, 15 May 2024 09:19:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA1E1384AB54 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 DA1E1384AB54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715764781; cv=none; b=XJdXbRhbygLvBq6F25+QfWlbEZarH+VVWhNxDcLJhzyFZ362ucd4Ig4Jw6zZOKOfB5vkWxhDMdkSIUHXFleGIsT4IDq6JQ/6oh/E29ZsP78Rd+kxHU6Bv2NQOo7OTMLdNrUbtXUU7lMQm5zoheVRDl8ti1rGd+Pn8kw1RxU8E0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715764781; c=relaxed/simple; bh=THZjUyNVgA7kPk3FxlwtkQdajXno2CO6XY+N9ZAbDf4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZhazWAMqpTCsehUJSnyBQ9p226tpCtoWn5kPtrpDaS946gSUcLtcOLvkiirV/nYFgCCAp74F1YC6uJpRLtpihdZFiWE1hrAraUvPAt41eBcrdgpqBz0JrkS1BSz0esEgmLtovjoIMCc/lMwmyA6VU6G5cMGzOD8nRmUnY/Nq52s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715764779; 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=U6VEySlbB++S/2kYJcrqW+15tdpm+VuruNHr4VgkAj8=; b=XIVoM078ia85QZTJE4RHhYxMks7dr2nIn/XSTebsJmsfh2o4B/6yfT+qjt9vAJ0iwh615L +U9BRzNMMldnQh5W6rjTDfL6XhUU8FSUV58ppqdUTNRCPoB+DOMrzfqod4nk+7b4u3tU+w XyY06wKXcOjr5E1WqeTgBEAUmpZLb9Y= 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-393-Qa98pkxOP2uDe3q9y_JYpg-1; Wed, 15 May 2024 05:19:36 -0400 X-MC-Unique: Qa98pkxOP2uDe3q9y_JYpg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 2BC303C0008E; Wed, 15 May 2024 09:19:36 +0000 (UTC) Received: from localhost (unknown [10.42.28.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFB1D400057; Wed, 15 May 2024 09:19:35 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Give std::memory_order a fixed underlying type [PR89624] Date: Wed, 15 May 2024 10:19:22 +0100 Message-ID: <20240515091935.525056-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 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 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 -- Prior to C++20 this enum type doesn't have a fixed underlying type, which means it can be modified by -fshort-enums, which then means the HLE bits are outside the range of valid values for the type. As it has a fixed type of int in C++20 and later, do the same for earlier standards too. This is technically a change for C++17 down, because the implicit underlying type (without -fshort-enums) was unsigned before. I doubt it matters in practice. That incompatibility already exists between C++17 and C++20 and nobody has noticed or complained. Now at least the underlying type will be int for all -std modes. libstdc++-v3/ChangeLog: PR libstdc++/89624 * include/bits/atomic_base.h (memory_order): Use int as underlying type. * testsuite/29_atomics/atomic/89624.cc: New test. --- libstdc++-v3/include/bits/atomic_base.h | 4 ++-- libstdc++-v3/testsuite/29_atomics/atomic/89624.cc | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/89624.cc diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h index dd360302f80..062f1549740 100644 --- a/libstdc++-v3/include/bits/atomic_base.h +++ b/libstdc++-v3/include/bits/atomic_base.h @@ -78,7 +78,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline constexpr memory_order memory_order_acq_rel = memory_order::acq_rel; inline constexpr memory_order memory_order_seq_cst = memory_order::seq_cst; #else - typedef enum memory_order + enum memory_order : int { memory_order_relaxed, memory_order_consume, @@ -86,7 +86,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION memory_order_release, memory_order_acq_rel, memory_order_seq_cst - } memory_order; + }; #endif /// @cond undocumented diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/89624.cc b/libstdc++-v3/testsuite/29_atomics/atomic/89624.cc new file mode 100644 index 00000000000..480f7c65e2d --- /dev/null +++ b/libstdc++-v3/testsuite/29_atomics/atomic/89624.cc @@ -0,0 +1,9 @@ +// { dg-options "-fshort-enums" } +// { dg-do compile { target c++11 } } + +// Bug 89624 HLE bits don't work with -fshort-enums or -fstrict-enums + +#include + +static_assert((std::memory_order_acquire | std::__memory_order_hle_acquire) + != std::memory_order_acquire, "HLE acquire sets a bit");