Bug 78534 - Use a larger integer type for character lengths on 64-bit targets
Summary: Use a larger integer type for character lengths on 64-bit targets
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: ---
Assignee: Janne Blomqvist
URL:
Keywords:
Depends on: 83344
Blocks:
  Show dependency treegraph
 
Reported: 2016-11-25 21:33 UTC by Janne Blomqvist
Modified: 2018-02-22 16:14 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-11-25 00:00:00


Attachments
Preliminary patch (11.63 KB, patch)
2016-11-26 08:19 UTC, Janne Blomqvist
Details | Diff
Updated patch (14.77 KB, patch)
2016-12-04 21:12 UTC, Janne Blomqvist
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Janne Blomqvist 2016-11-25 21:33:06 UTC
Currently GFortran uses a plain C int for character lengths. This prevents longer characters on 64-bit targets. We should change to use size_t instead, similar to the C string functions (str*(), mem*()), malloc(), etc. Also Intel Fortran does this nowadays.

Now that the libgfortran ABI version has been bumped, it is the right time to do this.

See also https://gcc.gnu.org/wiki/LibgfortranAbiCleanup
Comment 1 Jerry DeLisle 2016-11-25 22:33:23 UTC
(In reply to Janne Blomqvist from comment #0)
> Currently GFortran uses a plain C int for character lengths. This prevents
> longer characters on 64-bit targets. We should change to use size_t instead,
> similar to the C string functions (str*(), mem*()), malloc(), etc. Also
> Intel Fortran does this nowadays.
> 
> Now that the libgfortran ABI version has been bumped, it is the right time
> to do this.
> 
> See also https://gcc.gnu.org/wiki/LibgfortranAbiCleanup

Agree, Are you going to do this?
Comment 2 Jakub Jelinek 2016-11-26 00:26:55 UTC
So are you going to do everything that is in the wiki (or most of it)?
Also, I couldn't find in the list, I think some descriptor changes were considered (to use 15 dimensions instead of 7, etc.).
Comment 3 Janne Blomqvist 2016-11-26 08:18:13 UTC
(In reply to Jerry DeLisle from comment #1)
> (In reply to Janne Blomqvist from comment #0)
> > Currently GFortran uses a plain C int for character lengths. This prevents
> > longer characters on 64-bit targets. We should change to use size_t instead,
> > similar to the C string functions (str*(), mem*()), malloc(), etc. Also
> > Intel Fortran does this nowadays.
> > 
> > Now that the libgfortran ABI version has been bumped, it is the right time
> > to do this.
> > 
> > See also https://gcc.gnu.org/wiki/LibgfortranAbiCleanup
> 
> Agree, Are you going to do this?

I'm working on a patch. I have managed to make it work except for the char_result_8.f90 testcase, which fails with an internal compiler error in the middle end when optimization is enabled. So it seems I'm passing the middle-end some nonsensical data.

Also the patch so far changes the charlen type to ptrdiff_t, there are some places in the frontend where we use a negative charlen as a flag value. I though I'd get the size change working first before tackling the signed->unsigned change.
Comment 4 Janne Blomqvist 2016-11-26 08:19:23 UTC
Created attachment 40154 [details]
Preliminary patch

Preliminary patch changing gfc_charlen_t from int to ptrdiff_t. Fails the char_result_8.f90 testcase.
Comment 5 Janne Blomqvist 2016-11-26 08:24:21 UTC
(In reply to Jakub Jelinek from comment #2)
> So are you going to do everything that is in the wiki (or most of it)?
> Also, I couldn't find in the list, I think some descriptor changes were
> considered (to use 15 dimensions instead of 7, etc.).

The array descriptor changes are on the fortran-dev branch, which apparently isn't ready for merging yet. So it seems we'll bump the ABI both for GCC 7 and for GCC 8.. :(

The plan was to do all the changes at once so we don't have to bump the ABI many times, but it was accidentally broken for GCC 7 before fortran-dev was ready.

As for the rest of the list, we'll see. I don't have that much time myself, but maybe if the other maintainers would take an interest.
Comment 6 Jakub Jelinek 2016-11-26 09:05:38 UTC
(In reply to Janne Blomqvist from comment #5)
> (In reply to Jakub Jelinek from comment #2)
> > So are you going to do everything that is in the wiki (or most of it)?
> > Also, I couldn't find in the list, I think some descriptor changes were
> > considered (to use 15 dimensions instead of 7, etc.).
> 
> The array descriptor changes are on the fortran-dev branch, which apparently
> isn't ready for merging yet. So it seems we'll bump the ABI both for GCC 7
> and for GCC 8.. :(

Which exact change broke the ABI, couldn't it be adjusted to be backwards ABI compatible and do the full ABI break in GCC 8?
Comment 7 Janne Blomqvist 2016-11-26 13:24:42 UTC
(In reply to Jakub Jelinek from comment #6)
> (In reply to Janne Blomqvist from comment #5)
> > (In reply to Jakub Jelinek from comment #2)
> > > So are you going to do everything that is in the wiki (or most of it)?
> > > Also, I couldn't find in the list, I think some descriptor changes were
> > > considered (to use 15 dimensions instead of 7, etc.).
> > 
> > The array descriptor changes are on the fortran-dev branch, which apparently
> > isn't ready for merging yet. So it seems we'll bump the ABI both for GCC 7
> > and for GCC 8.. :(
> 
> Which exact change broke the ABI, couldn't it be adjusted to be backwards
> ABI compatible and do the full ABI break in GCC 8?

It was the DTIO (derived type I/O) stuff (which certainly is a major feature, so I'm not suggesting that it should be backed out). Subsequently there has AFAICS been other patches that have changed the ABI too, IIRC the DEC compatibility stuff at least.

I tried to suggest trying to fix it here: https://gcc.gnu.org/ml/gcc-patches/2016-10/msg01987.html . But nobody (except me, apparently?) took it seriously, and with me having extremely limited time for GFortran these days, it seems we'll have an ABI break for both GCC 7 and 8.
Comment 8 Dominique d'Humieres 2016-11-26 13:39:41 UTC
Will it help for pr66310?
Comment 9 Janne Blomqvist 2016-11-26 13:51:28 UTC
(In reply to Dominique d'Humieres from comment #8)
> Will it help for pr66310?

Probably yes, to the extent that with 64-bit indices the repeat count can be a lot larger than you can afford to buy RAM. :)

I ran into a similar issues as in that PR, and put in an arbitrary limit in the frontend simplicitation function of 4 MB.
Comment 10 Dominique d'Humieres 2016-11-26 14:56:14 UTC
BTW did you test the patch in comment 4 with -m32?
Comment 11 Janne Blomqvist 2016-11-26 17:21:26 UTC
(In reply to Dominique d'Humieres from comment #10)
> BTW did you test the patch in comment 4 with -m32?

No, though I did test by reverting the few lines changing the definitions of gfc_charlen_type_node and gfc_charlen_t. The rest of the patch (i.e. the vast majority) deals with fixing situations where we accidentally have used the wrong types and it happened to work because the character length and plain integer were the same thing. So this test showed that the patch didn't break anything else.
Comment 12 Janne Blomqvist 2016-12-04 21:12:45 UTC
Created attachment 40243 [details]
Updated patch

Updated patch with a few more improvements. Still fails the char_result_8.f90 testcase with -O1, though.
Comment 13 Jerry DeLisle 2016-12-05 00:36:54 UTC
Note: PR66310 is a related issue.
Comment 14 Janne Blomqvist 2017-01-02 20:00:50 UTC
Author: jb
Date: Mon Jan  2 20:00:18 2017
New Revision: 244003

URL: https://gcc.gnu.org/viewcvs?rev=244003&root=gcc&view=rev
Log:
PR 78534 Modify string copy to avoid -Wstringop-overflow warning

When the character length is changed from int to size_t the existing
algorithm causes a -Wstringop-overflow warning with -O1 on the
gfortran.dg/allocate_deferred_char_scalar_1.f03 testcase. This change
is committed separately from the character length size change in order
to make bisecting potential performance issues easier.

2017-01-02  Janne Blomqvist  <jb@gcc.gnu.org>

        PR fortran/78534
	* trans-expr.c (gfc_trans_string_copy): Rework string copy
	algorithm to avoid -Wstringop-overflow warning.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
Comment 15 Janne Blomqvist 2017-01-03 07:04:34 UTC
Author: jb
Date: Tue Jan  3 07:04:01 2017
New Revision: 244011

URL: https://gcc.gnu.org/viewcvs?rev=244011&root=gcc&view=rev
Log:
PR 78534 Change character length from int to size_t

In order to handle large character lengths on (L)LP64 targets, switch
the GFortran character length from an int to a size_t.

This is an ABI change, as procedures with character arguments take
hidden arguments with the character length.

I also changed the _size member in vtables from int to size_t, as
there were some cases where character lengths and sizes were
apparently mixed up and caused regressions otherwise. Although I
haven't tested, this might enable very large derived types as well.

Also, as there are some places in the frontend were negative character
lengths are used as special flag values, in the frontend the character
length is handled as a signed variable of the same size as a size_t,
although in the runtime library it really is size_t.

I haven't changed the character length variables for the co-array
intrinsics, as this is something that may need to be synchronized with
OpenCoarrays.

This is v3 of the patch. All the issues pointed out by FX's review of
v2 have been fixed. In particular, there are now new functions
gfc_mpz_get_hwi and gfc_mpz_set_hwi, similar to the GMP functions
mpz_get_si and mpz_set_si, except that they get/set a HOST_WIDE_INT
instead of a long value. Similarly, gfc_get_int_expr now takes a
HOST_WIDE_INT instead of a long, gfc_extract_long is replaced by
gfc_extract_hwi. Also, the preliminary work to handle
gfc_charlen_type_node being unsigned has been removed.

Regtested on x86_64-pc-linux-gnu.

frontend:

2017-01-03  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/78534
	PR fortran/66310
	* class.c (gfc_find_derived_vtab): Use gfc_size_kind instead of
	hardcoded kind.
	(find_intrinsic_vtab): Likewise.
	* expr.c (gfc_get_character_expr): Length parameter of type
	gfc_charlen_t.
	(gfc_get_int_expr): Value argument of type HOST_WIDE_INT.
	(gfc_extract_hwi): New function.
	(simplify_const_ref): Make string_len of type gfc_charlen_t.
	(gfc_simplify_expr): Use HOST_WIDE_INT for substring refs.
	* gfortran.h (gfc_mpz_get_hwi): New prototype.
	(gfc_mpz_set_hwi): Likewise.
	(gfc_charlen_t): New typedef.
	(gfc_expr): Use gfc_charlen_t for character lengths.
	(gfc_size_kind): New extern variable.
	(gfc_extract_hwi): New prototype.
	(gfc_get_character_expr): Use gfc_charlen_t for character length.
	(gfc_get_int_expr): Use HOST_WIDE_INT type for value argument.
	* iresolve.c (gfc_resolve_repeat): Pass string length directly without
	temporary, use gfc_charlen_int_kind.
	* match.c (select_intrinsic_set_tmp): Use HOST_WIDE_INT for charlen.
	* misc.c (gfc_mpz_get_hwi): New function.
	(gfc_mpz_set_hwi): New function.
	* module.c (atom_int): Change type from int to HOST_WIDE_INT.
	(parse_integer): Don't complain about large integers.
	(write_atom): Use HOST_WIDE_INT for integers.
	(mio_integer): Handle integer type mismatch.
	(mio_hwi): New function.
	(mio_intrinsic_op): Use HOST_WIDE_INT.
	(mio_array_ref): Likewise.
	(mio_expr): Likewise.
	* resolve.c (resolve_select_type): Use HOST_WIDE_INT for charlen,
	use snprintf.
	(resolve_charlen): Use mpz_sgn to determine sign.
	* simplify.c (gfc_simplify_repeat): Use HOST_WIDE_INT/gfc_charlen_t
	instead of long.
	* target-memory.c (size_character): Length argument of type
	gfc_charlen_t.
	(gfc_encode_character): Likewise.
	(gfc_interpret_character): Use gfc_charlen_t.
	* target-memory.h (gfc_encode_character): Modify prototype.
	* trans-array.c (get_array_ctor_var_strlen): Use
	gfc_conv_mpz_to_tree_type.
	* trans-const.c (gfc_conv_mpz_to_tree_type): New function.
	* trans-const.h (gfc_conv_mpz_to_tree_type): New prototype.
	* trans-expr.c (gfc_class_len_or_zero_get): Build const of type
	gfc_charlen_type_node.
	(gfc_conv_intrinsic_to_class): Use gfc_charlen_int_kind instead of
	4, fold_convert to correct type.
	(gfc_conv_class_to_class): Build const of type size_type_node for
	size.
	(gfc_copy_class_to_class): Likewise.
	(gfc_conv_string_length): Use same type in expression.
	(gfc_conv_substring): Likewise, use HOST_WIDE_INT for charlen.
	(gfc_conv_string_tmp): Make sure len is of the right type.
	(gfc_conv_concat_op): Use same type in expression.
	(gfc_conv_procedure_call): Likewise.
	(alloc_scalar_allocatable_for_subcomponent_assignment):
	fold_convert to right type.
	(gfc_trans_subcomponent_assign): Likewise.
	(trans_class_vptr_len_assignment): Build const of correct type.
	(gfc_trans_pointer_assignment): Likewise.
	(alloc_scalar_allocatable_for_assignment): fold_convert to right
	type in expr.
	(trans_class_assignment): Build const of correct type.
	* trans-intrinsic.c (gfc_conv_associated): Likewise.
	(gfc_conv_intrinsic_repeat): Do calculation in sizetype.
	* trans-io.c (gfc_build_io_library_fndecls): Use
	gfc_charlen_type_node for character lengths.
	* trans-stmt.c (gfc_trans_label_assign): Build const of
	gfc_charlen_type_node.
	(gfc_trans_character_select): Likewise.
	(gfc_trans_allocate): Likewise, don't typecast strlen result.
	(gfc_trans_deallocate): Don't typecast strlen result.
	* trans-types.c (gfc_size_kind): New variable.
	(gfc_init_types): Determine gfc_charlen_int_kind and gfc_size_kind
	from size_type_node.

testsuite:

2017-01-03  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/78534
	PR fortran/66310
	* gfortran.dg/dependency_49.f90: Change scan-tree-dump-times
          due to gfc_trans_string_copy change to avoid
          -Wstringop-overflow.
	* gfortran.dg/repeat_4.f90: Use integers of kind C_SIZE_T.
	* gfortran.dg/repeat_7.f90: New test for PR 66310.
	* gfortran.dg/scan_2.f90: Handle potential cast in assignment.
	* gfortran.dg/string_1.f90: Limit to ilp32 targets.
	* gfortran.dg/string_1_lp64.f90: New test.
	* gfortran.dg/string_3.f90: Limit to ilp32 targets.
	* gfortran.dg/string_3_lp64.f90: New test.
	* gfortran.dg/transfer_intrinsic_1.f90: Change
          scan-tree-dump-times due to gfc_trans_string_copy change to
          avoid -Wstringop-overflow.

libgfortran:

2017-01-03  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/78534
	* intrinsics/args.c (getarg_i4): Use gfc_charlen_type.
	(get_command_argument_i4): Likewise.
	(get_command_i4): Likewise.
	* intrinsics/chmod.c (chmod_internal): Likewise.
	* intrinsics/env.c (get_environment_variable_i4): Likewise.
	* intrinsics/extends_type_of.c (struct vtype): Use size_t for size
	member.
	* intrinsics/gerror.c (gerror): Use gfc_charlen_type.
	* intrinsics/getlog.c (getlog): Likewise.
	* intrinsics/hostnm.c (hostnm_0): Likewise.
	* intrinsics/string_intrinsics_inc.c (string_len_trim): Rework to
	work if gfc_charlen_type is unsigned.
	(string_scan): Likewise.
	* io/transfer.c (transfer_character): Modify prototype.
	(transfer_character_write): Likewise.
	(transfer_character_wide): Likewise.
	(transfer_character_wide_write): Likewise.
	(transfer_array): Typecast to avoid signed-unsigned comparison.
	* io/unit.c (is_trim_ok): Use gfc_charlen_type.
	* io/write.c (namelist_write): Likewise.
	* libgfortran.h (gfc_charlen_type): Change typedef to size_t.


Added:
    trunk/gcc/testsuite/gfortran.dg/repeat_7.f90
    trunk/gcc/testsuite/gfortran.dg/string_1_lp64.f90
    trunk/gcc/testsuite/gfortran.dg/string_3_lp64.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/class.c
    trunk/gcc/fortran/dump-parse-tree.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/gfortran.texi
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/misc.c
    trunk/gcc/fortran/module.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/simplify.c
    trunk/gcc/fortran/target-memory.c
    trunk/gcc/fortran/target-memory.h
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-const.c
    trunk/gcc/fortran/trans-const.h
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/fortran/trans-io.c
    trunk/gcc/fortran/trans-stmt.c
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/fortran/trans-types.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/dependency_49.f90
    trunk/gcc/testsuite/gfortran.dg/repeat_4.f90
    trunk/gcc/testsuite/gfortran.dg/scan_2.f90
    trunk/gcc/testsuite/gfortran.dg/string_1.f90
    trunk/gcc/testsuite/gfortran.dg/string_3.f90
    trunk/gcc/testsuite/gfortran.dg/transfer_intrinsic_1.f90
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/intrinsics/args.c
    trunk/libgfortran/intrinsics/chmod.c
    trunk/libgfortran/intrinsics/env.c
    trunk/libgfortran/intrinsics/extends_type_of.c
    trunk/libgfortran/intrinsics/gerror.c
    trunk/libgfortran/intrinsics/getlog.c
    trunk/libgfortran/intrinsics/hostnm.c
    trunk/libgfortran/intrinsics/string_intrinsics_inc.c
    trunk/libgfortran/io/transfer.c
    trunk/libgfortran/io/unit.c
    trunk/libgfortran/io/write.c
    trunk/libgfortran/libgfortran.h
Comment 16 Janne Blomqvist 2017-01-03 18:02:02 UTC
Author: jb
Date: Tue Jan  3 18:01:30 2017
New Revision: 244027

URL: https://gcc.gnu.org/viewcvs?rev=244027&root=gcc&view=rev
Log:
PR 78534 Revert r244011

r244011 caused regressions on 32-bit hosts.

Removed:
    trunk/gcc/testsuite/gfortran.dg/repeat_7.f90
    trunk/gcc/testsuite/gfortran.dg/string_1_lp64.f90
    trunk/gcc/testsuite/gfortran.dg/string_3_lp64.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/class.c
    trunk/gcc/fortran/dump-parse-tree.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/gfortran.texi
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/misc.c
    trunk/gcc/fortran/module.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/simplify.c
    trunk/gcc/fortran/target-memory.c
    trunk/gcc/fortran/target-memory.h
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-const.c
    trunk/gcc/fortran/trans-const.h
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/fortran/trans-io.c
    trunk/gcc/fortran/trans-stmt.c
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/fortran/trans-types.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/dependency_49.f90
    trunk/gcc/testsuite/gfortran.dg/repeat_4.f90
    trunk/gcc/testsuite/gfortran.dg/scan_2.f90
    trunk/gcc/testsuite/gfortran.dg/string_1.f90
    trunk/gcc/testsuite/gfortran.dg/string_3.f90
    trunk/gcc/testsuite/gfortran.dg/transfer_intrinsic_1.f90
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/intrinsics/args.c
    trunk/libgfortran/intrinsics/chmod.c
    trunk/libgfortran/intrinsics/env.c
    trunk/libgfortran/intrinsics/extends_type_of.c
    trunk/libgfortran/intrinsics/gerror.c
    trunk/libgfortran/intrinsics/getlog.c
    trunk/libgfortran/intrinsics/hostnm.c
    trunk/libgfortran/intrinsics/string_intrinsics_inc.c
    trunk/libgfortran/io/transfer.c
    trunk/libgfortran/io/unit.c
    trunk/libgfortran/io/write.c
    trunk/libgfortran/libgfortran.h
Comment 17 Janne Blomqvist 2017-01-04 08:07:27 UTC
Author: jb
Date: Wed Jan  4 08:06:54 2017
New Revision: 244048

URL: https://gcc.gnu.org/viewcvs?rev=244048&root=gcc&view=rev
Log:
PR 78796 Modify testcases due to gfc_trans_string_copy change

As r244011 had to be reverted, this change adds back the testcase
changes that are needed due to r244003.

2017-01-04  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/78534
	PR fortran/78976
	* gfortran.dg/dependency_49.f90: Change scan-tree-dump-times
	due to gfc_trans_string_copy change to avoid -Wstringop-overflow.
	* gfortran.dg/transfer_intrinsic_1.f90: Change
	scan-tree-dump-times due to gfc_trans_string_copy change to
	avoid -Wstringop-overflow.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/dependency_49.f90
    trunk/gcc/testsuite/gfortran.dg/transfer_intrinsic_1.f90
Comment 18 Janne Blomqvist 2017-01-13 17:06:20 UTC
Author: jb
Date: Fri Jan 13 17:05:48 2017
New Revision: 244448

URL: https://gcc.gnu.org/viewcvs?rev=244448&root=gcc&view=rev
Log:
PR 78534 Change character length from int to size_t

In order to handle large character lengths on (L)LP64 targets, switch
the GFortran character length from an int to a size_t.

This is an ABI change, as procedures with character arguments take
hidden arguments with the character length.

I also changed the _size member in vtables from int to size_t, as
there were some cases where character lengths and sizes were
apparently mixed up and caused regressions otherwise. Although I
haven't tested, this might enable very large derived types as well.

Also, as there are some places in the frontend were negative character
lengths are used as special flag values, in the frontend the character
length is handled as a signed variable of the same size as a size_t,
although in the runtime library it really is size_t.

I haven't changed the character length variables for the co-array
intrinsics, as this is something that may need to be synchronized with
OpenCoarrays.

This is v4 of the patch. v3 was applied but had to reverted due to
breaking bootstrap. The fix is in resolve.c:resolve_charlen, where
it's necessary to check that an expression is constant before using
mpz_sgn.

Overview of v3 of the patch: All the issues pointed out by FX's review
of v2 have been fixed. In particular, there are now new functions
gfc_mpz_get_hwi and gfc_mpz_set_hwi, similar to the GMP functions
mpz_get_si and mpz_set_si, except that they get/set a HOST_WIDE_INT
instead of a long value. Similarly, gfc_get_int_expr now takes a
HOST_WIDE_INT instead of a long, gfc_extract_long is replaced by
gfc_extract_hwi. Also, the preliminary work to handle
gfc_charlen_type_node being unsigned has been removed.

Regtested on x86_64-pc-linux-gnu and i686-pc-linux-gnu.

frontend:

2017-01-13  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/78534
	PR fortran/66310
	* class.c (gfc_find_derived_vtab): Use gfc_size_kind instead of
	hardcoded kind.
	(find_intrinsic_vtab): Likewise.
	* expr.c (gfc_get_character_expr): Length parameter of type
	gfc_charlen_t.
	(gfc_get_int_expr): Value argument of type HOST_WIDE_INT.
	(gfc_extract_hwi): New function.
	(simplify_const_ref): Make string_len of type gfc_charlen_t.
	(gfc_simplify_expr): Use HOST_WIDE_INT for substring refs.
	* gfortran.h (gfc_mpz_get_hwi): New prototype.
	(gfc_mpz_set_hwi): Likewise.
	(gfc_charlen_t): New typedef.
	(gfc_expr): Use gfc_charlen_t for character lengths.
	(gfc_size_kind): New extern variable.
	(gfc_extract_hwi): New prototype.
	(gfc_get_character_expr): Use gfc_charlen_t for character length.
	(gfc_get_int_expr): Use HOST_WIDE_INT type for value argument.
	* iresolve.c (gfc_resolve_repeat): Pass string length directly without
	temporary, use gfc_charlen_int_kind.
	* match.c (select_intrinsic_set_tmp): Use HOST_WIDE_INT for charlen.
	* misc.c (gfc_mpz_get_hwi): New function.
	(gfc_mpz_set_hwi): New function.
	* module.c (atom_int): Change type from int to HOST_WIDE_INT.
	(parse_integer): Don't complain about large integers.
	(write_atom): Use HOST_WIDE_INT for integers.
	(mio_integer): Handle integer type mismatch.
	(mio_hwi): New function.
	(mio_intrinsic_op): Use HOST_WIDE_INT.
	(mio_array_ref): Likewise.
	(mio_expr): Likewise.
	* resolve.c (resolve_select_type): Use HOST_WIDE_INT for charlen,
	use snprintf.
	(resolve_substring_charlen): Use gfc_charlen_int_kind.
	(resolve_charlen): Use mpz_sgn to determine sign.
	* simplify.c (gfc_simplify_repeat): Use HOST_WIDE_INT/gfc_charlen_t
	instead of long.
	* target-memory.c (size_character): Length argument of type
	gfc_charlen_t.
	(gfc_encode_character): Likewise.
	(gfc_interpret_character): Use gfc_charlen_t.
	* target-memory.h (gfc_encode_character): Modify prototype.
	* trans-array.c (get_array_ctor_var_strlen): Use
	gfc_conv_mpz_to_tree_type.
	* trans-const.c (gfc_conv_mpz_to_tree_type): New function.
	* trans-const.h (gfc_conv_mpz_to_tree_type): New prototype.
	* trans-expr.c (gfc_class_len_or_zero_get): Build const of type
	gfc_charlen_type_node.
	(gfc_conv_intrinsic_to_class): Use gfc_charlen_int_kind instead of
	4, fold_convert to correct type.
	(gfc_conv_class_to_class): Build const of type size_type_node for
	size.
	(gfc_copy_class_to_class): Likewise.
	(gfc_conv_string_length): Use same type in expression.
	(gfc_conv_substring): Likewise, use HOST_WIDE_INT for charlen.
	(gfc_conv_string_tmp): Make sure len is of the right type.
	(gfc_conv_concat_op): Use same type in expression.
	(gfc_conv_procedure_call): Likewise.
	(alloc_scalar_allocatable_for_subcomponent_assignment):
	fold_convert to right type.
	(gfc_trans_subcomponent_assign): Likewise.
	(trans_class_vptr_len_assignment): Build const of correct type.
	(gfc_trans_pointer_assignment): Likewise.
	(alloc_scalar_allocatable_for_assignment): fold_convert to right
	type in expr.
	(trans_class_assignment): Build const of correct type.
	* trans-intrinsic.c (gfc_conv_associated): Likewise.
	(gfc_conv_intrinsic_repeat): Do calculation in sizetype.
	* trans-io.c (gfc_build_io_library_fndecls): Use
	gfc_charlen_type_node for character lengths.
	* trans-stmt.c (gfc_trans_label_assign): Build const of
	gfc_charlen_type_node.
	(gfc_trans_character_select): Likewise.
	(gfc_trans_allocate): Likewise, don't typecast strlen result.
	(gfc_trans_deallocate): Don't typecast strlen result.
	* trans-types.c (gfc_size_kind): New variable.
	(gfc_init_types): Determine gfc_charlen_int_kind and gfc_size_kind
	from size_type_node.

testsuite:

2017-01-13  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/78534
	PR fortran/66310
	* gfortran.dg/repeat_4.f90: Use integers of kind C_SIZE_T.
	* gfortran.dg/repeat_7.f90: New test for PR 66310.
	* gfortran.dg/scan_2.f90: Handle potential cast in assignment.
	* gfortran.dg/string_1.f90: Limit to ilp32 targets.
	* gfortran.dg/string_1_lp64.f90: New test.
	* gfortran.dg/string_3.f90: Limit to ilp32 targets.
	* gfortran.dg/string_3_lp64.f90: New test.

libgfortran:

2017-01-13  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/78534
	* intrinsics/args.c (getarg_i4): Use gfc_charlen_type.
	(get_command_argument_i4): Likewise.
	(get_command_i4): Likewise.
	* intrinsics/chmod.c (chmod_internal): Likewise.
	* intrinsics/env.c (get_environment_variable_i4): Likewise.
	* intrinsics/extends_type_of.c (struct vtype): Use size_t for size
	member.
	* intrinsics/gerror.c (gerror): Use gfc_charlen_type.
	* intrinsics/getlog.c (getlog): Likewise.
	* intrinsics/hostnm.c (hostnm_0): Likewise.
	* intrinsics/string_intrinsics_inc.c (string_len_trim): Rework to
	work if gfc_charlen_type is unsigned.
	(string_scan): Likewise.
	* io/transfer.c (transfer_character): Modify prototype.
	(transfer_character_write): Likewise.
	(transfer_character_wide): Likewise.
	(transfer_character_wide_write): Likewise.
	(transfer_array): Typecast to avoid signed-unsigned comparison.
	* io/unit.c (is_trim_ok): Use gfc_charlen_type.
	* io/write.c (namelist_write): Likewise.
	* libgfortran.h (gfc_charlen_type): Change typedef to size_t.


Added:
    trunk/gcc/testsuite/gfortran.dg/repeat_7.f90
    trunk/gcc/testsuite/gfortran.dg/string_1_lp64.f90
    trunk/gcc/testsuite/gfortran.dg/string_3_lp64.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/class.c
    trunk/gcc/fortran/dump-parse-tree.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/gfortran.texi
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/misc.c
    trunk/gcc/fortran/module.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/simplify.c
    trunk/gcc/fortran/target-memory.c
    trunk/gcc/fortran/target-memory.h
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-const.c
    trunk/gcc/fortran/trans-const.h
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/fortran/trans-io.c
    trunk/gcc/fortran/trans-stmt.c
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/fortran/trans-types.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/repeat_4.f90
    trunk/gcc/testsuite/gfortran.dg/scan_2.f90
    trunk/gcc/testsuite/gfortran.dg/string_1.f90
    trunk/gcc/testsuite/gfortran.dg/string_3.f90
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/intrinsics/args.c
    trunk/libgfortran/intrinsics/chmod.c
    trunk/libgfortran/intrinsics/env.c
    trunk/libgfortran/intrinsics/extends_type_of.c
    trunk/libgfortran/intrinsics/gerror.c
    trunk/libgfortran/intrinsics/getlog.c
    trunk/libgfortran/intrinsics/hostnm.c
    trunk/libgfortran/intrinsics/string_intrinsics_inc.c
    trunk/libgfortran/io/transfer.c
    trunk/libgfortran/io/unit.c
    trunk/libgfortran/io/write.c
    trunk/libgfortran/libgfortran.h
Comment 19 Janne Blomqvist 2017-12-09 15:38:07 UTC
It seems that PR 83344 makes my patch changing the character length to fail on big endian targets.
Comment 20 Janne Blomqvist 2018-01-05 19:01:44 UTC
Author: jb
Date: Fri Jan  5 19:01:12 2018
New Revision: 256284

URL: https://gcc.gnu.org/viewcvs?rev=256284&root=gcc&view=rev
Log:
PR 78534 Change character length from int to size_t

In order to handle large character lengths on (L)LP64 targets, switch
the GFortran character length from an int to a size_t.

This is an ABI change, as procedures with character arguments take
hidden arguments with the character length.

I also changed the _size member in vtables from int to size_t, as
there were some cases where character lengths and sizes were
apparently mixed up and caused regressions otherwise. Although I
haven't tested, this might enable very large derived types as well.

Also, as there are some places in the frontend were negative character
lengths are used as special flag values, in the frontend the character
length is handled as a signed variable of the same size as a size_t,
although in the runtime library it really is size_t.

I haven't changed the character length variables for the co-array
intrinsics, as this is something that may need to be synchronized with
OpenCoarrays.

This is v5 of the patch. v4 was applied but caused breakage on big
endian targets. These have been fixed and tested, thanks to access to
the GCC compile farm.

Overview of v4 of the patch: v3 was applied but had to reverted due to
breaking bootstrap. The fix is in resolve.c:resolve_charlen, where
it's necessary to check that an expression is constant before using
mpz_sgn.

Overview of v3 of the patch: All the issues pointed out by FX's review
of v2 have been fixed. In particular, there are now new functions
gfc_mpz_get_hwi and gfc_mpz_set_hwi, similar to the GMP functions
mpz_get_si and mpz_set_si, except that they get/set a HOST_WIDE_INT
instead of a long value. Similarly, gfc_get_int_expr now takes a
HOST_WIDE_INT instead of a long, gfc_extract_long is replaced by
gfc_extract_hwi. Also, the preliminary work to handle
gfc_charlen_type_node being unsigned has been removed.

Regtested on x86_64-pc-linux-gnu, i686-pc-linux-gnu and
powerpc64-unknown-linux-gnu. Also regtested all three targets by
modifying gfortran-dg.exp to also test with "-g -flto", no new
failures observed.

frontend:

2018-01-05  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/78534
	PR fortran/66310
	* array.c (got_charlen): Use gfc_charlen_int_kind.
	* class.c (gfc_find_derived_vtab): Use gfc_size_kind instead of
	hardcoded kind.
	(find_intrinsic_vtab): Likewise.
	* decl.c (match_char_length): Use gfc_charlen_int_kind.
	(add_init_expr_to_sym): Use gfc_charlen_t and gfc_charlen_int_kind.
	(gfc_match_implicit): Use gfc_charlen_int_kind.
	* dump-parse-tree.c (show_char_const): Use gfc_charlen_t and size_t.
	(show_expr): Use HOST_WIDE_INT_PRINT_DEC.
	* expr.c (gfc_get_character_expr): Length parameter of type
	gfc_charlen_t.
	(gfc_get_int_expr): Value argument of type HOST_WIDE_INT.
	(gfc_extract_hwi): New function.
	(simplify_const_ref): Make string_len of type gfc_charlen_t.
	(gfc_simplify_expr): Use HOST_WIDE_INT for substring refs.
	* frontend-passes.c (optimize_trim): Use gfc_charlen_int_kind.
	* gfortran.h (gfc_mpz_get_hwi): New prototype.
	(gfc_mpz_set_hwi): Likewise.
	(gfc_charlen_t): New typedef.
	(gfc_expr): Use gfc_charlen_t for character lengths.
	(gfc_size_kind): New extern variable.
	(gfc_extract_hwi): New prototype.
	(gfc_get_character_expr): Use gfc_charlen_t for character length.
	(gfc_get_int_expr): Use HOST_WIDE_INT type for value argument.
	* gfortran.texi: Update description of hidden string length argument.
	* iresolve.c (check_charlen_present): Use gfc_charlen_int_kind.
	(gfc_resolve_char_achar): Likewise.
	(gfc_resolve_repeat): Pass string length directly without
	temporary, use gfc_charlen_int_kind.
	(gfc_resolve_transfer): Use gfc_charlen_int_kind.
	* match.c (select_intrinsic_set_tmp): Use HOST_WIDE_INT for charlen.
	* misc.c (gfc_mpz_get_hwi): New function.
	(gfc_mpz_set_hwi): New function.
	* module.c (atom_int): Change type from int to HOST_WIDE_INT.
	(parse_integer): Don't complain about large integers.
	(write_atom): Use HOST_WIDE_INT for integers.
	(mio_integer): Handle integer type mismatch.
	(mio_hwi): New function.
	(mio_intrinsic_op): Use HOST_WIDE_INT.
	(mio_array_ref): Likewise.
	(mio_expr): Likewise.
	* primary.c (match_substring): Use gfc_charlen_int_kind.
	* resolve.c (resolve_substring_charlen): Use gfc_charlen_int_kind.
	(resolve_character_operator): Likewise.
	(resolve_assoc_var): Likewise.
	(resolve_select_type): Use HOST_WIDE_INT for charlen, use snprintf.
	(resolve_charlen): Use mpz_sgn to determine sign.
	* simplify.c (gfc_simplify_repeat): Use HOST_WIDE_INT/gfc_charlen_t
	instead of long.
	* symbol.c (generate_isocbinding_symbol): Use gfc_charlen_int_kind.
	* target-memory.c (size_character): Length argument of type
	gfc_charlen_t.
	(gfc_encode_character): Likewise.
	(gfc_interpret_character): Use gfc_charlen_t.
	* target-memory.h (gfc_encode_character): Modify prototype.
	* trans-array.c (gfc_trans_array_ctor_element): Use existing type.
	(get_array_ctor_var_strlen): Use gfc_conv_mpz_to_tree_type.
	(trans_array_constructor): Use existing type.
	(get_array_charlen): Likewise.
	* trans-const.c (gfc_conv_mpz_to_tree_type): New function.
	* trans-const.h (gfc_conv_mpz_to_tree_type): New prototype.
	* trans-decl.c (gfc_trans_deferred_vars): Use existing type.
	(add_argument_checking): Likewise.
	* trans-expr.c (gfc_class_len_or_zero_get): Build const of type
	gfc_charlen_type_node.
	(gfc_conv_intrinsic_to_class): Use gfc_charlen_int_kind instead of
	4, fold_convert to correct type.
	(gfc_conv_class_to_class): Build const of type size_type_node for
	size.
	(gfc_copy_class_to_class): Likewise.
	(gfc_conv_string_length): Use same type in expression.
	(gfc_conv_substring): Likewise, use HOST_WIDE_INT for charlen.
	(gfc_conv_string_tmp): Make sure len is of the right type.
	(gfc_conv_concat_op): Use same type in expression.
	(gfc_conv_procedure_call): Likewise.
	(fill_with_spaces): Comment out memset() block due to spurious
	-Wstringop-overflow warnings.
	(gfc_trans_string_copy): Use gfc_charlen_type_node.
	(alloc_scalar_allocatable_for_subcomponent_assignment):
	fold_convert to right type.
	(gfc_trans_subcomponent_assign): Likewise.
	(trans_class_vptr_len_assignment): Build const of correct type.
	(gfc_trans_pointer_assignment): Likewise.
	(alloc_scalar_allocatable_for_assignment): fold_convert to right
	type in expr.
	(trans_class_assignment): Build const of correct type.
	* trans-intrinsic.c (gfc_conv_associated): Likewise.
	(gfc_conv_intrinsic_repeat): Do calculation in sizetype.
	* trans-io.c (gfc_build_io_library_fndecls): Use
	gfc_charlen_type_node for character lengths.
	(set_string): Convert to right type in assignment.
	* trans-stmt.c (gfc_trans_label_assign): Build const of
	gfc_charlen_type_node.
	(trans_associate_var): Likewise.
	(gfc_trans_character_select): Likewise.
	(gfc_trans_allocate): Likewise, don't typecast strlen result.
	(gfc_trans_deallocate): Don't typecast strlen result.
	* trans-types.c (gfc_size_kind): New variable.
	(gfc_init_types): Determine gfc_charlen_int_kind and gfc_size_kind
	from size_type_node.
	* trans-types.h: Fix comment.

testsuite:

2018-01-05  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/78534
	PR fortran/66310
	* gfortran.dg/char_cast_1.f90: Update scan pattern.
	* gfortran.dg/dependency_49.f90: Likewise.
	* gfortran.dg/repeat_4.f90: Use integers of kind C_SIZE_T.
	* gfortran.dg/repeat_7.f90: New test for PR 66310.
	* gfortran.dg/scan_2.f90: Handle potential cast in assignment.
	* gfortran.dg/string_1.f90: Limit to ilp32 targets.
	* gfortran.dg/string_1_lp64.f90: New test.
	* gfortran.dg/string_3.f90: Limit to ilp32 targets.
	* gfortran.dg/string_3_lp64.f90: New test.

libgfortran:

2019-01-05  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/78534
	* intrinsics/args.c (getarg_i4): Use gfc_charlen_type.
	(get_command_argument_i4): Likewise.
	(get_command_i4): Likewise.
	* intrinsics/chmod.c (chmod_internal): Likewise.
	* intrinsics/env.c (get_environment_variable_i4): Likewise.
	* intrinsics/extends_type_of.c (struct vtype): Use size_t for size
	member.
	* intrinsics/gerror.c (gerror): Use gfc_charlen_type.
	* intrinsics/getlog.c (getlog): Likewise.
	* intrinsics/hostnm.c (hostnm_0): Likewise.
	* intrinsics/string_intrinsics_inc.c (string_len_trim): Rework to
	work if gfc_charlen_type is unsigned.
	(string_scan): Likewise.
	* io/transfer.c (transfer_character): Modify prototype.
	(transfer_character_write): Likewise.
	(transfer_character_wide): Likewise.
	(transfer_character_wide_write): Likewise.
	(transfer_array): Typecast to avoid signed-unsigned comparison.
	* io/unit.c (is_trim_ok): Use gfc_charlen_type.
	* io/write.c (namelist_write): Likewise.
	* libgfortran.h (gfc_charlen_type): Change typedef to size_t.


Added:
    trunk/gcc/testsuite/gfortran.dg/repeat_7.f90
    trunk/gcc/testsuite/gfortran.dg/string_1_lp64.f90
    trunk/gcc/testsuite/gfortran.dg/string_3_lp64.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/array.c
    trunk/gcc/fortran/class.c
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/dump-parse-tree.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/frontend-passes.c
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/gfortran.texi
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/misc.c
    trunk/gcc/fortran/module.c
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/simplify.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/fortran/target-memory.c
    trunk/gcc/fortran/target-memory.h
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-const.c
    trunk/gcc/fortran/trans-const.h
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/fortran/trans-io.c
    trunk/gcc/fortran/trans-stmt.c
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/fortran/trans-types.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/char_cast_1.f90
    trunk/gcc/testsuite/gfortran.dg/dependency_49.f90
    trunk/gcc/testsuite/gfortran.dg/repeat_4.f90
    trunk/gcc/testsuite/gfortran.dg/scan_2.f90
    trunk/gcc/testsuite/gfortran.dg/string_1.f90
    trunk/gcc/testsuite/gfortran.dg/string_3.f90
    trunk/libgfortran/intrinsics/args.c
    trunk/libgfortran/intrinsics/chmod.c
    trunk/libgfortran/intrinsics/env.c
    trunk/libgfortran/intrinsics/extends_type_of.c
    trunk/libgfortran/intrinsics/gerror.c
    trunk/libgfortran/intrinsics/getlog.c
    trunk/libgfortran/intrinsics/hostnm.c
    trunk/libgfortran/intrinsics/string_intrinsics_inc.c
    trunk/libgfortran/io/transfer.c
    trunk/libgfortran/io/unit.c
    trunk/libgfortran/io/write.c
    trunk/libgfortran/libgfortran.h
Comment 21 Jerry DeLisle 2018-01-05 19:37:16 UTC
Regrssion tested on x86_64-pc-freeBSD, no failures
Comment 22 Janne Blomqvist 2018-01-06 10:43:28 UTC
Author: jb
Date: Sat Jan  6 10:42:57 2018
New Revision: 256311

URL: https://gcc.gnu.org/viewcvs?rev=256311&root=gcc&view=rev
Log:
PR 78534 libgfortran ChangeLog

The libgfortran/ChangeLog entry was accidentally not included in
r256284.

Modified:
    trunk/libgfortran/ChangeLog
Comment 23 Janne Blomqvist 2018-01-07 10:18:24 UTC
Author: jb
Date: Sun Jan  7 10:17:52 2018
New Revision: 256322

URL: https://gcc.gnu.org/viewcvs?rev=256322&root=gcc&view=rev
Log:
PR 78534, 83704 Handle large formatted I/O

In order to handle large characters when doing formatted I/O, use
size_t and ptrdiff_t for lengths.  Compared to the previous patch,
based on discussions on IRC use size_t for sizes that don't need to be
negative rather than ptrdiff_t everywhere.

Regtested on x86_64-pc-linux-gnu, approved as part of the PR 78534
approval, committed to trunk.

libgfortran/ChangeLog:

2018-01-07  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/78534
	PR fortran/83704
	* io/fbuf.c (fbuf_init): Use size_t instead of int for length.
	(fbuf_debug): Convert debug output to unsigned long.
	(fbuf_reset): Use ptrdiff_t for return value.
	(fbuf_alloc): Use size_t for length argument.
	(fbuf_flush): Handle large buffers.
	(fbuf_flush_list): Likewise.
	(fbuf_seek): Use ptrdiff_t for offset and return value.
	(fbuf_read): Use size_t for length argument.
	(fbuf_getc_refill): Use size_t to match fbuf_read.
	* io/fbuf.h (struct fbuf): Use size_t for lengths.
	(fbuf_init): Use size_t instead of int for length.
	(fbuf_reset): Use ptrdiff_t for return value.
	(fbuf_alloc): Use size_t for length argument.
	(fbuf_seek): Use ptrdiff_t for offset and return value.
	(fbuf_read): Use size_t for length argument.
	* io/io.h (read_block_form): Likewise.
	(read_block_form4): Likewise.
	(write_block): Likewise.
	(read_a): Likewise.
	(read_a_char4): Likewise.
	(read_x): Likewise.
	(write_a): Likewise.
	(write_a_char4): Likewise.
	* io/list_read.c (list_formatted_read_scalar): Use size_t to
	handle large buffers.
	* io/read.c (read_l): Likewise.
	(read_utf8): Likewise.
	(read_utf8_char1): Likewise.
	(read_default_char1): Likewise.
	(read_utf8_char4): Likewise.
	(read_default_char4): Likewise.
	(read_a): Likewise.
	(read_a_char4): Likewise.
	(eat_leading_spaces): Likewise.
	(next_char): Likewise.
	(read_decimal): Likewise.
	(read_radix): Likewise.
	(read_f): Likewise.
	(read_x): Likewise.
	* io/transfer.c (read_sf_internal): Likewise.
	(read_sf): Likewise.
	(read_block_form): Likewise.
	(read_block_form4): Likewise.
	(write_block): Likewise.
	(formatted_transfer_scalar_write): Likewise.
	(next_record_w): Likewise.
	* io/unix.c (mem_alloc_r): Likewise.
	(mem_alloc_r4): Likewise.
	(mem_alloc_w): Likewise.
	(mem_alloc_w4): Likewise.
	(mem_read): Likewise.
	(mem_read4): Likewise.
	(mem_write): Likewise.
	(mem_write4): Likewise.
	(open_internal): Likewise.
	(open_internal4): Likewise.
	* io/unix.h (open_internal): Likewise.
	(open_internal4): Likewise.
	(mem_alloc_w): Likewise.
	(mem_alloc_r): Likewise.
	(mem_alloc_w4): Likewise.
	(mem_alloc_r4): Likewise.
	* io/write.c (write_check_cc): Likewise.
	(write_cc): Likewise.
	(write_a): Likewise.
	(write_a_char4): Likewise.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/fbuf.c
    trunk/libgfortran/io/fbuf.h
    trunk/libgfortran/io/io.h
    trunk/libgfortran/io/list_read.c
    trunk/libgfortran/io/read.c
    trunk/libgfortran/io/transfer.c
    trunk/libgfortran/io/unix.c
    trunk/libgfortran/io/unix.h
    trunk/libgfortran/io/write.c
Comment 24 Janne Blomqvist 2018-01-08 12:12:37 UTC
Author: jb
Date: Mon Jan  8 12:12:05 2018
New Revision: 256337

URL: https://gcc.gnu.org/viewcvs?rev=256337&root=gcc&view=rev
Log:
PR 78534 Regression on 32-bit targets

By switching from int to size_t in order to handle larger values,
r256322 introduced a bug that manifested itself on 32-bit
targets. Fixed by using the correct type to store the result of a
next_array_record call.

Regtested on x86_64-pc-linux-gnu and i686-pc-linux-gnu, committed to
trunk as obvious.

libgfortran/ChangeLog:

2018-01-08  Janne Blomqvist  <jb@gcc.gnu.org>

	PR 78534, bugfix for r256322
	* io/transfer.c (next_record_w): Use correct type for return value
	of next_array_record.

Modified:
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/transfer.c
Comment 25 Janne Blomqvist 2018-01-22 13:31:39 UTC
Author: jb
Date: Mon Jan 22 13:31:08 2018
New Revision: 256944

URL: https://gcc.gnu.org/viewcvs?rev=256944&root=gcc&view=rev
Log:
PR 78534, 83704 Large character lengths

This patch fixes various parts of the code to use a larger type than
int for the character length. Depending on the situation,
HOST_WIDE_INT, size_t, or gfc_charlen_t is appropriate.

Regtested on x86_64-pc-linux-gnu and i686-pc-linux-gnu.

gcc/fortran/ChangeLog:

2018-01-22  Janne Blomqvist  <jb@gcc.gnu.org>

	PR 78534
	PR 83704
	* arith.c (gfc_arith_concat): Use size_t for string length.
	(gfc_compare_string): Likewise.
	(gfc_compare_with_Cstring): Likewise.
	* array.c (gfc_resolve_character_array_constructor): Use
	HOST_WIDE_INT, gfc_mpz_get_hwi.
	* check.c (gfc_check_fe_runtime_error): Use size_t.
	* data.c (create_character_initializer): Use HOST_WIDE_INT,
	gfc_extract_hwi.
	* decl.c (gfc_set_constant_character_len): Use gfc_charlen_t.
	(add_init_expr_to_sym): Use HOST_WIDE_INT.
	* expr.c (gfc_build_init_expr): Use HOST_WIDE_INT,
	gfc_extract_hwi.
	(gfc_apply_init): Likewise.
	* match.h (gfc_set_constant_character_len): Update prototype.
	* primary.c (match_string_constant): Use size_t.
	* resolve.c (resolve_ordinary_assign): Use HOST_WIDE_INT,
	gfc_mpz_get_hwi.
	* simplify.c (init_result_expr): Likewise.
	(gfc_simplify_len_trim): Use size_t.
	* target-memory.c (gfc_encode_character): Use size_t.
	(gfc_target_encode_expr): Use HOST_WIDE_INT, gfc_mpz_get_hwi.
	(interpret_array): Use size_t.
	(gfc_interpret_character): Likewise.
	* target-memory.h (gfc_encode_character): Update prototype.
	(gfc_interpret_character): Likewise.
	(gfc_target_interpret_expr): Likewise.
	* trans-const.c (gfc_build_string_const): Use size_t for length
	argument.
	(gfc_build_wide_string_const): Likewise.
	* trans-const.h (gfc_build_string_const): Likewise.
	(gfc_build_wide_string_const): Likewise.

2018-01-22  Janne Blomqvist  <jb@gcc.gnu.org>

	PR 78534
	PR 83704
	* gfortran.dg/string_1.f90: Remove printing the length.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/arith.c
    trunk/gcc/fortran/array.c
    trunk/gcc/fortran/check.c
    trunk/gcc/fortran/data.c
    trunk/gcc/fortran/decl.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/match.h
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/simplify.c
    trunk/gcc/fortran/target-memory.c
    trunk/gcc/fortran/target-memory.h
    trunk/gcc/fortran/trans-const.c
    trunk/gcc/fortran/trans-const.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/string_1.f90
Comment 26 Janne Blomqvist 2018-01-31 13:23:52 UTC
Author: jb
Date: Wed Jan 31 13:23:20 2018
New Revision: 257233

URL: https://gcc.gnu.org/viewcvs?rev=257233&root=gcc&view=rev
Log:
PR 78534 Reinstate better string copy algorithm

As part of the change to larger character lengths, the string copy
algorithm was temporarily pessimized to get around some spurious
-Wstringop-overflow warnings.  Having tried a number of variations of
this algorithm I have managed to get it down to one spurious warning,
only with -O1 optimization, in the testsuite.  This patch reinstates
the optimized variant and modifies this one testcase to ignore the
warning.

Regtested on x86_64-pc-linux-gnu.

gcc/fortran/ChangeLog:

2018-01-31  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/78534
	* trans-expr.c (fill_with_spaces): Use memset instead of
	generating loop.
	(gfc_trans_string_copy): Improve opportunity to use builtins with
	constant lengths.

gcc/testsuite/ChangeLog:

2018-01-31  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/78534
	* gfortran.dg/allocate_deferred_char_scalar_1.f03: Prune
	-Wstringop-overflow warnings due to spurious warning with -O1.
	* gfortran.dg/char_cast_1.f90: Update dump scan pattern.
	* gfortran.dg/transfer_intrinsic_1.f90: Likewise.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/allocate_deferred_char_scalar_1.f03
    trunk/gcc/testsuite/gfortran.dg/char_cast_1.f90
    trunk/gcc/testsuite/gfortran.dg/transfer_intrinsic_1.f90
Comment 27 Janne Blomqvist 2018-02-01 08:02:12 UTC
Fixed on trunk, closing.
Comment 28 Janne Blomqvist 2018-02-22 16:14:53 UTC
Author: jb
Date: Thu Feb 22 16:14:21 2018
New Revision: 257903

URL: https://gcc.gnu.org/viewcvs?rev=257903&root=gcc&view=rev
Log:
PR 78534, 84509 Fix libgfortran API for PAUSE statement

This patch changes the libgfortran API for the PAUSE statement. By
passing a GFC_INTEGER_8 it handles -fdefault-integer-8, and for the
character version passing the length as a size_t.

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

gcc/fortran/ChangeLog:

2018-02-22  Janne Blomqvist  <jb@gcc.gnu.org>

	PR 78534
	PR 84509
	* trans-decl.c (gfc_build_builtin_function_decls): Pass
	gfc_int8_type node to pause_numeric, size_type_node to
	pause_string.
	* trans-stmt.c (gfc_trans_pause): Likewise.

libgfortran/ChangeLog:

2018-02-22  Janne Blomqvist  <jb@gcc.gnu.org>

	PR 78534
	PR 84509
	* runtime/pause.c (pause_numeric): Modify to take GFC_INTEGER_8
	argument.
	(pause_string): Modify to take size_t character length argument.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/fortran/trans-stmt.c
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/runtime/pause.c