public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Flag-controlled type conversions/promotions
@ 2011-11-10  0:57 Andreas Kloeckner
  2011-12-24 18:07 ` Steve Kargl
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Andreas Kloeckner @ 2011-11-10  0:57 UTC (permalink / raw)
  To: gcc-patches, fortran, Zydrunas Gimbutas


[-- Attachment #1.1: Type: text/plain, Size: 1119 bytes --]

Hi there,

please find attached the patch and the Changelog entry for our work on
the fortran bug #48426.

The attached patch implements the options

-finteger-4-integer-8
-freal-4-real-8
-freal-4-real-10
-freal-4-real-16
-freal-8-real-4
-freal-8-real-10
-freal-8-real-16

to implement a variety of automatic type promotions. (This is particularly
helpful if one wants to quickly check whether a certain code has a bug limiting
its precision away from full machine accuracy.)

A similar promotion feature is available in Fujitsu compilers, see here:

http://www.lahey.com/docs/fujitsu%20compiler%20option%20list.pdf

(e.g. -CcR8R16)

The implementation work on this was done by Zydrunas Gimbutas, not by me.
Zydrunas has authorized me to submit this for inclusion in gcc. Both he
and I have gone through the FSF's copyright assignment process and have
current papers for that on file.

We tested the change by running Kahan's Fortran paranoia tests using all
supported conversions, we ran the LINPACK tests (at all supported
conversions) as well as a number of manually-written conversion tests.

Zydrunas and Andreas


[-- Attachment #1.2: Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Changelog-PR48426 --]
[-- Type: application/octet-stream, Size: 728 bytes --]

2011-11-09  Zydrunas Gimbutas <gimbutas@cims.nyu.edu>
	    Andreas Kloeckner <kloeckner@cims.nyu.edu>

        PR fortran/48426
        * gfortran.h: Make global variables flag_*_kind to store
	user-desired type conversion information.
	* decl.c: Realize type conversions in declaration parsing.
	* lang.opt: Document flags added for type conversion. Flags 
	added: -freal-4-real-10 -freal-4-real-16 -freal-4-real-8 
	-freal-8-real-10 -freal-8-real-16 -freal-8-real-4 
	-finteger-4-integer-8.
	* trans-types.c: Check if user-specified type conversion
	is valid for current backend.
	* primary.c: Implement type conversion in constant parsing.
	* options.c: Translate input options to flags in internal options
	data structure.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: gcc-quad-promote-v3.diff --]
[-- Type: text/x-diff, Size: 9250 bytes --]

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 181224)
+++ gcc/fortran/decl.c	(working copy)
@@ -2097,8 +2097,24 @@
 	  return MATCH_ERROR;
 	}
       ts->kind /= 2;
+
     }
 
+  if (ts->type == BT_INTEGER)
+    {
+      if( ts->kind == 4 && gfc_option.flag_integer4_kind ==  8) ts->kind =  8;
+    }
+
+  if (ts->type == BT_REAL || ts->type == BT_COMPLEX)
+    {
+      if( ts->kind == 4 && gfc_option.flag_real4_kind ==  8) ts->kind =  8;
+      if( ts->kind == 4 && gfc_option.flag_real4_kind == 10) ts->kind = 10;
+      if( ts->kind == 4 && gfc_option.flag_real4_kind == 16) ts->kind = 16;
+      if( ts->kind == 8 && gfc_option.flag_real8_kind ==  4) ts->kind =  4;
+      if( ts->kind == 8 && gfc_option.flag_real8_kind == 10) ts->kind = 10;
+      if( ts->kind == 8 && gfc_option.flag_real8_kind == 16) ts->kind = 16;
+    }
+
   if (gfc_validate_kind (ts->type, ts->kind, true) < 0)
     {
       gfc_error ("Old-style type declaration %s*%d not supported at %C",
@@ -2243,6 +2259,22 @@
   if(m == MATCH_ERROR)
      gfc_current_locus = where;
   
+
+  if (ts->type == BT_INTEGER)
+    {
+      if( ts->kind == 4 && gfc_option.flag_integer4_kind ==  8) ts->kind =  8;
+    }
+
+  if (ts->type == BT_REAL || ts->type == BT_COMPLEX)
+    {
+      if( ts->kind == 4 && gfc_option.flag_real4_kind ==  8) ts->kind =  8;
+      if( ts->kind == 4 && gfc_option.flag_real4_kind == 10) ts->kind = 10;
+      if( ts->kind == 4 && gfc_option.flag_real4_kind == 16) ts->kind = 16;
+      if( ts->kind == 8 && gfc_option.flag_real8_kind ==  4) ts->kind =  4;
+      if( ts->kind == 8 && gfc_option.flag_real8_kind == 10) ts->kind = 10;
+      if( ts->kind == 8 && gfc_option.flag_real8_kind == 16) ts->kind = 16;
+    }
+
   /* Return what we know from the test(s).  */
   return m;
 
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h	(revision 181224)
+++ gcc/fortran/gfortran.h	(working copy)
@@ -2215,6 +2215,9 @@
   int flag_default_double;
   int flag_default_integer;
   int flag_default_real;
+  int flag_integer4_kind;
+  int flag_real4_kind;
+  int flag_real8_kind;
   int flag_dollar_ok;
   int flag_underscoring;
   int flag_second_underscore;
Index: gcc/fortran/lang.opt
===================================================================
--- gcc/fortran/lang.opt	(revision 181224)
+++ gcc/fortran/lang.opt	(working copy)
@@ -394,6 +394,10 @@
 Fortran RejectNegative
 Assume that the source file is fixed form
 
+finteger-4-integer-8
+Fortran RejectNegative
+Interpret any 4-byte integer as an 8-byte integer
+
 fintrinsic-modules-path
 Fortran RejectNegative Joined Separate
 Specify where to find the compiled intrinsic modules
@@ -494,6 +498,30 @@
 Fortran
 Enable range checking during compilation
 
+freal-4-real-8
+Fortran RejectNegative
+Interpret any 4-byte real as an 8-byte real
+
+freal-4-real-10
+Fortran RejectNegative
+Interpret any 4-byte real as a 10-byte real
+
+freal-4-real-16
+Fortran RejectNegative
+Interpret any 4-byte real as a 16-byte real
+
+freal-8-real-4
+Fortran RejectNegative
+Interpret any 8-byte real as a 4-byte real
+
+freal-8-real-10
+Fortran RejectNegative
+Interpret any 8-byte real as a 10-byte real
+
+freal-8-real-16
+Fortran RejectNegative
+Interpret any 8-byte real as a 16-byte real
+
 frealloc-lhs
 Fortran
 Reallocate the LHS in assignments
Index: gcc/fortran/trans-types.c
===================================================================
--- gcc/fortran/trans-types.c	(revision 181224)
+++ gcc/fortran/trans-types.c	(working copy)
@@ -362,7 +362,7 @@
   unsigned int mode;
   int i_index, r_index, kind;
   bool saw_i4 = false, saw_i8 = false;
-  bool saw_r4 = false, saw_r8 = false, saw_r16 = false;
+  bool saw_r4 = false, saw_r8 = false, saw_r10 = false, saw_r16 = false;
 
   for (i_index = 0, mode = MIN_MODE_INT; mode <= MAX_MODE_INT; mode++)
     {
@@ -456,6 +456,8 @@
 	saw_r4 = true;
       if (kind == 8)
 	saw_r8 = true;
+      if (kind == 10)
+	saw_r10 = true;
       if (kind == 16)
 	saw_r16 = true;
 
@@ -495,6 +497,17 @@
 	 be issued when NUMERIC_STORAGE_SIZE is used.  */
       gfc_numeric_storage_size = 4 * 8;
     }
+  else if (saw_i8 && gfc_option.flag_integer4_kind == 8 )
+    {
+      if (!saw_i8)
+	fatal_error ("integer kind=8 not available for -finteger-4-integer-8 option");
+      gfc_default_integer_kind = 8;
+
+      /* Even if the user specified that the default integer kind be 8,
+         the numeric storage size isn't 64.  In this case, a warning will
+	 be issued when NUMERIC_STORAGE_SIZE is used.  */
+      gfc_numeric_storage_size = 4 * 8;
+    }
   else if (saw_i4)
     {
       gfc_default_integer_kind = 4;
@@ -513,6 +526,24 @@
 	fatal_error ("real kind=8 not available for -fdefault-real-8 option");
       gfc_default_real_kind = 8;
     }
+  else if (gfc_option.flag_real4_kind == 8 )
+  {
+    if (!saw_r8)
+      fatal_error ("real kind=8 not available for -freal-4-real-8 option");
+    gfc_default_real_kind = 8;
+  }
+  else if (gfc_option.flag_real4_kind == 10 )
+  {
+    if (!saw_r10)
+      fatal_error ("real kind=10 not available for -freal-4-real-10 option");
+    gfc_default_real_kind = 10;
+  }
+  else if (gfc_option.flag_real4_kind == 16 )
+  {
+    if (!saw_r16)
+      fatal_error ("real kind=16 not available for -freal-4-real-16 option");
+    gfc_default_real_kind = 16;
+  }
   else if (saw_r4)
     gfc_default_real_kind = 4;
   else
@@ -529,6 +560,24 @@
     gfc_default_double_kind = 8;
   else if (gfc_option.flag_default_real && saw_r16)
     gfc_default_double_kind = 16;
+  else if (gfc_option.flag_real8_kind == 4 )
+  {
+    if (!saw_r4)
+      fatal_error ("real kind=4 not available for -freal-8-real-4 option");
+    gfc_default_double_kind = 4;
+  }
+  else if (gfc_option.flag_real8_kind == 10 )
+  {
+    if (!saw_r10)
+      fatal_error ("real kind=10 not available for -freal-8-real-10 option");
+    gfc_default_double_kind = 10;
+  }
+  else if (gfc_option.flag_real8_kind == 16 )
+  {
+    if (!saw_r16)
+      fatal_error ("real kind=10 not available for -freal-8-real-16 option");
+    gfc_default_double_kind = 16;
+  }
   else if (saw_r4 && saw_r8)
     gfc_default_double_kind = 8;
   else
Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c	(revision 181224)
+++ gcc/fortran/primary.c	(working copy)
@@ -224,6 +224,8 @@
   if (kind == -1)
     return MATCH_ERROR;
 
+  if( kind == 4 && gfc_option.flag_integer4_kind ==  8) kind =  8;
+
   if (gfc_validate_kind (BT_INTEGER, kind, true) < 0)
     {
       gfc_error ("Integer kind %d at %C not available", kind);
@@ -636,6 +638,14 @@
 	  goto cleanup;
 	}
       kind = gfc_default_double_kind;
+
+      if (kind == 4 && gfc_option.flag_real4_kind ==  8) kind =  8;
+      if (kind == 4 && gfc_option.flag_real4_kind == 10) kind = 10;
+      if (kind == 4 && gfc_option.flag_real4_kind == 16) kind = 16;
+      if (kind == 8 && gfc_option.flag_real8_kind ==  4) kind =  4;
+      if (kind == 8 && gfc_option.flag_real8_kind == 10) kind = 10;
+      if (kind == 8 && gfc_option.flag_real8_kind == 16) kind = 16;
+
       break;
 
     case 'q':
@@ -666,6 +676,13 @@
       if (kind == -2)
 	kind = gfc_default_real_kind;
 
+      if (kind == 4 && gfc_option.flag_real4_kind ==  8) kind =  8;
+      if (kind == 4 && gfc_option.flag_real4_kind == 10) kind = 10;
+      if (kind == 4 && gfc_option.flag_real4_kind == 16) kind = 16;
+      if (kind == 8 && gfc_option.flag_real8_kind ==  4) kind =  4;
+      if (kind == 8 && gfc_option.flag_real8_kind == 10) kind = 10;
+      if (kind == 8 && gfc_option.flag_real8_kind == 16) kind = 16;
+
       if (gfc_validate_kind (BT_REAL, kind, true) < 0)
 	{
 	  gfc_error ("Invalid real kind %d at %C", kind);
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c	(revision 181224)
+++ gcc/fortran/options.c	(working copy)
@@ -116,6 +116,9 @@
   gfc_option.flag_default_double = 0;
   gfc_option.flag_default_integer = 0;
   gfc_option.flag_default_real = 0;
+  gfc_option.flag_integer4_kind = 0;
+  gfc_option.flag_real4_kind = 0;
+  gfc_option.flag_real8_kind = 0;
   gfc_option.flag_dollar_ok = 0;
   gfc_option.flag_underscoring = 1;
   gfc_option.flag_whole_file = 1;
@@ -849,6 +852,34 @@
       gfc_option.flag_default_double = value;
       break;
 
+    case OPT_finteger_4_integer_8:
+      gfc_option.flag_integer4_kind = 8;
+      break;
+
+    case OPT_freal_4_real_8:
+      gfc_option.flag_real4_kind = 8;
+      break;
+
+    case OPT_freal_4_real_10:
+      gfc_option.flag_real4_kind = 10;
+      break;
+
+    case OPT_freal_4_real_16:
+      gfc_option.flag_real4_kind = 16;
+      break;
+
+    case OPT_freal_8_real_4:
+      gfc_option.flag_real8_kind = 4;
+      break;
+
+    case OPT_freal_8_real_10:
+      gfc_option.flag_real8_kind = 10;
+      break;
+
+    case OPT_freal_8_real_16:
+      gfc_option.flag_real8_kind = 16;
+      break;
+
     case OPT_finit_local_zero:
       gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
       gfc_option.flag_init_integer_value = 0;

[-- Attachment #4: Type: text/plain, Size: 132 bytes --]


-- 
Andreas Kloeckner 
Room 1105A (Warren Weaver Hall), Courant Institute, NYU
http://www.cims.nyu.edu/~kloeckner/
+1-401-648-0599

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

* Re: [patch] Flag-controlled type conversions/promotions
  2011-11-10  0:57 [patch] Flag-controlled type conversions/promotions Andreas Kloeckner
@ 2011-12-24 18:07 ` Steve Kargl
  2011-12-26  8:18 ` Steve Kargl
  2012-01-13 23:43 ` Steve Kargl
  2 siblings, 0 replies; 13+ messages in thread
