The following prints: INTEGER, PARAMETER, DIMENSION(10) :: A = [(i, i = 1,10)] 1 Error: Magnitude of second argument of ISHFTC exceeds third argument at (1) However, the error actually occurs in the second line. NAG f95 gets this right: Error: fhj.f90, line 2: Element 6 of SHIFT array (6) to intrinsic ISHFTC out of range (-5:5) INTEGER, PARAMETER, DIMENSION(10) :: A = [(i, i = 1,10)] INTEGER, PARAMETER, DIMENSION(10) :: B = ISHFTC(3, A, 5) !ICE end
With the following patch, the message shown is: INTEGER, PARAMETER, DIMENSION(10) :: B = ISHFTC(3, A, 5) !ICE 1 Error: Magnitude of second argument of ISHFTC exceeds third argument at (1) I think there are more places were one should use expr->where instead of sym->where; however, I do not see ad hoc whether this causes a less helpful message for variables (as opposed to PARAMETERs); in this case it is simple as the message states that it is the "second" and the "third" argument, which makes the possition of the "1" less crutial. Index: simplify.c =================================================================== --- simplify.c (revision 133965) +++ simplify.c (working copy) @@ -1878,37 +1878,37 @@ gfc_expr * gfc_simplify_ishft (gfc_expr *e, gfc_expr *s) { gfc_expr *result; int shift, ashift, isize, k, *bits, i; if (e->expr_type != EXPR_CONSTANT || s->expr_type != EXPR_CONSTANT) return NULL; if (gfc_extract_int (s, &shift) != NULL) { - gfc_error ("Invalid second argument of ISHFT at %L", &s->where); + gfc_error ("Invalid second argument of ISHFT at %L", &e->where);
Do you plan to commit this?
(In reply to comment #2) > Do you plan to commit this? The problem is that the patch is effectively wrong. The "s->where" is correct - except that "s" happens to be a parameter where "s->where" points to the parameter definition. For "e->where" and "sz->where" one has the same problem if they are PARAMETERS. (Unless, I missed something.) Complete test - might be useful as it tests all error conditions; could be checked in independenly of fixing the line problem. INTEGER, PARAMETER, DIMENSION(10) :: A = [(i, i = 1,10)] INTEGER, PARAMETER, DIMENSION(10) :: B = ISHFTC(j, A, -20) ! { dg-error "Invalid third argument" } INTEGER, PARAMETER, DIMENSION(10) :: C = ISHFTC(1_1, A, j) ! { dg-error "third argument of ISHFTC exceeds BIT_SIZE of first" } INTEGER, PARAMETER, DIMENSION(10) :: D = ISHFTC(3, A, 5) ! { dg-error "second argument of ISHFTC exceeds third argument" } INTEGER, PARAMETER, DIMENSION(10) :: E = ISHFTC(3_1, A) ! { dg-error "second argument of ISHFTC exceeds BIT_SIZE of first argument" } end
A similar example: $ cat conversion.f90 REAL(8), PARAMETER :: h = HUGE(0.0_8) real*4 x data x / h / end $ gfortran-svn -Wall conversion.f90 conversion.f90:1.28: REAL(8), PARAMETER :: h = HUGE(0.0_8) 1 Error: Arithmetic overflow converting REAL(8) to REAL(4) at (1). This check can be disabled with the option -fno-range-check The overflowing conversion occurs in the DATA statement ^^
Index: simplify.c =================================================================== --- simplify.c (revision 237855) +++ simplify.c (working copy) @@ -3280,7 +3280,6 @@ gfc_simplify_ishftc (gfc_expr *e, gfc_ex return NULL; gfc_extract_int (sz, &ssize); - } else ssize = isize; @@ -3294,7 +3293,10 @@ gfc_simplify_ishftc (gfc_expr *e, gfc_ex { if (sz == NULL) gfc_error ("Magnitude of second argument of ISHFTC exceeds " - "BIT_SIZE of first argument at %L", &s->where); + "BIT_SIZE of first argument at %C"); + else + gfc_error ("Absolute value of SHIFT shall be less than or equal " + "to SIZE at %C"); return &gfc_bad_expr; }
Author: jvdelisle Date: Mon Jul 4 19:14:54 2016 New Revision: 237993 URL: https://gcc.gnu.org/viewcvs?rev=237993&root=gcc&view=rev Log: 2016-07-04 Jerry DeLisle <jvdelisle@gcc.gnu.org> Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/35849 * simplify.c (gfc_simplify_ishftc): Check that absolute value of SHIFT is less than or equal to SIZE. * gfortran.dg: pr35849.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/pr35849.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/simplify.c trunk/gcc/testsuite/ChangeLog
Closing, Fixed on Trunk.