[Fortran] dec comparisons - for review

Message ID 3d0c58f3-d755-7880-94d0-26134e24b8b5@codethink.co.uk
State New
Headers show
Series
  • [Fortran] dec comparisons - for review
Related show

Commit Message

Mark Eggleston Nov. 15, 2019, 10:40 a.m.
This patch allows comparison of numeric values with Holleriths. This 
feature is not guarded by a compiler option as it is preferred that 
extra options should avoided, this seems reasonable as current Hollerith 
support does not have such an option.

In addition it also allows comparison of character values with 
Holleriths, this is guarded by a compiler option, I've used the existing 
-fdec-char-conversions because the Hollerith is converted to character 
for the comparison to be made.

These legacy features are supported by xlf, Sun and flang compilers.

I know the deadline for new features is close. Does the process have to 
completed before the deadline or can it overlap? If not I'll withdraw it 
until stage 1 is re-opened.

While preparing the patch I noticed that the test cases need to re-use 
duplicate code via the include mechanism. I'll work on fixing that while 
this patch is being reviewed.

ChangeLogs

gcc/fortran

     Jim MacArthur  <jim.macarthur@codethink.co.uk>
     Mark Eggleston  <mark.eggleston@codethink.com>

     * gfortran.texi: Update Hollerith constants support for character types
     and use in comparisons.
     * invoke.texi: Tidy up list of options. Update description of
     -fdec-char-conversions for character to hollerith comparisons.
     * lang.opt: -fdec-char-conversions also allows comparison of characters
     with Hollerith constants.
     * resolve.c (is_character_based): New.
     (Convert_hollerith_to_character): New. (convert_to_numeric): New.
     (resolve_operator): If both sides are character based convert Hollerith
     to character. If an operand is Hollerith and the other is numeric
     convert to numeric.  (resolve_ordinary_assign): Add check for
     -fdec-char-conversions for assignment of character literals.

gcc/testsuite

     Jim MacArthur <jim.macarthur@codethink.co.uk>
     Mark Eggleston <mark.eggleston@codethink.com>

     * gfortran.dg/dec-comparison-character_1.f90: New test.
     * gfortran.dg/dec-comparison-character_2.f90: New test.
     * gfortran.dg/dec-comparison-character_3.f90: New test.
     * gfortran.dg/dec-comparison-complex_1.f90: New test.
     * gfortran.dg/dec-comparison-complex_2.f90: New test.
     * gfortran.dg/dec-comparison-complex_3.f90: New test.
     * gfortran.dg/dec-comparison-complex_4.f90: New test.
     * gfortran.dg/dec-comparison-int_1.f90: New test.
     * gfortran.dg/dec-comparison-int_2.f90: New test.
     * gfortran.dg/dec-comparison-int_3.f90: New test.
     * gfortran.dg/dec-comparison-int_4.f90: New test.
     * gfortran.dg/dec-comparison-real_1.f90: New test.
     * gfortran.dg/dec-comparison-real_2.f90: New test.
     * gfortran.dg/dec-comparison-real_3.f90: New test.
     * gfortran.dg/dec-comparison-real_4.f90: New test.
     * gfortran.dg/dec-comparison.f90: New test.


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

Comments

Steve Kargl Nov. 15, 2019, 2:34 p.m. | #1
On Fri, Nov 15, 2019 at 10:40:56AM +0000, Mark Eggleston wrote:
> This patch allows comparison of numeric values with Holleriths. This 

> feature is not guarded by a compiler option as it is preferred that 

> extra options should avoided, this seems reasonable as current Hollerith 

> support does not have such an option.


IMHO.

Has the comparison of a numeric value and a hollerith 
ever been allowed in a Fortran standard?  If the answer
is 'No', then you should (1) put the comparison behind
an option, and (2) have gfortran issue an error without
the option.  If this is a DEC extension, then put it
behind -fdec.  If this misfeature is not a DEC extension
but allow some ancient piece of code to compile, then
put it behind -std=lagacy.

-- 
steve
Jeff Law Nov. 17, 2019, 6:27 p.m. | #2
On 11/15/19 3:40 AM, Mark Eggleston wrote:
> This patch allows comparison of numeric values with Holleriths. This

> feature is not guarded by a compiler option as it is preferred that

> extra options should avoided, this seems reasonable as current Hollerith

> support does not have such an option.

> 

> In addition it also allows comparison of character values with

> Holleriths, this is guarded by a compiler option, I've used the existing

> -fdec-char-conversions because the Hollerith is converted to character

> for the comparison to be made.

> 

