This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR 78534 Change character length from int to size_t
- From: Janne Blomqvist <blomqvist dot janne at gmail dot com>
- To: Dominique d'Humières <dominiq at lps dot ens dot fr>
- Cc: GCC-Fortran-ML <fortran at gcc dot gnu dot org>, GCC-Patches-ML <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 14 Jan 2017 10:39:13 +0200
- Subject: Re: [PATCH] PR 78534 Change character length from int to size_t
- Authentication-results: sourceware.org; auth=none
- References: <60948DB4-4A24-4836-85B4-66F422215080@lps.ens.fr>
On Sun, Jan 8, 2017 at 4:29 PM, Dominique d'Humières <dominiq@lps.ens.fr> wrote:
>> r244027 reverts r244011. Sorry for the breakage. It seems to affect
>> all i686 as well in addition to power, maybe all 32-bit hosts.
>
> For the record, I see the following failures with an instrumented r244026 (as in pr78672)
>
> FAIL: gfortran.dg/char_length_20.f90 -O* execution test
> FAIL: gfortran.dg/char_length_21.f90 -O* execution test
> FAIL: gfortran.dg/repeat_2.f90 -O1 execution test
> …
> FAIL: gfortran.dg/repeat_2.f90 -Os execution test
> FAIL: gfortran.dg/widechar_6.f90 -O1 execution test
> …
> FAIL: gfortran.dg/widechar_6.f90 -Os execution test
> FAIL: gfortran.dg/widechar_intrinsics_6.f90 -O* execution test
>
> The run time failures are all of the kind
Sorry, I missed that I had to use an instrumented build to catch
these, and assumed everything was Ok once I managed to regtest cleanly
on i686.
The following patch fixes these issues for me, does it work for you?
diff --git a/libgfortran/intrinsics/string_intrinsics_inc.c
b/libgfortran/intrinsics/string_intrinsics_inc.c
index 0da5130..74a994b 100644
--- a/libgfortran/intrinsics/string_intrinsics_inc.c
+++ b/libgfortran/intrinsics/string_intrinsics_inc.c
@@ -177,23 +177,25 @@ string_trim (gfc_charlen_type *len, CHARTYPE
**dest, gfc_charlen_type slen,
gfc_charlen_type
string_len_trim (gfc_charlen_type len, const CHARTYPE *s)
{
- const gfc_charlen_type long_len = (gfc_charlen_type) sizeof (unsigned long);
- gfc_charlen_type i;
+ if (len <= 0)
+ return 0;
+
+ const size_t long_len = sizeof (unsigned long);
- i = len - 1;
+ size_t i = len - 1;
/* If we've got the standard (KIND=1) character type, we scan the string in
long word chunks to speed it up (until a long word is hit that does not
consist of ' 's). */
if (sizeof (CHARTYPE) == 1 && i >= long_len)
{
- int starting;
+ size_t starting;
unsigned long blank_longword;
/* Handle the first characters until we're aligned on a long word
boundary. Actually, s + i + 1 must be properly aligned, because
s + i will be the last byte of a long word read. */
- starting = ((unsigned long)
+ starting = (
#ifdef __INTPTR_TYPE__
(__INTPTR_TYPE__)
#endif
--
Janne Blomqvist