From patchwork Fri Sep 29 10:42:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 146485 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3928034vqu; Fri, 29 Sep 2023 03:42:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTIb7qb3hVOejjBZzV7bag7rRx6dPoiRngn0fpCWKp0SRcsurxpnUx/FP8/v98zkQHV8h6 X-Received: by 2002:a17:906:5185:b0:9ae:6da8:1819 with SMTP id y5-20020a170906518500b009ae6da81819mr3954792ejk.48.1695984167700; Fri, 29 Sep 2023 03:42:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695984167; cv=none; d=google.com; s=arc-20160816; b=e1WcQDAz/ENayhw3jS2KGTOc+ls+b+XcttzdcbnlXMlVXYnYc1udzTT7PBRX2JcmDf Qm3JW4egpONZuO0PPOhRgtGWZ383mQtEzVDFrttJISlYDsg/V4iAUyu49iBwQw3y1E1M Xe+HuZ8OjSgB4PLOR52dDhV4EOHoMTPgVZzlZ6hv1rkJtH0PTwVTI/6VrnP5OzGCX1Tt oBsu4zxRXlW/R7QbqhffLPdwJOsWxKlVUR/56T3f+G7jYEdKV37GcqNW/rqyLTbGMSmJ nImXV21Uj14IUE509cM0H4f5YZR8qaH86yIBDEv5v3Fi7KgCXlfQ4NOhzsZI4vHnYiXk 0d9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :dmarc-filter:delivered-to; bh=Amtlak050ZdHDtXJdpFdO4B1XPykgUPOmpfp/S5bch8=; fh=oayCf35IQVLSJXM2OPEoTR08ZJTh4x/UL/3gykff6VM=; b=k71qVxar0bLwuOMJftvSmRTbyZuecEi352eq6A92fNwD6nFTDkugVLU9QvHb90dMrZ S6sbFLi0J+UYTUKa5Yh9Gudew3Sui+okHzwR6Ovu4mOyYbh9BZr3IZOvBxQyu73/xz2q M1xIMtSU+eUft70zIa5aclk2f1RidNL/DczQXs00PDKIN9MTwAwlnzTDaOzkIP/UZK6e eoqu1Q+zO2W9+FHBJDcy0nEK5D+YuMydHqIfkx04OlsOFxdwcBrjJ2/879w3xerBtcrH Twg2ieRZ7dJGhHI87N3rbrkCcGqsa4dWTK8Tai9UpaJvq5rSjv0yrJaTRwNpF1m6TOPC GmpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IHWkWlpx; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u24-20020a170906951800b0099cb6622adasi15127048ejx.205.2023.09.29.03.42.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 03:42:47 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IHWkWlpx; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 305EF38708BC for ; Fri, 29 Sep 2023 10:42:43 +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 80C963858C78 for ; Fri, 29 Sep 2023 10:42:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80C963858C78 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695984139; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=Amtlak050ZdHDtXJdpFdO4B1XPykgUPOmpfp/S5bch8=; b=IHWkWlpxwy5tZkSfOzXCUNimsCaLTjDJOHwZCl2RGkR5WPBz2IWrdywv2rOnKEVnvhRN1L rQOXQueUs2aqnq9f4jyIa6c+8Bq01ZC9chLo9mnXfneavJYxax/ZnQ0hE3VpQQAhtAxeNB wLlSfU8F8ttgA34u7AsWHJk3xfn6cGg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-602-8Px-UTzoN2Grc1aMA-WCYQ-1; Fri, 29 Sep 2023 06:42:15 -0400 X-MC-Unique: 8Px-UTzoN2Grc1aMA-WCYQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6EE978002B2; Fri, 29 Sep 2023 10:42:15 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.202]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3088940C2064; Fri, 29 Sep 2023 10:42:15 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 38TAgC4f992301 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 29 Sep 2023 12:42:12 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 38TAgBYo992300; Fri, 29 Sep 2023 12:42:11 +0200 Date: Fri, 29 Sep 2023 12:42:11 +0200 From: Jakub Jelinek To: Richard Biener , Jonathan Wakely Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] vec.h: Guard most of static assertions for GCC >= 5 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778368294545562009 X-GMAIL-MSGID: 1778368294545562009 Hi! As reported by Jonathan on IRC, my vec.h patch broke build with GCC 4.8.x or 4.9.x as system compiler, e.g. on CFarm. The problem is that while all of std::is_trivially_{destructible,copyable,default_constructible} traits are in C++, only std::is_trivially_destructible has been implemented in GCC 4.8, the latter two were added only in GCC 5. Only std::is_trivially_destructible is the really important one though, which is used to decide what pop returns and whether to invoke the destructors or not. The rest are solely used in static_asserts and as such I think it is acceptable if we don't assert those when built with GCC 4.8 or 4.9, anybody doing bootstrap from those system compilers or doing builds with newer GCC will catch that. So, the following patch guards those for 5+. If we switch to C++14 later on and start requiring newer version of system GCC as well (do we require GCC >= 5 which claims the last C++14 language features, or what provides all C++14 library features, or GCC >= 6 which uses -std=c++14 by default?), this patch then can be reverted. Ok for trunk? 2023-09-29 Jakub Jelinek * vec.h (quick_insert, ordered_remove, unordered_remove, block_remove, qsort, sort, stablesort, quick_grow): Guard std::is_trivially_{copyable,default_constructible} and vec_detail::is_trivially_copyable_or_pair static assertions with GCC_VERSION >= 5000. (vec_detail::is_trivially_copyable_or_pair): Guard definition with GCC_VERSION >= 5000. Jakub --- gcc/vec.h.jj 2023-09-29 10:59:09.830551963 +0200 +++ gcc/vec.h 2023-09-29 12:29:32.676428677 +0200 @@ -1086,7 +1086,12 @@ vec::quick_insert (unsig { gcc_checking_assert (length () < allocated ()); gcc_checking_assert (ix <= length ()); +#if GCC_VERSION >= 5000 + /* GCC 4.8 and 4.9 only implement std::is_trivially_destructible, + but not std::is_trivially_copyable nor + std::is_trivially_default_constructible. */ static_assert (std::is_trivially_copyable ::value, ""); +#endif T *slot = &address ()[ix]; memmove (slot + 1, slot, (m_vecpfx.m_num++ - ix) * sizeof (T)); *slot = obj; @@ -1102,7 +1107,9 @@ inline void vec::ordered_remove (unsigned ix) { gcc_checking_assert (ix < length ()); +#if GCC_VERSION >= 5000 static_assert (std::is_trivially_copyable ::value, ""); +#endif T *slot = &address ()[ix]; memmove (slot, slot + 1, (--m_vecpfx.m_num - ix) * sizeof (T)); } @@ -1150,7 +1157,9 @@ inline void vec::unordered_remove (unsigned ix) { gcc_checking_assert (ix < length ()); +#if GCC_VERSION >= 5000 static_assert (std::is_trivially_copyable ::value, ""); +#endif T *p = address (); p[ix] = p[--m_vecpfx.m_num]; } @@ -1164,13 +1173,16 @@ inline void vec::block_remove (unsigned ix, unsigned len) { gcc_checking_assert (ix + len <= length ()); +#if GCC_VERSION >= 5000 static_assert (std::is_trivially_copyable ::value, ""); +#endif T *slot = &address ()[ix]; m_vecpfx.m_num -= len; memmove (slot, slot + len, (m_vecpfx.m_num - ix) * sizeof (T)); } +#if GCC_VERSION >= 5000 namespace vec_detail { /* gcc_{qsort,qsort_r,stablesort_r} implementation under the hood @@ -1189,6 +1201,7 @@ namespace vec_detail : std::integral_constant::value && std::is_trivially_copyable::value> { }; } +#endif /* Sort the contents of this vector with qsort. CMP is the comparison function to pass to qsort. */ @@ -1197,7 +1210,9 @@ template inline void vec::qsort (int (*cmp) (const void *, const void *)) { +#if GCC_VERSION >= 5000 static_assert (vec_detail::is_trivially_copyable_or_pair ::value, ""); +#endif if (length () > 1) gcc_qsort (address (), length (), sizeof (T), cmp); } @@ -1210,7 +1225,9 @@ inline void vec::sort (int (*cmp) (const void *, const void *, void *), void *data) { +#if GCC_VERSION >= 5000 static_assert (vec_detail::is_trivially_copyable_or_pair ::value, ""); +#endif if (length () > 1) gcc_sort_r (address (), length (), sizeof (T), cmp, data); } @@ -1223,7 +1240,9 @@ inline void vec::stablesort (int (*cmp) (const void *, const void *, void *), void *data) { +#if GCC_VERSION >= 5000 static_assert (vec_detail::is_trivially_copyable_or_pair ::value, ""); +#endif if (length () > 1) gcc_stablesort_r (address (), length (), sizeof (T), cmp, data); } @@ -1396,7 +1415,9 @@ inline void vec::quick_grow (unsigned len) { gcc_checking_assert (length () <= len && len <= m_vecpfx.m_alloc); +#if GCC_VERSION >= 5000 // static_assert (std::is_trivially_default_constructible ::value, ""); +#endif m_vecpfx.m_num = len; }