Blame SOURCES/gcc11-fortran-fdec-ichar.patch

237f7c
From f883ac209b0feea860354cb4ef7ff06dc8063fab Mon Sep 17 00:00:00 2001
237f7c
From: Mark Eggleston <markeggleston@gcc.gnu.org>
237f7c
Date: Fri, 22 Jan 2021 12:53:35 +0000
237f7c
Subject: [PATCH 03/10] Allow more than one character as argument to ICHAR
237f7c
237f7c
Use -fdec to enable.
237f7c
---
237f7c
 gcc/fortran/check.c                           |  2 +-
237f7c
 gcc/fortran/simplify.c                        |  4 ++--
237f7c
 .../gfortran.dg/dec_ichar_with_string_1.f     | 21 +++++++++++++++++++
237f7c
 3 files changed, 24 insertions(+), 3 deletions(-)
237f7c
 create mode 100644 gcc/testsuite/gfortran.dg/dec_ichar_with_string_1.f
237f7c
237f7c
diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
237f7c
index 82db8e4e1b2..623c1cc470e 100644
237f7c
--- a/gcc/fortran/check.c
237f7c
+++ b/gcc/fortran/check.c
237f7c
@@ -3157,7 +3157,7 @@ gfc_check_ichar_iachar (gfc_expr *c, gfc_expr *kind)
237f7c
   else
237f7c
     return true;
237f7c
 
237f7c
-  if (i != 1)
237f7c
+  if (i != 1 && !flag_dec)
237f7c
     {
237f7c
       gfc_error ("Argument of %s at %L must be of length one",
237f7c
 		 gfc_current_intrinsic, &c->where);
237f7c
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
237f7c
index 23317a2e2d9..9900572424f 100644
237f7c
--- a/gcc/fortran/simplify.c
237f7c
+++ b/gcc/fortran/simplify.c
237f7c
@@ -3261,7 +3261,7 @@ gfc_simplify_iachar (gfc_expr *e, gfc_expr *kind)
237f7c
   if (e->expr_type != EXPR_CONSTANT)
237f7c
     return NULL;
237f7c
 
237f7c
-  if (e->value.character.length != 1)
237f7c
+  if (e->value.character.length != 1 && !flag_dec)
237f7c
     {
237f7c
       gfc_error ("Argument of IACHAR at %L must be of length one", &e->where);
237f7c
       return &gfc_bad_expr;
237f7c
@@ -3459,7 +3459,7 @@ gfc_simplify_ichar (gfc_expr *e, gfc_expr *kind)
237f7c
   if (e->expr_type != EXPR_CONSTANT)
237f7c
     return NULL;
237f7c
 
237f7c
-  if (e->value.character.length != 1)
237f7c
+  if (e->value.character.length != 1 && !flag_dec)
237f7c
     {
237f7c
       gfc_error ("Argument of ICHAR at %L must be of length one", &e->where);
237f7c
       return &gfc_bad_expr;
237f7c
diff --git a/gcc/testsuite/gfortran.dg/dec_ichar_with_string_1.f b/gcc/testsuite/gfortran.dg/dec_ichar_with_string_1.f
237f7c
new file mode 100644
237f7c
index 00000000000..85efccecc0f
237f7c
--- /dev/null
237f7c
+++ b/gcc/testsuite/gfortran.dg/dec_ichar_with_string_1.f
237f7c
@@ -0,0 +1,21 @@
237f7c
+! { dg-do run }
237f7c
+! { dg-options "-fdec" }
237f7c
+!
237f7c
+! Test ICHAR and IACHAR with more than one character as argument
237f7c
+!
237f7c
+! Test case contributed by Jim MacArthur <jim.macarthur@codethink.co.uk>
237f7c
+! Modified by Mark Eggleston <mark.eggleston@codethink.com>
237f7c
+!
237f7c
+        PROGRAM ichar_more_than_one_character
237f7c
+          CHARACTER*4 st/'Test'/
237f7c
+          INTEGER i
237f7c
+
237f7c
+          i = ICHAR(st)
237f7c
+          if (i.NE.84) STOP 1
237f7c
+          i = IACHAR(st)
237f7c
+          if (i.NE.84) STOP 2
237f7c
+          i = ICHAR('Test')
237f7c
+          if (i.NE.84) STOP 3
237f7c
+          i = IACHAR('Test')
237f7c
+          if (i.NE.84) STOP 4
237f7c
+        END
237f7c
-- 
237f7c
2.27.0
237f7c