The NCOPIES argument of REPEAT is not converted to the integer king the library expects (kind=4), which can lead to segfaults. I changed that code recently, so I'll fix it. I'll probably take this opportunity to have the front-end actually emit an error if the NCOPIES argument is larger than a fixed value. $ cat repeat.f90 implicit none integer(kind=1) i real(kind=8) r character(len=2) s1, s2 i = 1 r = 1 s1 = '42' r = nearest(r,r) s2 = repeat(s1,i) end $ gfortran repeat.f90 && ./a.out Segmentation fault
We should also diagnostic better the cases of negative of too large NCOPIES argument, for both parameters (in simplification routine) and non-parameters.
Created attachment 13307 [details] Patch that fixes the PR and a few related issues This patch fixes both the simplification routine and the code generation. It removes the need for the libgfortran string_repeat function by emitting inline calls to memmove(), which probably allows greater optimization. I added checking on too large values of the NCOPIES argument: NCOPIES has to be such that the destination length fits in the character length integer kind (which is for now hardcoded as kind=4, but I hope we can change that someday).
Subject: Bug 31304 Author: fxcoudert Date: Tue Apr 3 22:05:14 2007 New Revision: 123481 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123481 Log: PR fortran/31304 * fortran/gfortran.h (gfc_charlen_int_kind): New prototype. * fortran/trans-types.c (gfc_charlen_int_kind): New variable. (gfc_init_types): Define gfc_charlen_int_kind. * fortran/trans.h (gfor_fndecl_string_repeat): Remove prototype. * fortran/trans-decl.c (gfor_fndecl_string_repeat): Delete. (gfc_build_intrinsic_function_decls): Don't set gfor_fndecl_string_repeat. * fortran/trans-intrinsic.c (gfc_conv_intrinsic_repeat): Rewrite so that we don't have to call a library function. * fortran/simplify.c (gfc_simplify_repeat): Perform the necessary checks on the NCOPIES argument, and work with arbitrary size arguments. * intrinsics/string_intrinsics.c (string_repeat): Remove. * gfortran.dg/repeat_2.f90: New test. * gfortran.dg/repeat_3.f90: New test. * gfortran.dg/repeat_4.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/repeat_2.f90 trunk/gcc/testsuite/gfortran.dg/repeat_3.f90 trunk/gcc/testsuite/gfortran.dg/repeat_4.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/gfortran.h trunk/gcc/fortran/simplify.c trunk/gcc/fortran/trans-decl.c trunk/gcc/fortran/trans-intrinsic.c trunk/gcc/fortran/trans-types.c trunk/gcc/fortran/trans.h trunk/gcc/testsuite/ChangeLog trunk/libgfortran/ChangeLog trunk/libgfortran/intrinsics/string_intrinsics.c
Fixed on mainline, closing.