The following gives the wrong answers. It may have to do with broadcasting things to arrays. The all scalar case works and an array first argument works. program FA1031 ! fails on Windows XP ! gcc version 4.4.0 20080312 (experimental) [trunk revision 133139] INTEGER IDA1(10) LOGICAL GDA1(10) IDA1 = 0 gda1 = (/ (i/2*2 .ne. I, i=1,10) /) print '(10L2)', gda1 IDA1 = INDEX ( 'DEFDEF' , 'DEF', GDA1 ) !fails print '(10I2)', ida1 IDA1 = INDEX ( (/ ('DEFDEF',i=1,10) /) , 'DEF', GDA1 ) !works print '(10I2)', ida1 IDA = INDEX ( 'DEFDEF' , 'DEF', .true. ) !works print '(I2)', ida END
I forgot to include the output C:\gfortran>gfortran fa1031.f C:\gfortran>a T F T F T F T F T F 1 1 1 1 1 1 1 1 1 1 4 1 4 1 4 1 4 1 4 1 4
Confirmed, not a regression.
this looks promising: Index: gcc/gcc/fortran/simplify.c =================================================================== --- gcc/gcc/fortran/simplify.c (revision 134801) +++ gcc/gcc/fortran/simplify.c (working copy) @@ -1570,7 +1570,8 @@ int back, len, lensub; int i, j, k, count, index = 0, start; - if (x->expr_type != EXPR_CONSTANT || y->expr_type != EXPR_CONSTANT) + if (x->expr_type != EXPR_CONSTANT || y->expr_type != EXPR_CONSTANT + || b->expr_type != EXPR_CONSTANT) return NULL; if (b != NULL && b->value.logical != 0)
Note the last line of patch is checking for b != NULL before using it. Probably want to do likewise for the added test condition above.
close. here is a better patch. http://gcc.gnu.org/ml/fortran/2008-04/msg00278.html
notice the 6 minutes between the above posts :) jerry was correct, it needed a NULL check.
Patch committed, fixed on mainline.