> These legacy features are supported by xlf, Sun and flang compilers.

> 

> I know the deadline for new features is close. Does the process have to

> completed before the deadline or can it overlap? If not I'll withdraw it

> until stage 1 is re-opened.

The general guidance is patch should be posted prior to stage1 close;
some iteration on the patch is certainly allowed.  If the patch requires
major rework then we deal with those on a case-by-case basis.  I think
Jason has once characterized it as "no new concepts" after stage1 close.

We also usually give some port, language and runtime maintainers a bit
more leeway.

You've clearly met the submission deadline, so it's in the hands of the
Fortran maintainers to decide if this should go forward.

jeff
Thomas Koenig Nov. 17, 2019, 7:32 p.m. | #3
Hi Steve,

> On Fri, Nov 15, 2019 at 10:40:56AM +0000, Mark Eggleston wrote:

>> This patch allows comparison of numeric values with Holleriths. This

>> feature is not guarded by a compiler option as it is preferred that

>> extra options should avoided, this seems reasonable as current Hollerith

>> support does not have such an option.

> 

> IMHO.

> 

> Has the comparison of a numeric value and a hollerith

> ever been allowed in a Fortran standard?  If the answer

> is 'No', then you should (1) put the comparison behind

> an option, and (2) have gfortran issue an error without

> the option.  If this is a DEC extension, then put it

> behind -fdec.  If this misfeature is not a DEC extension

> but allow some ancient piece of code to compile, then

> put it behind -std=lagacy.


I concur.

Additionally, please put in a test case which confirms that
an error is indeed emitted without that particular option.

Regards

	Thomas

Patch

From 14547b653c02711a980d3d376cdd26545eb152f2 Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggleston@codethink.com>
Date: Thu, 23 May 2019 09:42:26 +0100
Subject: [PATCH] dec comparisons

Allow comparison of Hollerith constants with numeric and character
expressions. Also allow comparison of character literalsa with numeric
expressions.

Enable using -fdec-comparisons or -fdec
---
 gcc/fortran/gfortran.texi                          | 32 +++++++++-----
 gcc/fortran/invoke.texi                            | 27 ++++++------
 gcc/fortran/lang.opt                               |  3 +-
 gcc/fortran/resolve.c                              | 51 +++++++++++++++++++++-
 .../gfortran.dg/dec-comparison-character_1.f90     | 35 +++++++++++++++
 .../gfortran.dg/dec-comparison-character_2.f90     | 18 ++++++++
 .../gfortran.dg/dec-comparison-character_3.f90     | 17 ++++++++
 .../gfortran.dg/dec-comparison-complex_1.f90       | 17 ++++++++
 .../gfortran.dg/dec-comparison-complex_2.f90       | 17 ++++++++
 .../gfortran.dg/dec-comparison-complex_3.f90       | 17 ++++++++
 .../gfortran.dg/dec-comparison-complex_4.f90       | 17 ++++++++
 gcc/testsuite/gfortran.dg/dec-comparison-int_1.f90 | 22 ++++++++++
 gcc/testsuite/gfortran.dg/dec-comparison-int_2.f90 | 22 ++++++++++
 gcc/testsuite/gfortran.dg/dec-comparison-int_3.f90 | 22 ++++++++++
 gcc/testsuite/gfortran.dg/dec-comparison-int_4.f90 | 40 +++++++++++++++++
 .../gfortran.dg/dec-comparison-real_1.f90          | 22 ++++++++++
 .../gfortran.dg/dec-comparison-real_2.f90          | 22 ++++++++++
 .../gfortran.dg/dec-comparison-real_3.f90          | 22 ++++++++++
 .../gfortran.dg/dec-comparison-real_4.f90          | 22 ++++++++++
 gcc/testsuite/gfortran.dg/dec-comparison.f90       | 41 +++++++++++++++++
 20 files changed, 461 insertions(+), 25 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-character_1.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-character_2.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-character_3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-complex_1.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-complex_2.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-complex_3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-complex_4.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-int_1.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-int_2.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-int_3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-int_4.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-real_1.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-real_2.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-real_3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison-real_4.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-comparison.f90

diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index a34ac5aa1bf..67493a94b01 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -1916,14 +1916,14 @@  in I/O operations.
 @subsection Hollerith constants support
 @cindex Hollerith constants
 
