From patchwork Wed May 27 22:11:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1299250 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=hhNvsoOm; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49XQ670q1Gz9sRY for ; Thu, 28 May 2020 08:11:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CF4CB395B801; Wed, 27 May 2020 22:11:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CF4CB395B801 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1590617497; bh=uP7d/XDtqbAHCf5w3dAqZa0nC7FwtQTJGRQTLVyqRcA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=hhNvsoOmNOVIcLb3XGRRAtn3GYJ/bEyZkw84gHOH1T5RThldZyg8HKepIauLJYoAG d5m3rq8awkjkBEDOIj08achlwoJdRrhRM1tJcMGDvTyDGTUDzGoW2UUMhSHkL1roU7 PzbUyzn2nMftU1cC/IGvVYDKKXJsy8dpz6bDhd+0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id 64CED388B030 for ; Wed, 27 May 2020 22:11:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 64CED388B030 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-281-Gd1COAd-NHygsjnHLNwsGw-1; Wed, 27 May 2020 18:11:29 -0400 X-MC-Unique: Gd1COAd-NHygsjnHLNwsGw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CA48F460; Wed, 27 May 2020 22:11:28 +0000 (UTC) Received: from localhost (unknown [10.33.36.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 419A0768AD; Wed, 27 May 2020 22:11:27 +0000 (UTC) Date: Wed, 27 May 2020 23:11:27 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix atomic::load (PR 95282) Message-ID: <20200527221127.GA3050184@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" PR libstdc++/95282 * include/bits/atomic_base.h (__atomic_impl::load): Add cv-qualifiers to parameter so that _Tp is deduced as the unqualified type. * testsuite/29_atomics/atomic_float/95282.cc: New test. Tested powerpc64le-linbux, committed to master. Backport to gcc-10 to follow. I've added this testcase to my out-of-testsuite clang tests. commit bbaec68c86f8e89a3460cc022c75d4c4179bfb0a Author: Jonathan Wakely Date: Wed May 27 22:55:21 2020 +0100 libstdc++: Fix atomic::load (PR 95282) PR libstdc++/95282 * include/bits/atomic_base.h (__atomic_impl::load): Add cv-qualifiers to parameter so that _Tp is deduced as the unqualified type. * testsuite/29_atomics/atomic_float/95282.cc: New test. diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h index 3b66b040976..01f77a0f372 100644 --- a/libstdc++-v3/include/bits/atomic_base.h +++ b/libstdc++-v3/include/bits/atomic_base.h @@ -871,7 +871,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template _GLIBCXX_ALWAYS_INLINE _Tp - load(_Tp* __ptr, memory_order __m) noexcept + load(const volatile _Tp* __ptr, memory_order __m) noexcept { alignas(_Tp) unsigned char __buf[sizeof(_Tp)]; _Tp* __dest = reinterpret_cast<_Tp*>(__buf); diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_float/95282.cc b/libstdc++-v3/testsuite/29_atomics/atomic_float/95282.cc new file mode 100644 index 00000000000..2de751c6ad4 --- /dev/null +++ b/libstdc++-v3/testsuite/29_atomics/atomic_float/95282.cc @@ -0,0 +1,35 @@ +// 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 +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +float +test01() +{ + std::atomic a; + return a.load(); +} + +float +test02() +{ + volatile std::atomic a; + return a.load(); +}