* [Committed] PR fortran/85520 -- check for negative length
@ 2018-04-25 7:38 Steve Kargl
0 siblings, 0 replies; only message in thread
From: Steve Kargl @ 2018-04-25 7:38 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 469 bytes --]
I've committed the attached patch after checking that
it does not cause any regression and that it fixes the
problem in the PR. The patch checks for a negative
string length, and resets it to 0 if it is < 0.
2018-04-24 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/85520
* decl.c (gfc_match_char_spec): Check for negative length and set to 0.
2018-04-24 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/85520
* gfortran.dg/pr85520.f90: New test.
--
Steve
[-- Attachment #2: pr85520.diff --]
[-- Type: text/x-diff, Size: 957 bytes --]
Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c (revision 259619)
+++ gcc/fortran/decl.c (working copy)
@@ -3235,7 +3249,11 @@ done:
e = gfc_copy_expr (len);
gfc_reduce_init_expr (e);
if (e->expr_type == EXPR_CONSTANT)
- gfc_replace_expr (len, e);
+ {
+ gfc_replace_expr (len, e);
+ if (mpz_cmp_si (len->value.integer, 0) < 0)
+ mpz_set_ui (len->value.integer, 0);
+ }
else
gfc_free_expr (e);
cl->length = len;
Index: gcc/testsuite/gfortran.dg/pr85520.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr85520.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr85520.f90 (working copy)
@@ -0,0 +1,7 @@
+! { dg-do run }
+! PR fortran/85520
+! Original code from Gerhard Steinmetz <gscfq at t-online dot de>
+program p
+ character(-huge(1)) :: c = ' '
+ if (len(c) /= 0) stop 1
+end
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-04-25 0:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-25 7:38 [Committed] PR fortran/85520 -- check for negative length 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).