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

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