From: Steve Kargl @ 2011-12-24 18:07 UTC (permalink / raw)
  To: Andreas Kloeckner; +Cc: gcc-patches, fortran, Zydrunas Gimbutas

On Wed, Nov 09, 2011 at 06:09:58PM -0500, Andreas Kloeckner wrote:
> Hi there,
> 
> please find attached the patch and the Changelog entry for our work on
> the fortran bug #48426.
> 
> The attached patch implements the options
> 
> -finteger-4-integer-8
> -freal-4-real-8
> -freal-4-real-10
> -freal-4-real-16
> -freal-8-real-4
> -freal-8-real-10
> -freal-8-real-16
> 
> to implement a variety of automatic type promotions. (This is particularly
> helpful if one wants to quickly check whether a certain code has a bug limiting
> its precision away from full machine accuracy.)
> 
> A similar promotion feature is available in Fujitsu compilers, see here:
> 
> http://www.lahey.com/docs/fujitsu%20compiler%20option%20list.pdf
> 
> (e.g. -CcR8R16)
> 
> The implementation work on this was done by Zydrunas Gimbutas, not by me.
> Zydrunas has authorized me to submit this for inclusion in gcc. Both he
> and I have gone through the FSF's copyright assignment process and have
> current papers for that on file.
> 
> We tested the change by running Kahan's Fortran paranoia tests using all
> supported conversions, we ran the LINPACK tests (at all supported
> conversions) as well as a number of manually-written conversion tests.
> 
> Zydrunas and Andreas

Andreas,

My apologies for letting this feature/patch fall through the
cracks.  I have time over the next few days to review/test/
and commit this patch.  Are there any changes that I need to
known about?

-- 
Steve

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

