Message ID | CACb0b4kFPDWmG-u-QMznjWwbCn53etpq16X2F0=Lr3ftQzX-6w@mail.gmail.com |
---|---|
State | Committed |
Commit | c15aa46cca0649b68613d3292cf71c7cc57ef78f |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3A6523858433 for <patchwork@sourceware.org>; Wed, 8 Dec 2021 23:48:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A6523858433 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1639007322; bh=QYQDgVJLb6XHEn1aSqguXJmzd13UyAtj+0zxxClIZsc=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=gFxy8Sn63QnJNeQjddKNFw3nPuyBkSJlsHKzmNCAVP+wCMQXwtJCksBt5jGKwuhy2 l80HFNA1lLmH9pggwPhBPwcPnbGRqyJ4b0vge69BD+j1hfvDWdYdbIspZD+0tKlmoq hUoay+0PWh2NW6Mzzu1aFjA9u9vlN/amUPwvctCg= 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 A55B63858433 for <gcc-patches@gcc.gnu.org>; Wed, 8 Dec 2021 23:47:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A55B63858433 Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-349-b5FUL2_UMq-gUIz5ztZfKg-1; Wed, 08 Dec 2021 18:47:24 -0500 X-MC-Unique: b5FUL2_UMq-gUIz5ztZfKg-1 Received: by mail-yb1-f197.google.com with SMTP id s7-20020a5b0447000000b005fb83901511so7228678ybp.11 for <gcc-patches@gcc.gnu.org>; Wed, 08 Dec 2021 15:47:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QYQDgVJLb6XHEn1aSqguXJmzd13UyAtj+0zxxClIZsc=; b=q5h9j5Mbksd18lurZLQXS6PUYCmwpOwT38ZdnAyss4NnyqGH9/UGzGsvcTdTFBwuPn PRwtDslJxbwcg3fK7RjMwIGQXTfW01SPIUbFDpryqwok7xJIq+igF0t3Y2dZtby06y/I Zfzf4OMHCVRzvh+DgVDcDuCYtlPZ5AqaKInttdyzeKFK5jXpOygJmZMstkb3021rehE1 fyRmyvBHwBDElNun/AcEVt6Kd+uclitIhlhiuLv2cE/ledVjO6W+Fc51xoM4waXEs9h0 m7QvfAc3YH+qZW1Lptd1O5Ksva+GyAfpXUXgsiNsi4LE2D7sSmhjbuN3ouju5S0gtrYv hbLQ== X-Gm-Message-State: AOAM530VNeU+HZeuX8a0CZNAi1jKeVxPkLjyATi+GdRo1Y4v2FEo6iSM wO8mAstxVheHf2R5nAPy4tB2/UmYMO12EMdCbrYyQQ7oCrLELwyvg/ARPjq1zmackaDcu3tfdAR As4HevEzL+VG0Ma2p48HqSNfgxuEnu9hHZw== X-Received: by 2002:a25:bcc9:: with SMTP id l9mr2270265ybm.13.1639007244389; Wed, 08 Dec 2021 15:47:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZs0PwHWwJ+GVlBEVmYG0GfDs+N+dqwwWsFKpiqKoi+j/mz9BsShdW003dmv+arQexWu8XeUlBaxZd61AZYxU= X-Received: by 2002:a25:bcc9:: with SMTP id l9mr2270241ybm.13.1639007244166; Wed, 08 Dec 2021 15:47:24 -0800 (PST) MIME-Version: 1.0 References: <CABBFi095Sn2-=DiZyLEfAP2=XCf9jA6F6uATBBe0LAK16EhogA@mail.gmail.com> <CAH6eHdQzMFVVrnaKiL5v_bF-HtC+H1reLaimN6x=9LxRxvERCg@mail.gmail.com> <CABBFi08YYQRgU-bMweP1gA_qDtKiD42JaptEsZPpG+KMYNw_WQ@mail.gmail.com> <CABBFi0-+oRNUDM3TxDetxMzhmfzrxBHJQxBvM3TWsogbM8hMZw@mail.gmail.com> <CABBFi0_QP2Psm2RbSmr38WnjX9MJgehywTfhjXRtJ3rXFsN4-w@mail.gmail.com> <CAH6eHdSH9uOpOLrH37qztYe=eRpdX=iWSYkzAaC4EOZio9ekwA@mail.gmail.com> <CAH6eHdT=WCfPt+CaAJtEN_+tbEn52X=Q7jR7_aQmktv6zs-zVg@mail.gmail.com> <CABBFi0-ZfBW4xU9GSbNe8HZaJ44cwdmO-CVjwF-X7XviXZmqow@mail.gmail.com> <CAH6eHdQmpH_jpub6YjHuwf=qXJKv0rZnHCBEV4DjBbTax73aJQ@mail.gmail.com> <CABBFi09QX=ncPgBrK7qX-mEHzodD9WDo5j9bomYgD7nkNenwug@mail.gmail.com> <CACb0b4=aEZ_jt=1hbnOfXY4w=9nfag9=yAzbNSrKwh0tGwp8dw@mail.gmail.com> <ydd7dcesyb7.fsf@CeBiTec.Uni-Bielefeld.DE> <CACb0b4mK2+6Kit3ikEFpPEabZyy=e5Jq4kcj09mGOCZpR0P3oA@mail.gmail.com> <CACb0b4kT7FN=DMoYy3WMNCY-bq88FzSf-=dUERJFy6Rad4naPw@mail.gmail.com> In-Reply-To: <CACb0b4kT7FN=DMoYy3WMNCY-bq88FzSf-=dUERJFy6Rad4naPw@mail.gmail.com> Date: Wed, 8 Dec 2021 23:47:13 +0000 Message-ID: <CACb0b4kFPDWmG-u-QMznjWwbCn53etpq16X2F0=Lr3ftQzX-6w@mail.gmail.com> Subject: [committed] libstdc++: Fix undefined shift when _Atomic_word is 64-bit To: Rainer Orth <ro@cebitec.uni-bielefeld.de> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="00000000000092fcd705d2ab1cd0" X-Spam-Status: No, score=-12.9 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_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Jonathan Wakely via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Jonathan Wakely <jwakely@redhat.com> Cc: libstdc++ <libstdc++@gcc.gnu.org>, Jonathan Wakely via Gcc-patches <gcc-patches@gcc.gnu.org> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[committed] libstdc++: Fix undefined shift when _Atomic_word is 64-bit
|
|
Commit Message
Jonathan Wakely
Dec. 8, 2021, 11:47 p.m. UTC
On Wed, 8 Dec 2021 at 19:27, Jonathan Wakely wrote: > > On Wed, 8 Dec 2021 at 19:21, Jonathan Wakely wrote: > > > > On Wed, 8 Dec 2021 at 19:17, Rainer Orth wrote: > > > > > > Hi Jonathan, > > > > > > > I've pushed this change to trunk now (it was posted and reviewed in > > > > stage 1, I just didn't get around to pushing it until now). > > > > > > > > The final version of the patch is attached to this mail. > > > > > > unfortunately, it breaks Solaris/SPARC bootstrap: > > > > > > In file included from /var/gcc/regression/master/11.4-gcc-gas/build/sparc-sun-solaris2.11/sparcv9/libstdc++-v3/include/bits/shared_ptr.h:53, > > > from /var/gcc/regression/master/11.4-gcc-gas/build/sparc-sun-solaris2.11/sparcv9/libstdc++-v3/include/memory:77, > > > from /vol/gcc/src/hg/master/local/libstdc++-v3/include/precompiled/stdc++.h:82: > > > /var/gcc/regression/master/11.4-gcc-gas/build/sparc-sun-solaris2.11/sparcv9/libstdc++-v3/include/bits/shared_ptr_base.h: In member function 'void std::_Sp_counted_base<_Lp>::_M_release() [with __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]': > > > /var/gcc/regression/master/11.4-gcc-gas/build/sparc-sun-solaris2.11/sparcv9/libstdc++-v3/include/bits/shared_ptr_base.h:329:26: error: right operand of shift expression '(1 << 64)' is greater than or equal to the precision 64 of the left operand [-fpermissive] > > > 329 | = 1LL + (1LL << (__CHAR_BIT__ * sizeof(_Atomic_word))); > > > | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > make[9]: *** [Makefile:1875: sparc-sun-solaris2.11/bits/stdc++.h.gch/O2ggnu++0x.gch] Error 1 > > > > > > For 64-bit SPARC, _Atomic_word is long. > > > > Ah yes, so we need to disable this optimization. Patch coming up ... > > Gah, I remembered to check that: > > constexpr bool __double_word > = sizeof(long long) == 2 * sizeof(_Atomic_word); > // The ref-count members follow the vptr, so are aligned to > // alignof(void*). > constexpr bool __aligned = __alignof(long long) <= alignof(void*); > if _GLIBCXX17_CONSTEXPR (__lock_free && __double_word && __aligned) > > > But for C++11 and C++14 that is a normal runtime condition not > if-constexpr, so the undefined shift still gets compiled, even though > it can never be reached at runtime. Fixed like so. Tested sparc-sun-solaris2.11, pushed to trunk. commit c15aa46cca0649b68613d3292cf71c7cc57ef78f Author: Jonathan Wakely <jwakely@redhat.com> Date: Wed Dec 8 19:36:24 2021 libstdc++: Fix undefined shift when _Atomic_word is 64-bit The check for _Atomic_word being 32-bit is just a normal runtime condition for C++11 and C++14, because it doesn't use if-constexpr. That means the 1LL << (CHAR_BIT * sizeof(_Atomic_word)) expression expands to 1LL << 64 on Solaris, which is ill-formed. This adds another indirection so that the shift width is zero if the code is unreachable. libstdc++-v3/ChangeLog: * include/bits/shared_ptr_base.h (_Sp_counted_base::_M_release()): Make shift width conditional on __double_word condition.
Comments
Hi Jonathan, >> > Ah yes, so we need to disable this optimization. Patch coming up ... >> >> Gah, I remembered to check that: >> >> constexpr bool __double_word >> = sizeof(long long) == 2 * sizeof(_Atomic_word); >> // The ref-count members follow the vptr, so are aligned to >> // alignof(void*). >> constexpr bool __aligned = __alignof(long long) <= alignof(void*); >> if _GLIBCXX17_CONSTEXPR (__lock_free && __double_word && __aligned) >> >> >> But for C++11 and C++14 that is a normal runtime condition not >> if-constexpr, so the undefined shift still gets compiled, even though >> it can never be reached at runtime. > > Fixed like so. Tested sparc-sun-solaris2.11, pushed to trunk. great, thanks a lot. Rainer
diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 90ad30947b0..f315d8f354f 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -325,8 +325,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr bool __aligned = __alignof(long long) <= alignof(void*); if _GLIBCXX17_CONSTEXPR (__lock_free && __double_word && __aligned) { - constexpr long long __unique_ref - = 1LL + (1LL << (__CHAR_BIT__ * sizeof(_Atomic_word))); + constexpr int __wordbits = __CHAR_BIT__ * sizeof(_Atomic_word); + constexpr int __shiftbits = __double_word ? __wordbits : 0; + constexpr long long __unique_ref = 1LL + (1LL << __shiftbits); auto __both_counts = reinterpret_cast<long long*>(&_M_use_count); _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_weak_count);