public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, Fortran] pad char to int conversions with spaces instead of zeros (legacy)
@ 2018-12-04 14:47 Mark Eggleston
  2018-12-04 15:11 ` Jakub Jelinek
  0 siblings, 1 reply; 17+ messages in thread
From: Mark Eggleston @ 2018-12-04 14:47 UTC (permalink / raw)
  To: fortran, gcc-patches; +Cc: Jakub Jelinek, Jeff Law

[-- Attachment #1: Type: text/plain, Size: 792 bytes --]

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


[-- Attachment #2: 0001-Pad-character-to-int-conversions-with-spaces-instead.patch --]
[-- Type: text/x-patch, Size: 4907 bytes --]

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 #3: gcc-fortran-changelog.txt --]
[-- Type: text/plain, Size: 370 bytes --]

	Jim MacArthur <jim.macarthur@codethink.co.uk>
	Mark Eggleston <mark.eggleston@codethink.com>

	-fdec-pad-with-spaces
	* gcc/fortran/lang.opt: add new option.
	* gcc/fortran/options.c (set_dec_flags): add SET_BITFLAG for
	flag_dec_pad_with_spaces.
	* gcc/fortran/simplify.c (gfc_simplify_transfer): memset with
	0x20 instead of 0x0 when flag_dec_pad_with_spaces is set.

[-- Attachment #4: gcc-testsuite-changelog.txt --]
[-- Type: text/plain, Size: 228 bytes --]

	Mark Eggleston <mark.eggleston@codethink.com>

	-fdec-pad-with-spaces
	* gfortran.dg/dec-pad-with-spaces-1.f90: New test.
	* gfortran.dg/dec-pad-with-spaces-2.f90: New test.
	* gfortran.dg/dec-pad-with-spaces-3.f90: New test.


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2018-12-12 15:12 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-04 14:47 [PATCH, Fortran] pad char to int conversions with spaces instead of zeros (legacy) Mark Eggleston
2018-12-04 15:11 ` Jakub Jelinek
2018-12-04 17:04   ` Fritz Reese
2018-12-06  2:27     ` Jerry DeLisle
2018-12-06 10:50       ` Jakub Jelinek
2018-12-06 10:54         ` Mark Eggleston
2018-12-07  1:57         ` Jerry DeLisle
2018-12-06 10:34     ` Mark Eggleston
2018-12-10 14:09       ` Mark Eggleston
2018-12-10 17:12         ` Jakub Jelinek
2018-12-10 19:44           ` Fritz Reese
2018-12-12 11:37           ` Mark Eggleston
2018-12-12 11:53             ` Jakub Jelinek
2018-12-12 12:06               ` Mark Eggleston
2018-12-12 12:12                 ` Jakub Jelinek
2018-12-12 15:12                 ` Mark Eggleston
2018-12-06 10:23   ` Mark Eggleston

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).