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

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