From patchwork Fri Sep 27 15:44:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1990339 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=EuCRu8fB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4XFZYN0cn3z1xt9 for ; Sat, 28 Sep 2024 01:45:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F8E6385DDEB for ; Fri, 27 Sep 2024 15:45:24 +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 ESMTP id B430A3858D37 for ; Fri, 27 Sep 2024 15:44:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B430A3858D37 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 B430A3858D37 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=1727451898; cv=none; b=pOyCSqcUAsCEPEvKfLYMHUFQFvyVAhFNxK/o1tTsYKiVSkBCtJKtUKK9CCxaYMukPjdLaF1PXLSXWPupZ4m0zwFJxRRdQ4p0RKOcjmNxCEGetwWVlR4Bu1wWFlSZcrdy3bdb1KRaNZaiV29/Yw+8d04sE64d5YifBmwWdeRZWuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727451898; c=relaxed/simple; bh=SAWmmO1DVTSGj9uOvWN+giJSgSTs745v3l709t6SNTU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fDEqY+ME6m5w578m/ASg9+cIKUOBjfG0y3dCE5xTd9/UbuIQbFYNsW82XHmjct+ojev/MqkODh5xDj6MP/J7OQJjmOWHyAe1lkasFUiz+MtXzqm914MuPmglUYITQo80Z7winlTykhiB4BPUfQbpBId6jq3Wkin/qkCOrZxnBDA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727451895; 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=mDyaqKYpb9R0XqdqO7a6QHoOmVWfm4GeC5ZKi7gr7UI=; b=EuCRu8fBY2Sbbb1gWhyHtyKF5wRyrmkJ0p4HqY6FgW4vLYzQa0RMHxPSSfKsv3NEOPF8om vjGcQWrMlDY7f6Jar8H+8mevu0NjpTraRnW5eldpL3hiP0yhC3BuHFWKGJFwAkkWHE4wTx Bs7qzt+Qk9dooyZNGgfdRQ1z5OSVCpg= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-UjkjbyQyOcOzGDqOH0lfXw-1; Fri, 27 Sep 2024 11:44:52 -0400 X-MC-Unique: UjkjbyQyOcOzGDqOH0lfXw-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.40]) (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 mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8E1661880301; Fri, 27 Sep 2024 15:44:50 +0000 (UTC) Received: from localhost (unknown [10.42.28.136]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EEE82191C66F; Fri, 27 Sep 2024 15:44:46 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix test FAIL due to -Wpointer-arith Date: Fri, 27 Sep 2024 16:44:31 +0100 Message-ID: <20240927154445.2277705-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, 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 -- This fixes a FAIL due to a -Wpointer-arith warning when testing with c++11 or c++14 dialects. As an extension our std::atomic supports pointer arithmetic in C++11 and C++14, but due to the system header changes there is now a warning about it. The warning seems reasonable, so rather than suppress it we should make the test expect it. While looking into this I decided to simplify some of the code related to atomic arithmetic. libstdc++-v3/ChangeLog: * include/bits/atomic_base.h (__atomic_base::_M_type_size): Replace overloaded functions with static _S_type_size. * include/std/atomic (atomic): Use is_object_v instead of is_object. * testsuite/29_atomics/atomic/operators/pointer_partial_void.cc: Add dg-warning for -Wpointer-arith warning. --- libstdc++-v3/include/bits/atomic_base.h | 33 +++++++++---------- libstdc++-v3/include/std/atomic | 32 +++++++++--------- .../atomic/operators/pointer_partial_void.cc | 1 + 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h index 7093d0fc822..72cc4bae6cf 100644 --- a/libstdc++-v3/include/bits/atomic_base.h +++ b/libstdc++-v3/include/bits/atomic_base.h @@ -687,12 +687,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __pointer_type _M_p _GLIBCXX20_INIT(nullptr); - // Factored out to facilitate explicit specialization. - constexpr ptrdiff_t - _M_type_size(ptrdiff_t __d) const { return __d * sizeof(_PTp); } - - constexpr ptrdiff_t - _M_type_size(ptrdiff_t __d) const volatile { return __d * sizeof(_PTp); } + static constexpr ptrdiff_t + _S_type_size(ptrdiff_t __d) + { return __d * sizeof(_PTp); } public: __atomic_base() noexcept = default; @@ -742,42 +739,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __pointer_type operator++() noexcept - { return __atomic_add_fetch(&_M_p, _M_type_size(1), + { return __atomic_add_fetch(&_M_p, _S_type_size(1), int(memory_order_seq_cst)); } __pointer_type operator++() volatile noexcept - { return __atomic_add_fetch(&_M_p, _M_type_size(1), + { return __atomic_add_fetch(&_M_p, _S_type_size(1), int(memory_order_seq_cst)); } __pointer_type operator--() noexcept - { return __atomic_sub_fetch(&_M_p, _M_type_size(1), + { return __atomic_sub_fetch(&_M_p, _S_type_size(1), int(memory_order_seq_cst)); } __pointer_type operator--() volatile noexcept - { return __atomic_sub_fetch(&_M_p, _M_type_size(1), + { return __atomic_sub_fetch(&_M_p, _S_type_size(1), int(memory_order_seq_cst)); } __pointer_type operator+=(ptrdiff_t __d) noexcept - { return __atomic_add_fetch(&_M_p, _M_type_size(__d), + { return __atomic_add_fetch(&_M_p, _S_type_size(__d), int(memory_order_seq_cst)); } __pointer_type operator+=(ptrdiff_t __d) volatile noexcept - { return __atomic_add_fetch(&_M_p, _M_type_size(__d), + { return __atomic_add_fetch(&_M_p, _S_type_size(__d), int(memory_order_seq_cst)); } __pointer_type operator-=(ptrdiff_t __d) noexcept - { return __atomic_sub_fetch(&_M_p, _M_type_size(__d), + { return __atomic_sub_fetch(&_M_p, _S_type_size(__d), int(memory_order_seq_cst)); } __pointer_type operator-=(ptrdiff_t __d) volatile noexcept - { return __atomic_sub_fetch(&_M_p, _M_type_size(__d), + { return __atomic_sub_fetch(&_M_p, _S_type_size(__d), int(memory_order_seq_cst)); } bool @@ -932,22 +929,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_ALWAYS_INLINE __pointer_type fetch_add(ptrdiff_t __d, memory_order __m = memory_order_seq_cst) noexcept - { return __atomic_fetch_add(&_M_p, _M_type_size(__d), int(__m)); } + { return __atomic_fetch_add(&_M_p, _S_type_size(__d), int(__m)); } _GLIBCXX_ALWAYS_INLINE __pointer_type fetch_add(ptrdiff_t __d, memory_order __m = memory_order_seq_cst) volatile noexcept - { return __atomic_fetch_add(&_M_p, _M_type_size(__d), int(__m)); } + { return __atomic_fetch_add(&_M_p, _S_type_size(__d), int(__m)); } _GLIBCXX_ALWAYS_INLINE __pointer_type fetch_sub(ptrdiff_t __d, memory_order __m = memory_order_seq_cst) noexcept - { return __atomic_fetch_sub(&_M_p, _M_type_size(__d), int(__m)); } + { return __atomic_fetch_sub(&_M_p, _S_type_size(__d), int(__m)); } _GLIBCXX_ALWAYS_INLINE __pointer_type fetch_sub(ptrdiff_t __d, memory_order __m = memory_order_seq_cst) volatile noexcept - { return __atomic_fetch_sub(&_M_p, _M_type_size(__d), int(__m)); } + { return __atomic_fetch_sub(&_M_p, _S_type_size(__d), int(__m)); } }; namespace __atomic_impl diff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic index 37fd7103bd9..c0568d3320b 100644 --- a/libstdc++-v3/include/std/atomic +++ b/libstdc++-v3/include/std/atomic @@ -453,7 +453,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator++(int) noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return _M_b++; } @@ -462,7 +462,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator++(int) volatile noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return _M_b++; } @@ -471,7 +471,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator--(int) noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return _M_b--; } @@ -480,7 +480,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator--(int) volatile noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return _M_b--; } @@ -489,7 +489,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator++() noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return ++_M_b; } @@ -498,7 +498,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator++() volatile noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return ++_M_b; } @@ -507,7 +507,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator--() noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return --_M_b; } @@ -516,7 +516,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator--() volatile noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return --_M_b; } @@ -525,7 +525,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator+=(ptrdiff_t __d) noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return _M_b.operator+=(__d); } @@ -534,7 +534,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator+=(ptrdiff_t __d) volatile noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return _M_b.operator+=(__d); } @@ -543,7 +543,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator-=(ptrdiff_t __d) noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return _M_b.operator-=(__d); } @@ -552,7 +552,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator-=(ptrdiff_t __d) volatile noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return _M_b.operator-=(__d); } @@ -673,7 +673,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION memory_order __m = memory_order_seq_cst) noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return _M_b.fetch_add(__d, __m); } @@ -683,7 +683,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION memory_order __m = memory_order_seq_cst) volatile noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return _M_b.fetch_add(__d, __m); } @@ -693,7 +693,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION memory_order __m = memory_order_seq_cst) noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return _M_b.fetch_sub(__d, __m); } @@ -703,7 +703,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION memory_order __m = memory_order_seq_cst) volatile noexcept { #if __cplusplus >= 201703L - static_assert( is_object<_Tp>::value, "pointer to object type" ); + static_assert( is_object_v<_Tp>, "pointer to object type" ); #endif return _M_b.fetch_sub(__d, __m); } diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/operators/pointer_partial_void.cc b/libstdc++-v3/testsuite/29_atomics/atomic/operators/pointer_partial_void.cc index cef43ec26f3..60f6a624aae 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic/operators/pointer_partial_void.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic/operators/pointer_partial_void.cc @@ -68,3 +68,4 @@ int main(void) return 0; } +// { dg-warning "invalid application of 'sizeof' to a void type" "" { target *-*-* } 0 }