Bug 35849 - "wrong" line shown in error message for parameter
Summary: "wrong" line shown in error message for parameter
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, patch
Depends on:
Blocks:
 
Reported: 2008-04-06 20:17 UTC by Tobias Burnus
Modified: 2016-07-04 19:44 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-03-28 15:35:23


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2008-04-06 20:17:36 UTC
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
Comment 1 Tobias Burnus 2008-04-06 20:38:50 UTC
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);
Comment 2 Daniel Franke 2009-01-03 23:33:45 UTC
Do you plan to commit this?
Comment 3 Tobias Burnus 2009-11-01 20:21:25 UTC
(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
Comment 4 Daniel Franke 2010-05-20 14:33:36 UTC
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 ^^
Comment 5 kargls 2016-07-01 19:30:06 UTC
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;
     }
Comment 6 Jerry DeLisle 2016-07-04 19:15:27 UTC
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
Comment 7 Jerry DeLisle 2016-07-04 19:44:56 UTC
Closing, Fixed on Trunk.