0006-Let-fpclassify-use-the-builtin-when-optimizing-for-s.patch 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. From 33f54cf4f81a51e5c8cbfb2408edd439bdee9435 Mon Sep 17 00:00:00 2001
  2. From: "Gabriel F. T. Gomes" <gabriel@inconstante.eti.br>
  3. Date: Wed, 20 Sep 2017 15:10:26 -0300
  4. Subject: [PATCH] Let fpclassify use the builtin when optimizing for size in
  5. C++ mode (bug 22146)
  6. When optimization for size is on (-Os), fpclassify does not use the
  7. type-generic __builtin_fpclassify builtin, instead it uses __MATH_TG.
  8. However, when library support for float128 is available, __MATH_TG uses
  9. __builtin_types_compatible_p, which is not available in C++ mode.
  10. On the other hand, libstdc++ undefines (in cmath) many macros from
  11. math.h, including fpclassify, so that it can provide its own functions.
  12. However, during its configure tests, libstdc++ just tests for the
  13. availability of the macros (it does not undefine them, nor does it
  14. provide its own functions).
  15. Finally, when libstdc++ is configured with optimization for size
  16. enabled, its configure tests include math.h and get the definition of
  17. fpclassify that uses __MATH_TG (and __builtin_types_compatible_p).
  18. Since libstdc++ does not undefine the macros during its configure tests,
  19. they fail.
  20. This patch lets fpclassify use the builtin in C++ mode, even when
  21. optimization for size is on. This allows the configure test in
  22. libstdc++ to work.
  23. Tested for powerpc64le and x86_64.
  24. [BZ #22146]
  25. math/math.h: Let fpclassify use the builtin in C++ mode, even
  26. when optimazing for size.
  27. (cherry picked from commit c5c4a626098ec884b8527356abdf2a4bb7b6bf27)
  28. [Romain rebase on glibc 2.26)
  29. Signed-off-by: Romain Naour <romain.naour@gmail.com>
  30. ---
  31. math/math.h | 8 +++++++-
  32. 1 file changed, 7 insertions(+), 1 deletion(-)
  33. diff --git a/math/math.h b/math/math.h
  34. index 7c0fc6d..f9348ec 100644
  35. --- a/math/math.h
  36. +++ b/math/math.h
  37. @@ -402,7 +402,13 @@ enum
  38. /* Return number of classification appropriate for X. */
  39. # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__ \
  40. - && !defined __OPTIMIZE_SIZE__
  41. + && (!defined __OPTIMIZE_SIZE__ || defined __cplusplus)
  42. + /* The check for __cplusplus allows the use of the builtin, even
  43. + when optimization for size is on. This is provided for
  44. + libstdc++, only to let its configure test work when it is built
  45. + with -Os. No further use of this definition of fpclassify is
  46. + expected in C++ mode, since libstdc++ provides its own version
  47. + of fpclassify in cmath (which undefines fpclassify). */
  48. # define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \
  49. FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
  50. # else
  51. --
  52. 2.9.5