From patchwork Sun Oct 15 19:36:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Naour X-Patchwork-Id: 23580 Received: (qmail 87847 invoked by alias); 15 Oct 2017 19:37:07 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 87827 invoked by uid 89); 15 Oct 2017 19:37:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f66.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=THt7nm/WeYzwKO/E+1Ux9uZYeDNqVoFcaxRSIZoE75I=; b=UaQ2h57KVChDSiW1UqVFp7hvikEcX/+6sClsEY3e64QEpcPmENcreQDBgT6te2vJEV 5aLoCL0rmF4sKBKsAOLGXAhRO1rVsErovcBOD1m7TcUqTVtE7axfcS71s0USEPbsKF3G NouskMOOcm3Rn1Fxc9LDX5LcRdgewuhvrLiBGymwgvQ1maoyBeU9SUXjJKvpjt2STk1h FGGV6iIPRHkZd+p9q+wzYUBoI1CF6XVAoKN9RYE8XnnHQ374vSF7H7HsousWg6mQe4TH 4CdvDUut8Phadks9pajzTyVB0TSY43VsdbUYtVA5Ne4lXGs8yC3RbH7aTNdxlO+VPM8J Byww== X-Gm-Message-State: AMCzsaWwZ4zRBRuZT/sTLBNhRkvvM41/JQ9djrRcMih99sgQwvfDhGV2 2298Jadt2bEaBInxKaWRQK7n+Cwr X-Google-Smtp-Source: ABhQp+SnK2dVWkdeB+m6DlSLwNuJO9BKXFJd95VJyIH6zaDMVnRR0ib2oAaRfm2Dmn491b7dCB9JXg== X-Received: by 10.28.153.85 with SMTP id b82mr5149538wme.121.1508096222982; Sun, 15 Oct 2017 12:37:02 -0700 (PDT) From: Romain Naour To: libc-alpha@sourceware.org Cc: Romain Naour , "Gabriel F . T . Gomes" Subject: [PATCH] Provide a C++ version of signbit that does not use __MATH_TG (bug 22296) Date: Sun, 15 Oct 2017 21:36:52 +0200 Message-Id: <20171015193652.28657-1-romain.naour@gmail.com> The macro __MATH_TG contains the logic to select between long double and _Float128, when these types are ABI-distinct. This logic relies on __builtin_types_compatible_p, which is not available in C++ mode. On the other hand, C++ function overloading provides the means to distinguish between the floating-point types. The overloading resolution will match the correct parameter regardless of type qualifiers, i.e.: const and volatile. This is the same fix as for issignaling [1] but the issue appear only with gcc < 6.x. Since GCC 6.0, __builtin_signbit is type-generic, so signbit() is defined without __MATH_TG. Tested for x86_64. * math/math.h [defined __cplusplus] (signbit): Provide a C++ definition for signbit that does not rely on __MATH_TG, since __MATH_TG uses __builtin_types_compatible_p, which is only available in C mode. [1] a16e8bc08edca84d507715c66d6cddbbc7ed3b62 Cc: Gabriel F. T. Gomes --- --- ChangeLog | 8 ++++++++ math/math.h | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/ChangeLog b/ChangeLog index 17fbe55..2fe5719 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2017-10-15 Romain Naour (tiny change) + + [BZ #22296] + * math/math.h [defined __cplusplus] (signbit): Provide a C++ + definition for signbit that does not rely on __MATH_TG, + since __MATH_TG uses __builtin_types_compatible_p, which is only + available in C mode. + 2017-10-15 H.J. Lu [BZ #22052] diff --git a/math/math.h b/math/math.h index faa24817..2c94cdf 100644 --- a/math/math.h +++ b/math/math.h @@ -448,6 +448,21 @@ enum /* Return nonzero value if sign of X is negative. */ # if __GNUC_PREREQ (6,0) # define signbit(x) __builtin_signbit (x) +# elif defined __cplusplus + /* In C++ mode, __MATH_TG cannot be used, because it relies on + __builtin_types_compatible_p, which is a C-only builtin. On the + other hand, overloading provides the means to distinguish between + the floating-point types. The overloading resolution will match + the correct parameter (regardless of type qualifiers (i.e.: const + and volatile). */ +extern "C++" { +inline int signbit (float __val) { return __signbitf (__val); } +inline int signbit (double __val) { return __signbit (__val); } +inline int signbit (long double __val) { return __signbitl (__val); } +# if __HAVE_DISTINCT_FLOAT128 +inline int signbit (_Float128 __val) { return __signbitf128 (__val); } +# endif +} /* extern C++ */ # elif __GNUC_PREREQ (4,0) # define signbit(x) __MATH_TG ((x), __builtin_signbit, (x)) # else