public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR94397 the compiler consider "type is( real(kind(1.)) )" as a syntax error
@ 2020-05-13 17:19 Mark Eggleston
  2020-05-27  6:55 ` Mark Eggleston
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Eggleston @ 2020-05-13 17:19 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Please find attached a patch for PR94397.

Commit message:

Fortran  : "type is( real(kind(1.)) )" spurious syntax error PR94397

Based on a patch in the comments of the PR. That patch fixed this problem
but caused the test cases for PR93484 to fail. Changed to reduce
initialisation expressions if the expression is not EXPR_VARIABLE and not
EXPR_CONSTANT.

2020-05-13  Steven G. Kargl  <kargl@gcc.gnu.org>
             Mark Eggleston <markeggleston@gcc.gnu.org>

gcc/fortran/

     PR fortran/94397
     * match.c (gfc_match_type_spec): New variable ok initialised
     to true. Set ok with the return value of gfc_reduce_init_expr
     called only if the expression is not EXPR_CONSTANT and is not
     EXPR_VARIABLE. Add !ok to the check for type not being integer
     or the rank being greater than zero.

2020-05-13  Mark Eggleston <markeggleston@gcc.gnu.org>

gcc/testsuite/

     PR fortran/94397
     * gfortran.dg/pr94397.F90: New test.

The formatting with tabs and date will be corrected prior to commit.

Tested on x86_64 for master, releases/gcc-9, releases/gcc-10 branches. 
OK to commit and backport?

-- 
https://www.codethink.co.uk/privacy.html


[-- Attachment #2: 0001-pr94397.patch --]
[-- Type: text/x-patch, Size: 2512 bytes --]

From 425d05f2e735cf5fd30de2d0edc9d8a0e99b823c Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggleston@gcc.gnu.org>
Date: Wed, 1 Apr 2020 09:52:41 +0100
Subject: [PATCH] Fortran  : "type is( real(kind(1.)) )" spurious syntax error
 PR94397

Based on a patch in the comments of the PR. That patch fixed this problem
but caused the test cases for PR93484 to fail. Changed to reduce
initialisation expressions if the expression is not EXPR_VARIABLE and not
EXPR_CONSTANT.

2020-05-13  Steven G. Kargl  <kargl@gcc.gnu.org>
	    Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/fortran/

	PR fortran/94397
	* match.c (gfc_match_type_spec): New variable ok initialised
	to true. Set ok with the return value of gfc_reduce_init_expr
	called only if the expression is not EXPR_CONSTANT and is not
	EXPR_VARIABLE. Add !ok to the check for type not being integer
	or the rank being greater than zero.

2020-05-13  Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/testsuite/

	PR fortran/94397
	* gfortran.dg/pr94397.F90: New test.
---
 gcc/fortran/match.c                   |  5 ++++-
 gcc/testsuite/gfortran.dg/pr94397.F90 | 26 ++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr94397.F90

diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index 8ae34a94a95..82d2b5087e5 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -2265,7 +2265,10 @@ found:
 	 a scalar integer initialization-expr and valid kind parameter. */
       if (c == ')')
 	{
-	  if (e->ts.type != BT_INTEGER || e->rank > 0)
+	  bool ok = true;
+	  if (e->expr_type != EXPR_CONSTANT && e->expr_type != EXPR_VARIABLE)
+	    ok = gfc_reduce_init_expr (e);
+	  if (!ok || e->ts.type != BT_INTEGER || e->rank > 0)
 	    {
 	      gfc_free_expr (e);
 	      return MATCH_NO;
diff --git a/gcc/testsuite/gfortran.dg/pr94397.F90 b/gcc/testsuite/gfortran.dg/pr94397.F90
new file mode 100644
index 00000000000..fda10c1a88b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr94397.F90
@@ -0,0 +1,26 @@
+! { dg-do run }
+!
+
+module m
+  implicit none
+contains
+  function is_real8(a)
+    class(*) :: a
+    logical :: is_real8
+    is_real8 = .false.
+    select type(a)
+      type is(real(kind(1.0_8)))
+        is_real8 = .true. 
+    end select
+  end function is_real8
+end module m
+
+program test
+  use m
+
+  if (is_real8(1.0_4)) stop 1
+  if (.not. is_real8(1.0_8)) stop 2
+#ifdef __GFC_REAL_16__
+  if (is_real8(1.0_16)) stop 3
+#endif
+end program
-- 
2.11.0


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

* Re: [PATCH] PR94397 the compiler consider "type is( real(kind(1.)) )" as a syntax error
  2020-05-13 17:19 [PATCH] PR94397 the compiler consider "type is( real(kind(1.)) )" as a syntax error Mark Eggleston
@ 2020-05-27  6:55 ` Mark Eggleston
  2020-05-27 13:04   ` Thomas Koenig
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Eggleston @ 2020-05-27  6:55 UTC (permalink / raw)
  To: fortran, gcc-patches

ping

On 13/05/2020 18:19, Mark Eggleston wrote:
> Please find attached a patch for PR94397.
>
> Commit message:
>
> Fortran  : "type is( real(kind(1.)) )" spurious syntax error PR94397
>
> Based on a patch in the comments of the PR. That patch fixed this problem
> but caused the test cases for PR93484 to fail. Changed to reduce
> initialisation expressions if the expression is not EXPR_VARIABLE and not
> EXPR_CONSTANT.
>
> 2020-05-13  Steven G. Kargl  <kargl@gcc.gnu.org>
>             Mark Eggleston <markeggleston@gcc.gnu.org>
>
> gcc/fortran/
>
>     PR fortran/94397
>     * match.c (gfc_match_type_spec): New variable ok initialised
>     to true. Set ok with the return value of gfc_reduce_init_expr
>     called only if the expression is not EXPR_CONSTANT and is not
>     EXPR_VARIABLE. Add !ok to the check for type not being integer
>     or the rank being greater than zero.
>
> 2020-05-13  Mark Eggleston <markeggleston@gcc.gnu.org>
>
> gcc/testsuite/
>
>     PR fortran/94397
>     * gfortran.dg/pr94397.F90: New test.
>
> The formatting with tabs and date will be corrected prior to commit.
>
> Tested on x86_64 for master, releases/gcc-9, releases/gcc-10 branches. 
> OK to commit and backport?
>
-- 
https://www.codethink.co.uk/privacy.html


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

* Re: [PATCH] PR94397 the compiler consider "type is( real(kind(1.)) )" as a syntax error
  2020-05-27  6:55 ` Mark Eggleston
@ 2020-05-27 13:04   ` Thomas Koenig
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Koenig @ 2020-05-27 13:04 UTC (permalink / raw)
  To: Mark Eggleston, fortran, gcc-patches

Hi Mark,

> ping

the patch looks good do me.

Regards

	Thomas

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

end of thread, other threads:[~2020-05-27 13:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-13 17:19 [PATCH] PR94397 the compiler consider "type is( real(kind(1.)) )" as a syntax error Mark Eggleston
2020-05-27  6:55 ` Mark Eggleston
2020-05-27 13:04   ` 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).