* Re: [patch] Flag-controlled type conversions/promotions
  2011-11-10  0:57 [patch] Flag-controlled type conversions/promotions Andreas Kloeckner
  2011-12-24 18:07 ` Steve Kargl
@ 2011-12-26  8:18 ` Steve Kargl
  2012-01-13 23:43 ` Steve Kargl
  2 siblings, 0 replies; 13+ messages in thread
From: Steve Kargl @ 2011-12-26  8:18 UTC (permalink / raw)
  To: Andreas Kloeckner; +Cc: gcc-patches, fortran, Zydrunas Gimbutas

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

On Wed, Nov 09, 2011 at 06:09:58PM -0500, Andreas Kloeckner wrote:
> 
> please find attached the patch and the Changelog entry for our work on
> the fortran bug #48426.
> 
> The attached patch implements the options
> 
> -finteger-4-integer-8
> -freal-4-real-8
> -freal-4-real-10
> -freal-4-real-16
> -freal-8-real-4
> -freal-8-real-10
> -freal-8-real-16
> 
> to implement a variety of automatic type promotions.  (This is
> particularly helpful if one wants to quickly check whether a
> certain code has a bug limiting its precision away from full
> machine accuracy.)
> 
> A similar promotion feature is available in Fujitsu compilers, see here:
> 
> http://www.lahey.com/docs/fujitsu%20compiler%20option%20list.pdf
> 
> (e.g. -CcR8R16)
> 
> The implementation work on this was done by Zydrunas Gimbutas, not by me.
> Zydrunas has authorized me to submit this for inclusion in gcc. Both he
> and I have gone through the FSF's copyright assignment process and have
> current papers for that on file.
> 
> We tested the change by running Kahan's Fortran paranoia tests using all
> supported conversions, we ran the LINPACK tests (at all supported
> conversions) as well as a number of manually-written conversion tests.
> 

All, 

I have taken Zydrunas and Andreas patche applied it to my tree,
updated for it GNU Coding Style, and written the gfortran manual
entries.  The ChangeLog is
 
2011-12-25  Zydrunas Gimbutas  <gimbutas@cims.nyu.edu>
	    Andreas Kloeckner  <kloeckner@cims.nyu.edu>
	    Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/48426
	* gfortran.h: Make global variables flag_*_kind to store
	* lang.opt: Add options -freal-4-real-8, -freal-4-real-10,
	-freal-4-real-16, -freal-8-real-4, -freal-8-real-10, -freal-8-real-16
	and -finteger-4-integer-8.
	user-desired type conversion information.
	* decl.c (gfc_match_old_kind_spec,kind_expr): Type conversions
	in declaration parsing.
	* trans-types.c (gfc_init_kinds): User-specified type conversion
	checked for current backend.
	* primary.c (match_integer_constant,match_real_constant): Implement
	type conversion in constant parsing.
	* options.c (gfc_init_options,gfc_handle_option): Translate input
	options to flags in internal options data structure.
	* invoke.texi: Document new options.  Re-order options in Options
	summary section.

I regression tested the patch on i686-*-freebsd.  No problems occurred.
Can one of the other gfortran reviewers/committers cast a quick glance
over the patch.  I would like to commit this within next day or two.

OK for trunk?

-- 
Steve

[-- Attachment #2: promotion.diff --]
[-- Type: text/x-diff, Size: 19447 bytes --]

Index: decl.c
===================================================================
--- decl.c	(revision 182680)
+++ decl.c	(working copy)
@@ -2101,6 +2101,33 @@ gfc_match_old_kind_spec (gfc_typespec *t
 	  return MATCH_ERROR;
 	}
       ts->kind /= 2;
+
+    }
+
+  if (ts->type == BT_INTEGER && ts->kind == 4 && gfc_option.flag_integer4_kind == 8)
+    ts->kind = 8;
+
+  if (ts->type == BT_REAL || ts->type == BT_COMPLEX)
+    {
+      if (ts->kind == 4)
+	{
+	  if (gfc_option.flag_real4_kind == 8)
+	    ts->kind =  8;
+	  if (gfc_option.flag_real4_kind == 10)
+	    ts->kind = 10;
+	  if (gfc_option.flag_real4_kind == 16)
+	    ts->kind = 16;
+	}
+
+      if (ts->kind == 8)
+	{
+	  if (gfc_option.flag_real8_kind == 4)
+	    ts->kind = 4;
+	  if (gfc_option.flag_real8_kind == 10)
+	    ts->kind = 10;
+	  if (gfc_option.flag_real8_kind == 16)
+	    ts->kind = 16;
+	}
     }
 
   if (gfc_validate_kind (ts->type, ts->kind, true) < 0)
@@ -2246,7 +2273,33 @@ kind_expr:
 
   if(m == MATCH_ERROR)
      gfc_current_locus = where;
-  
+
+  if (ts->type == BT_INTEGER && ts->kind == 4 && gfc_option.flag_integer4_kind == 8)
+    ts->kind =  8;
+
+  if (ts->type == BT_REAL || ts->type == BT_COMPLEX)
+    {
+      if (ts->kind == 4)
+	{
+	  if (gfc_option.flag_real4_kind == 8)
+	    ts->kind =  8;
+	  if (gfc_option.flag_real4_kind == 10)
+	    ts->kind = 10;
+	  if (gfc_option.flag_real4_kind == 16)
+	    ts->kind = 16;
+	}
+
+      if (ts->kind == 8)
+	{
+	  if (gfc_option.flag_real8_kind == 4)
+	    ts->kind = 4;
+	  if (gfc_option.flag_real8_kind == 10)
+	    ts->kind = 10;
+	  if (gfc_option.flag_real8_kind == 16)
+	    ts->kind = 16;
+	}
+    }
+
   /* Return what we know from the test(s).  */
   return m;
 
Index: trans-types.c
===================================================================
--- trans-types.c	(revision 182680)
+++ trans-types.c	(working copy)
@@ -362,7 +362,7 @@ gfc_init_kinds (void)
   unsigned int mode;
   int i_index, r_index, kind;
   bool saw_i4 = false, saw_i8 = false;
-  bool saw_r4 = false, saw_r8 = false, saw_r16 = false;
+  bool saw_r4 = false, saw_r8 = false, saw_r10 = false, saw_r16 = false;
 
   for (i_index = 0, mode = MIN_MODE_INT; mode <= MAX_MODE_INT; mode++)
     {
@@ -456,6 +456,8 @@ gfc_init_kinds (void)
 	saw_r4 = true;
       if (kind == 8)
 	saw_r8 = true;
+      if (kind == 10)
+	saw_r10 = true;
       if (kind == 16)
 	saw_r16 = true;
 
@@ -482,23 +484,31 @@ gfc_init_kinds (void)
       r_index += 1;
     }
 
-  /* Choose the default integer kind.  We choose 4 unless the user
-     directs us otherwise.  */
+  /* Choose the default integer kind.  We choose 4 unless the user directs us
+     otherwise.  Even if the user specified that the default integer kind is 8,
+     the numeric storage size is not 64 bits.  In this case, a warning will be
+     issued when NUMERIC_STORAGE_SIZE is used.  Set NUMERIC_STORAGE_SIZE to 32.  */
+
+  gfc_numeric_storage_size = 4 * 8;
+
   if (gfc_option.flag_default_integer)
     {
       if (!saw_i8)
-	fatal_error ("integer kind=8 not available for -fdefault-integer-8 option");
+	fatal_error ("INTEGER(KIND=8) is not available for -fdefault-integer-8 option");
+
       gfc_default_integer_kind = 8;
 
-      /* Even if the user specified that the default integer kind be 8,
-         the numeric storage size isn't 64.  In this case, a warning will
-	 be issued when NUMERIC_STORAGE_SIZE is used.  */
-      gfc_numeric_storage_size = 4 * 8;
+    }
+  else if (gfc_option.flag_integer4_kind == 8)
+    {
+      if (!saw_i8)
+	fatal_error ("INTEGER(KIND=8) is not available for -finteger-4-integer-8 option");
+
+      gfc_default_integer_kind = 8;
     }
   else if (saw_i4)
     {
       gfc_default_integer_kind = 4;
-      gfc_numeric_storage_size = 4 * 8;
     }
   else
     {
@@ -510,9 +520,31 @@ gfc_init_kinds (void)
   if (gfc_option.flag_default_real)
     {
       if (!saw_r8)
-	fatal_error ("real kind=8 not available for -fdefault-real-8 option");
+	fatal_error ("REAL(KIND=8) is not available for -fdefault-real-8 option");
+
       gfc_default_real_kind = 8;
     }
+  else if (gfc_option.flag_real4_kind == 8)
+  {
+    if (!saw_r8)
+      fatal_error ("REAL(KIND=8) is not available for -freal-4-real-8 option");
+
+    gfc_default_real_kind = 8;
+  }
+  else if (gfc_option.flag_real4_kind == 10)
+  {
+    if (!saw_r10)
+      fatal_error ("REAL(KIND=10) is not available for -freal-4-real-10 option");
+
+    gfc_default_real_kind = 10;
+  }
+  else if (gfc_option.flag_real4_kind == 16)
+  {
+    if (!saw_r16)
+      fatal_error ("REAL(KIND=16) is not available for -freal-4-real-16 option");
+
+    gfc_default_real_kind = 16;
+  }
   else if (saw_r4)
     gfc_default_real_kind = 4;
   else
@@ -529,6 +561,27 @@ gfc_init_kinds (void)
     gfc_default_double_kind = 8;
   else if (gfc_option.flag_default_real && saw_r16)
     gfc_default_double_kind = 16;
+  else if (gfc_option.flag_real8_kind == 4)
+    {
+      if (!saw_r4)
+	fatal_error ("REAL(KIND=4) is not available for -freal-8-real-4 option");
+
+	gfc_default_double_kind = 4;
+    }
+  else if (gfc_option.flag_real8_kind == 10 )
+    {
+      if (!saw_r10)
+	fatal_error ("REAL(KIND=10) is not available for -freal-8-real-10 option");
+
+	gfc_default_double_kind = 10;
+    }
+  else if (gfc_option.flag_real8_kind == 16 )
+    {
+      if (!saw_r16)
+	fatal_error ("REAL(KIND=10) is not available for -freal-8-real-16 option");
+
+	gfc_default_double_kind = 16;
+    }
   else if (saw_r4 && saw_r8)
     gfc_default_double_kind = 8;
   else
Index: primary.c
===================================================================
--- primary.c	(revision 182680)
+++ primary.c	(working copy)
@@ -1,5 +1,6 @@
 /* Primary expression subroutines
-   Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
+   2011
    Free Software Foundation, Inc.
    Contributed by Andy Vaught
 
@@ -224,6 +225,9 @@ match_integer_constant (gfc_expr **resul
   if (kind == -1)
     return MATCH_ERROR;
 
+  if (kind == 4 && gfc_option.flag_integer4_kind == 8)
+    kind = 8;
+
   if (gfc_validate_kind (BT_INTEGER, kind, true) < 0)
     {
       gfc_error ("Integer kind %d at %C not available", kind);
@@ -636,6 +640,26 @@ done:
 	  goto cleanup;
 	}
       kind = gfc_default_double_kind;
+
+      if (kind == 4)
+	{
+	  if (gfc_option.flag_real4_kind == 8)
+	    kind = 8;
+	  if (gfc_option.flag_real4_kind == 10)
+	    kind = 10;
+	  if (gfc_option.flag_real4_kind == 16)
+	    kind = 16;
+	}
+
+      if (kind == 8)
+	{
+	  if (gfc_option.flag_real8_kind == 4)
+	    kind = 4;
+	  if (gfc_option.flag_real8_kind == 10)
+	    kind = 10;
+	  if (gfc_option.flag_real8_kind == 16)
+	    kind = 16;
+	}
       break;
 
     case 'q':
@@ -666,6 +690,26 @@ done:
       if (kind == -2)
 	kind = gfc_default_real_kind;
 
+      if (kind == 4)
+	{
+	  if (gfc_option.flag_real4_kind == 8)
+	    kind = 8;
+	  if (gfc_option.flag_real4_kind == 10)
+	    kind = 10;
+	  if (gfc_option.flag_real4_kind == 16)
+	    kind = 16;
+	}
+
+      if (kind == 8)
+	{
+	  if (gfc_option.flag_real8_kind == 4)
+	    kind = 4;
+	  if (gfc_option.flag_real8_kind == 10)
+	    kind = 10;
+	  if (gfc_option.flag_real8_kind == 16)
+	    kind = 16;
+	}
+
       if (gfc_validate_kind (BT_REAL, kind, true) < 0)
 	{
 	  gfc_error ("Invalid real kind %d at %C", kind);
Index: options.c
===================================================================
--- options.c	(revision 182680)
+++ options.c	(working copy)
@@ -116,6 +116,9 @@ gfc_init_options (unsigned int decoded_o
   gfc_option.flag_default_double = 0;
   gfc_option.flag_default_integer = 0;
   gfc_option.flag_default_real = 0;
+  gfc_option.flag_integer4_kind = 0;
+  gfc_option.flag_real4_kind = 0;
+  gfc_option.flag_real8_kind = 0;
   gfc_option.flag_dollar_ok = 0;
   gfc_option.flag_underscoring = 1;
   gfc_option.flag_whole_file = 1;
@@ -849,6 +852,34 @@ gfc_handle_option (size_t scode, const c
       gfc_option.flag_default_double = value;
       break;
 
+    case OPT_finteger_4_integer_8:
+      gfc_option.flag_integer4_kind = 8;
+      break;
+
+    case OPT_freal_4_real_8:
+      gfc_option.flag_real4_kind = 8;
+      break;
+
+    case OPT_freal_4_real_10:
+      gfc_option.flag_real4_kind = 10;
+      break;
+
+    case OPT_freal_4_real_16:
+      gfc_option.flag_real4_kind = 16;
+      break;
+
+    case OPT_freal_8_real_4:
+      gfc_option.flag_real8_kind = 4;
+      break;
+
+    case OPT_freal_8_real_10:
+      gfc_option.flag_real8_kind = 10;
+      break;
+
+    case OPT_freal_8_real_16:
+      gfc_option.flag_real8_kind = 16;
+      break;
+
     case OPT_finit_local_zero:
       gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
       gfc_option.flag_init_integer_value = 0;
Index: gfortran.h
===================================================================
--- gfortran.h	(revision 182680)
+++ gfortran.h	(working copy)
@@ -2215,6 +2215,9 @@ typedef struct
   int flag_default_double;
   int flag_default_integer;
   int flag_default_real;
+  int flag_integer4_kind;
+  int flag_real4_kind;
+  int flag_real8_kind;
   int flag_dollar_ok;
   int flag_underscoring;
   int flag_second_underscore;
Index: lang.opt
===================================================================
--- lang.opt	(revision 182680)
+++ lang.opt	(working copy)
@@ -1,5 +1,5 @@
 ; Options for the Fortran 95 front end.
-; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
 ; Free Software Foundation, Inc.
 ;
 ; This file is part of GCC.
@@ -394,6 +394,10 @@ ffixed-form
 Fortran RejectNegative
 Assume that the source file is fixed form
 
+finteger-4-integer-8
+Fortran RejectNegative
+Interpret any INTEGER(4) as an INTEGER(8)
+
 fintrinsic-modules-path
 Fortran RejectNegative Joined Separate
 Specify where to find the compiled intrinsic modules
@@ -494,6 +498,30 @@ frange-check
 Fortran
 Enable range checking during compilation
 
+freal-4-real-8
+Fortran RejectNegative
+Interpret any REAl(4) as a REAL(8)
+
+freal-4-real-10
+Fortran RejectNegative
+Interpret any REAL(4) as a REAL(10)
+
+freal-4-real-16
+Fortran RejectNegative
+Interpret any REAL(4) as a REAl(16)
+
+freal-8-real-4
+Fortran RejectNegative
+Interpret any REAL(8) as a REAL(4)
+
+freal-8-real-10
+Fortran RejectNegative
+Interpret any REAL(8) as a REAL(10)
+
+freal-8-real-16
+Fortran RejectNegative
+Interpret any REAL(8) as a REAl(16)
+
 frealloc-lhs
 Fortran
 Reallocate the LHS in assignments
Index: invoke.texi
===================================================================
--- invoke.texi	(revision 182680)
+++ invoke.texi	(working copy)
@@ -66,7 +66,8 @@ GNU Fortran.
 @c man begin DESCRIPTION
 
 The @command{gfortran} command supports all the options supported by the
-@command{gcc} command.  Only options specific to GNU Fortran are documented here.
+@command{gcc} command.  Only options specific to GNU Fortran are documented
+here.
 
 @xref{Invoking GCC,,GCC Command Options,gcc,Using the GNU Compiler
 Collection (GCC)}, for information
@@ -115,37 +116,46 @@ by type.  Explanations are in the follow
 @table @emph
 @item Fortran Language Options
 @xref{Fortran Dialect Options,,Options controlling Fortran dialect}.
-@gccoptlist{-fall-intrinsics  -ffree-form  -fno-fixed-form @gol
--fdollar-ok  -fimplicit-none  -fmax-identifier-length @gol
--std=@var{std} -fd-lines-as-code  -fd-lines-as-comments @gol
--ffixed-line-length-@var{n}  -ffixed-line-length-none @gol
--ffree-line-length-@var{n}  -ffree-line-length-none @gol
--fdefault-double-8  -fdefault-integer-8  -fdefault-real-8 @gol
--fcray-pointer  -fopenmp  -fno-range-check -fbackslash -fmodule-private}
+@gccoptlist{-fall-intrinsics -fbackslash -fcray-pointer -fd-lines-as-code @gol
+-fd-lines-as-comments -fdefault-double-8 -fdefault-integer-8 @gol
+-fdefault-real-8 -fdollar-ok -ffixed-line-length-@var{n} @gol
+-ffixed-line-length-none -ffree-form -ffree-line-length-@var{n} @gol
+-ffree-line-length-none -fimplicit-none -finteger-4-integer-8 @gol
+-fmax-identifier-length -fmodule-private -fno-fixed-form -fno-range-check @gol
+-fopenmp -freal-4-real-10 -freal-4-real-16 -freal-4-real-8 @gol
+-freal-8-real-10 -freal-8-real-16 -freal-8-real-4 -std=@var{std}
+}
 
 @item Preprocessing Options
 @xref{Preprocessing Options,,Enable and customize preprocessing}.
-@gccoptlist{-cpp -dD -dI -dM -dN -dU -fworking-directory @gol
--imultilib @var{dir} -iprefix @var{file} -isysroot @var{dir} @gol
--iquote -isystem @var{dir} -nocpp -nostdinc -undef @gol
--A@var{question}=@var{answer} -A-@var{question}@r{[}=@var{answer}@r{]} @gol
--C -CC -D@var{macro}@r{[}=@var{defn}@r{]} -U@var{macro} -H -P}
+@gccoptlist{-A-@var{question}@r{[}=@var{answer}@r{]}
+-A@var{question}=@var{answer} -C -CC -D@var{macro}@r{[}=@var{defn}@r{]}
+-H -P @gol
+-U@var{macro} -cpp -dD -dI -dM -dN -dU -fworking-directory
+-imultilib @var{dir} @gol
+-iprefix @var{file} -iquote -isysroot @var{dir} -isystem @var{dir} -nocpp 
+-nostdinc @gol
+-undef
+}
 
 @item Error and Warning Options
 @xref{Error and Warning Options,,Options to request or suppress errors
 and warnings}.
-@gccoptlist{-fmax-errors=@var{n}
--fsyntax-only -pedantic -pedantic-errors -Wall @gol
--Waliasing -Wampersand -Warray-bounds -Wcharacter-truncation @gol
--Wconversion -Wimplicit-interface -Wimplicit-procedure -Wline-truncation @gol
--Wintrinsics-std -Wreal-q-constant -Wsurprising -Wno-tabs -Wunderflow @gol
--Wunused-parameter -Wintrinsic-shadow -Wno-align-commons @gol
--Wfunction-elimination}
+@gccoptlist{-Waliasing -Wall -Wampersand -Warray-bounds
+-Wcharacter-truncation @gol
+-Wconversion -Wfunction-elimination -Wimplicit-interface @gol
+-Wimplicit-procedure -Wintrinsic-shadow -Wintrinsics-std @gol
+-Wline-truncation -Wno-align-commons -Wno-tabs -Wreal-q-constant @gol
+-Wsurprising -Wunderflow -Wunused-parameter -fmax-errors=@var{n}
+-fsyntax-only @gol
+-pedantic -pedantic-errors
+}
 
 @item Debugging Options
 @xref{Debugging Options,,Options for debugging your program or GNU Fortran}.
-@gccoptlist{-fdump-fortran-original  -fdump-fortran-optimized @gol
--ffpe-trap=@var{list} -fbacktrace -fdump-parse-tree}
+@gccoptlist{-fbacktrace -fdump-fortran-optimized -fdump-fortran-original @gol
+-fdump-parse-tree -ffpe-trap=@var{list}
+}
 
 @item Directory Options
 @xref{Directory Options,,Options for directory search}.
@@ -157,39 +167,29 @@ and warnings}.
 
 @item Runtime Options
 @xref{Runtime Options,,Options for influencing runtime behavior}.
-@gccoptlist{-fconvert=@var{conversion}  -fno-range-check
--frecord-marker=@var{length} @gol  -fmax-subrecord-length=@var{length}
--fsign-zero}
+@gccoptlist{-fconvert=@var{conversion} -fmax-subrecord-length=@var{length}
+-fno-range-check @gol
+-frecord-marker=@var{length} -fsign-zero
+}
 
 @item Code Generation Options
 @xref{Code Gen Options,,Options for code generation conventions}.
-@gccoptlist{-fno-automatic  -ff2c  -fno-underscoring @gol
--fno-whole-file -fsecond-underscore @gol
--fbounds-check -fcheck-array-temporaries  -fmax-array-constructor =@var{n} @gol
+@gccoptlist{-faggressive-function-elimination -fblas-matmul-limit=@var{n} @gol
+-fbounds-check -fcheck-array-temporaries @gol
 -fcheck=@var{<all|array-temps|bounds|do|mem|pointer|recursion>} @gol
--fcoarray=@var{<none|single|lib>} -fmax-stack-var-size=@var{n} @gol
--fstack-arrays @gol
--fpack-derived  -frepack-arrays  -fshort-enums  -fexternal-blas @gol
--fblas-matmul-limit=@var{n} -frecursive -finit-local-zero @gol
--finit-integer=@var{n} -finit-real=@var{<zero|inf|-inf|nan|snan>} @gol
--finit-logical=@var{<true|false>} -finit-character=@var{n} @gol
--fno-align-commons -fno-protect-parens -frealloc-lhs @gol
--faggressive-function-elimination -ffrontend-optimize}
+-fcoarray=@var{<none|single|lib>} -fexternal-blas -ff2c
+-ffrontend-optimize @gol
+-finit-character=@var{n} -finit-integer=@var{n} -finit-local-zero @gol
+-finit-logical=@var{<true|false>}
+-finit-real=@var{<zero|inf|-inf|nan|snan>} @gol
+-fmax-array-constructor=@var{n} -fmax-stack-var-size=@var{n}
+-fno-align-commons @gol
+-fno-automatic -fno-protect-parens -fno-underscoring -fno-whole-file @gol
+-fsecond-underscore -fpack-derived -frealloc-lhs -frecursive @gol
+-frepack-arrays -fshort-enums -fstack-arrays
+}
 @end table
 
-@menu
-* Fortran Dialect Options::  Controlling the variant of Fortran language
-                             compiled.
-* Preprocessing Options::  Enable and customize preprocessing.
-* Error and Warning Options::     How picky should the compiler be?
-* Debugging Options::   Symbol tables, measurements, and debugging dumps.
-* Directory Options::   Where to find module files
-* Link Options ::       Influencing the linking step
-* Runtime Options::     Influencing runtime behavior
-* Code Gen Options::    Specifying conventions for function calls, data layout
-                        and register usage.
-@end menu
-
 @node Fortran Dialect Options
 @section Options controlling Fortran dialect
 @cindex dialect options
@@ -324,6 +324,11 @@ Specify that no implicit typing is allow
 @code{IMPLICIT} statements.  This is the equivalent of adding
 @code{implicit none} to the start of every procedure.
 
+@item -finteger-4-integer-8
+@opindex @code{finteger-4-integer-8}
+Promote @code{INTEGER(KIND=4)} entities to an @code{INTEGER(KIND=8)} entities.
+If @code{KIND=8} is unavailable, then an error will be issued.
+
 @item -fcray-pointer
 @opindex @code{fcray-pointer}
 Enable the Cray pointer extension, which provides C-like pointer
@@ -354,6 +359,42 @@ Similarly, @code{DATA i/Z'FFFFFFFF'/} wi
 on most systems, but with @option{-fno-range-check} the value will
 ``wrap around'' and @code{i} will be initialized to @math{-1} instead.
 
+@item -freal-4-real-8
+@opindex @code{freal-4-real-8}
+Promote @code{REAL(KIND=4)} entities to @code{REAL(KIND=8)} entities.
+If @code{KIND=8} is unavailable, then an error will be issued.
+All other real kind types are unaffected by this option.
+
+@item -freal-4-real-10
+@opindex @code{freal-4-real-10}
+Promote @code{REAL(KIND=4)} entities to @code{REAL(KIND=10)} entities.
+If @code{KIND=10} is unavailable, then an error will be issued.
+All other real kind types are unaffected by this option.
+
+@item -freal-4-real-16
+@opindex @code{freal-4-real-16}
+Promote @code{REAL(KIND=4)} entities to @code{REAL(KIND=16)} entities.
+If @code{KIND=16} is unavailable, then an error will be issued.
+All other real kind types are unaffected by this option.
+
+@item -freal-8-real-4
+@opindex @code{freal-8-real-4}
+Demote @code{REAL(KIND=8)} entities to @code{REAL(KIND=4)} entities.
+If @code{KIND=4} is unavailable, then an error will be issued.
+All other real kind types are unaffected by this option.
+
+@item -freal-8-real-10
+@opindex @code{freal-8-real-10}
+Promote @code{REAL(KIND=8)} entities to @code{REAL(KIND=10)} entities.
+If @code{KIND=10} is unavailable, then an error will be issued.
+All other real kind types are unaffected by this option.
+
+@item -freal-8-real-16
+@opindex @code{freal-8-real-16}
+Promote @code{REAL(KIND=8)} entities to @code{REAL(KIND=16)} entities.
+If @code{KIND=16} is unavailable, then an error will be issued.
+All other real kind types are unaffected by this option.
+
 @item -std=@var{std}
 @opindex @code{std=}@var{std} option
 Specify the standard to which the program is expected to conform, which

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

* Re: [patch] Flag-controlled type conversions/promotions
  2011-11-10  0:57 [patch] Flag-controlled type conversions/promotions Andreas Kloeckner
  2011-12-24 18:07 ` Steve Kargl
  2011-12-26  8:18 ` Steve Kargl
@ 2012-01-13 23:43 ` Steve Kargl
  2012-01-15 18:39   ` Zydrunas Gimbutas
  2 siblings, 1 reply; 13+ messages in thread
From: Steve Kargl @ 2012-01-13 23:43 UTC (permalink / raw)
  To: Andreas Kloeckner; +Cc: gcc-patches, fortran, Zydrunas Gimbutas

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

On Wed, Nov 09, 2011 at 06:09:58PM -0500, Andreas Kloeckner wrote:
> Hi there,
> 
> please find attached the patch and the Changelog entry for our work on
> the fortran bug #48426.
> 
> The attached patch implements the options
> 
> -finteger-4-integer-8
> -freal-4-real-8
> -freal-4-real-10
> -freal-4-real-16
> -freal-8-real-4
> -freal-8-real-10
> -freal-8-real-16
> 
> to implement a variety of automatic type promotions. (This is particularly
> helpful if one wants to quickly check whether a certain code has a bug limiting
> its precision away from full machine accuracy.)
> 

I plan to commit the attached patch this weekend.

2011-11-09  Zydrunas Gimbutas  <gimbutas@cims.nyu.edu>
	    Andreas Kloeckner  <kloeckner@cims.nyu.edu>
	    Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/48426
	* gfortran.h (gfc_option_t): Add members flag_*_kind to store kind.
	* lang.opt: Add options -freal-4-real-8, -freal-4-real-10,
	-freal-4-real-16, -freal-8-real-4, -freal-8-real-10, -freal-8-real-16
	and -finteger-4-integer-8. User-desired type conversion information.
	* decl.c (gfc_match_old_kind_spec,kind_expr): Type conversions
	in declaration parsing.
	* trans-types.c (gfc_init_kinds): User-specified type conversion
	checked for current backend.
	* primary.c (match_integer_constant,match_real_constant): Implement
	type conversion in constant parsing.
	* options.c (gfc_init_options,gfc_handle_option): Translate input
	options to flags in internal options data structure.
	* invoke.texi: Document new options.  Re-order options in Options
	summary section.

-- 
Steve

[-- Attachment #2: precision.diff --]
[-- Type: text/x-diff, Size: 20078 bytes --]

Index: decl.c
===================================================================
--- decl.c	(revision 183169)
+++ decl.c	(working copy)
@@ -1572,7 +1572,8 @@ build_struct (const char *name, gfc_char
 
   /* Should this ever get more complicated, combine with similar section
      in add_init_expr_to_sym into a separate function.  */
-  if (c->ts.type == BT_CHARACTER && !c->attr.pointer && c->initializer && c->ts.u.cl
+  if (c->ts.type == BT_CHARACTER && !c->attr.pointer && c->initializer
+      && c->ts.u.cl
       && c->ts.u.cl->length && c->ts.u.cl->length->expr_type == EXPR_CONSTANT)
     {
       int len;
@@ -2101,6 +2102,33 @@ gfc_match_old_kind_spec (gfc_typespec *t
 	  return MATCH_ERROR;
 	}
       ts->kind /= 2;
+
+    }
+
+  if (ts->type == BT_INTEGER && ts->kind == 4 && gfc_option.flag_integer4_kind == 8)
+    ts->kind = 8;
+
+  if (ts->type == BT_REAL || ts->type == BT_COMPLEX)
+    {
+      if (ts->kind == 4)
+	{
+	  if (gfc_option.flag_real4_kind == 8)
+	    ts->kind =  8;
+	  if (gfc_option.flag_real4_kind == 10)
+	    ts->kind = 10;
+	  if (gfc_option.flag_real4_kind == 16)
+	    ts->kind = 16;
+	}
+
+      if (ts->kind == 8)
+	{
+	  if (gfc_option.flag_real8_kind == 4)
+	    ts->kind = 4;
+	  if (gfc_option.flag_real8_kind == 10)
+	    ts->kind = 10;
+	  if (gfc_option.flag_real8_kind == 16)
+	    ts->kind = 16;
+	}
     }
 
   if (gfc_validate_kind (ts->type, ts->kind, true) < 0)
@@ -2246,7 +2274,33 @@ kind_expr:
 
   if(m == MATCH_ERROR)
      gfc_current_locus = where;
-  
+
+  if (ts->type == BT_INTEGER && ts->kind == 4 && gfc_option.flag_integer4_kind == 8)
+    ts->kind =  8;
+
+  if (ts->type == BT_REAL || ts->type == BT_COMPLEX)
+    {
+      if (ts->kind == 4)
+	{
+	  if (gfc_option.flag_real4_kind == 8)
+	    ts->kind =  8;
+	  if (gfc_option.flag_real4_kind == 10)
+	    ts->kind = 10;
+	  if (gfc_option.flag_real4_kind == 16)
+	    ts->kind = 16;
+	}
+
+      if (ts->kind == 8)
+	{
+	  if (gfc_option.flag_real8_kind == 4)
+	    ts->kind = 4;
+	  if (gfc_option.flag_real8_kind == 10)
+	    ts->kind = 10;
+	  if (gfc_option.flag_real8_kind == 16)
+	    ts->kind = 16;
+	}
+    }
+
   /* Return what we know from the test(s).  */
   return m;
 
Index: trans-types.c
===================================================================
--- trans-types.c	(revision 183169)
+++ trans-types.c	(working copy)
@@ -362,7 +362,7 @@ gfc_init_kinds (void)
   unsigned int mode;
   int i_index, r_index, kind;
   bool saw_i4 = false, saw_i8 = false;
-  bool saw_r4 = false, saw_r8 = false, saw_r16 = false;
+  bool saw_r4 = false, saw_r8 = false, saw_r10 = false, saw_r16 = false;
 
   for (i_index = 0, mode = MIN_MODE_INT; mode <= MAX_MODE_INT; mode++)
     {
@@ -456,6 +456,8 @@ gfc_init_kinds (void)
 	saw_r4 = true;
       if (kind == 8)
 	saw_r8 = true;
+      if (kind == 10)
+	saw_r10 = true;
       if (kind == 16)
 	saw_r16 = true;
 
@@ -482,23 +484,31 @@ gfc_init_kinds (void)
       r_index += 1;
     }
 
-  /* Choose the default integer kind.  We choose 4 unless the user
-     directs us otherwise.  */
+  /* Choose the default integer kind.  We choose 4 unless the user directs us
+     otherwise.  Even if the user specified that the default integer kind is 8,
+     the numeric storage size is not 64 bits.  In this case, a warning will be
+     issued when NUMERIC_STORAGE_SIZE is used.  Set NUMERIC_STORAGE_SIZE to 32.  */
+
+  gfc_numeric_storage_size = 4 * 8;
+
   if (gfc_option.flag_default_integer)
     {
       if (!saw_i8)
-	fatal_error ("integer kind=8 not available for -fdefault-integer-8 option");
+	fatal_error ("INTEGER(KIND=8) is not available for -fdefault-integer-8 option");
+
       gfc_default_integer_kind = 8;
 
-      /* Even if the user specified that the default integer kind be 8,
-         the numeric storage size isn't 64.  In this case, a warning will
-	 be issued when NUMERIC_STORAGE_SIZE is used.  */
-      gfc_numeric_storage_size = 4 * 8;
+    }
+  else if (gfc_option.flag_integer4_kind == 8)
+    {
+      if (!saw_i8)
+	fatal_error ("INTEGER(KIND=8) is not available for -finteger-4-integer-8 option");
+
+      gfc_default_integer_kind = 8;
     }
   else if (saw_i4)
     {
       gfc_default_integer_kind = 4;
-      gfc_numeric_storage_size = 4 * 8;
     }
   else
     {
@@ -510,9 +520,31 @@ gfc_init_kinds (void)
   if (gfc_option.flag_default_real)
     {
       if (!saw_r8)
-	fatal_error ("real kind=8 not available for -fdefault-real-8 option");
+	fatal_error ("REAL(KIND=8) is not available for -fdefault-real-8 option");
+
       gfc_default_real_kind = 8;
     }
+  else if (gfc_option.flag_real4_kind == 8)
+  {
+    if (!saw_r8)
+      fatal_error ("REAL(KIND=8) is not available for -freal-4-real-8 option");
+
+    gfc_default_real_kind = 8;
+  }
+  else if (gfc_option.flag_real4_kind == 10)
+  {
+    if (!saw_r10)
+      fatal_error ("REAL(KIND=10) is not available for -freal-4-real-10 option");
+
+    gfc_default_real_kind = 10;
+  }
+  else if (gfc_option.flag_real4_kind == 16)
+  {
+    if (!saw_r16)
+      fatal_error ("REAL(KIND=16) is not available for -freal-4-real-16 option");
+
+    gfc_default_real_kind = 16;
+  }
   else if (saw_r4)
     gfc_default_real_kind = 4;
   else
@@ -529,6 +561,27 @@ gfc_init_kinds (void)
     gfc_default_double_kind = 8;
   else if (gfc_option.flag_default_real && saw_r16)
     gfc_default_double_kind = 16;
+  else if (gfc_option.flag_real8_kind == 4)
+    {
+      if (!saw_r4)
+	fatal_error ("REAL(KIND=4) is not available for -freal-8-real-4 option");
+
+	gfc_default_double_kind = 4;
+    }
+  else if (gfc_option.flag_real8_kind == 10 )
+    {
+      if (!saw_r10)
+	fatal_error ("REAL(KIND=10) is not available for -freal-8-real-10 option");
+
+	gfc_default_double_kind = 10;
+    }
+  else if (gfc_option.flag_real8_kind == 16 )
+    {
+      if (!saw_r16)
+	fatal_error ("REAL(KIND=10) is not available for -freal-8-real-16 option");
+
+	gfc_default_double_kind = 16;
+    }
   else if (saw_r4 && saw_r8)
     gfc_default_double_kind = 8;
   else
Index: primary.c
===================================================================
--- primary.c	(revision 183169)
+++ primary.c	(working copy)
@@ -1,5 +1,6 @@
 /* Primary expression subroutines
-   Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
+   2011
    Free Software Foundation, Inc.
    Contributed by Andy Vaught
 
@@ -224,6 +225,9 @@ match_integer_constant (gfc_expr **resul
   if (kind == -1)
     return MATCH_ERROR;
 
+  if (kind == 4 && gfc_option.flag_integer4_kind == 8)
+    kind = 8;
+
   if (gfc_validate_kind (BT_INTEGER, kind, true) < 0)
     {
       gfc_error ("Integer kind %d at %C not available", kind);
@@ -636,6 +640,26 @@ done:
 	  goto cleanup;
 	}
       kind = gfc_default_double_kind;
+
+      if (kind == 4)
+	{
+	  if (gfc_option.flag_real4_kind == 8)
+	    kind = 8;
+	  if (gfc_option.flag_real4_kind == 10)
+	    kind = 10;
+	  if (gfc_option.flag_real4_kind == 16)
+	    kind = 16;
+	}
+
+      if (kind == 8)
+	{
+	  if (gfc_option.flag_real8_kind == 4)
+	    kind = 4;
+	  if (gfc_option.flag_real8_kind == 10)
+	    kind = 10;
+	  if (gfc_option.flag_real8_kind == 16)
+	    kind = 16;
+	}
       break;
 
     case 'q':
@@ -666,6 +690,26 @@ done:
       if (kind == -2)
 	kind = gfc_default_real_kind;
 
+      if (kind == 4)
+	{
+	  if (gfc_option.flag_real4_kind == 8)
+	    kind = 8;
+	  if (gfc_option.flag_real4_kind == 10)
+	    kind = 10;
+	  if (gfc_option.flag_real4_kind == 16)
+	    kind = 16;
+	}
+
+      if (kind == 8)
+	{
+	  if (gfc_option.flag_real8_kind == 4)
+	    kind = 4;
+	  if (gfc_option.flag_real8_kind == 10)
+	    kind = 10;
+	  if (gfc_option.flag_real8_kind == 16)
+	    kind = 16;
+	}
+
       if (gfc_validate_kind (BT_REAL, kind, true) < 0)
 	{
 	  gfc_error ("Invalid real kind %d at %C", kind);
Index: options.c
===================================================================
--- options.c	(revision 183169)
+++ options.c	(working copy)
@@ -116,6 +116,9 @@ gfc_init_options (unsigned int decoded_o
   gfc_option.flag_default_double = 0;
   gfc_option.flag_default_integer = 0;
   gfc_option.flag_default_real = 0;
+  gfc_option.flag_integer4_kind = 0;
+  gfc_option.flag_real4_kind = 0;
+  gfc_option.flag_real8_kind = 0;
   gfc_option.flag_dollar_ok = 0;
   gfc_option.flag_underscoring = 1;
   gfc_option.flag_whole_file = 1;
@@ -849,6 +852,34 @@ gfc_handle_option (size_t scode, const c
       gfc_option.flag_default_double = value;
       break;
 
+    case OPT_finteger_4_integer_8:
+      gfc_option.flag_integer4_kind = 8;
+      break;
+
+    case OPT_freal_4_real_8:
+      gfc_option.flag_real4_kind = 8;
+      break;
+
+    case OPT_freal_4_real_10:
+      gfc_option.flag_real4_kind = 10;
+      break;
+
+    case OPT_freal_4_real_16:
+      gfc_option.flag_real4_kind = 16;
+      break;
+
+    case OPT_freal_8_real_4:
+      gfc_option.flag_real8_kind = 4;
+      break;
+
+    case OPT_freal_8_real_10:
+      gfc_option.flag_real8_kind = 10;
+      break;
+
+    case OPT_freal_8_real_16:
+      gfc_option.flag_real8_kind = 16;
+      break;
+
     case OPT_finit_local_zero:
       gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
       gfc_option.flag_init_integer_value = 0;
Index: gfortran.h
===================================================================
--- gfortran.h	(revision 183169)
+++ gfortran.h	(working copy)
@@ -2221,6 +2221,9 @@ typedef struct
   int flag_default_double;
   int flag_default_integer;
   int flag_default_real;
+  int flag_integer4_kind;
+  int flag_real4_kind;
+  int flag_real8_kind;
   int flag_dollar_ok;
   int flag_underscoring;
   int flag_second_underscore;
Index: lang.opt
===================================================================
--- lang.opt	(revision 183169)
+++ lang.opt	(working copy)
@@ -1,5 +1,5 @@
 ; Options for the Fortran 95 front end.
-; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
 ; Free Software Foundation, Inc.
 ;
 ; This file is part of GCC.
@@ -394,6 +394,10 @@ ffixed-form
 Fortran RejectNegative
 Assume that the source file is fixed form
 
+finteger-4-integer-8
+Fortran RejectNegative
+Interpret any INTEGER(4) as an INTEGER(8)
+
 fintrinsic-modules-path
 Fortran RejectNegative Joined Separate
 Specify where to find the compiled intrinsic modules
@@ -494,6 +498,30 @@ frange-check
 Fortran
 Enable range checking during compilation
 
+freal-4-real-8
+Fortran RejectNegative
+Interpret any REAl(4) as a REAL(8)
+
+freal-4-real-10
+Fortran RejectNegative
+Interpret any REAL(4) as a REAL(10)
+
+freal-4-real-16
+Fortran RejectNegative
+Interpret any REAL(4) as a REAl(16)
+
+freal-8-real-4
+Fortran RejectNegative
+Interpret any REAL(8) as a REAL(4)
+
+freal-8-real-10
+Fortran RejectNegative
+Interpret any REAL(8) as a REAL(10)
+
+freal-8-real-16
+Fortran RejectNegative
+Interpret any REAL(8) as a REAl(16)
+
 frealloc-lhs
 Fortran
 Reallocate the LHS in assignments
Index: invoke.texi
===================================================================
--- invoke.texi	(revision 183169)
+++ invoke.texi	(working copy)
@@ -1,4 +1,4 @@
-@c Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+@c Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
 @c Free Software Foundation, Inc.
 @c This is part of the GNU Fortran manual.   
 @c For copying conditions, see the file gfortran.texi.
@@ -66,7 +66,8 @@ GNU Fortran.
 @c man begin DESCRIPTION
 
 The @command{gfortran} command supports all the options supported by the
-@command{gcc} command.  Only options specific to GNU Fortran are documented here.
+@command{gcc} command.  Only options specific to GNU Fortran are documented
+here.
 
 @xref{Invoking GCC,,GCC Command Options,gcc,Using the GNU Compiler
 Collection (GCC)}, for information
@@ -115,37 +116,46 @@ by type.  Explanations are in the follow
 @table @emph
 @item Fortran Language Options
 @xref{Fortran Dialect Options,,Options controlling Fortran dialect}.
-@gccoptlist{-fall-intrinsics  -ffree-form  -fno-fixed-form @gol
--fdollar-ok  -fimplicit-none  -fmax-identifier-length @gol
--std=@var{std} -fd-lines-as-code  -fd-lines-as-comments @gol
--ffixed-line-length-@var{n}  -ffixed-line-length-none @gol
--ffree-line-length-@var{n}  -ffree-line-length-none @gol
--fdefault-double-8  -fdefault-integer-8  -fdefault-real-8 @gol
--fcray-pointer  -fopenmp  -fno-range-check -fbackslash -fmodule-private}
+@gccoptlist{-fall-intrinsics -fbackslash -fcray-pointer -fd-lines-as-code @gol
+-fd-lines-as-comments -fdefault-double-8 -fdefault-integer-8 @gol
+-fdefault-real-8 -fdollar-ok -ffixed-line-length-@var{n} @gol
+-ffixed-line-length-none -ffree-form -ffree-line-length-@var{n} @gol
+-ffree-line-length-none -fimplicit-none -finteger-4-integer-8 @gol
+-fmax-identifier-length -fmodule-private -fno-fixed-form -fno-range-check @gol
+-fopenmp -freal-4-real-10 -freal-4-real-16 -freal-4-real-8 @gol
+-freal-8-real-10 -freal-8-real-16 -freal-8-real-4 -std=@var{std}
+}
 
 @item Preprocessing Options
 @xref{Preprocessing Options,,Enable and customize preprocessing}.
-@gccoptlist{-cpp -dD -dI -dM -dN -dU -fworking-directory @gol
--imultilib @var{dir} -iprefix @var{file} -isysroot @var{dir} @gol
--iquote -isystem @var{dir} -nocpp -nostdinc -undef @gol
--A@var{question}=@var{answer} -A-@var{question}@r{[}=@var{answer}@r{]} @gol
--C -CC -D@var{macro}@r{[}=@var{defn}@r{]} -U@var{macro} -H -P}
+@gccoptlist{-A-@var{question}@r{[}=@var{answer}@r{]}
+-A@var{question}=@var{answer} -C -CC -D@var{macro}@r{[}=@var{defn}@r{]}
+-H -P @gol
+-U@var{macro} -cpp -dD -dI -dM -dN -dU -fworking-directory
+-imultilib @var{dir} @gol
+-iprefix @var{file} -iquote -isysroot @var{dir} -isystem @var{dir} -nocpp 
+-nostdinc @gol
+-undef
+}
 
 @item Error and Warning Options
 @xref{Error and Warning Options,,Options to request or suppress errors
 and warnings}.
-@gccoptlist{-fmax-errors=@var{n}
--fsyntax-only -pedantic -pedantic-errors -Wall @gol
--Waliasing -Wampersand -Warray-bounds -Wcharacter-truncation @gol
--Wconversion -Wimplicit-interface -Wimplicit-procedure -Wline-truncation @gol
--Wintrinsics-std -Wreal-q-constant -Wsurprising -Wno-tabs -Wunderflow @gol
--Wunused-parameter -Wintrinsic-shadow -Wno-align-commons @gol
--Wfunction-elimination}
+@gccoptlist{-Waliasing -Wall -Wampersand -Warray-bounds
+-Wcharacter-truncation @gol
+-Wconversion -Wfunction-elimination -Wimplicit-interface @gol
+-Wimplicit-procedure -Wintrinsic-shadow -Wintrinsics-std @gol
+-Wline-truncation -Wno-align-commons -Wno-tabs -Wreal-q-constant @gol
+-Wsurprising -Wunderflow -Wunused-parameter -fmax-errors=@var{n}
+-fsyntax-only @gol
+-pedantic -pedantic-errors
+}
 
 @item Debugging Options
 @xref{Debugging Options,,Options for debugging your program or GNU Fortran}.
-@gccoptlist{-fdump-fortran-original  -fdump-fortran-optimized @gol
--ffpe-trap=@var{list} -fbacktrace -fdump-parse-tree}
+@gccoptlist{-fbacktrace -fdump-fortran-optimized -fdump-fortran-original @gol
+-fdump-parse-tree -ffpe-trap=@var{list}
+}
 
 @item Directory Options
 @xref{Directory Options,,Options for directory search}.
@@ -157,39 +167,29 @@ and warnings}.
 
 @item Runtime Options
 @xref{Runtime Options,,Options for influencing runtime behavior}.
-@gccoptlist{-fconvert=@var{conversion}  -fno-range-check
--frecord-marker=@var{length} @gol  -fmax-subrecord-length=@var{length}
--fsign-zero}
+@gccoptlist{-fconvert=@var{conversion} -fmax-subrecord-length=@var{length}
+-fno-range-check @gol
+-frecord-marker=@var{length} -fsign-zero
+}
 
 @item Code Generation Options
 @xref{Code Gen Options,,Options for code generation conventions}.
-@gccoptlist{-fno-automatic  -ff2c  -fno-underscoring @gol
--fno-whole-file -fsecond-underscore @gol
--fbounds-check -fcheck-array-temporaries  -fmax-array-constructor =@var{n} @gol
+@gccoptlist{-faggressive-function-elimination -fblas-matmul-limit=@var{n} @gol
+-fbounds-check -fcheck-array-temporaries @gol
 -fcheck=@var{<all|array-temps|bounds|do|mem|pointer|recursion>} @gol
--fcoarray=@var{<none|single|lib>} -fmax-stack-var-size=@var{n} @gol
--fstack-arrays @gol
--fpack-derived  -frepack-arrays  -fshort-enums  -fexternal-blas @gol
--fblas-matmul-limit=@var{n} -frecursive -finit-local-zero @gol
--finit-integer=@var{n} -finit-real=@var{<zero|inf|-inf|nan|snan>} @gol
--finit-logical=@var{<true|false>} -finit-character=@var{n} @gol
--fno-align-commons -fno-protect-parens -frealloc-lhs @gol
--faggressive-function-elimination -ffrontend-optimize}
+-fcoarray=@var{<none|single|lib>} -fexternal-blas -ff2c
+-ffrontend-optimize @gol
+-finit-character=@var{n} -finit-integer=@var{n} -finit-local-zero @gol
+-finit-logical=@var{<true|false>}
+-finit-real=@var{<zero|inf|-inf|nan|snan>} @gol
+-fmax-array-constructor=@var{n} -fmax-stack-var-size=@var{n}
+-fno-align-commons @gol
+-fno-automatic -fno-protect-parens -fno-underscoring -fno-whole-file @gol
+-fsecond-underscore -fpack-derived -frealloc-lhs -frecursive @gol
+-frepack-arrays -fshort-enums -fstack-arrays
+}
 @end table
 
-@menu
-* Fortran Dialect Options::  Controlling the variant of Fortran language
-                             compiled.
-* Preprocessing Options::  Enable and customize preprocessing.
-* Error and Warning Options::     How picky should the compiler be?
-* Debugging Options::   Symbol tables, measurements, and debugging dumps.
-* Directory Options::   Where to find module files
-* Link Options ::       Influencing the linking step
-* Runtime Options::     Influencing runtime behavior
-* Code Gen Options::    Specifying conventions for function calls, data layout
-                        and register usage.
-@end menu
-
 @node Fortran Dialect Options
 @section Options controlling Fortran dialect
 @cindex dialect options
@@ -324,6 +324,17 @@ Specify that no implicit typing is allow
 @code{IMPLICIT} statements.  This is the equivalent of adding
 @code{implicit none} to the start of every procedure.
 
+@item -finteger-4-integer-8
+@opindex @code{finteger-4-integer-8}
+Promote all @code{INTEGER(KIND=4)} entities to an @code{INTEGER(KIND=8)}
+entities.  If @code{KIND=8} is unavailable, then an error will be issued.
+This option should be used with care and may not be suitable for your codes.
+Areas of possible concern include calls to external procedures,
+alignement in @code{EQUIVALENCE} and/or @code{COMMON}, generic interfaces,
+BOZ literal constant conversion, and I/O.  Inspection of the intermediate
+representation of the translated Fortran code, produced by
+@option{-fdump-tree-original}, is suggested.
+
 @item -fcray-pointer
 @opindex @code{fcray-pointer}
 Enable the Cray pointer extension, which provides C-like pointer
@@ -354,6 +365,28 @@ Similarly, @code{DATA i/Z'FFFFFFFF'/} wi
 on most systems, but with @option{-fno-range-check} the value will
 ``wrap around'' and @code{i} will be initialized to @math{-1} instead.
 
+@item  -freal-4-real-8
+@itemx -freal-4-real-10
+@itemx -freal-8-real-4
+@itemx -freal-8-real-10
+@itemx -freal-8-real-16
+@opindex @code{freal-4-real-8}
+@opindex @code{freal-4-real-10}
+@opindex @code{freal-4-real-16}
+@opindex @code{freal-8-real-4}
+@opindex @code{freal-8-real-10}
+@opindex @code{freal-8-real-16}
+@cindex options, real kind type promotion
+Promote all @code{REAL(KIND=M)} entities to @code{REAL(KIND=N)} entities.
+If @code{REAL(KIND=N)} is unavailable, then an error will be issued.
+All other real kind types are unaffected by this option.
+These options should be used with care and may not be suitable for your
+codes.  Areas of possible concern include calls to external procedures,
+alignement in @code{EQUIVALENCE} and/or @code{COMMON}, generic interfaces,
+BOZ literal constant conversion, and I/O.  Inspection of the intermediate
+representation of the translated Fortran code, produced by
+@option{-fdump-tree-original}, is suggested.
+
 @item -std=@var{std}
 @opindex @code{std=}@var{std} option
 Specify the standard to which the program is expected to conform, which

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

* Re: [patch] Flag-controlled type conversions/promotions
  2012-01-13 23:43 ` Steve Kargl
