From 35fe62889f49952de8ad3246f8b76301bbc50ee8 Mon Sep 17 00:00:00 2001 From: laokz Date: Wed, 18 Jan 2023 20:27:05 +0800 Subject: [PATCH] riscv: backport upstream patch to fix -NaN test failure --- ...port-Fix-negative-NaN-issue-on-RiscV.patch | 71 +++++++++++++++++++ gawk.spec | 9 ++- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 backport-Fix-negative-NaN-issue-on-RiscV.patch diff --git a/backport-Fix-negative-NaN-issue-on-RiscV.patch b/backport-Fix-negative-NaN-issue-on-RiscV.patch new file mode 100644 index 0000000..6ae3e95 --- /dev/null +++ b/backport-Fix-negative-NaN-issue-on-RiscV.patch @@ -0,0 +1,71 @@ +commit a3799ae3f5dd6648040d499224cc6dea61b355dd +Author: Arnold D. Robbins +Date: Mon Sep 19 18:51:28 2022 +0300 + + Fix negative NaN issue on RiscV. + +diff --git a/ChangeLog b/ChangeLog +index 35941d0a..d751baf1 100644 +--- a/ChangeLog ++++ b/ChangeLog +@@ -1,0 +1,6 @@ ++2022-09-19 Arnold D. Robbins ++ ++ * eval.c (fix_nan_sign): New function. See bug list citation ++ in the code. ++ * interpret.h (r_interpret): Use it for plus and minus cases. ++ +diff --git a/eval.c b/eval.c +index 1069570b..3bfff0ca 100644 +--- a/eval.c ++++ b/eval.c +@@ -39,6 +39,8 @@ static int num_exec_hook = 0; + static Func_pre_exec pre_execute[MAX_EXEC_HOOKS]; + static Func_post_exec post_execute = NULL; + ++static double fix_nan_sign(double left, double right, double result); ++ + extern void frame_popped(); + + int OFSlen; +@@ -1901,3 +1903,20 @@ elem_new_to_scalar(NODE *n) + + return n; + } ++ ++/* fix_nan_sign --- fix NaN sign on RiscV */ ++ ++// See the thread starting at ++// https://lists.gnu.org/archive/html/bug-gawk/2022-09/msg00005.html ++// for why we need this function. ++ ++static double ++fix_nan_sign(double left, double right, double result) ++{ ++ if (isnan(left) && signbit(left)) ++ return copysign(result, -1.0); ++ else if (isnan(right) && signbit(right)) ++ return copysign(result, -1.0); ++ else ++ return result; ++} +diff --git a/interpret.h b/interpret.h +index 26010ada..955d918f 100644 +--- a/interpret.h ++++ b/interpret.h +@@ -583,6 +583,7 @@ uninitialized_scalar: + plus: + t1 = TOP_NUMBER(); + r = make_number(t1->numbr + x2); ++ r->numbr = fix_nan_sign(t1->numbr, x2, r->numbr); + DEREF(t1); + REPLACE(r); + break; +@@ -597,6 +598,7 @@ plus: + minus: + t1 = TOP_NUMBER(); + r = make_number(t1->numbr - x2); ++ r->numbr = fix_nan_sign(t1->numbr, x2, r->numbr); + DEREF(t1); + REPLACE(r); + break; diff --git a/gawk.spec b/gawk.spec index 65634b3..6264f4d 100644 --- a/gawk.spec +++ b/gawk.spec @@ -4,7 +4,7 @@ egrep -i "gawk_api_minor.*[0-9]+" | egrep -o "[0-9]") Name: gawk Version: 5.2.0 -Release: 2 +Release: 3 License: GPLv3+ and GPLv2+ and LGPLv2+ and BSD Summary: The GNU version of the AWK text processing utility URL: https://www.gnu.org/software/gawk/ @@ -21,6 +21,7 @@ Patch7: backport-Additional-fix-for-Node_elem_new.patch Patch8: backport-Yet-another-fix-and-test-for-Node_elem_new.patch Patch9: backport-Fix-a-memory-leak.patch Patch10: backport-Code-simplification-in-interpret.h.patch +Patch11: backport-Fix-negative-NaN-issue-on-RiscV.patch BuildRequires: gcc automake grep BuildRequires: bison texinfo texinfo-tex ghostscript texlive-ec texlive-cm-super glibc-all-langpacks @@ -116,6 +117,12 @@ install -m 0644 -p doc/gawkinet.{pdf,ps} ${RPM_BUILD_ROOT}%{_docdir}/%{name} %{_datadir}/locale/* %changelog +* Thu Jan 19 2023 laokz - 5.2.0-3 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC: backport 5.2.1 patch to fix -NaN test on riscv + * Thu Jan 12 2023 Jiayi Chen - 5.2.0-2 - Type:bugfix - ID:NA -- Gitee