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


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

[patch,fortran] Fix PR19310 unnecessary error for overflowing results


:ADDPATCH fortran:

The attached patch puts in place a -fno-range-check feature for gfortran so that if desired, compile time range checking can be disabled and allow things like this:

a = exp(1000)

I also expanded the error message for range_check to include underflow, overflow, and other 'range' errors.

This patch puts in place the infrastructure needed to take care of PR19904 which is an error for things like this:

double precision, parameter :: zero=0, nan=0/zero

I will be following with another patch for PR19904. (I may have run into some mpfr bugs. I am getting an assert error in the mpfr library when dividing by zero. I am exploring mpfr for the first time so it may just be a learning curve. ;) )

Bootstrapped and regression tested.

Is this patch OK for Trunk?

I will generate a test case and test before I commit.

Regards,

Jerry

2006-06-08 Jerry DeLisle <jvdelisle@gcc.gnu.org>

	PR fortran/19310
	* gfortran.h (gfc_option_t): Add new flag.
	* invoke.texi: Document new flag.
	* lang.opt: Add option -fno-range-check.
	* options.c (gfc_init_options): Initialize new flag.
	(gfc_handle_options): Set flag if invoked.
	* simplify.c (range_check): Return result if -fno-range-check.
	Add error messages for overflow, underflow, and other errors.



Index: gfortran.h
===================================================================
*** gfortran.h	(revision 114499)
--- gfortran.h	(working copy)
*************** typedef struct
*** 1627,1632 ****
--- 1627,1633 ----
    int flag_max_stack_var_size;
    int flag_module_access_private;
    int flag_no_backend;
+   int flag_no_range_check;
    int flag_pack_derived;
    int flag_repack_arrays;
    int flag_preprocessed;
Index: lang.opt
===================================================================
*** lang.opt	(revision 114499)
--- lang.opt	(working copy)
*************** fno-backend
*** 181,186 ****
--- 181,190 ----
  Fortran RejectNegative
  Don't generate code, just do syntax and semantics checking
  
+ fno-range-check
+ Fortran RejectNegative
+ Disable range checking during compilation
+ 
  fpack-derived
  Fortran
  Try to layout derived types as compact as possible
Index: invoke.texi
===================================================================
*** invoke.texi	(revision 114499)
--- invoke.texi	(working copy)
*************** by type.  Explanations are in the follow
*** 122,128 ****
  -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 }
  
  @item Warning Options
  @xref{Warning Options,,Options to Request or Suppress Warnings}.
--- 122,128 ----
  -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 }
  
  @item Warning Options
  @xref{Warning Options,,Options to Request or Suppress Warnings}.
*************** and @code{c$}, @code{*$} and @code{!$} s
*** 308,313 ****
--- 308,322 ----
  and when linking arranges for the OpenMP runtime library to be linked
  in.
  
+ @cindex -fno-range-check
+ @cindex options, -fno-range-check
+ @item -fno-range-check
+ Disables range checking on results of simplification of constant expressions
+ during compilation.  For example, by default, @command{gfortran} will give
+ an overflow error at compile time when simplifying @code{a = EXP(1000)}.
+ With @samp{-fno-range-check}, no error will be given and the variable @code{a}
+ will be assigned the value @code{+Infinity}.
+ 
  @cindex -std=@var{std} option
  @cindex option, -std=@var{std}
  @item -std=@var{std}
Index: options.c
===================================================================
*** options.c	(revision 114499)
--- options.c	(working copy)
*************** gfc_init_options (unsigned int argc ATTR
*** 73,78 ****
--- 73,79 ----
    gfc_option.flag_max_stack_var_size = 32768;
    gfc_option.flag_module_access_private = 0;
    gfc_option.flag_no_backend = 0;
+   gfc_option.flag_no_range_check = 0;
    gfc_option.flag_pack_derived = 0;
    gfc_option.flag_repack_arrays = 0;
    gfc_option.flag_preprocessed = 0;
*************** gfc_handle_option (size_t scode, const c
*** 519,524 ****
--- 520,529 ----
        gfc_option.flag_no_backend = value;
        break;
  
+     case OPT_fno_range_check:
+       gfc_option.flag_no_range_check = 1;
+       break;
+ 
      case OPT_fpack_derived:
        gfc_option.flag_pack_derived = value;
        break;
Index: simplify.c
===================================================================
*** simplify.c	(revision 114499)
--- simplify.c	(working copy)
*************** static int xascii_table[256];
*** 90,104 ****
  
  
  /* Range checks an expression node.  If all goes well, returns the
!    node, otherwise returns &gfc_bad_expr and frees the node.  */
  
  static gfc_expr *
  range_check (gfc_expr * result, const char *name)
  {
!   if (gfc_range_check (result) == ARITH_OK)
      return result;
  
!   gfc_error ("Result of %s overflows its kind at %L", name, &result->where);
    gfc_free_expr (result);
    return &gfc_bad_expr;
  }
--- 90,122 ----
  
  
  /* Range checks an expression node.  If all goes well, returns the
!    node, otherwise returns &gfc_bad_expr and frees the node.  Just
!    returns the result if -fno-range-check was given.  */
  
  static gfc_expr *
  range_check (gfc_expr * result, const char *name)
  {
!   if (gfc_option.flag_no_range_check == 1)
      return result;
  
!   switch (gfc_range_check (result))
!     {
!       case ARITH_OK:
! 	return result;
!  
!       case ARITH_OVERFLOW:
! 	gfc_error ("Result of %s overflows its kind at %L", name, &result->where);
! 	break;
! 
!       case ARITH_UNDERFLOW:
! 	gfc_error ("Result of %s underflows its kind at %L", name, &result->where);
! 	break;
! 
!       default:
! 	gfc_error ("Result of %s gives range error for its kind at %L", name, &result->where);
! 	break;
!     }
! 
    gfc_free_expr (result);
    return &gfc_bad_expr;
  }

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