@ 2012-01-15 18:39   ` Zydrunas Gimbutas
  2012-01-15 19:37     ` Steve Kargl
  0 siblings, 1 reply; 13+ messages in thread
From: Zydrunas Gimbutas @ 2012-01-15 18:39 UTC (permalink / raw)
  To: Steve Kargl; +Cc: Andreas Kloeckner, gcc-patches, fortran

Hi,

Everything seems to be ok in this patch, except for minor typos in
documentation: REAl -> REAL, alignement -> alignment.

It would also be nice to extend the type conversion facility to
include -fdefault-real-16, -fdefault-double-16, -fdefault-real-10,
-fdefault-double-10,  and add conversions for logical types, to
complete the conversion table. These are not very commonly used
(except for -fdefault-real-16, -fdefault-double-16, which would
correspond to -r16 and -autodouble flags in some compilers), so we
should be fine at this time.

Thanks to everyone for making this work!

Zydrunas

On Fri, Jan 13, 2012 at 6:43 PM, Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
> On Wed, Nov 09, 2011 at 06:09:58PM -0500, Andreas Kloeckner wrote:
>> Hi there,
>>
>> please find attached the patch and the Changelog entry for our work on
>> the fortran bug #48426.
>>
>> The attached patch implements the options
>>
>> -finteger-4-integer-8
>> -freal-4-real-8
>> -freal-4-real-10
>> -freal-4-real-16
>> -freal-8-real-4
>> -freal-8-real-10
>> -freal-8-real-16
>>
>> to implement a variety of automatic type promotions. (This is particularly
>> helpful if one wants to quickly check whether a certain code has a bug limiting
>> its precision away from full machine accuracy.)
>>
>
> I plan to commit the attached patch this weekend.
>
> 2011-11-09  Zydrunas Gimbutas  <gimbutas@cims.nyu.edu>
>            Andreas Kloeckner  <kloeckner@cims.nyu.edu>
>            Steven G. Kargl  <kargl@gcc.gnu.org>
>
>        PR fortran/48426
>        * gfortran.h (gfc_option_t): Add members flag_*_kind to store kind.
>        * lang.opt: Add options -freal-4-real-8, -freal-4-real-10,
>        -freal-4-real-16, -freal-8-real-4, -freal-8-real-10, -freal-8-real-16
>        and -finteger-4-integer-8. User-desired type conversion information.
>        * decl.c (gfc_match_old_kind_spec,kind_expr): Type conversions
>        in declaration parsing.
>        * trans-types.c (gfc_init_kinds): User-specified type conversion
>        checked for current backend.
>        * primary.c (match_integer_constant,match_real_constant): Implement
>        type conversion in constant parsing.
>        * options.c (gfc_init_options,gfc_handle_option): Translate input
>        options to flags in internal options data structure.
>        * invoke.texi: Document new options.  Re-order options in Options
>        summary section.
>
> --
> Steve

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

