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