This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[patch] PR 13070 Asymmetric Integers
- From: Scott Robert Ladd <coyote at coyotegulch dot com>
- To: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 19 Oct 2004 14:09:45 -0400
- Subject: [patch] PR 13070 Asymmetric Integers
It's been ten months since I submitted the original patch for this PR.
I've gone back over these past discussions (below) and generated a new
patch.
http://gcc.gnu.org/ml/fortran/2003-12/msg00095.html
http://gcc.gnu.org/ml/fortran/2003-12/msg00082.html
http://groups.google.com/groups?threadm=nT7Hb.471073%24Dw6.1384364%40attbi_s02
I've had another Fortran 95 program fail to compile with gfortran
because of this "inconsistency" with general practice. To me, it matters
little whether or not gfortran is being exceptionally pedantic or not;
what matters is the ability to compile code containing a common (and
somewhat obvious) convention.
Bootstrapped and tested on i686-pc-linux and x86_64-pc-linux.
..Scott
2004-10-19 Scott Robert Ladd <scott.ladd@coyotegulch.com>
PR c++/13070
* gcc/fortran/gfortran.h: Added flag_asymmetric_integers
to gfc_option_t
* gcc/fortran/options.c (gfc_init_options): Initialized
flag_asymmetric_integers to 0 (false)
* gcc/fortran/options.c (gfc_handle_option): Added section
for setting flag_asymmetric_integers
* gcc/fortran/arith.c (gfc_arith_init_1): When
-fasymmetric_integers is set, subtract 1 from minimum
limit to reflect realities of two's complement signed
integers.
* gcc/fortran/lang.opt: Added entry for -fasymmetric_integers
Index: arith.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/arith.c,v
retrieving revision 1.16
diff -u -3 -p -b -r1.16 arith.c
--- arith.c 8 Oct 2004 18:53:13 -0000 1.16
+++ arith.c 19 Oct 2004 17:52:43 -0000
@@ -198,7 +198,16 @@ gfc_arith_init_1 (void)
mpz_init (int_info->min_int);
mpz_neg (int_info->min_int, int_info->huge);
- /* No -1 here, because the representation is symmetric. */
+
+ /* On systems with two's complement integers, the minimum value
+ lies outside the range of the symmetric integers required by
+ the Fortran Standard (13.7.1 in F95, 13.4 in F0x). Other
+ other compilers accept the minimum 2's complement value
+ (-(2**(n-1)); the -fasymmetric-integers switch allows
+ gfortran to violate the standard for the sake of
+ compatability. */
+ if (gfc_option.flag_asymmetric_integers)
+ mpz_sub_ui (int_info->min_int, int_info->min_int, 1);
mpz_init (int_info->max_int);
mpz_add (int_info->max_int, int_info->huge, int_info->huge);
Index: gfortran.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/gfortran.h,v
retrieving revision 1.39
diff -u -3 -p -b -r1.39 gfortran.h
--- gfortran.h 4 Oct 2004 21:30:26 -0000 1.39
+++ gfortran.h 19 Oct 2004 17:52:44 -0000
@@ -1396,6 +1396,7 @@ typedef struct
int flag_no_backend;
int flag_pack_derived;
int flag_repack_arrays;
+ int flag_asymmetric_integers;
int q_kind;
int r8;
Index: lang.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/lang.opt,v
retrieving revision 1.7
diff -u -3 -p -b -r1.7 lang.opt
--- lang.opt 18 Jul 2004 13:00:34 -0000 1.7
+++ lang.opt 19 Oct 2004 17:52:44 -0000
@@ -129,6 +129,10 @@ frepack-arrays
F95
Copy array sections into a contiguous block on procedure entry
+fasymmetric-integers
+F95
+Accept minimum integer values of -(2**(n-1)), where n is bit-length of an integer type
+
i8
F95
Set the default integer kind to double precision
Index: options.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/options.c,v
retrieving revision 1.12
diff -u -3 -p -b -r1.12 options.c
--- options.c 8 Oct 2004 22:03:36 -0000 1.12
+++ options.c 19 Oct 2004 17:52:44 -0000
@@ -69,6 +69,7 @@ gfc_init_options (unsigned int argc ATTR
gfc_option.flag_no_backend = 0;
gfc_option.flag_pack_derived = 0;
gfc_option.flag_repack_arrays = 0;
+ gfc_option.flag_asymmetric_integers = 0;
gfc_option.q_kind = gfc_default_double_kind;
gfc_option.i8 = 0;
@@ -264,6 +265,10 @@ gfc_handle_option (size_t scode, const c
gfc_option.flag_repack_arrays = value;
break;
+ case OPT_fasymmetric_integers:
+ gfc_option.flag_asymmetric_integers = value;
+ break;
+
case OPT_ffixed_line_length_none:
gfc_option.fixed_line_length = 0;
break;