* Re: [patch] Flag-controlled type conversions/promotions
  2012-01-15 18:39   ` Zydrunas Gimbutas
@ 2012-01-15 19:37     ` Steve Kargl
  0 siblings, 0 replies; 13+ messages in thread
From: Steve Kargl @ 2012-01-15 19:37 UTC (permalink / raw)
  To: Zydrunas Gimbutas; +Cc: Andreas Kloeckner, gcc-patches, fortran

On Sun, Jan 15, 2012 at 01:39:23PM -0500, Zydrunas Gimbutas wrote:
> Hi,
> 
> Everything seems to be ok in this patch, except for minor typos in
> documentation: REAl -> REAL, alignement -> alignment.

Good catch.

> It would also be nice to extend the type conversion facility to
> include -fdefault-real-16, -fdefault-double-16, -fdefault-real-10,
> -fdefault-double-10,  and add conversions for logical types, to
> complete the conversion table. These are not very commonly used
> (except for -fdefault-real-16, -fdefault-double-16, which would
> correspond to -r16 and -autodouble flags in some compilers), so we
> should be fine at this time.

Well, historically, -fdefault-real-8, -fdefault-integer-8,
and -fdefault-double-8 were provided for backwards compatibility
with g77's -r8, -d8, and -i8 options.  There was no consideration
for other compilers.*  Thus, I would discourage these new options
in favor of your -freal-N-real-M options. 