-GNU Fortran supports Hollerith constants in assignments, function
-arguments, and @code{DATA} statements.  A Hollerith constant is written
-as a string of characters preceded by an integer constant indicating the
-character count, and the letter @code{H} or @code{h}, and stored in
-bytewise fashion in a numeric (@code{INTEGER}, @code{REAL}, or
-@code{COMPLEX}) or @code{LOGICAL} variable.  The constant will be padded
-with spaces or truncated to fit the size of the variable in which it is
-stored.
+GNU Fortran supports Hollerith constants in assignments, @code{DATA}
+statements, function and subroutine arguments. A Hollerith constant is
+written as a string of characters preceded by an integer constant 
+indicating the character count, and the letter @code{H} or
+@code{h}, and stored in bytewise fashion in a numeric (@code{INTEGER},
+@code{REAL}, or @code{COMPLEX}), @code{LOGICAL} or @code{CHARACTER} variable.
+The constant will be padded with spaces or truncated to fit the size of
+the variable in which it is stored.
 
 Examples of valid uses of Hollerith constants:
 @smallexample
@@ -1951,10 +1951,22 @@  case where the intent is specifically to initialize a numeric variable
 with a given byte sequence.  In these cases, the same result can be
 obtained by using the @code{TRANSFER} statement, as in this example.
 @smallexample
-      INTEGER(KIND=4) :: a
-      a = TRANSFER ("abcd", a)     ! equivalent to: a = 4Habcd
+      integer(kind=4) :: a
+      a = transfer ("abcd", a)     ! equivalent to: a = 4Habcd
 @end smallexample
 
+The use of the @option{-fdec-char-conversions} option extends support of
+Hollerith constants to comparisons:
+@smallexample
+      integer*4 a
+      a = 4hABCD
+      if (a .ne. 4habcd) then
+        write(*,*) "no match"
+      end if
+@end smallexample
+
+Supported types are numeric (@code{INTEGER}, @code{REAL}, or @code{COMPLEX}),
+and @code{CHARACTER}.
 
 @node Character conversion
 @subsection Character conversion
diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi
index 46ee3c9241b..c1dc7afaab6 100644
--- a/gcc/fortran/invoke.texi
+++ b/gcc/fortran/invoke.texi
@@ -117,17 +117,17 @@  by type.  Explanations are in the following sections.
 @item Fortran Language Options
 @xref{Fortran Dialect Options,,Options controlling Fortran dialect}.
 @gccoptlist{-fall-intrinsics -fallow-argument-mismatch -fallow-invalid-boz @gol
--fbackslash -fcray-pointer -fd-lines-as-code -fd-lines-as-comments -fdec @gol
--fdec-char-conversions -fdec-structure -fdec-intrinsic-ints -fdec-static @gol
--fdec-math -fdec-include -fdec-format-defaults -fdec-blank-format-item @gol
--fdefault-double-8 -fdefault-integer-8 -fdefault-real-8 -fdefault-real-10 @gol
--fdefault-real-16 -fdollar-ok -ffixed-line-length-@var{n} @gol
--ffixed-line-length-none -fpad-source -ffree-form @gol
--ffree-line-length-@var{n} -ffree-line-length-none -fimplicit-none @gol
--finteger-4-integer-8 -fmax-identifier-length -fmodule-private @gol
--ffixed-form -fno-range-check -fopenacc -fopenmp -freal-4-real-10 @gol
--freal-4-real-16 -freal-4-real-8 -freal-8-real-10 -freal-8-real-16 @gol
--freal-8-real-4 -std=@var{std} -ftest-forall-temp
+-fbackslash -fcray-pointer -fd-lines-as-code -fd-lines-as-comments @gol
+-fdec -fdec-char-conversions -fdec-structure -fdec-intrinsic-ints @gol
+-fdec-static -fdec-math -fdec-include -fdec-format-defaults @gol
+-fdec-blank-format-item -fdefault-double-8 -fdefault-integer-8 @gol
+-fdefault-real-8 -fdefault-real-10 -fdefault-real-16 -fdollar-ok @gol
+-ffixed-line-length-@var{n} -ffixed-line-length-none -fpad-source @gol
+-ffree-form -ffree-line-length-@var{n} -ffree-line-length-none @gol
+-fimplicit-none -finteger-4-integer-8 -fmax-identifier-length @gol
+-fmodule-private -ffixed-form -fno-range-check -fopenacc -fopenmp @gol
+-freal-4-real-10 -freal-4-real-16 -freal-4-real-8 -freal-8-real-10 @gol
+-freal-8-real-16 -freal-8-real-4 -std=@var{std} -ftest-forall-temp
 }
 
 @item Preprocessing Options
