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

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