* Craig Burley may have included -r8, -i8, and -d8 to be
compatible with other compilers, but I'm too lazy to go
code spelunking.

-- 
Steve

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

* Re: [patch] Flag-controlled type conversions/promotions
  2011-12-27 12:26     ` Dominique Dhumieres
  2011-12-27 16:27       ` Zydrunas Gimbutas
@ 2011-12-27 18:35       ` Steve Kargl
  1 sibling, 0 replies; 13+ messages in thread
From: Steve Kargl @ 2011-12-27 18:35 UTC (permalink / raw)
  To: Dominique Dhumieres
  Cc: zydrunas.gimbutas, kloeckner, gcc-patches, fortran, burnus

On Tue, Dec 27, 2011 at 12:52:19PM +0100, Dominique Dhumieres wrote:
> > -freal-4-real-8 is not equivalent to -fdefault-real-8 and -fdefault-double-8.
> > 
> > -freal-4-real-8 interprets any 4-byte real type, whether it is a
> > default real type or explicitly declared as 4-byte, as a 8-byte double
> > precision type, and that applies to all variables, functions and
> > constants.
> > 
> > -fdefault-real-8 will promote only default real type to double
> > precision and only variables and functions. Since constants are
> > usually declared explicitly as 4-byte, e.g. 1.01223e0 is an explicitly
> > defined 4-byte constant in gfortran, they will not be promoted.
> 
> I agree with the above and I think this should go into the manual. One 
> thing which can be done with -fdefault-real-8, but not with 
> -freal-4-real-8 is to work around some pitfalls of these otions by 
> specifying explicit kinds when needed (this probably explains why less 
> tests fail with the former option than with the later, see results at the 
> end of this mail).

AFAICT, the whole point of these options is to promote
everything, so one doesn't need to remember, for example,
if literal constants, which are declarated with kind
suffixes, are promoted or not.   I don't see that as
a pitfall.  If one is testing the stability or accuracy
of an algorithm, then promoting 'x = 1._4 / 1._4' may
be important.  Consider

program k
   real x
   x = 1._4 / 3._4
end program k

gfc4x -c -fdump-tree-original -fdefault-real-8 k.f90

  real(kind=8) x;
  x = 3.333333432674407958984375e-1;

gfc4x -c -fdump-tree-original -freal-4-real-8 k.f90

  real(kind=8) x;
  x = 3.33333333333333314829616256247390992939472198486328125e-1;

The difference is one heck of alot of ULPs.

> In my opinion, these options, while useful, have several pitfalls:
> 
> (1) call to external procedures (especially in libraries),
> (2) alignements in EQUIVALENCE and/or COMMON,
> (3) generic interfaces,
> (4) BOZ,
> (5) I/Os,
> (6) ...

One needs to worry about these things with the -fdefault-*
options as well.  In particular, anything that may depend on 
NUMERIC_STORAGE_SIZE will present a problem, because it is
always set to 32 (except on a possibly pathological target
without a 32-bit float type).

> I wonder if they should not have their own page in the manual with a big 
> warning at the beginning telling the user that these options are likely to 
> break "legacy" codes.

These options as well as the -fdefault-* are likely to break
any Fortran code.  It is up to the user to test whether these 
options are suitable for his/her purpose.  I'll update the
manual with a sentence of the form: "This option should be
used with case and may not be suitable for codes.  Inspection
of the intermediate representation of the translated Fortran
code, produced by the -fdump-tree-original option, is suggested."

> 		=== gfortran Summary for unix/-m32/-finteger-4-integer-8 ===
> 
> # of expected passes		37336
> # of unexpected failures	896
> # of expected failures		39
> # of unresolved testcases	1
> # of unsupported tests		570
> 

Well, I think you'll find a large number of these unexpected
failures are due to hard coded assumptions about sizeof(INTEGER)
etc.  All of the failures I saw in gfortran.fortran-torture 
were of this variety. 

-- 
Steve

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

* Re: [patch] Flag-controlled type conversions/promotions
  2011-12-27 12:26     ` Dominique Dhumieres
@ 2011-12-27 16:27       ` Zydrunas Gimbutas
  2011-12-27 18:35       ` Steve Kargl
  1 sibling, 0 replies; 13+ messages in thread
From: Zydrunas Gimbutas @ 2011-12-27 16:27 UTC (permalink / raw)
  To: Dominique Dhumieres; +Cc: sgk, kloeckner, gcc-patches, fortran, burnus

On Tue, Dec 27, 2011 at 6:52 AM, Dominique Dhumieres <dominiq@lps.ens.fr> wrote:
>> -freal-4-real-8 is not equivalent to -fdefault-real-8 and -fdefault-double-8.
>>
>> -freal-4-real-8 interprets any 4-byte real type, whether it is a
>> default real type or explicitly declared as 4-byte, as a 8-byte double
>> precision type, and that applies to all variables, functions and
>> constants.
>>
>> -fdefault-real-8 will promote only default real type to double
>> precision and only variables and functions. Since constants are
>> usually declared explicitly as 4-byte, e.g. 1.01223e0 is an explicitly
>> defined 4-byte constant in gfortran, they will not be promoted.
>
> I agree with the above and I think this should go into the manual. One
> thing which can be done with -fdefault-real-8, but not with
> -freal-4-real-8 is to work around some pitfalls of these otions by
> specifying explicit kinds when needed (this probably explains why less
> tests fail with the former option than with the later, see results at the
> end of this mail).
>