@@ -283,8 +283,9 @@  If @option{-fd-lines-as-code}/@option{-fd-lines-as-comments} are unset, then
 
 @item -fdec-char-conversions
 @opindex @code{fdec-char-conversions}
-Enable the use of character literals in assignments and data statements
-for non-character variables.
+Enable the use of character literals in assignments and @code{DATA} statements
+for non-character variables. Use of character literals in comparisons with
+HOLLERITH constants is also enabled.
 
 @item -fdec-structure
 @opindex @code{fdec-structure}
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
index 5fcd1ff9075..dcb8776849c 100644
--- a/gcc/fortran/lang.opt
+++ b/gcc/fortran/lang.opt
@@ -463,7 +463,8 @@  Enable the use of blank format items in format strings.
 fdec-char-conversions
 Fortran Var(flag_dec_char_conversions)
 Enable the use of character literals in assignments and data statements
-for non-character variables.
+for non-character variables. Also enables comparison of characters
+with Hollerith constants.
 
 fdec-include
 Fortran Var(flag_dec_include)
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 2371a9e201f..16bc2e1a13c 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -3900,6 +3900,42 @@  impure_function_callback (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED,
   return 0;
 }
 
+/* Return true if TYPE is character based, false otherwise.  */
+
+static int
+is_character_based (bt type)
+{
+  return type == BT_CHARACTER || type == BT_HOLLERITH;
+}
+
+
+/* If expression is a hollerith, convert it to character and issue a warning
+   for the conversion.  */
+
+static void
+convert_hollerith_to_character (gfc_expr *e)
+{
+  if (e->ts.type == BT_HOLLERITH)
+    {
+      gfc_typespec t;
+      gfc_clear_ts (&t);
+      t.type = BT_CHARACTER;
+      t.kind = e->ts.kind;
+      gfc_convert_type_warn (e, &t, 2, 1);
+    }
+}
+
+/* Convert to numeric and issue a warning for the conversion.  */
+
+static void
+convert_to_numeric (gfc_expr *a, gfc_expr *b)
+{
+  gfc_typespec t;
+  gfc_clear_ts (&t);
+  t.type = b->ts.type;
+  t.kind = b->ts.kind;
+  gfc_convert_type_warn (a, &t, 2, 1);
+}
 
 /* Resolve an operator expression node.  This can involve replacing the
    operation with a user defined function call.  */
@@ -4100,6 +4136,14 @@  resolve_operator (gfc_expr *e)
     case INTRINSIC_EQ_OS:
     case INTRINSIC_NE:
     case INTRINSIC_NE_OS:
+
+      if (is_character_based (op1->ts.type)
+	  && is_character_based (op2->ts.type))
+	{
+	  convert_hollerith_to_character (op1);
+	  convert_hollerith_to_character (op2);
+	}
+
       if (op1->ts.type == BT_CHARACTER && op2->ts.type == BT_CHARACTER
 	  && op1->ts.kind == op2->ts.kind)
 	{
@@ -4137,6 +4181,11 @@  resolve_operator (gfc_expr *e)
 	  if (op1->ts.type == BT_REAL && !gfc_boz2real (op2, op1->ts.kind))
 	    return false;
 	}
