Re: [PATCH] Fortran: make IEEE_VALUE produce signaling NaNs
Hello, Le 10/01/2022 à 18:32, FX via Fortran a écrit : Hi, Second part of a three-patch series to fix PR 82207 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82207), making gfortran handle signaling NaNs. This part fixes the library code implementing IEEE_VALUE. To do so, I switched that part of library code from Fortran to C, because in C we have access to all GCC built-ins related to NaNs/infinities/etc, which is super useful for generating the right bit patterns (instead of using roundabout ways, like the previous Fortran implementation, for which I am guilty). I needed to add to kinds.h the value of TINY for each floating-point (which is used to produce denormals, by halving TINY). The patch comes with a testcase, which is still conditional on issignaling support at this stage (and therefore will run on glibc targets only). I had to amend the gfortran.dg/ieee/ieee_10.f90 testcase, which produces signaling NaNs while -ffpe-trap=invalid is set. It passed before, but only by accident, because we were not actually generating signaling NaNs. I’m not sure what is the expected behaviour, but the patch does not affect the real behaviour. Bootstrapped and regtested on x86_64-pc-gnu-linux. OK to commit? This looks good to me. Thanks.
[pushed] fortan testsuite: Enrich tests with variants failing on the branch.
Hello, I have just pushed the attached patch after testing the impacted tests individually. MikaelFrom 15630e6e9eb019477d1fc5c0966b43979e18ae18 Mon Sep 17 00:00:00 2001 From: Mikael Morin Date: Sun, 16 Jan 2022 18:33:36 +0100 Subject: [PATCH] testsuite: Enrich tests with variants failing on the branch. Backporting the fix for pr103789 on the 11 branch revealed a lack of test coverage for the tests provided with that fix. Indeed, the tests use the KIND argument of the respective intrinsics only with keyword arguments. This adds variants with non-keyword arguments. The tests enriched this way fail on the branch if the fix is cherry-picked straightforwardly. The fix will have to be tweaked slightly there. PR fortran/103789 PR fortran/87711 PR fortran/97896 gcc/testsuite/ChangeLog: * gfortran.dg/index_5.f90: Enrich test with usages of INDEX with a non-keyword KIND argument. * gfortran.dg/len_trim.f90: Same for LEN_TRIM. * gfortran.dg/maskl_1.f90: Same for MASKL. * gfortran.dg/maskr_1.f90: Same for MASKR. * gfortran.dg/scan_3.f90: Same for SCAN. * gfortran.dg/verify_3.f90: Same for VERIFY. --- gcc/testsuite/gfortran.dg/index_5.f90 | 2 ++ gcc/testsuite/gfortran.dg/len_trim.f90 | 6 ++ gcc/testsuite/gfortran.dg/maskl_1.f90 | 3 ++- gcc/testsuite/gfortran.dg/maskr_1.f90 | 3 ++- gcc/testsuite/gfortran.dg/scan_3.f90 | 5 - gcc/testsuite/gfortran.dg/verify_3.f90 | 5 - 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/gcc/testsuite/gfortran.dg/index_5.f90 b/gcc/testsuite/gfortran.dg/index_5.f90 index e039455d175..4dc2ce4c0a1 100644 --- a/gcc/testsuite/gfortran.dg/index_5.f90 +++ b/gcc/testsuite/gfortran.dg/index_5.f90 @@ -19,5 +19,7 @@ program p d = index ('xyxyz','yx', back=a, kind=8) b = index ('xyxyz','yx', back=a, kind=8) d = index ('xyxyz','yx', back=a, kind=4) + b = index ('xyxyz','yx', a, 4) + d = index ('xyxyz','yx', a, 8) end diff --git a/gcc/testsuite/gfortran.dg/len_trim.f90 b/gcc/testsuite/gfortran.dg/len_trim.f90 index 2252b81f084..77e3d30c669 100644 --- a/gcc/testsuite/gfortran.dg/len_trim.f90 +++ b/gcc/testsuite/gfortran.dg/len_trim.f90 @@ -17,11 +17,17 @@ program main kk = len_trim (a) mm = len_trim (a, kind=4) nn = len_trim (a, kind=8) + mm = len_trim (a, 4) + nn = len_trim (a, 8) kk = len_trim ([b]) mm = len_trim ([b],kind=4) nn = len_trim ([b],kind=8) + mm = len_trim ([b], 4) + nn = len_trim ([b], 8) kk = len_trim (c) mm = len_trim (c, kind=4) nn = len_trim (c, kind=8) + mm = len_trim (c, 4) + nn = len_trim (c, 8) if (any (l4 /= 2_4) .or. any (l8 /= 2_8)) stop 1 end program main diff --git a/gcc/testsuite/gfortran.dg/maskl_1.f90 b/gcc/testsuite/gfortran.dg/maskl_1.f90 index 9e25c2c9cdc..56350e269da 100644 --- a/gcc/testsuite/gfortran.dg/maskl_1.f90 +++ b/gcc/testsuite/gfortran.dg/maskl_1.f90 @@ -4,7 +4,8 @@ ! Check the absence of ICE when generating calls to MASKL with a KIND argument. program p - integer :: z(2), y(2) + integer :: z(2), y(2), x(2) y = [1, 13] z = maskl(y, kind=4) + 1 + x = maskl(y, 4) + 1 end program p diff --git a/gcc/testsuite/gfortran.dg/maskr_1.f90 b/gcc/testsuite/gfortran.dg/maskr_1.f90 index ebfd3dbba33..f8ccdd11ab3 100644 --- a/gcc/testsuite/gfortran.dg/maskr_1.f90 +++ b/gcc/testsuite/gfortran.dg/maskr_1.f90 @@ -4,7 +4,8 @@ ! Check the absence of ICE when generating calls to MASKR with a KIND argument. program p - integer :: z(2), y(2) + integer :: z(2), y(2), x(2) y = [1, 13] z = maskr(y, kind=4) + 1 + x = maskr(y, 4) + 1 end program p diff --git a/gcc/testsuite/gfortran.dg/scan_3.f90 b/gcc/testsuite/gfortran.dg/scan_3.f90 index 80262ae2167..2a9ed080957 100644 --- a/gcc/testsuite/gfortran.dg/scan_3.f90 +++ b/gcc/testsuite/gfortran.dg/scan_3.f90 @@ -5,7 +5,10 @@ program p character(len=10) :: y(2) - integer :: z(2) + integer :: z(2), x(2), w(2), v(2) y = ['abc', 'def'] z = scan(y, 'e', kind=4) + 1 + x = scan(y, 'e', back=.false., kind=4) + 1 + w = scan(y, 'e', .false., kind=4) + 1 + v = scan(y, 'e', .false., 4) + 1 end program p diff --git a/gcc/testsuite/gfortran.dg/verify_3.f90 b/gcc/testsuite/gfortran.dg/verify_3.f90 index f01e24e199e..c8b26b70614 100644 --- a/gcc/testsuite/gfortran.dg/verify_3.f90 +++ b/gcc/testsuite/gfortran.dg/verify_3.f90 @@ -5,7 +5,10 @@ program p character(len=10) :: y(2) - integer :: z(2) + integer :: z(2), x(2), w(2), v(2) y = ['abc', 'def'] z = verify(y, 'e', kind=4) + 1 + x = verify(y, 'e', back=.false., kind=4) + 1 + w = verify(y, 'e', .false., kind=4) + 1 + x = verify(y, 'e', .false., 4) + 1 end program p -- 2.34.1
[pushed 0/3][gcc11] fortran: Backpoprt KIND arg of intrinsics fix [PR103789]
Hello, I noticed a bug while backporting the fix for PR103789 on the 11 branch. It makes the cherry-pick not exactly straightforward. The bug is fixed in the first patch, the backport comes in the second, and additional test coverage (pushed earlier today on master) is added in the third. Tested on x86_64-linux on the 11 branch, pushed. Mikael Morin (3): Fortran: Fix KIND argument index for LEN_TRIM. Fortran: Ignore KIND argument of a few more intrinsics. [PR103789] testsuite: Enrich tests with variants failing on the branch. gcc/fortran/trans-array.c | 45 -- gcc/testsuite/gfortran.dg/index_5.f90 | 2 ++ gcc/testsuite/gfortran.dg/len_trim.f90 | 6 gcc/testsuite/gfortran.dg/maskl_1.f90 | 11 +++ gcc/testsuite/gfortran.dg/maskr_1.f90 | 11 +++ gcc/testsuite/gfortran.dg/scan_3.f90 | 14 gcc/testsuite/gfortran.dg/verify_3.f90 | 14 7 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/maskl_1.f90 create mode 100644 gcc/testsuite/gfortran.dg/maskr_1.f90 create mode 100644 gcc/testsuite/gfortran.dg/scan_3.f90 create mode 100644 gcc/testsuite/gfortran.dg/verify_3.f90 -- 2.34.1
[pushed 1/3] Fortran: Fix KIND argument index for LEN_TRIM.
The mainline code to check whether an argument has to be included in scalarization uses only the name of a dummy argument object to recognize a specific argument of an intrinsic procedure. On the 11 branch, the dummy argument object is not available and the code uses a mix of check for argument name (for keyword arguments) and argument index (for non-keyword ones). This makes backports non-straightforward in this area, as the argument indexes depend on the intrinsics. This change fixes a bogus backport for LEN_TRIM, whose KIND argument index should be different from that of INDEX. PR fortran/87711 PR fortran/97896 gcc/fortran/ChangeLog: * trans-array.c (arg_evaluated_for_scalarization): Handle keyword and non-keyword arguments separatedly. Adapt the expected argument index for KIND to each intrinsic in the non-keyword case. gcc/testsuite/ChangeLog: * gfortran.dg/index_5.f90: Enrich test with usages of INDEX with a non-keyword KIND argument. * gfortran.dg/len_trim.f90: Same for LEN_TRIM. (tests cherry picked from commit 15630e6e9eb019477d1fc5c0966b43979e18ae18) --- gcc/fortran/trans-array.c | 41 +++--- gcc/testsuite/gfortran.dg/index_5.f90 | 2 ++ gcc/testsuite/gfortran.dg/len_trim.f90 | 6 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index db14daca459..e187a08f8f0 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -11220,18 +11220,39 @@ arg_evaluated_for_scalarization (gfc_intrinsic_sym *function, { if (function != NULL) { - switch (function->id) + if (actual_arg.name == NULL) { - case GFC_ISYM_INDEX: - case GFC_ISYM_LEN_TRIM: - if ((actual_arg.name == NULL && arg_num == 3) - || (actual_arg.name != NULL - && strcmp ("kind", actual_arg.name) == 0)) - return false; - /* Fallthrough. */ + switch (function->id) + { + case GFC_ISYM_INDEX: + if (arg_num == 3) + return false; + break; - default: - break; + case GFC_ISYM_LEN_TRIM: + if (arg_num == 1) + return false; + + /* Fallthrough. */ + + default: + break; + } + } + else + { + switch (function->id) + { + case GFC_ISYM_INDEX: + case GFC_ISYM_LEN_TRIM: + if (strcmp ("kind", actual_arg.name) == 0) + return false; + + /* Fallthrough. */ + + default: + break; + } } } diff --git a/gcc/testsuite/gfortran.dg/index_5.f90 b/gcc/testsuite/gfortran.dg/index_5.f90 index e039455d175..4dc2ce4c0a1 100644 --- a/gcc/testsuite/gfortran.dg/index_5.f90 +++ b/gcc/testsuite/gfortran.dg/index_5.f90 @@ -19,5 +19,7 @@ program p d = index ('xyxyz','yx', back=a, kind=8) b = index ('xyxyz','yx', back=a, kind=8) d = index ('xyxyz','yx', back=a, kind=4) + b = index ('xyxyz','yx', a, 4) + d = index ('xyxyz','yx', a, 8) end diff --git a/gcc/testsuite/gfortran.dg/len_trim.f90 b/gcc/testsuite/gfortran.dg/len_trim.f90 index 2252b81f084..77e3d30c669 100644 --- a/gcc/testsuite/gfortran.dg/len_trim.f90 +++ b/gcc/testsuite/gfortran.dg/len_trim.f90 @@ -17,11 +17,17 @@ program main kk = len_trim (a) mm = len_trim (a, kind=4) nn = len_trim (a, kind=8) + mm = len_trim (a, 4) + nn = len_trim (a, 8) kk = len_trim ([b]) mm = len_trim ([b],kind=4) nn = len_trim ([b],kind=8) + mm = len_trim ([b], 4) + nn = len_trim ([b], 8) kk = len_trim (c) mm = len_trim (c, kind=4) nn = len_trim (c, kind=8) + mm = len_trim (c, 4) + nn = len_trim (c, 8) if (any (l4 /= 2_4) .or. any (l8 /= 2_8)) stop 1 end program main
[pushed 2/3] Fortran: Ignore KIND argument of a few more intrinsics. [PR103789]
After PR97896 for which some code was added to ignore the KIND argument of the INDEX intrinsics, and PR87711 for which that was extended to LEN_TRIM as well, this propagates it further to MASKL, MASKR, SCAN and VERIFY. PR fortran/103789 gcc/fortran/ChangeLog: * trans-array.c (arg_evaluated_for_scalarization): Add MASKL, MASKR, SCAN and VERIFY to the list of intrinsics whose KIND argument is to be ignored. gcc/testsuite/ChangeLog: * gfortran.dg/maskl_1.f90: New test. * gfortran.dg/maskr_1.f90: New test. * gfortran.dg/scan_3.f90: New test. * gfortran.dg/verify_3.f90: New test. (cherry picked from commit c1c17a43e172ebc28f2cd247f6e83c5fdbc6219f) --- gcc/fortran/trans-array.c | 4 gcc/testsuite/gfortran.dg/maskl_1.f90 | 10 ++ gcc/testsuite/gfortran.dg/maskr_1.f90 | 10 ++ gcc/testsuite/gfortran.dg/scan_3.f90 | 11 +++ gcc/testsuite/gfortran.dg/verify_3.f90 | 11 +++ 5 files changed, 46 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/maskl_1.f90 create mode 100644 gcc/testsuite/gfortran.dg/maskr_1.f90 create mode 100644 gcc/testsuite/gfortran.dg/scan_3.f90 create mode 100644 gcc/testsuite/gfortran.dg/verify_3.f90 diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index e187a08f8f0..308213c57e3 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -11225,11 +11225,15 @@ arg_evaluated_for_scalarization (gfc_intrinsic_sym *function, switch (function->id) { case GFC_ISYM_INDEX: + case GFC_ISYM_SCAN: + case GFC_ISYM_VERIFY: if (arg_num == 3) return false; break; case GFC_ISYM_LEN_TRIM: + case GFC_ISYM_MASKL: + case GFC_ISYM_MASKR: if (arg_num == 1) return false; diff --git a/gcc/testsuite/gfortran.dg/maskl_1.f90 b/gcc/testsuite/gfortran.dg/maskl_1.f90 new file mode 100644 index 000..9e25c2c9cdc --- /dev/null +++ b/gcc/testsuite/gfortran.dg/maskl_1.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! +! PR fortran/103789 +! Check the absence of ICE when generating calls to MASKL with a KIND argument. + +program p + integer :: z(2), y(2) + y = [1, 13] + z = maskl(y, kind=4) + 1 +end program p diff --git a/gcc/testsuite/gfortran.dg/maskr_1.f90 b/gcc/testsuite/gfortran.dg/maskr_1.f90 new file mode 100644 index 000..ebfd3dbba33 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/maskr_1.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! +! PR fortran/103789 +! Check the absence of ICE when generating calls to MASKR with a KIND argument. + +program p + integer :: z(2), y(2) + y = [1, 13] + z = maskr(y, kind=4) + 1 +end program p diff --git a/gcc/testsuite/gfortran.dg/scan_3.f90 b/gcc/testsuite/gfortran.dg/scan_3.f90 new file mode 100644 index 000..80262ae2167 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/scan_3.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! +! PR fortran/103789 +! Check the absence of ICE when generating calls to SCAN with a KIND argument. + +program p + character(len=10) :: y(2) + integer :: z(2) + y = ['abc', 'def'] + z = scan(y, 'e', kind=4) + 1 +end program p diff --git a/gcc/testsuite/gfortran.dg/verify_3.f90 b/gcc/testsuite/gfortran.dg/verify_3.f90 new file mode 100644 index 000..f01e24e199e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/verify_3.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! +! PR fortran/103789 +! Check the absence of ICE when generating calls to VERIFY with a KIND argument. + +program p + character(len=10) :: y(2) + integer :: z(2) + y = ['abc', 'def'] + z = verify(y, 'e', kind=4) + 1 +end program p
[pushed 3/3] testsuite: Enrich tests with variants failing on the branch.
Backporting the fix for pr103789 on the 11 branch revealed a lack of test coverage for the tests provided with that fix. Indeed, the tests use the KIND argument of the respective intrinsics only with keyword arguments. This adds variants with non-keyword arguments. The tests enriched this way fail on the branch if the fix is cherry-picked straightforwardly. The fix will have to be tweaked slightly there. PR fortran/103789 PR fortran/87711 PR fortran/97896 gcc/testsuite/ChangeLog: * gfortran.dg/maskl_1.f90: Enrich test with usages of MASKL with a non-keyword KIND argument. * gfortran.dg/maskr_1.f90: Same for MASKR. * gfortran.dg/scan_3.f90: Same for SCAN. * gfortran.dg/verify_3.f90: Same for VERIFY. (cherry picked from commit 15630e6e9eb019477d1fc5c0966b43979e18ae18) --- gcc/testsuite/gfortran.dg/maskl_1.f90 | 3 ++- gcc/testsuite/gfortran.dg/maskr_1.f90 | 3 ++- gcc/testsuite/gfortran.dg/scan_3.f90 | 5 - gcc/testsuite/gfortran.dg/verify_3.f90 | 5 - 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/gcc/testsuite/gfortran.dg/maskl_1.f90 b/gcc/testsuite/gfortran.dg/maskl_1.f90 index 9e25c2c9cdc..56350e269da 100644 --- a/gcc/testsuite/gfortran.dg/maskl_1.f90 +++ b/gcc/testsuite/gfortran.dg/maskl_1.f90 @@ -4,7 +4,8 @@ ! Check the absence of ICE when generating calls to MASKL with a KIND argument. program p - integer :: z(2), y(2) + integer :: z(2), y(2), x(2) y = [1, 13] z = maskl(y, kind=4) + 1 + x = maskl(y, 4) + 1 end program p diff --git a/gcc/testsuite/gfortran.dg/maskr_1.f90 b/gcc/testsuite/gfortran.dg/maskr_1.f90 index ebfd3dbba33..f8ccdd11ab3 100644 --- a/gcc/testsuite/gfortran.dg/maskr_1.f90 +++ b/gcc/testsuite/gfortran.dg/maskr_1.f90 @@ -4,7 +4,8 @@ ! Check the absence of ICE when generating calls to MASKR with a KIND argument. program p - integer :: z(2), y(2) + integer :: z(2), y(2), x(2) y = [1, 13] z = maskr(y, kind=4) + 1 + x = maskr(y, 4) + 1 end program p diff --git a/gcc/testsuite/gfortran.dg/scan_3.f90 b/gcc/testsuite/gfortran.dg/scan_3.f90 index 80262ae2167..2a9ed080957 100644 --- a/gcc/testsuite/gfortran.dg/scan_3.f90 +++ b/gcc/testsuite/gfortran.dg/scan_3.f90 @@ -5,7 +5,10 @@ program p character(len=10) :: y(2) - integer :: z(2) + integer :: z(2), x(2), w(2), v(2) y = ['abc', 'def'] z = scan(y, 'e', kind=4) + 1 + x = scan(y, 'e', back=.false., kind=4) + 1 + w = scan(y, 'e', .false., kind=4) + 1 + v = scan(y, 'e', .false., 4) + 1 end program p diff --git a/gcc/testsuite/gfortran.dg/verify_3.f90 b/gcc/testsuite/gfortran.dg/verify_3.f90 index f01e24e199e..c8b26b70614 100644 --- a/gcc/testsuite/gfortran.dg/verify_3.f90 +++ b/gcc/testsuite/gfortran.dg/verify_3.f90 @@ -5,7 +5,10 @@ program p character(len=10) :: y(2) - integer :: z(2) + integer :: z(2), x(2), w(2), v(2) y = ['abc', 'def'] z = verify(y, 'e', kind=4) + 1 + x = verify(y, 'e', back=.false., kind=4) + 1 + w = verify(y, 'e', .false., kind=4) + 1 + x = verify(y, 'e', .false., 4) + 1 end program p
Re: [PATCH] Fortran: make IEEE_VALUE produce signaling NaNs
Thanks Mikael, > This looks good to me. Thanks. Thanks. Pushed: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=90045c5df5b3c8853e7740fb72a11aead1c489bb FX
Re: [pushed 3/3] testsuite: Enrich tests with variants failing on the branch.
Hi Mikael, Backporting the fix for pr103789 on the 11 branch revealed a lack of test coverage for the tests provided with that fix. Indeed, the tests use the KIND argument of the respective intrinsics only with keyword arguments. This adds variants with non-keyword arguments. The tests enriched this way fail on the branch if the fix is cherry-picked straightforwardly. The fix will have to be tweaked slightly there. As a general principle, we should not add or amend test cases unless it is wrong code that we need to remove The reason is that changing a test case makes regression testing, especially the automated version, harder - if a test starts failing, is it due to a change in the test case or a change in the compiler or library? I don't think there is a need to revert this patch, but please add separate test cases if you have new things to test in the future. Best regards Thomas
Re: [PATCH] Fortran: make IEEE_VALUE produce signaling NaNs
Hi Mikael, team, > Thanks. Pushed: > https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=90045c5df5b3c8853e7740fb72a11aead1c489bb Pushed a further commit to XFAIL the testcases on x87: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=86e3b476d5defaa79c94d40b76cbeec21cd02e5f There the ABI does not allow us to meaningfully pass signaling NaNs in float and double types, sadly. FX
[PATCH] Fortran: detect signaling NaNs on targets without issignaling macro in libc
This patch is the third in my “signaling NaN” series. For targets with IEEE support but without the issignaling macro in libc (i.e., everywhere except glibc), this allows us to provide a fallback implementation. In order to keep the code in ieee_helper.c relatively readable, I’ve put that new implementation in a separate file, issignaling_fallback.h. The logic is borrowed from different routines in glibc, but gathered into a single file and much simpler than the glibc implementation, because we do not need to cover all the cases they have (comments with details are available in issignaling_fallback.h). I can’t test this on all the targets I’d like to, obviously. But it was tested on x86_64-pc-linux-gnu (where it doesn’t do anything), on x86_64-pc-linux-gnu by mimicking the lack of a issignaling macro, and on x86_64-apple-darwin (which does not have issignaling). OK to push? issignaling.diff Description: Binary data
Re: [patch, libgfortran, power-ieee128] Add multiple defaults for GFORTRAN_CONVERT_UNIT
On 13.01.22 22:58, Thomas Koenig via Fortran wrote: with this patch, it is now possible to specify both the endianness and the REAL(KIND=16) format using the environment variable GFORTRAN_CONVERT_UNIT. I have now pushed this to trunk. Best regards Thomas