Bug 34559 - [4.3 Regression]: ICE using REPEAT on string literals
[4.3 Regression]: ICE using REPEAT on string literals
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: fortran
4.3.0
: P3 normal
: 4.3.0
Assigned To: Not yet assigned to anyone
: ice-on-valid-code
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2007-12-22 19:16 UTC by Tobias Burnus
Modified: 2007-12-26 01:20 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-12-22 20:31:59


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-12-22 19:16:29 UTC
==27207== Invalid read of size 4
==27207==    at 0x46E5F6: gfc_simplify_repeat (simplify.c:3131)
==27207==    by 0x42AE72: do_simplify (intrinsic.c:3180)
==27207==    by 0x42BD39: gfc_intrinsic_func_interface (intrinsic.c:3446)
==27207==    by 0x45FCA9: gfc_resolve_expr (resolve.c:1629)
==27207==    by 0x461BD3: resolve_operator (resolve.c:2854)

! Regression. ICE on valid code
! Works with 4.1.2 and 4.2.2, but fails with 4.3.0
! (segmentation fault).
!
! Found using the Fortran Company Fortran 90 Test Suite (Lite),
! Version 1.4
program npr
implicit none
print *, "a" // repeat ("", 3) // repeat ("xxx", 0) // &
                repeat ("string", 4)
end program npr
Comment 1 Thomas Koenig 2007-12-22 20:31:59 UTC
Confirmed.

Simplified test case:

$ cat npr.f90 
program main
  print *, repeat ("", 3)
end program main
$ gfortran npr.f90 
f951: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 2 Daniel Franke 2007-12-22 20:40:13 UTC
Fixed.

Index: simplify.c
===================================================================
--- simplify.c  (revision 131122)
+++ simplify.c  (working copy)
@@ -3128,7 +3128,9 @@ gfc_simplify_repeat (gfc_expr *e, gfc_ex
   if (e->expr_type != EXPR_CONSTANT)
     return NULL;

-  if (len || mpz_sgn (e->ts.cl->length->value.integer) != 0)
+  if (len ||
+      (e->ts.cl->length &&
+       mpz_sgn (e->ts.cl->length->value.integer)) != 0)
     {
       const char *res = gfc_extract_int (n, &ncop);
       gcc_assert (res == NULL);


(not yet regression tested, obviously)
Comment 3 Daniel Franke 2007-12-22 22:18:44 UTC
Subject: Bug 34559

Author: dfranke
Date: Sat Dec 22 22:18:28 2007
New Revision: 131139

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131139
Log:
gcc/fortran:
2007-12-22  Daniel Franke  <franke.daniel@gmail.com>

        PR fortran/34559
        * simplify.c (gfc_simplify_repeat): Added safeguard for empty string
        literals.

gcc/testsuite:
2007-12-22  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/34559
	* gfortran.dg/repeat_6.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/repeat_6.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/simplify.c
    trunk/gcc/testsuite/ChangeLog

Comment 4 Daniel Franke 2007-12-22 22:19:55 UTC
Fixed in trunk. Closing.