* [PATCH] PR 83705 Repeat with large values
@ 2018-01-31 20:18 Janne Blomqvist
2018-01-31 22:59 ` Steve Kargl
0 siblings, 1 reply; 2+ messages in thread
From: Janne Blomqvist @ 2018-01-31 20:18 UTC (permalink / raw)
To: fortran, gcc-patches; +Cc: Janne Blomqvist
This patch fixes the regression by increasing the limit where we fall
back to runtime to 2**28 elements, which is the same limit where
previous releases failed. The are still bugs in the runtime
evaluation, so in many cases longer characters will still fail, so
print a warning message.
Regtested on x86_64-pc-linux-gnu, Ok for trunk?
gcc/fortran/ChangeLog:
2018-01-31 Janne Blomqvist <jb@gcc.gnu.org>
PR fortran/83705
* simplify.c (gfc_simplify_repeat): Increase limit for deferring
to runtime, print a warning message.
gcc/testsuite/ChangeLog:
2018-01-31 Janne Blomqvist <jb@gcc.gnu.org>
PR fortran/83705
* gfortran.dg/repeat_7.f90: Catch warning message.
---
gcc/fortran/simplify.c | 12 ++++++++----
gcc/testsuite/gfortran.dg/repeat_7.f90 | 2 +-
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 2458956..324f858 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -6121,12 +6121,16 @@ gfc_simplify_repeat (gfc_expr *e, gfc_expr *n)
len = e->value.character.length;
gfc_charlen_t nlen = ncop * len;
- /* Here's a semi-arbitrary limit. If the string is longer than 32 MB
- (8 * 2**20 elements * 4 bytes (wide chars) per element) defer to
+ /* Here's a semi-arbitrary limit. If the string is longer than 1 GB
+ (2**28 elements * 4 bytes (wide chars) per element) defer to
runtime instead of consuming (unbounded) memory and CPU at
compile time. */
- if (nlen > 8388608)
- return NULL;
+ if (nlen > 268435456)
+ {
+ gfc_warning_now (0, "Evaluation of string longer than 2**28 at %L"
+ " deferred to runtime, expect bugs", &e->where);
+ return NULL;
+ }
result = gfc_get_character_expr (e->ts.kind, &e->where, NULL, nlen);
for (size_t i = 0; i < (size_t) ncop; i++)
diff --git a/gcc/testsuite/gfortran.dg/repeat_7.f90 b/gcc/testsuite/gfortran.dg/repeat_7.f90
index 82f8dbf..80a2506 100644
--- a/gcc/testsuite/gfortran.dg/repeat_7.f90
+++ b/gcc/testsuite/gfortran.dg/repeat_7.f90
@@ -4,5 +4,5 @@
! compile time.
program p
character, parameter :: z = 'z'
- print *, repeat(z, huge(1_4))
+ print *, repeat(z, huge(1_4)) ! { dg-warning "Evaluation of string" }
end program p
--
2.7.4
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] PR 83705 Repeat with large values
2018-01-31 20:18 [PATCH] PR 83705 Repeat with large values Janne Blomqvist
@ 2018-01-31 22:59 ` Steve Kargl
0 siblings, 0 replies; 2+ messages in thread
From: Steve Kargl @ 2018-01-31 22:59 UTC (permalink / raw)
To: Janne Blomqvist; +Cc: fortran, gcc-patches
On Wed, Jan 31, 2018 at 10:18:46PM +0200, Janne Blomqvist wrote:
> This patch fixes the regression by increasing the limit where we fall
> back to runtime to 2**28 elements, which is the same limit where
> previous releases failed. The are still bugs in the runtime
> evaluation, so in many cases longer characters will still fail, so
> print a warning message.
>
> Regtested on x86_64-pc-linux-gnu, Ok for trunk?
>
Yes.
--
Steve
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-01-31 22:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-31 20:18 [PATCH] PR 83705 Repeat with large values Janne Blomqvist
2018-01-31 22:59 ` 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).