002-Fix-mpfr_custom_get_kind-macro-bug.patch 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. From 0ce17bae34a6c54de31b126f969d3ddd72c6bc37 Mon Sep 17 00:00:00 2001
  2. From: Vincent Lefevre <[email protected]>
  3. Date: Tue, 22 Nov 2022 16:33:00 +0100
  4. Subject: [PATCH] Fix mpfr_custom_get_kind() macro bug.
  5. * src/mpfr.h: in the mpfr_custom_get_kind() macro, changed mpfr_ptr to
  6. mpfr_srcptr for _x to agree with the function prototype, in order to
  7. avoid a compilation failure of user code in some cases. This bug was
  8. introduced by commit 9f94e0311ed53d0c64d4fbca249d19cc4888027e, which
  9. introduced the temporary variable _x to avoid an incorrect number of
  10. evaluations of the x argument.
  11. * tests/tstckintc.c: improved the tests to detect this bug.
  12. This should fix mpfr bug #1.
  13. Bug initially reported by FX Coudert:
  14. https://github.com/CGAL/cgal/issues/7064
  15. It affects Fedora Linux:
  16. https://bugzilla.redhat.com/show_bug.cgi?id=2144197
  17. ---
  18. src/mpfr.h | 2 +-
  19. tests/tstckintc.c | 10 +++++++---
  20. 2 files changed, 8 insertions(+), 4 deletions(-)
  21. --- a/src/mpfr.h
  22. +++ b/src/mpfr.h
  23. @@ -1027,7 +1027,7 @@ __MPFR_DECLSPEC int mpfr_total_order_p (
  24. #if __GNUC__ > 2 || __GNUC_MINOR__ >= 95
  25. #define mpfr_custom_get_kind(x) \
  26. __extension__ ({ \
  27. - mpfr_ptr _x = (x); \
  28. + mpfr_srcptr _x = (x); \
  29. _x->_mpfr_exp > __MPFR_EXP_INF ? \
  30. (mpfr_int) MPFR_REGULAR_KIND * MPFR_SIGN (_x) \
  31. : _x->_mpfr_exp == __MPFR_EXP_INF ? \
  32. --- a/tests/tstckintc.c
  33. +++ b/tests/tstckintc.c
  34. @@ -295,14 +295,16 @@ static void
  35. test_nan_inf_zero (void)
  36. {
  37. mpfr_ptr val;
  38. + mpfr_srcptr sval; /* for compilation error checking */
  39. int sign;
  40. int kind;
  41. reset_stack ();
  42. val = new_mpfr (MPFR_PREC_MIN);
  43. + sval = val;
  44. mpfr_set_nan (val);
  45. - kind = (mpfr_custom_get_kind) (val);
  46. + kind = (mpfr_custom_get_kind) (sval);
  47. if (kind != MPFR_NAN_KIND)
  48. {
  49. printf ("mpfr_custom_get_kind error: ");
  50. @@ -380,7 +382,8 @@ static long *
  51. dummy_set_si (long si)
  52. {
  53. mpfr_t x;
  54. - long * r = dummy_new ();
  55. + mpfr_srcptr px; /* for compilation error checking */
  56. + long *r = dummy_new ();
  57. int i1, i2, i3, i4, i5;
  58. /* Check that the type "void *" can be used, like with the function.
  59. @@ -405,7 +408,8 @@ dummy_set_si (long si)
  60. MPFR_ASSERTN (i5 == 1);
  61. mpfr_set_si (x, si, MPFR_RNDN);
  62. - r[0] = mpfr_custom_get_kind (x);
  63. + px = x;
  64. + r[0] = mpfr_custom_get_kind (px);
  65. /* Check that the type "void *" can be used in C, like with the function
  66. (forbidden in C++). Also check side effects. */