That is correct. -fdefault-real-8 provides a finely tuned type
promotion mechanism, while -freal-*-real-* overrides all type
definitions via brute force. We actually like that: some of the codes
we have date back to the 70's, we don't want to convert them into
Fortran 95 and/or maintain several copies with different type
definitions - this is just too expensive and time consuming. In such
cases, we really do want to override all old-style definitions. In our
work, this doesn't happen often, usually, we are running our code in
double precision, but from time to time we would like to raise
precision to pre-compute tables with more digits or to investigate
ill-conditioning and numerical stability issues.

> In my opinion, these options, while useful, have several pitfalls:
>
> (1) call to external procedures (especially in libraries),
> (2) alignements in EQUIVALENCE and/or COMMON,
> (3) generic interfaces,
> (4) BOZ,
> (5) I/Os,
> (6) ...
>
> I wonder if they should not have their own page in the manual with a big
> warning at the beginning telling the user that these options are likely to
> break "legacy" codes.
>

We do recompile all codes with the promotion flags to address this,
usually, with only minor modifications. Things like calls to external
C functions need to be fixed, although this is also needed if using
-fdefault-* flags. Alignment could be also a problem, especially if
promoting to quad precision which currently requires 128-bit variable
aligment, again this also might also happen with -fdefault-* flags.
The user has to be somewhat aware of this and adjust the code
accordingly.  We tend to ignore such issues in practice and proceed
anyway with fingers crossed: everything works 90% of the time just
fine!

Zydrunas

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

* Re: [patch] Flag-controlled type conversions/promotions
  2011-12-27  0:04   ` Zydrunas Gimbutas
@ 2011-12-27 12:26     ` Dominique Dhumieres
  2011-12-27 16:27       ` Zydrunas Gimbutas
  2011-12-27 18:35       ` Steve Kargl
  0 siblings, 2 replies; 13+ messages in thread
From: Dominique Dhumieres @ 2011-12-27 12:26 UTC (permalink / raw)
  To: zydrunas.gimbutas, sgk; +Cc: kloeckner, gcc-patches, fortran, dominiq, burnus

> -freal-4-real-8 is not equivalent to -fdefault-real-8 and -fdefault-double-8.
> 
> -freal-4-real-8 interprets any 4-byte real type, whether it is a
> default real type or explicitly declared as 4-byte, as a 8-byte double
> precision type, and that applies to all variables, functions and
> constants.
> 
> -fdefault-real-8 will promote only default real type to double
> precision and only variables and functions. Since constants are
> usually declared explicitly as 4-byte, e.g. 1.01223e0 is an explicitly
> defined 4-byte constant in gfortran, they will not be promoted.

I agree with the above and I think this should go into the manual. One 
thing which can be done with -fdefault-real-8, but not with 
-freal-4-real-8 is to work around some pitfalls of these otions by 
specifying explicit kinds when needed (this probably explains why less 
tests fail with the former option than with the later, see results at the 
end of this mail).

In my opinion, these options, while useful, have several pitfalls:

(1) call to external procedures (especially in libraries),
(2) alignements in EQUIVALENCE and/or COMMON,
(3) generic interfaces,
(4) BOZ,
(5) I/Os,
(6) ...

I wonder if they should not have their own page in the manual with a big 
warning at the beginning telling the user that these options are likely to 
break "legacy" codes.

The raw test results are the following

make -k check-gfortran RUNTESTFLAGS="--target_board=unix'{-m32/-finteger-4-integer-8,
-m64/-finteger-4-integer-8,-m32/-freal-4-real-8,-m64/-freal-4-real-8,-m32/-freal-8-real-10,-m64/-freal-8-real-10}'"

		=== gfortran Summary for unix/-m32/-finteger-4-integer-8 ===

# of expected passes		37336
# of unexpected failures	896
# of expected failures		39
# of unresolved testcases	1
# of unsupported tests		570

		=== gfortran Summary for unix/-m64/-finteger-4-integer-8 ===

# of expected passes		37728
# of unexpected failures	840
# of expected failures		39
# of unsupported tests		409

		=== gfortran Summary for unix/-m32/-freal-4-real-8 ===

# of expected passes		37526
# of unexpected failures	702
# of expected failures		39
# of unsupported tests		570

		=== gfortran Summary for unix/-m64/-freal-4-real-8 ===

# of expected passes		37857
# of unexpected failures	698
# of expected failures		39
# of unsupported tests		409

		=== gfortran Summary for unix/-m32/-freal-8-real-10 ===

# of expected passes		37928
# of unexpected failures	394
# of expected failures		39
# of untested testcases		8
# of unsupported tests		570

		=== gfortran Summary for unix/-m64/-freal-8-real-10 ===

# of expected passes		38300
# of unexpected failures	357
# of expected failures		39
# of untested testcases		8
# of unsupported tests		409

		=== gfortran Summary ===

# of expected passes		226675
# of unexpected failures	3887
# of expected failures		234
# of unresolved testcases	1
# of untested testcases		16
# of unsupported tests		2937

to be compared with

make -k check-gfortran RUNTESTFLAGS="--target_board=unix'{-m32/-fdefault-integer-8,
-m64/-fdefault-integer-8,-m32/-fdefault-real-8,-m64/-fdefault-real-8}'"

		=== gfortran Summary for unix/-m32/-fdefault-integer-8 ===

# of expected passes		37794
# of unexpected failures	489
# of expected failures		39
# of unresolved testcases	24
# of unsupported tests		570

		=== gfortran Summary for unix/-m64/-fdefault-integer-8 ===

# of expected passes		38111
# of unexpected failures	499
# of expected failures		39
# of unresolved testcases	24
# of unsupported tests		409

		=== gfortran Summary for unix/-m32/-fdefault-real-8 ===

# of expected passes		37705
# of unexpected failures	539
# of expected failures		39
# of untested testcases		8
# of unsupported tests		570

		=== gfortran Summary for unix/-m64/-fdefault-real-8 ===

# of expected passes		38028
# of unexpected failures	535
# of expected failures		39
# of untested testcases		8
# of unsupported tests		409

		=== gfortran Summary ===

# of expected passes		151638
# of unexpected failures	2062
# of expected failures		156
# of unresolved testcases	48
# of untested testcases		16
# of unsupported tests		1958

I did not have the time to look in detail to the results. From a quick 
glance I can tell that there are overlaps between the failures of 
-fdefault-*-8 and -f*-4-*-8. In particular the ICEs with coarray appear 
for both cases (I have open pr51682).

Dominique

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

* Re: [patch] Flag-controlled type conversions/promotions
  2011-12-26 18:29 ` Steve Kargl
  2011-12-26 19:34   ` Steve Kargl
@ 2011-12-27  0:04   ` Zydrunas Gimbutas
  2011-12-27 12:26     ` Dominique Dhumieres
  1 sibling, 1 reply; 13+ messages in thread
From: Zydrunas Gimbutas @ 2011-12-27  0:04 UTC (permalink / raw)
  To: Steve Kargl; +Cc: Dominique Dhumieres, fortran, gcc-patches, burnus, kloeckner

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

Hi all,

Attached are three test file, that stress the type-promotion patch.

>> The difference between -fdefault-*-8 and -f*-4-*-8 should probably also be documented.
>>
>
> It is documented for the -freal-* options.  The manual has, for example,
>
> -freal-4-real-8
>     Promote REAL(KIND=4) entities to REAL(KIND=8) entities. If KIND=8 is unavail-
>     able, then an error will be issued.  All other real kind types are unaffected
>     by this option.
>
> The last sentence is the same for the other options.  This literally means
> that only REAL(4) is effected by the -freal-4-real-8 option.  If one reads
> he description of -fdefault-*, one will that -freal-4-real-8 is equivalent
> to specifying both -fdefault-real-8 and -fdefault-double-8.
>

-freal-4-real-8 is not equivalent to -fdefault-real-8 and -fdefault-double-8.

-freal-4-real-8 interprets any 4-byte real type, whether it is a
default real type or explicitly declared as 4-byte, as a 8-byte double
precision type, and that applies to all variables, functions and
constants.

-fdefault-real-8 will promote only default real type to double
precision and only variables and functions. Since constants are
usually declared explicitly as 4-byte, e.g. 1.01223e0 is an explicitly
defined 4-byte constant in gfortran, they will not be promoted.

$ gfortran -freal-4-real-8 test-r4.f
$ a.out
  0.90929742682568171
  0.90929742682568171
   0.0000000000000000
   0.0000000000000000
   0.0000000000000000
   0.0000000000000000
   0.0000000000000000
   0.0000000000000000
   0.0000000000000000
   0.0000000000000000

but

$ gfortran -fdefault-real-8 -fdefault-double-8 test-r4.f
$ a.out
  0.90929742682568171
  0.90929741
 -2.01522503129325514E-008
 -2.01522503129325514E-008
 -2.01522503129325514E-008
 -2.01522503129325514E-008
 -2.01522503129325514E-008
 -2.01522503129325514E-008
 -2.01522503129325514E-008
 -2.01522503129325514E-008

Note how constants are truncated to single precision, while using
-fdefault-real-8 -fdefault-double-8.

The same promotion convention applies to other -freal-*-real-*, and
-finteger-*-integer-* flags.

For example, -fdefault-integer-8 is not equivalent to
-finteger-4-integer-8, because integer*4 types and constants are being
interpreted in a different way, see test-i4.f test:

$ gfortran -fdefault-integer-8 test-i4.f
test-i4.f:6.8:

      j=2**40
        1
Error: Arithmetic overflow converting INTEGER(8) to INTEGER(4) at (1).
This check can be disabled with the option -fno-range-check

The error above is due to inability of standard gfortran to promote
explicitly declared integer*4 type to integer*8.

$ gfortran -finteger-4-integer-8 test-i4.f
$ a.out
        1099511627776
        1099511627776

This fixes the above problem.

Finally,

$ gfortran -freal-8-real-16 test-r8.f
$ a.out
  0.90929742682568169539601986591174487
  0.90929742682568169539601986591174487
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000

We have nothing to compare this result with since, currently, gfortran
has no facility to promote double precision to real*16 (no
-fdefault-double-16 flag).

>> Last point for this batch is that using '-freal-8-real-10 -freal-8-real-16' does not
>> generate an error, the last option being the one used.
>
> Yes, that is correct.  Consider it to be similar to '-Os -O -O2 -O0'.  The
> last one wins.  Note, there is this combination: '-freal-4-real-8 -freal-8-real-16'
> which will promote both REAL(4) and (8) to REAL(16).
>

One caveat here, we have not attempted to chain constant conversion in
this patch.

This combination will promote real*4 constants to real*8, and real*8
constants to real*16,

$ gfortran -freal-4-real-8 -freal-8-real-16 test-r4.f
$ a.out
  0.90929742682568169539601986591174487
  0.90929742682568169539601986591174487
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000
  1.40209065578162555042101269140459185E-0017 <- constant truncation
   0.0000000000000000000000000000000000
  1.40209065578162555042101269140459185E-0017 <- constant truncation
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000

While this combination will promote real*4 constants to real*16, and
real *8 constants to real*16,

$ gfortran -freal-4-real-16 -freal-8-real-16 test-r4.f
$ a.out
  0.90929742682568169539601986591174487
  0.90929742682568169539601986591174487
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000
   0.0000000000000000000000000000000000

The second promotion declaration is cleaner, but the declaration
chaining may be worth the effort.


The patch has been tested on Fortran 77 and Fortran 95 codes, so as
for the errors in coarray tests, it is quite possible that we have
simply missed some kind of type processing/declaration since this is a
relative new Fortran feature, sorry about that.


Zydrunas