+      if (op1->ts.type == BT_HOLLERITH && gfc_numeric_ts (&op2->ts))
+	convert_to_numeric (op1, op2);
+
+      if (gfc_numeric_ts (&op1->ts) && op2->ts.type == BT_HOLLERITH)
+	convert_to_numeric (op2, op1);
 
       if (gfc_numeric_ts (&op1->ts) && gfc_numeric_ts (&op2->ts))
 	{
@@ -10693,7 +10742,7 @@  resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns)
 
   if ((gfc_numeric_ts (&lhs->ts) || lhs->ts.type == BT_LOGICAL)
       && rhs->ts.type == BT_CHARACTER
-      && rhs->expr_type != EXPR_CONSTANT)
+      && (rhs->expr_type != EXPR_CONSTANT || !flag_dec_char_conversions))
     {
       /* Use of -fdec-char-conversions allows assignment of character data
 	 to non-character variables.  This not permited for nonconstant
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-character_1.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-character_1.f90
new file mode 100644
index 00000000000..43004a27618
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison-character_1.f90
@@ -0,0 +1,35 @@ 
+! { dg-do run }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+
+program convert
+  character(4) :: c = 4HJMAC
+  if (4HJMAC.ne.4HJMAC) stop 1
+  if (4HJMAC.ne."JMAC") stop 2
+  if (4HJMAC.eq."JMAN") stop 3
+  if ("JMAC".eq.4HJMAN) stop 4
+  if ("AAAA".eq.5HAAAAA) stop 5
+  if ("BBBBB".eq.5HBBBB ) stop 6
+  if (4HJMAC.ne.c) stop 7
+  if (c.ne.4HJMAC) stop 8
+end program
+
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 7 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 8 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 9 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 10 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 11 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 12 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 13 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 14 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 15 }
+! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 7 }
+! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 8 }
+! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 9 }
+! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 10 }
+! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 11 }
+! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 12 }
+! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 13 }
+! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 14 }
+! { dg-warning "HOLLERITH to CHARACTER" " " { target *-*-* } 15 }
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-character_2.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-character_2.f90
new file mode 100644
index 00000000000..6a68a71737a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison-character_2.f90
@@ -0,0 +1,18 @@ 
+! { dg-do run }
+! { dg-options "-std=legacy -Wconversion" }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+
+program convert
+  character(4) :: c = 4HJMAC ! { dg-warning "HOLLERITH to CHARACTER" }
+  if (4HJMAC.ne.4HJMAC) stop 1 ! { dg-warning "HOLLERITH to CHARACTER" }
+  if (4HJMAC.ne."JMAC") stop 2 ! { dg-warning "HOLLERITH to CHARACTER" }
+  if (4HJMAC.eq."JMAN") stop 3 ! { dg-warning "HOLLERITH to CHARACTER" }
+  if ("JMAC".eq.4HJMAN) stop 4 ! { dg-warning "HOLLERITH to CHARACTER" }
+  if ("AAAA".eq.5HAAAAA) stop 5 ! { dg-warning "HOLLERITH to CHARACTER" }
+  if ("BBBBB".eq.5HBBBB ) stop 6 ! { dg-warning "HOLLERITH to CHARACTER" }
+  if (4HJMAC.ne.c) stop 7 ! { dg-warning "HOLLERITH to CHARACTER" }
+  if (c.ne.4HJMAC) stop 8 ! { dg-warning "HOLLERITH to CHARACTER" }
+end program
+
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-character_3.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-character_3.f90
new file mode 100644
index 00000000000..a0ad446dcf2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison-character_3.f90
@@ -0,0 +1,17 @@ 
+! { dg-do run }
+! { dg-options "-std=legacy" }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+
+program convert
+  character(4) :: c = 4HJMAC
+  if (4HJMAC.ne.4HJMAC) stop 1
+  if (4HJMAC.ne."JMAC") stop 2
+  if (4HJMAC.eq."JMAN") stop 3
+  if ("JMAC".eq.4HJMAN) stop 4
+  if ("AAAA".eq.5HAAAAA) stop 5
+  if ("BBBBB".eq.5HBBBB ) stop 6
+  if (4HJMAC.ne.c) stop 7
+end program
+
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-complex_1.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-complex_1.f90
new file mode 100644
index 00000000000..5956f01a43a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison-complex_1.f90
@@ -0,0 +1,17 @@ 
+! { dg-do run }
+! { dg-options "-std=legacy -fdec -Wconversion" }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+
+program convert
+  complex(4) :: a
+  complex(4) :: b
+  a = 8HABCDABCD ! { dg-warning "Conversion from HOLLERITH" }
+  b = transfer("ABCDABCD", b);
+  ! Hollerith constants
+  if (a.ne.8HABCDABCD) stop 1 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.eq.8HABCEABCE) stop 2 ! { dg-warning "Conversion from HOLLERITH" }
+  if (8HABCDABCD.ne.b) stop 3 ! { dg-warning "Conversion from HOLLERITH" }
+  if (8HABCEABCE.eq.b) stop 4 ! { dg-warning "Conversion from HOLLERITH" }
+end program
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-complex_2.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-complex_2.f90
new file mode 100644
index 00000000000..8727f15b0fd
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison-complex_2.f90
@@ -0,0 +1,17 @@ 
+! { dg-do run }
+! { dg-options "-std=legacy -fdec-char-conversions -Wconversion" }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+
+program convert
+  complex(4) :: a
+  complex(4) :: b
+  a = 8HABCDABCD ! { dg-warning "Conversion from HOLLERITH" }
+  b = transfer("ABCDABCD", b);
+  ! Hollerith constants
+  if (a.ne.8HABCDABCD) stop 1 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.eq.8HABCEABCE) stop 2 ! { dg-warning "Conversion from HOLLERITH" }
+  if (8HABCDABCD.ne.b) stop 3 ! { dg-warning "Conversion from HOLLERITH" }
+  if (8HABCEABCE.eq.b) stop 4 ! { dg-warning "Conversion from HOLLERITH" }
+end program
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-complex_3.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-complex_3.f90
new file mode 100644
index 00000000000..002d0e64ffd
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison-complex_3.f90
@@ -0,0 +1,17 @@ 
+! { dg-do run }
+! { dg-options "-std=legacy -fdec -fno-dec-char-conversions -Wconversion" }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+
+program convert
+  complex(4) :: a
+  complex(4) :: b
+  a = 8HABCDABCD ! { dg-warning "Conversion from HOLLERITH" }
+  b = transfer("ABCDABCD", b);
+  ! character literals
+  if (a.ne."ABCDABCD") stop 1 ! { dg-error "Operands of comparison" }
+  if (a.eq."ABCEABCE") stop 2 ! { dg-error "Operands of comparison" }
+  if ("ABCDABCD".ne.b) stop 3 ! { dg-error "Operands of comparison" }
+  if ("ABCEABCE".eq.b) stop 4 ! { dg-error "Operands of comparison" }
+end program
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-complex_4.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-complex_4.f90
new file mode 100644
index 00000000000..1f76d4c4b77
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison-complex_4.f90
@@ -0,0 +1,17 @@ 
+! { dg-do run }
+! { dg-options "-std=legacy -Wconversion" }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+
+program convert
+  complex(4) :: a
+  complex(4) :: b
+  a = 8HABCDABCD ! { dg-warning "Conversion from HOLLERITH" }
+  b = transfer("ABCDABCD", b);
+  ! Hollerith constants
+  if (a.ne.8HABCDABCD) stop 1 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.eq.8HABCEABCE) stop 2 ! { dg-warning "Conversion from HOLLERITH" }
+  if (8HABCDABCD.ne.b) stop 3 ! { dg-warning "Conversion from HOLLERITH" }
+  if (8HABCEABCE.eq.b) stop 4 ! { dg-warning "Conversion from HOLLERITH" }
+end program
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-int_1.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-int_1.f90
new file mode 100644
index 00000000000..1557fe9bae6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison-int_1.f90
@@ -0,0 +1,22 @@ 
+! { dg-do run }
+! { dg-options "-std=legacy -fdec -Wconversion" }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+
+program convert
+  integer(4) :: a
+  integer(4) :: b
+  a = 4HABCD ! { dg-warning "Conversion from HOLLERITH" }
+  b = transfer("ABCD", b)
+  ! Hollerith constants
+  if (a.ne.4HABCD) stop 1 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.eq.4HABCE) stop 2 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCD.ne.b) stop 3 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCE.eq.b) stop 4 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCE.lt.a) stop 5 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.gt.4HABCE) stop 6 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCE.le.a) stop 7 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.ge.4HABCE) stop 8 ! { dg-warning "Conversion from HOLLERITH" }
+end program
+
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-int_2.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-int_2.f90
new file mode 100644
index 00000000000..90b8301716f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison-int_2.f90
@@ -0,0 +1,22 @@ 
+! { dg-do run }
+! { dg-options "-std=legacy -fdec-char-conversions -Wconversion" }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+
+program convert
+  integer(4) :: a
+  integer(4) :: b
+  a = 4HABCD ! { dg-warning "Conversion from HOLLERITH" }
+  b = transfer("ABCD", b)
+  ! Hollerith constants
+  if (a.ne.4HABCD) stop 1 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.eq.4HABCE) stop 2 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCD.ne.b) stop 3 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCE.eq.b) stop 4 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCE.lt.a) stop 5 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.gt.4HABCE) stop 6 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCE.le.a) stop 7 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.ge.4HABCE) stop 8 ! { dg-warning "Conversion from HOLLERITH" }
+end program
+
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-int_3.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-int_3.f90
new file mode 100644
index 00000000000..7a5d21ad659
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison-int_3.f90
@@ -0,0 +1,22 @@ 
+! { dg-do compile }
+! { dg-options "-fdec -fno-dec-char-conversions -Wconversion" }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+
+program convert
+  integer(4) :: a
+  integer(4) :: b
+  a = 4HABCD ! { dg-warning "Conversion from HOLLERITH" }
+  b = transfer("ABCD", b)
+  ! Character literals
+  if (a.ne."ABCD") stop 1 ! { dg-error "Operands of comparison" }
+  if (a.eq."ABCE") stop 2 ! { dg-error "Operands of comparison" }
+  if ("ABCD".ne.b) stop 3 ! { dg-error "Operands of comparison" }
+  if ("ABCE".eq.b) stop 4 ! { dg-error "Operands of comparison" }
+  if ("ABCE".lt.a) stop 5 ! { dg-error "Operands of comparison" }
+  if (a.gt."ABCE") stop 6 ! { dg-error "Operands of comparison" }
+  if ("ABCE".le.a) stop 7 ! { dg-error "Operands of comparison" }
+  if (a.ge."ABCE") stop 8 ! { dg-error "Operands of comparison" }
+end program
+
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-int_4.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-int_4.f90
new file mode 100644
index 00000000000..cd38e8641a6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison-int_4.f90
@@ -0,0 +1,40 @@ 
+! { dg-do run }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+
+program convert
+  integer(4) :: a
+  integer(4) :: b
+  a = 4HABCD
+  b = transfer("ABCD", b)
+  ! Hollerith constants
+  if (a.ne.4HABCD) stop 1
+  if (a.eq.4HABCE) stop 2
+  if (4HABCD.ne.b) stop 3
+  if (4HABCE.eq.b) stop 4
+  if (4HABCE.lt.a) stop 5
+  if (a.gt.4HABCE) stop 6
+  if (4HABCE.le.a) stop 7
+  if (a.ge.4HABCE) stop 8
+end program
+
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 9 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 12 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 13 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 14 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 15 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 16 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 17 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 18 }
+! { dg-warning "Extension: Hollerith constant at" " " { target *-*-* } 19 }
+! { dg-warning "HOLLERITH to INTEGER" " " { target *-*-* } 9 }
+! { dg-warning "HOLLERITH to INTEGER" " " { target *-*-* } 12 }
+! { dg-warning "HOLLERITH to INTEGER" " " { target *-*-* } 13 }
+! { dg-warning "HOLLERITH to INTEGER" " " { target *-*-* } 14 }
+! { dg-warning "HOLLERITH to INTEGER" " " { target *-*-* } 15 }
+! { dg-warning "HOLLERITH to INTEGER" " " { target *-*-* } 16 }
+! { dg-warning "HOLLERITH to INTEGER" " " { target *-*-* } 17 }
+! { dg-warning "HOLLERITH to INTEGER" " " { target *-*-* } 18 }
+! { dg-warning "HOLLERITH to INTEGER" " " { target *-*-* } 19 }
+
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-real_1.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-real_1.f90
new file mode 100644
index 00000000000..6a8784e38c2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison-real_1.f90
@@ -0,0 +1,22 @@ 
+! { dg-do run }
+! { dg-options "-std=legacy -fdec -Wconversion" }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+
+program convert
+  real(4) :: a
+  real(4) :: b
+  a = 4HABCD ! { dg-warning "Conversion from HOLLERITH" }
+  b = transfer("ABCD", b)
+  ! Hollerith constants
+  if (a.ne.4HABCD) stop 1 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.eq.4HABCE) stop 2 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCD.ne.b) stop 3 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCE.eq.b) stop 4 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCE.lt.a) stop 5 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.gt.4HABCE) stop 6 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCE.le.a) stop 7 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.ge.4HABCE) stop 8 ! { dg-warning "Conversion from HOLLERITH" }
+end program
+
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-real_2.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-real_2.f90
new file mode 100644
index 00000000000..38c5c163c42
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison-real_2.f90
@@ -0,0 +1,22 @@ 
+! { dg-do run }
+! { dg-options "-std=legacy -fdec-char-conversions -Wconversion" }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+
+program convert
+  real(4) :: a
+  real(4) :: b
+  a = 4HABCD ! { dg-warning "Conversion from HOLLERITH" }
+  b = transfer("ABCD", b)
+  ! Hollerith constants
+  if (a.ne.4HABCD) stop 1 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.eq.4HABCE) stop 2 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCD.ne.b) stop 3 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCE.eq.b) stop 4 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCE.lt.a) stop 5 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.gt.4HABCE) stop 6 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCE.le.a) stop 7 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.ge.4HABCE) stop 8 ! { dg-warning "Conversion from HOLLERITH" }
+end program
+
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-real_3.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-real_3.f90
new file mode 100644
index 00000000000..aa99ca0ae31
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison-real_3.f90
@@ -0,0 +1,22 @@ 
+! { dg-do run }
+! { dg-options "-std=legacy -fdec -fno-dec-char-conversions -Wconversion" }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+
+program convert
+  real(4) :: a
+  real(4) :: b
+  a = 4HABCD ! { dg-warning "Conversion from HOLLERITH" }
+  b = transfer("ABCD", b)
+  ! Character literals
+  if (a.ne."ABCD") stop 1 ! { dg-error "Operands of comparison" }
+  if (a.eq."ABCE") stop 2 ! { dg-error "Operands of comparison" }
+  if ("ABCD".ne.b) stop 3 ! { dg-error "Operands of comparison" }
+  if ("ABCE".eq.b) stop 4 ! { dg-error "Operands of comparison" }
+  if ("ABCE".lt.a) stop 5 ! { dg-error "Operands of comparison" }
+  if (a.gt."ABCE") stop 6 ! { dg-error "Operands of comparison" }
+  if ("ABCE".le.a) stop 7 ! { dg-error "Operands of comparison" }
+  if (a.ge."ABCE") stop 8 ! { dg-error "Operands of comparison" }
+end program
+
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison-real_4.f90 b/gcc/testsuite/gfortran.dg/dec-comparison-real_4.f90
new file mode 100644
index 00000000000..6a8784e38c2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison-real_4.f90
@@ -0,0 +1,22 @@ 
+! { dg-do run }
+! { dg-options "-std=legacy -fdec -Wconversion" }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+
+program convert
+  real(4) :: a
+  real(4) :: b
+  a = 4HABCD ! { dg-warning "Conversion from HOLLERITH" }
+  b = transfer("ABCD", b)
+  ! Hollerith constants
+  if (a.ne.4HABCD) stop 1 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.eq.4HABCE) stop 2 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCD.ne.b) stop 3 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCE.eq.b) stop 4 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCE.lt.a) stop 5 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.gt.4HABCE) stop 6 ! { dg-warning "Conversion from HOLLERITH" }
+  if (4HABCE.le.a) stop 7 ! { dg-warning "Conversion from HOLLERITH" }
+  if (a.ge.4HABCE) stop 8 ! { dg-warning "Conversion from HOLLERITH" }
+end program
+
diff --git a/gcc/testsuite/gfortran.dg/dec-comparison.f90 b/gcc/testsuite/gfortran.dg/dec-comparison.f90
new file mode 100644
index 00000000000..b0b28e55111
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-comparison.f90
@@ -0,0 +1,41 @@ 
+! { dg-do run }
+! { dg-options "-fdec" }
+!
+! Test case contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+!
+! Hollerith constants and character literals are allowed in comparisons,
+! check that character variables can not be compared with numeric variables.
+
+program convert
+  character(4) :: a = 4hJMAC
+  integer(4) :: b = "JMAC"
+  real(4) :: c = "JMAC"
+  complex(4) :: d = "JMACJMAC"
+  ! integers
+  if (a.ne.b) stop 1 ! { dg-error "Operands of comparison" }
+  if (b.eq.a) stop 2 ! { dg-error "Operands of comparison" }
+  if (a.ge.b) stop 3 ! { dg-error "Operands of comparison" }
+  if (b.ge.a) stop 4 ! { dg-error "Operands of comparison" }
+  if (a.gt.b) stop 5 ! { dg-error "Operands of comparison" }
+  if (b.gt.a) stop 6 ! { dg-error "Operands of comparison" }
+  if (a.le.b) stop 3 ! { dg-error "Operands of comparison" }
+  if (b.le.a) stop 4 ! { dg-error "Operands of comparison" }
+  if (a.lt.b) stop 5 ! { dg-error "Operands of comparison" }
+  if (b.lt.a) stop 6 ! { dg-error "Operands of comparison" }
+  ! reals
+  if (a.ne.c) stop 7 ! { dg-error "Operands of comparison" }
+  if (c.eq.a) stop 8 ! { dg-error "Operands of comparison" }
+  if (a.ge.c) stop 9 ! { dg-error "Operands of comparison" }
+  if (c.ge.a) stop 10 ! { dg-error "Operands of comparison" }
+  if (a.gt.c) stop 11 ! { dg-error "Operands of comparison" }
+  if (c.gt.a) stop 12 ! { dg-error "Operands of comparison" }
+  if (a.le.c) stop 13 ! { dg-error "Operands of comparison" }
+  if (c.le.a) stop 14 ! { dg-error "Operands of comparison" }
+  if (a.lt.c) stop 15 ! { dg-error "Operands of comparison" }
+  if (c.lt.a) stop 16 ! { dg-error "Operands of comparison" }
+  ! complexes
+  a = "JMACJMAC"
+  if (a.ne.d) stop 17 ! { dg-error "Operands of comparison" }
+  if (d.eq.a) stop 18 ! { dg-error "Operands of comparison" }
+end program
+
-- 
2.11.0