public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed 0/3][gcc11] fortran: Backpoprt KIND arg of intrinsics fix [PR103789]
@ 2022-01-16 21:21 Mikael Morin
  2022-01-16 21:21 ` [pushed 1/3] Fortran: Fix KIND argument index for LEN_TRIM Mikael Morin
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Mikael Morin @ 2022-01-16 21:21 UTC (permalink / raw)
  To: fortran, gcc-patches

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pushed 1/3] Fortran: Fix KIND argument index for LEN_TRIM.
  2022-01-16 21:21 [pushed 0/3][gcc11] fortran: Backpoprt KIND arg of intrinsics fix [PR103789] Mikael Morin
@ 2022-01-16 21:21 ` Mikael Morin
  2022-01-16 21:21 ` [pushed 2/3] Fortran: Ignore KIND argument of a few more intrinsics. [PR103789] Mikael Morin
  2022-01-16 21:21 ` [pushed 3/3] testsuite: Enrich tests with variants failing on the branch Mikael Morin
  2 siblings, 0 replies; 6+ messages in thread
From: Mikael Morin @ 2022-01-16 21:21 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1322 bytes --]


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(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-Fix-KIND-argument-index-for-LEN_TRIM.patch --]
[-- Type: text/x-patch; name="0001-Fortran-Fix-KIND-argument-index-for-LEN_TRIM.patch", Size: 2346 bytes --]

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pushed 2/3] Fortran: Ignore KIND argument of a few more intrinsics. [PR103789]
  2022-01-16 21:21 [pushed 0/3][gcc11] fortran: Backpoprt KIND arg of intrinsics fix [PR103789] Mikael Morin
  2022-01-16 21:21 ` [pushed 1/3] Fortran: Fix KIND argument index for LEN_TRIM Mikael Morin
@ 2022-01-16 21:21 ` Mikael Morin
  2022-01-17 10:54   ` [pushed 4/3] " Mikael Morin
  2022-01-16 21:21 ` [pushed 3/3] testsuite: Enrich tests with variants failing on the branch Mikael Morin
  2 siblings, 1 reply; 6+ messages in thread
From: Mikael Morin @ 2022-01-16 21:21 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1214 bytes --]


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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-Fortran-Ignore-KIND-argument-of-a-few-more-intrinsic.patch --]
[-- Type: text/x-patch; name="0002-Fortran-Ignore-KIND-argument-of-a-few-more-intrinsic.patch", Size: 2406 bytes --]

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 00000000000..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 00000000000..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 00000000000..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 00000000000..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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pushed 3/3] testsuite: Enrich tests with variants failing on the branch.
  2022-01-16 21:21 [pushed 0/3][gcc11] fortran: Backpoprt KIND arg of intrinsics fix [PR103789] Mikael Morin
  2022-01-16 21:21 ` [pushed 1/3] Fortran: Fix KIND argument index for LEN_TRIM Mikael Morin
  2022-01-16 21:21 ` [pushed 2/3] Fortran: Ignore KIND argument of a few more intrinsics. [PR103789] Mikael Morin
@ 2022-01-16 21:21 ` Mikael Morin
  2022-01-16 22:36   ` Thomas Koenig
  2 siblings, 1 reply; 6+ messages in thread
From: Mikael Morin @ 2022-01-16 21:21 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1045 bytes --]


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(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-testsuite-Enrich-tests-with-variants-failing-on-the-.patch --]
[-- Type: text/x-patch; name="0003-testsuite-Enrich-tests-with-variants-failing-on-the-.patch", Size: 2050 bytes --]

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [pushed 3/3] testsuite: Enrich tests with variants failing on the branch.
  2022-01-16 21:21 ` [pushed 3/3] testsuite: Enrich tests with variants failing on the branch Mikael Morin
@ 2022-01-16 22:36   ` Thomas Koenig
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Koenig @ 2022-01-16 22:36 UTC (permalink / raw)
  To: Mikael Morin, fortran, gcc-patches


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pushed 4/3] Fortran: Ignore KIND argument of a few more intrinsics. [PR103789]
  2022-01-16 21:21 ` [pushed 2/3] Fortran: Ignore KIND argument of a few more intrinsics. [PR103789] Mikael Morin
@ 2022-01-17 10:54   ` Mikael Morin
  0 siblings, 0 replies; 6+ messages in thread
From: Mikael Morin @ 2022-01-17 10:54 UTC (permalink / raw)
  To: Mikael Morin, fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 63 bytes --]

I managed to break a working patch by splitting it.
Now fixed.

[-- Attachment #2: 0001-Fortran-Ignore-KIND-argument-of-a-few-more-intrinsic.patch --]
[-- Type: text/x-patch, Size: 1315 bytes --]

From d7a44809924297a2ff26b6b1d040c72c22f07346 Mon Sep 17 00:00:00 2001
From: Mikael Morin <mikael@gcc.gnu.org>
Date: Mon, 17 Jan 2022 11:45:46 +0100
Subject: [PATCH] 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.

(cherry picked from commit c1c17a43e172ebc28f2cd247f6e83c5fdbc6219f)
---
 gcc/fortran/trans-array.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 308213c57e3..dc89e97b0a1 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -11249,6 +11249,10 @@ arg_evaluated_for_scalarization (gfc_intrinsic_sym *function,
 	    {
 	      case GFC_ISYM_INDEX:
 	      case GFC_ISYM_LEN_TRIM:
+	      case GFC_ISYM_MASKL:
+	      case GFC_ISYM_MASKR:
+	      case GFC_ISYM_SCAN:
+	      case GFC_ISYM_VERIFY:
 		if (strcmp ("kind", actual_arg.name) == 0)
 		  return false;
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-01-17 10:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-16 21:21 [pushed 0/3][gcc11] fortran: Backpoprt KIND arg of intrinsics fix [PR103789] Mikael Morin
2022-01-16 21:21 ` [pushed 1/3] Fortran: Fix KIND argument index for LEN_TRIM Mikael Morin
2022-01-16 21:21 ` [pushed 2/3] Fortran: Ignore KIND argument of a few more intrinsics. [PR103789] Mikael Morin
2022-01-17 10:54   ` [pushed 4/3] " Mikael Morin
2022-01-16 21:21 ` [pushed 3/3] testsuite: Enrich tests with variants failing on the branch Mikael Morin
2022-01-16 22:36   ` Thomas Koenig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).