[-- Attachment #2: test-r4.f --]
[-- Type: text/x-fortran, Size: 790 bytes --]

	implicit real *4 (a-h,o-z)
	real(4) :: x, xdata
	real get_real
	real *4 get_real4	
	data xdata/0.90929742682568169539601986591174487_4/
	data ydata/0.90929742682568169539601986591174487_4/
c
	write(*,*) sin(2.0e0)
	write(*,*) xdata
c
	x=0.90929742682568169539601986591174487e0
	write(*,*) x-sin(2.0e0)
	y=0.90929742682568169539601986591174487e0
	write(*,*) y-sin(2.0e0)
	x=get_real()
	write(*,*) x-sin(2.0e0)
	x=get_real4()
	write(*,*) x-sin(2.0e0)
	y=get_real()
	write(*,*) y-sin(2.0e0)
	y=get_real4()
	write(*,*) y-sin(2.0e0)
c
	write(*,*) xdata-sin(2.0e0)
	write(*,*) ydata-sin(2.0e0)
c
	stop
	end


	real function get_real()
	get_real=0.90929742682568169539601986591174487_4
	return
	end

	real *4 function get_real4()
	get_real4 =0.90929742682568169539601986591174487_4
	return
	end


[-- Attachment #3: test-r8.f --]
[-- Type: text/x-fortran, Size: 824 bytes --]

	implicit real *8 (a-h,o-z)
	real(8) :: x, xdata
	double precision get_double
	real *8 get_real8	
	data xdata/0.90929742682568169539601986591174487_8/
	data ydata/0.90929742682568169539601986591174487_8/
c
	write(*,*) sin(2.0d0)
	write(*,*) xdata
c
	x=0.90929742682568169539601986591174487d0
	write(*,*) x-sin(2.0d0)
	y=0.90929742682568169539601986591174487d0
	write(*,*) y-sin(2.0d0)
	x=get_double()
	write(*,*) x-sin(2.0d0)
	x=get_real8()
	write(*,*) x-sin(2.0d0)
	y=get_double()
	write(*,*) y-sin(2.0d0)
	y=get_real8()
	write(*,*) y-sin(2.0d0)
c
	write(*,*) xdata-sin(2.0d0)
	write(*,*) ydata-sin(2.0d0)
c
	stop
	end


	double precision function get_double()
	get_double=0.90929742682568169539601986591174487_8
	return
	end

	real *8 function get_real8()
	get_real8 =0.90929742682568169539601986591174487_8
	return
	end


[-- Attachment #4: test-i4.f --]
[-- Type: text/x-fortran, Size: 118 bytes --]

	implicit real *4 (a-h,o-z)
	integer i
	integer *4 j
c
	i=2**40
	j=2**40
c
	write(*,*) i
	write(*,*) j
c
	stop
	end



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

* Re: [patch] Flag-controlled type conversions/promotions
  2011-12-26 18:29 ` Steve Kargl
@ 2011-12-26 19:34   ` Steve Kargl
  2011-12-27  0:04   ` Zydrunas Gimbutas
  1 sibling, 0 replies; 13+ messages in thread
From: Steve Kargl @ 2011-12-26 19:34 UTC (permalink / raw)
  To: Dominique Dhumieres
  Cc: fortran, gcc-patches, burnus, zydrunas.gimbutas, kloeckner

On Mon, Dec 26, 2011 at 09:28:01AM -0800, Steve Kargl wrote:
> On Mon, Dec 26, 2011 at 05:14:46PM +0100, Dominique Dhumieres wrote:
> > > I regression tested the patch on i686-*-freebsd.  No problems occurred.
> > > Can one of the other gfortran reviewers/committers cast a quick glance
> > > over the patch.  I would like to commit this within next day or two.
> > 
> > I have applied the patch on trunk (incremental update). I did not get any
> > regression on x86_64-apple-darwin10 with either -m32 or -m64.
> 
> Thanks for testing.
> 
> > I get
> > 
> > 		=== gfortran Summary for unix/-m32/-finteger-4-integer-8 ===
> > 
> > # of expected passes		37336
> > # of unexpected failures	896
> > # of expected failures		39
> > # of unresolved testcases	1
> > # of unsupported tests		570
> > 

In gfortran.fortran-torture/execute, I did the simply test of 

#! /bin/csh
foreach i (*.f90)
  echo $i
  gfortran -O -finteger-4-integer-8 -o z $i
  ./z
end

These 6 tests all aborted:  

intrinsic_bitops.f90
intrinsic_leadz.f90
intrinsic_si_kind.f90
intrinsic_trailz.f90
iolength_1.f90
iolength_2.f90
iolength_3.f90

There were no ICE's.

Inspection of the tests show that indeed the programs should
abort.  For example, the guts of iolength_3.f90 are

  integer, parameter :: int32 = selected_int_kind(9)
  integer(int32) :: a, b, iol
  real(dp) :: c
  inquire (iolength = iol) a, b, c
  if ( 16 /= iol) then
     call abort
  end if

With -finteger-4-integer-8, iol should be 24.

-- 
Steve

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

* Re: [patch] Flag-controlled type conversions/promotions
  2011-12-26 17:28 Dominique Dhumieres
@ 2011-12-26 18:29 ` Steve Kargl
  2011-12-26 19:34   ` Steve Kargl
  2011-12-27  0:04   ` Zydrunas Gimbutas
  0 siblings, 2 replies; 13+ messages in thread
From: Steve Kargl @ 2011-12-26 18:29 UTC (permalink / raw)
  To: Dominique Dhumieres
  Cc: fortran, gcc-patches, burnus, zydrunas.gimbutas, kloeckner

On Mon, Dec 26, 2011 at 05:14:46PM +0100, Dominique Dhumieres wrote:
> > I regression tested the patch on i686-*-freebsd.  No problems occurred.
> > Can one of the other gfortran reviewers/committers cast a quick glance
> > over the patch.  I would like to commit this within next day or two.
> 
> I have applied the patch on trunk (incremental update). I did not get any
> regression on x86_64-apple-darwin10 with either -m32 or -m64.

Thanks for testing.

> I get
> 
> 		=== gfortran Summary for unix/-m32/-finteger-4-integer-8 ===
> 
> # of expected passes		37336
> # of unexpected failures	896
> # of expected failures		39
> # of unresolved testcases	1
> # of unsupported tests		570
> 
> 		=== gfortran Summary for unix/-m64/-finteger-4-integer-8 ===
> 
> # of expected passes		37728
> # of unexpected failures	840
> # of expected failures		39
> # of unsupported tests		409
> 
> related to pr32770.
> 
> I did not have the time to go through the details of the failures, but
> (1) there are a few ICEs after error as in
> 
> FAIL: gfortran.dg/coarray/image_index_1.f90 -fcoarray=lib  -O2  -lcaf_single (internal compiler error)
> Excess errors:
> /opt/gcc/work/gcc/testsuite/gfortran.dg/coarray/image_index_1.f90:14:0:0: error: mismatching comparison operand types
> integer(kind=4)
> integer(kind=8)
> one = _gfortran_caf_num_images.66 == 1;
> ...
> /opt/gcc/work/gcc/testsuite/gfortran.dg/coarray/image_index_1.f90:14:0:0: error: mismatching comparison operand types
> integer(kind=8)
> integer(kind=4)
> D.2567 = D.2100 <= _gfortran_caf_num_images.66;
> /opt/gcc/work/gcc/testsuite/gfortran.dg/coarray/image_index_1.f90:14:0:0: internal compiler error: verify_gimple failed
> 
> These ICEs on invalid occur mostly in coarray tests, but I also see
> 
> FAIL: gfortran.dg/popcnt_poppar_2.F90  -O0  (internal compiler error)
> FAIL: gfortran.dg/popcnt_poppar_2.F90  -O0  (test for excess errors)
> Excess errors:
> /opt/gcc/work/gcc/testsuite/gfortran.dg/popcnt_poppar_2.F90:30:0:0: error: type mismatch in binary expression
> integer(kind=8)
> integer(kind=4)
> integer(kind=4)
> res = D.1935 + D.1938;
> /opt/gcc/work/gcc/testsuite/gfortran.dg/popcnt_poppar_2.F90:30:0:0: internal compiler error: verify_gimple failed
> 
> I think the errors are exepcted, but gfortran should exit without ICE.  I'll`
> fill a pr when the patch will be committed.

This is worrisome.  These types of options go from debugging aids to people
depending on them for production codes.   I'll seee if I can reproduce some
of yor observation to try to understand the issues.

> The manual could probably lists some expected breakages such as this one.

Good point.  I'll update the manual to indicate that these options are 
intended for debugging purposes and that there are known issues.

> 
> The difference between -fdefault-*-8 and -f*-4-*-8 should probably also be documented.
> 

It is documented for the -freal-* options.  The manual has, for example,

-freal-4-real-8
     Promote REAL(KIND=4) entities to REAL(KIND=8) entities. If KIND=8 is unavail-
     able, then an error will be issued.  All other real kind types are unaffected
     by this option.

The last sentence is the same for the other options.  This literally means
that only REAL(4) is effected by the -freal-4-real-8 option.  If one reads
he description of -fdefault-*, one will that -freal-4-real-8 is equivalent
to specifying both -fdefault-real-8 and -fdefault-double-8.

> Last point for this batch is that using '-freal-8-real-10 -freal-8-real-16' does not
> generate an error, the last option being the one used.

Yes, that is correct.  Consider it to be similar to '-Os -O -O2 -O0'.  The
last one wins.  Note, there is this combination: '-freal-4-real-8 -freal-8-real-16'
which will promote both REAL(4) and (8) to REAL(16).

-- 
Steve

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

* Re: [patch] Flag-controlled type conversions/promotions
@ 2011-12-26 17:28 Dominique Dhumieres
  2011-12-26 18:29 ` Steve Kargl
  0 siblings, 1 reply; 13+ messages in thread
From: Dominique Dhumieres @ 2011-12-26 17:28 UTC (permalink / raw)
  To: fortran; +Cc: gcc-patches, burnus, zydrunas.gimbutas, kloeckner, sgk

> I regression tested the patch on i686-*-freebsd.  No problems occurred.
> Can one of the other gfortran reviewers/committers cast a quick glance
> over the patch.  I would like to commit this within next day or two.

I have applied the patch on trunk (incremental update). I did not get any
regression on x86_64-apple-darwin10 with either -m32 or -m64.

With the follwoing patch

--- /opt/gcc/_clean/gcc/testsuite/lib/prune.exp	2011-10-17 12:04:23.000000000 +0200
+++ /opt/gcc/work/gcc/testsuite/lib/prune.exp	2011-12-26 13:59:57.000000000 +0100
@@ -42,6 +42,9 @@ proc prune_gcc_output { text } {
     regsub -all "(^|\n)\[^\n\]*: Additional NOP may be necessary to workaround Itanium processor A/B step errata" $text "" text
     regsub -all "(^|\n)\[^\n*\]*: Assembler messages:\[^\n\]*" $text "" text
 
+    # Ignore warning for gfortran options passed to the C compilers.
+    regsub -all "(^|\n)cc1: warning: command line option .-f\[^\"\]*. is valid for Fortran but not for C\[^\n\]*" $text "" text
+
     # Ignore second line of IRIX 6 linker multiline message.
     regsub -all "(^|\n)\[ \t\]*that might degrade performance on an older version \\(rev. 2.2\\) R4000 processor.\[^\n\]*" $text "" text
 

I get

		=== gfortran Summary for unix/-m32/-finteger-4-integer-8 ===

# of expected passes		37336
# of unexpected failures	896
# of expected failures		39
# of unresolved testcases	1
# of unsupported tests		570

		=== gfortran Summary for unix/-m64/-finteger-4-integer-8 ===

# of expected passes		37728
# of unexpected failures	840
# of expected failures		39
# of unsupported tests		409

related to pr32770.

I did not have the time to go through the details of the failures, but
(1) there are a few ICEs after error as in

FAIL: gfortran.dg/coarray/image_index_1.f90 -fcoarray=lib  -O2  -lcaf_single (internal compiler error)
FAIL: gfortran.dg/coarray/image_index_1.f90 -fcoarray=lib  -O2  -lcaf_single (test for excess errors)
Excess errors:
/opt/gcc/work/gcc/testsuite/gfortran.dg/coarray/image_index_1.f90:14:0:0: error: mismatching comparison operand types
integer(kind=4)
integer(kind=8)
one = _gfortran_caf_num_images.66 == 1;
...
/opt/gcc/work/gcc/testsuite/gfortran.dg/coarray/image_index_1.f90:14:0:0: error: mismatching comparison operand types
integer(kind=8)
integer(kind=4)
D.2567 = D.2100 <= _gfortran_caf_num_images.66;
/opt/gcc/work/gcc/testsuite/gfortran.dg/coarray/image_index_1.f90:14:0:0: internal compiler error: verify_gimple failed

These ICEs on invalid occur mostly in coarray tests, but I also see

FAIL: gfortran.dg/popcnt_poppar_2.F90  -O0  (internal compiler error)
FAIL: gfortran.dg/popcnt_poppar_2.F90  -O0  (test for excess errors)
Excess errors:
/opt/gcc/work/gcc/testsuite/gfortran.dg/popcnt_poppar_2.F90:30:0:0: error: type mismatch in binary expression
integer(kind=8)
integer(kind=4)
integer(kind=4)
res = D.1935 + D.1938;
/opt/gcc/work/gcc/testsuite/gfortran.dg/popcnt_poppar_2.F90:30:0:0: internal compiler error: verify_gimple failed

I think the errors are exepcted, but gfortran should exit without ICE. I'll fill a pr when the patch
will be committed.

Among other errors, several ones are related to broken generic interfaces for different KIND.
The manual could probably lists some expected breakages such as this one.

The difference between -fdefault-*-8 and -f*-4-*-8 should probably also be documented.

Last point for this batch is that using '-freal-8-real-10 -freal-8-real-16' does not
generate an error, the last option being the one used.

Thanks fro the patch,

Dominique

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

end of thread, other threads:[~2012-01-15 19:37 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-10  0:57 [patch] Flag-controlled type conversions/promotions Andreas Kloeckner
2011-12-24 18:07 ` Steve Kargl
2011-12-26  8:18 ` Steve Kargl
2012-01-13 23:43 ` Steve Kargl
2012-01-15 18:39   ` Zydrunas Gimbutas
2012-01-15 19:37     ` Steve Kargl
2011-12-26 17:28 Dominique Dhumieres
2011-12-26 18:29 ` Steve Kargl
2011-12-26 19:34   ` Steve Kargl
2011-12-27  0:04   ` Zydrunas Gimbutas
2011-12-27 12:26     ` Dominique Dhumieres
2011-12-27 16:27       ` Zydrunas Gimbutas
2011-12-27 18:35       ` Steve Kargl

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).