public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/40158]  New: Misleading error message for passing a scalar to an array
@ 2009-05-15 12:45 burnus at gcc dot gnu dot org
  2009-12-18  6:47 ` [Bug fortran/40158] " pault at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-05-15 12:45 UTC (permalink / raw)
  To: gcc-bugs

The following program is rightly rejected. But the problem is not really that
the ranks are different (as the example shows for "i", which is valid). The
issue is that "j" is a scalar.  -- A user might also not be that familiar the
concept that a rank-0 array is equivalent to a scalar.


gfortran shows:
  Error: Rank mismatch in argument 'i' at (1) (1 and 0)
other compiles have, e.g.
  Error: Cannot pass scalar to array argument 'i' at (1)

  Error: Scalar supplied for array argument I (no. 1) of SUB

  Illegal association of a scalar actual argument with array dummy argument
"I".

  error #7836: If the actual argument is scalar, the corresponding dummy
argument shall be scalar unless the actual argument is an element of an array
that is not an assumed-shape or pointer array, or a substring of such an
element.   [I]

Though I'm not sure whether one needs to be as long as ifort.

Cool stuff: If one changes the "contains" into "end" and removes the last line,
gfortran -fwhole-file still detects the violated constraint, while ifort, g95,
openf95 miss it. NAG f95 also detects it.

implicit none
 integer :: i(4,5),j
 i = 0
 call sub(i)
 call sub(j)  ! Wrong scalar passed to array
 print '(5i0)', i
contains
 subroutine sub(i)
   integer :: i(*)
   i(1) = 2
 end subroutine sub
end


-- 
           Summary: Misleading error message for passing a scalar to an
                    array
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40158


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug fortran/40158] Misleading error message for passing a scalar to an array
  2009-05-15 12:45 [Bug fortran/40158] New: Misleading error message for passing a scalar to an array burnus at gcc dot gnu dot org
@ 2009-12-18  6:47 ` pault at gcc dot gnu dot org
  2010-05-07 19:57 ` dfranke at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pault at gcc dot gnu dot org @ 2009-12-18  6:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pault at gcc dot gnu dot org  2009-12-18 06:47 -------
This fixes it and even bootstraps and regtests:

Index: gcc/fortran/interface.c
===================================================================
--- gcc/fortran/interface.c     (revision 155192)
+++ gcc/fortran/interface.c     (working copy)
@@ -1375,6 +1375,29 @@
 }


+
+static void
+argument_rank_mismatch (const char *name, locus *where,
+                       int rank1, int rank2)
+{
+  if (rank1 == 0)
+    {
+      gfc_error ("Rank mismatch in argument '%s' at %L "
+                "(scalar and rank-%d)", name, where, rank2);
+    }
+  if (rank2 == 0)
+    {
+      gfc_error ("Rank mismatch in argument '%s' at %L "
+                "(rank-%d and scalar)", name, where, rank1);
+    }
+  else
+    {    
+      gfc_error ("Rank mismatch in argument '%s' at %L "
+                "(rank-%d and rank-%d)", name, where, rank1, rank2);
+    }
+}
+
+
 /* Given a symbol of a formal argument list and an expression, see if
    the two are compatible as arguments.  Returns nonzero if
    compatible, zero if not compatible.  */
@@ -1456,9 +1479,8 @@
       || (actual->rank == 0 && formal->as->type == AS_ASSUMED_SHAPE))
     {
       if (where)
-       gfc_error ("Rank mismatch in argument '%s' at %L (%d and %d)",
-                  formal->name, &actual->where, symbol_rank (formal),
-                  actual->rank);
+       argument_rank_mismatch (formal->name, &actual->where,
+                               symbol_rank (formal), actual->rank);
       return 0;
     }
   else if (actual->rank != 0 && (is_elemental || formal->attr.dimension))
@@ -1496,9 +1518,8 @@
   else if (ref == NULL)
     {
       if (where)
-       gfc_error ("Rank mismatch in argument '%s' at %L (%d and %d)",
-                  formal->name, &actual->where, symbol_rank (formal),
-                  actual->rank);
+       argument_rank_mismatch (formal->name, &actual->where,
+                               symbol_rank (formal), actual->rank);
       return 0;
     }


Cheers

Paul


-- 

pault at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |pault at gcc dot gnu dot org
                   |dot org                     |
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-12-18 06:47:14
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40158


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug fortran/40158] Misleading error message for passing a scalar to an array
  2009-05-15 12:45 [Bug fortran/40158] New: Misleading error message for passing a scalar to an array burnus at gcc dot gnu dot org
  2009-12-18  6:47 ` [Bug fortran/40158] " pault at gcc dot gnu dot org
