This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, Fortran] pad char to int conversions with spaces instead of zeros (legacy)


Here is a patch to considered for incorporation into gfortran adding to its legacy support. It pads character to integer conversions using spaces instead of zeros when enabled.

The pad character is 'undefined' or 'processor dependent' depending on which standard you read. This makes it 0x20 which matches the Oracle Fortran compiler.

Enabled using -fdec-pad-with-spaces and -fdec.

Please find attached a patch file and text files containing change log entries for gcc/fortran and gcc/testsuite.

Note: I do not have write access so can not commit changes. Someone else will have to commit the change if it is acceptable.

There are several more patches to support legacy Fortran which will be sent in order.

regards,

Mark Eggleston

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

>From de02d8bbab91a87c30672d1a9e1c3ecc95b800f7 Mon Sep 17 00:00:00 2001
From: Jim MacArthur <jim.macarthur@codethink.co.uk>
Date: Mon, 28 Sep 2015 16:06:30 +0100
Subject: [PATCH] Pad character-to-int conversions with spaces instead of
 zeros.

The pad character is 'undefined' or 'processor dependent' depending on which
standard you read. This makes it 0x20 which matches the Oracle Fortran
compiler.

Additions by Mark Eggleston <mark.eggleston@codethink.com>:

This feature is enabled using -fdec-pad-with-spaces. Also enabled using -fdec.
---
 gcc/fortran/lang.opt                                |  4 ++++
 gcc/fortran/options.c                               |  1 +
 gcc/fortran/simplify.c                              |  2 +-
 gcc/testsuite/gfortran.dg/dec-pad-with-spaces-1.f90 | 17 +++++++++++++++++
 gcc/testsuite/gfortran.dg/dec-pad-with-spaces-2.f90 | 17 +++++++++++++++++
 gcc/testsuite/gfortran.dg/dec-pad-with-spaces-3.f90 | 17 +++++++++++++++++
 6 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/dec-pad-with-spaces-1.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-pad-with-spaces-2.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec-pad-with-spaces-3.f90

diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
index dc9a94c829c..dbdea73ea1f 100644
--- a/gcc/fortran/lang.opt
+++ b/gcc/fortran/lang.opt
@@ -452,6 +452,10 @@ fdec-math
 Fortran Var(flag_dec_math)
 Enable legacy math intrinsics for compatibility.
 
+fdec-pad-with-spaces
+Fortran Var(flag_dec_pad_with_spaces)
+For character to integer conversions, use spaces for the pad rather than NUL.
+
 fdec-structure
 Fortran Var(flag_dec_structure)
 Enable support for DEC STRUCTURE/RECORD.
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
index 48e35e3524d..7abccd28aaf 100644
--- a/gcc/fortran/options.c
+++ b/gcc/fortran/options.c
@@ -74,6 +74,7 @@ set_dec_flags (int value)
   SET_BITFLAG (flag_dec_static, value, value);
   SET_BITFLAG (flag_dec_math, value, value);
   SET_BITFLAG (flag_dec_include, value, value);
+  SET_BITFLAG (flag_dec_pad_with_spaces, value, value);
 }
 
 /* Finalize DEC flags.  */
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index cdf748e4990..04c2c6ea13c 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -7830,7 +7830,7 @@ gfc_simplify_transfer (gfc_expr *source, gfc_expr *mold, gfc_expr *size)
   /* Allocate the buffer to store the binary version of the source.  */
   buffer_size = MAX (source_size, result_size);
   buffer = (unsigned char*)alloca (buffer_size);
-  memset (buffer, 0, buffer_size);
+  memset (buffer, (flag_dec_pad_with_spaces ? 0x20 : 0x0), buffer_size);
 
   /* Now write source to the buffer.  */
   gfc_target_encode_expr (source, buffer, buffer_size);
diff --git a/gcc/testsuite/gfortran.dg/dec-pad-with-spaces-1.f90 b/gcc/testsuite/gfortran.dg/dec-pad-with-spaces-1.f90
new file mode 100644
index 00000000000..c6b5302e79d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-pad-with-spaces-1.f90
@@ -0,0 +1,17 @@
+! { dg-do run }
+! { dg-options "-fdec-pad-with-spaces" }
+!
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
+
+program test
+  integer(kind=8) :: a
+  a = transfer("ABCE", 1_8)
+  ! If a has not been converted into big endian
+  ! or little endian integer it has failed.
+  if ((a.ne.int(z'4142434520202020',kind=8)).and. &
+      (a.ne.int(z'2020202045434241',kind=8))) then 
+    stop 1
+  end if
+end program test
+
+
diff --git a/gcc/testsuite/gfortran.dg/dec-pad-with-spaces-2.f90 b/gcc/testsuite/gfortran.dg/dec-pad-with-spaces-2.f90
new file mode 100644
index 00000000000..dd1d9fb3b32
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-pad-with-spaces-2.f90
@@ -0,0 +1,17 @@
+! { dg-do run }
+! { dg-options "-fdec" }
+!
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
+
+program test
+  integer(kind=8) :: a
+  a = transfer("ABCE", 1_8)
+  ! If a has not been converted into big endian
+  ! or little endian integer it has failed.
+  if ((a.ne.int(z'4142434520202020',kind=8)).and. &
+      (a.ne.int(z'2020202045434241',kind=8))) then 
+    stop 1
+  end if
+end program test
+
+
diff --git a/gcc/testsuite/gfortran.dg/dec-pad-with-spaces-3.f90 b/gcc/testsuite/gfortran.dg/dec-pad-with-spaces-3.f90
new file mode 100644
index 00000000000..131c5e1ceb1
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec-pad-with-spaces-3.f90
@@ -0,0 +1,17 @@
+! { dg-do run }
+! { dg-options "-fdec -fno-dec-pad-with-spaces" }
+!
+! Test case contributed by Mark Eggleston <mark.eggleston@codethink.com>
+
+program test
+  integer(kind=8) :: a
+  a = transfer("ABCE", 1_8)
+  ! If a has not been converted into big endian
+  ! or little endian integer it has failed.
+  if ((a.ne.int(z'4142434500000000',kind=8)).and. &
+      (a.ne.int(z'45434241',kind=8))) then 
+    stop 1
+  end if
+end program test
+
+
-- 
2.11.0

Attachment: gcc-fortran-changelog.txt
Description: Text document

Attachment: gcc-testsuite-changelog.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]