F2003, 13.7.85, NEW_LINE, Argument: A shall be of type character. It may be a scalar or an array. $> cat newline.f90 WRITE(*,*) NEW_LINE((/'a', 'b', 'c'/)) END $> gfortran-svn -g -Wall newline.f90 && ./a.out newline.f90: In function 'MAIN__': newline.f90:1: internal compiler error: in gfc_conv_intrinsic_function, at fortran/trans-intrinsic.c:3567 $> gfortran-svn -v gcc version 4.3.0 20070428 (experimental)
> F2003, 13.7.85, NEW_LINE, Argument: > A shall be of type character. It may be a scalar or an array. Additional information: Class. Inquiry function. Result Characteristics. Character scalar of length one with the same kind type parameter as A. I.e. no array should be returned! This is different to the elemental functions achar, iachar etc.
(Side note: NEW_LINE is not an elemental function. It can be used with an array argument, but it's different from being elemental.) As for the bug itself, there's no reason that the argument to NEW_LINE should be constant: the only requirement is that it's of character kind (all that is used in NEW_LINE is the character kind, which is always known at compile-time). So, the following patch fixes it, and I believe it does the right thing: Index: simplify.c =================================================================== --- simplify.c (revision 124415) +++ simplify.c (working copy) @@ -2641,13 +2641,8 @@ gfc_simplify_new_line (gfc_expr *e) { gfc_expr *result; - if (e->expr_type != EXPR_CONSTANT) - return NULL; - result = gfc_constant_result (BT_CHARACTER, e->ts.kind, &e->where); - result->value.character.string = gfc_getmem (2); - result->value.character.length = 1; result->value.character.string[0] = '\n'; result->value.character.string[1] = '\0'; /* For debugger */ This patch is donated to whomever has time to confirm that it does what it should, that it conforms to the standard and that it regtests. (I'll take care of it next week if noone has time before then.) The following testcase now passes: $ cat a.f90 character(len=10) :: a1 character(len=10) :: a2(2) character(len=10), parameter :: a3 = "1234567890" character(len=10), parameter :: a4(2) = "1234567890" character(len=10), parameter :: a5(2) = repeat("1234567890",2) print *, ichar(new_line(a1)) print *, ichar(new_line(a2)) print *, ichar(new_line(a3)) print *, ichar(new_line(a4)) print *, ichar(new_line(a5)) end $ gfortran a.f90 && ./a.out 10 10 10 10 10
Subject: Bug 31764 Author: fxcoudert Date: Sun May 6 22:56:52 2007 New Revision: 124482 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=124482 Log: PR fortran/31764 * simplify.c (gfc_simplify_new_line): NEW_LINE can be simplified even for non constant arguments. * gfortran.dg/new_line.f90: Add new checks. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/simplify.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/new_line.f90
Fixed on mainline.