@ 2010-05-07 19:57 ` dfranke at gcc dot gnu dot org
  2010-06-24 15:31 ` pault at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2010-05-07 19:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from dfranke at gcc dot gnu dot org  2010-05-07 19:56 -------
Paul, any reason not to commit the patch in comment #1?


-- 

dfranke at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dfranke at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40158


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug fortran/40158] Misleading error message for passing a scalar to an array
  2009-05-15 12:45 [Bug fortran/40158] New: Misleading error message for passing a scalar to an array burnus at gcc dot gnu dot org
  2009-12-18  6:47 ` [Bug fortran/40158] " pault at gcc dot gnu dot org
  2010-05-07 19:57 ` dfranke at gcc dot gnu dot org
@ 2010-06-24 15:31 ` pault at gcc dot gnu dot org
  2010-06-28 17:17 ` pault at gcc dot gnu dot org
  2010-07-16  4:39 ` pault at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: pault at gcc dot gnu dot org @ 2010-06-24 15:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pault at gcc dot gnu dot org  2010-06-24 15:31 -------
(In reply to comment #2)
> Paul, any reason not to commit the patch in comment #1?
> 

No!  I'll try to get to it on Sunday.

Cheers

Paul


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40158


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug fortran/40158] Misleading error message for passing a scalar to an array
  2009-05-15 12:45 [Bug fortran/40158] New: Misleading error message for passing a scalar to an array burnus at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2010-06-24 15:31 ` pault at gcc dot gnu dot org
@ 2010-06-28 17:17 ` pault at gcc dot gnu dot org
  2010-07-16  4:39 ` pault at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: pault at gcc dot gnu dot org @ 2010-06-28 17:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pault at gcc dot gnu dot org  2010-06-28 17:16 -------
Subject: Bug 40158

Author: pault
Date: Mon Jun 28 17:16:06 2010
New Revision: 161504

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161504
Log:
2010-06-28  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/40158
        * interface.c (argument_rank_mismatch): New function.
        (compare_parameter): Call new function instead of generating
        the error directly.

2010-06-28  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/40158
        * gfortran.dg/actual_rank_check_1.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/actual_rank_check_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/interface.c
    trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40158


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug fortran/40158] Misleading error message for passing a scalar to an array
  2009-05-15 12:45 [Bug fortran/40158] New: Misleading error message for passing a scalar to an array burnus at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2010-06-28 17:17 ` pault at gcc dot gnu dot org
@ 2010-07-16  4:39 ` pault at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: pault at gcc dot gnu dot org @ 2010-07-16  4:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pault at gcc dot gnu dot org  2010-07-16 04:39 -------
PR closed.  Thanks for the report.

Paul


-- 

pault at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40158


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-07-16  4:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-15 12:45 [Bug fortran/40158] New: Misleading error message for passing a scalar to an array burnus at gcc dot gnu dot org
2009-12-18  6:47 ` [Bug fortran/40158] " pault at gcc dot gnu dot org
2010-05-07 19:57 ` dfranke at gcc dot gnu dot org
2010-06-24 15:31 ` pault at gcc dot gnu dot org
2010-06-28 17:17 ` pault at gcc dot gnu dot org
2010-07-16  4:39 ` pault at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).