[Bug fortran/81552] -finit-integer=n is restricted to 32-bit INTEGER.

2019-02-14 Thread jb at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81552

Janne Blomqvist  changed:

   What|Removed |Added

 Status|WAITING |RESOLVED
 CC||jb at gcc dot gnu.org
 Resolution|--- |FIXED

--- Comment #6 from Janne Blomqvist  ---
Fixed on trunk, closing.

The patch uses strtol() since that is in C89 and thus available everywhere.
This close to the GCC 9 release I didn't want to risk breaking some targets I
don't have a GCC development environment setup on.

strtoll and int64_t are in C99 and with some GCC headers and libiberty they
should be available everywhere, which would make this patch work on 32-bit and
LLP64 (e.g. win64) targets. If anyone is interested in pursuing this I suggest
reopening this bug report and submitting a patch when GCC is in stage 1.

[Bug fortran/81552] -finit-integer=n is restricted to 32-bit INTEGER.

2019-02-14 Thread jb at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81552

--- Comment #5 from Janne Blomqvist  ---
Author: jb
Date: Thu Feb 14 21:33:29 2019
New Revision: 268906

URL: https://gcc.gnu.org/viewcvs?rev=268906=gcc=rev
Log:
PR 81552 Improve and document -flag-init-integer

Make the option handling code parse the -flag-init-integer value as a
C long type, allowing a larger range on systems where long is a larger
type than int.  Document the behavior.

Regtested on x86_64-pc-linux-gnu, committed as obvious.

2019-02-14  Janne Blomqvist  

PR fortran/81552
* gfortran.h (gfc_option_t): Make flag_init_integer_value a long.
* options.c (gfc_handle_option): Use strtol instead of atoi.
* invoke.texi: Document -finit-integer behavior in more detail

Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/gfortran.h
trunk/gcc/fortran/invoke.texi
trunk/gcc/fortran/options.c

[Bug fortran/81552] -finit-integer=n is restricted to 32-bit INTEGER.

2019-02-09 Thread dominiq at lps dot ens.fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81552

--- Comment #4 from Dominique d'Humieres  ---
> > IMO this PR should be closed as WONTFIX.
>
> Or document it - a single sentence should be enough.

Well the following patch (untested) "fixes" this PR:

--- ../_clean/gcc/fortran/gfortran.h2019-02-02 17:23:28.0 +0100
+++ gcc/fortran/gfortran.h  2019-02-09 11:17:44.0 +0100
@@ -2681,7 +2681,7 @@ typedef struct
   int flag_preprocessed;
   int flag_d_lines;
   int flag_init_integer;
-  int flag_init_integer_value;
+  long int flag_init_integer_value;
   int flag_init_logical;
   int flag_init_character;
   char flag_init_character_value;
@@ -708,7 +708,7 @@ gfc_handle_option (size_t scode, const c

 case OPT_finit_integer_:
   gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
-  gfc_option.flag_init_integer_value = atoi (arg);
+  gfc_option.flag_init_integer_value = atol(arg);
   break;

 case OPT_finit_character_:

While playing with the problem I have noticed that if the value in
-finit-integer=N is outside the representable integer, the value is wrapped
around: if N = 128, integer(1) is initialized with -128. IMO this should be
documented.

With the above patch, this is not true for integer(8): if N=Huge(1_8)+1,
integer(8) is initialized with huge(1_8). In addition integer(16) is also
initialized with huge(1_8).

[Bug fortran/81552] -finit-integer=n is restricted to 32-bit INTEGER.

2019-02-08 Thread tkoenig at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81552

Thomas Koenig  changed:

   What|Removed |Added

 CC||tkoenig at gcc dot gnu.org

--- Comment #3 from Thomas Koenig  ---
(In reply to Dominique d'Humieres from comment #2)
> IMO this PR should be closed as WONTFIX.

Or document it - a single sentence should be enough.

[Bug fortran/81552] -finit-integer=n is restricted to 32-bit INTEGER.

2019-02-07 Thread dominiq at lps dot ens.fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81552

Dominique d'Humieres  changed:

   What|Removed |Added

 Status|NEW |WAITING

--- Comment #2 from Dominique d'Humieres  ---
IMO this PR should be closed as WONTFIX.

[Bug fortran/81552] -finit-integer=n is restricted to 32-bit INTEGER.

2017-07-26 Thread dominiq at lps dot ens.fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81552

Dominique d'Humieres  changed:

   What|Removed |Added

   Priority|P3  |P5
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2017-07-26
Summary|-finit-integer=n|-finit-integer=n is
   ||restricted to 32-bit
   ||INTEGER.
 Ever confirmed|0   |1
   Severity|normal  |enhancement

--- Comment #1 from Dominique d'Humieres  ---
>   In fact, N is an 32-bit INTEGER in the range [-2147483648 ; 2147483647]

This is true even for arrays of 64-bit INTEGER:

integer(8) :: i(4)
print *, i
end

compiled with -finit-integer=2147483648 gives at run time

  -2147483648  -2147483648  -2147483648 
-2147483648

at least since gcc 4.8.5.