From patchwork Tue Dec 1 14:15:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1408861 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (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=DS9//cRw; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Clkdq3LTMz9sVk for ; Wed, 2 Dec 2020 01:15:24 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D184A388A40B; Tue, 1 Dec 2020 14:15:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D184A388A40B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1606832121; bh=LdF95iB/kWH2J1Rh88zwmk2ew7Uf9t/dE0fvUISWptg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DS9//cRwndFV3l9PYiW7fyunezgKuhSPiRZKsfHCGqjZoqkPjgL2WIjBig1QBiDuT PF9dpADPbe6zOIuRlo4+qZwIEZAg84kkq//wm7BU8ErN24OjUwXzVwsADb2Xwq6xX0 8R4PAdsFJwIdOsP0uwUPPpod5+hkvuzl5gEV0jDY= 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 [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id E33FF3857C46 for ; Tue, 1 Dec 2020 14:15:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E33FF3857C46 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-372-fzBk04eOPqyggNShzaPp7Q-1; Tue, 01 Dec 2020 09:15:16 -0500 X-MC-Unique: fzBk04eOPqyggNShzaPp7Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D44118C89E2; Tue, 1 Dec 2020 14:15:15 +0000 (UTC) Received: from localhost (unknown [10.33.37.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28D4260877; Tue, 1 Dec 2020 14:15:14 +0000 (UTC) Date: Tue, 1 Dec 2020 14:15:14 +0000 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Simplify detection of built-in functions Message-ID: <20201201141514.GA2754940@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-15.3 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_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" This fixes a regression affecting the Intel compiler. Because that compiler defines __GNUC__ to match whatever version of GCC it finds on the host system, it might claim to be a brand new GCC despite not actually supporting all the built-ins that the latest GCC supports. This means the config checks for __GNUC__ don't work. Most recently this broke when r11-3569-g73ae6eb572515ad627b575a7fbdfdd47a4368e1c switched us from using __is_same_as to __is_same when __GNUC__ >= 11. Because __has_builtin is supported by all of GCC, Clang, and Intel we can use that to reliably detect whether a given built-in is supported, instead of hardcoding anything based on __GNUC__. The big caveat is that for versions of Clang <= 9.0.0 and for (as far as I can tell) all released versions of Intel icc, __has_builtin only evaluates to true for built-ins with a name starting "__builtin_". For __is_aggregate, __is_same, and __has_unique_object_representations it's necessary to use __is_identifier to check if it's a valid identifeir token instead. The solution used in this patch is to define _GLIBCXX_HAS_BUILTIN and use that instead of using __has_builtin directly. For compilers that define __is_identifier as well as __has_builtin we use both, so that if __has_builtin evaluates to false we try again using !__is_identifier. libstdc++-v3/ChangeLog: * include/bits/c++config (_GLIBCXX_HAS_BUILTIN): Define macro to work around different implementations of __has_builtin. (_GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP) (_GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE) (_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED) (_GLIBCXX_HAVE_BUILTIN_IS_SAME, _GLIBCXX_HAVE_BUILTIN_LAUNDER): Define using _GLIBCXX_HAS_BUILTIN. Tested powerpc64le-linux. Committed to trunk. commit 6aa12274007bccbae2691a9d336c37fe167bb535 Author: Jonathan Wakely Date: Tue Dec 1 14:14:18 2020 libstdc++: Simplify detection of built-in functions This fixes a regression affecting the Intel compiler. Because that compiler defines __GNUC__ to match whatever version of GCC it finds on the host system, it might claim to be a brand new GCC despite not actually supporting all the built-ins that the latest GCC supports. This means the config checks for __GNUC__ don't work. Most recently this broke when r11-3569-g73ae6eb572515ad627b575a7fbdfdd47a4368e1c switched us from using __is_same_as to __is_same when __GNUC__ >= 11. Because __has_builtin is supported by all of GCC, Clang, and Intel we can use that to reliably detect whether a given built-in is supported, instead of hardcoding anything based on __GNUC__. The big caveat is that for versions of Clang <= 9.0.0 and for (as far as I can tell) all released versions of Intel icc, __has_builtin only evaluates to true for built-ins with a name starting "__builtin_". For __is_aggregate, __is_same, and __has_unique_object_representations it's necessary to use __is_identifier to check if it's a valid identifeir token instead. The solution used in this patch is to define _GLIBCXX_HAS_BUILTIN and use that instead of using __has_builtin directly. For compilers that define __is_identifier as well as __has_builtin we use both, so that if __has_builtin evaluates to false we try again using !__is_identifier. libstdc++-v3/ChangeLog: * include/bits/c++config (_GLIBCXX_HAS_BUILTIN): Define macro to work around different implementations of __has_builtin. (_GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP) (_GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE) (_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED) (_GLIBCXX_HAVE_BUILTIN_IS_SAME, _GLIBCXX_HAVE_BUILTIN_LAUNDER): Define using _GLIBCXX_HAS_BUILTIN. diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config index 2e6c880ad95..27302ed392e 100644 --- a/libstdc++-v3/include/bits/c++config +++ b/libstdc++-v3/include/bits/c++config @@ -653,35 +653,36 @@ namespace std #define _GLIBCXX_USE_FLOAT128 #endif -#if __GNUC__ >= 7 -// Assume these are available if the compiler claims to be a recent GCC: +#ifdef __has_builtin +# ifdef __is_identifier +// Intel and older Clang require !__is_identifier for some built-ins: +# define _GLIBCXX_HAS_BUILTIN(B) __has_builtin(B) || ! __is_identifier(B) +# else +# define _GLIBCXX_HAS_BUILTIN(B) __has_builtin(B) +# endif +#endif + +#if _GLIBCXX_HAS_BUILTIN(__has_unique_object_representations) # define _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP 1 +#endif + +#if _GLIBCXX_HAS_BUILTIN(__is_aggregate) # define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1 +#endif + +#if _GLIBCXX_HAS_BUILTIN(__builtin_is_constant_evaluated) +# define _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED 1 +#endif + +#if _GLIBCXX_HAS_BUILTIN(__is_same) +# define _GLIBCXX_HAVE_BUILTIN_IS_SAME 1 +#endif + +#if _GLIBCXX_HAS_BUILTIN(__builtin_launder) # define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1 -# if __GNUC__ >= 9 -# define _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED 1 -# endif -# if __GNUC__ >= 11 -# define _GLIBCXX_HAVE_BUILTIN_IS_SAME 1 -# endif -#elif defined(__is_identifier) && defined(__has_builtin) -// For non-GNU compilers: -# if ! __is_identifier(__has_unique_object_representations) -# define _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP 1 -# endif -# if ! __is_identifier(__is_aggregate) -# define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1 -# endif -# if __has_builtin(__builtin_launder) -# define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1 -# endif -# if __has_builtin(__builtin_is_constant_evaluated) -# define _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED 1 -# endif -# if ! __is_identifier(__is_same) -# define _GLIBCXX_HAVE_BUILTIN_IS_SAME 1 -# endif -#endif // GCC +#endif + +#undef _GLIBCXX_HAS_BUILTIN #if _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED # define __glibcxx_assert_1(_Condition) \