public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/53692] New: OPTIONAL: Scalarizing over the wrong array
@ 2012-06-15 20:47 burnus at gcc dot gnu.org
  2012-06-18 18:32 ` [Bug fortran/53692] " burnus at gcc dot gnu.org
  2012-06-18 18:38 ` burnus at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-06-15 20:47 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53692
           Summary: OPTIONAL: Scalarizing over the wrong array
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org
                CC: mikael@gcc.gnu.org
            Blocks: 50981


The following program of Daniel C Chen fails due to invalid OPTIONAL handling:
The scalarizer uses the first array instead of the first array belonging to a
nonoptional argument.

Cf. http://j3-fortran.org/pipermail/j3/2012-June/005356.html

See also: 12.5.2.12p3(6), 
  "An optional dummy argument that is not present is subject to the 
   following restrictions.
   ...
  "(6) If it is an array, it shall not be supplied as an actual argument to 
   an elemental procedure unless an array of the same rank is supplied as an 
   actual argument corresponding to a nonoptional dummy argument of that 
   elemental procedure."


Untested draft patch. I think one might need to have a fall back if there is no
actual argument (which is an array) belonging to a nonoptional dummy. In that
case (cf. above) one can assume that the first array in the list has to be
present.

--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -4356,3 +4356,4 @@ set_loop_bounds (gfc_loopinfo *loop)
              || ss_type == GFC_SS_TEMP
-             || ss_type == GFC_SS_REFERENCE)
+             || ss_type == GFC_SS_REFERENCE
+             || ss->info->can_be_null_ref)
            continue;



Program main
  implicit none
  integer :: arr(2)

  arr = [ 1, 2 ]
  call sub1(arg2=arr)
contains
   subroutine sub1(arg1,arg2)
      integer, optional :: arg1(:)
      integer :: arg2(:)
      print *,fun1 (arg1, arg2)
      if (size (fun1 (arg1, arg2)) /= 2) call abort()
      if (any (fun1 (arg1, arg2) /= [1,2])) call abort()
   end subroutine

   elemental function fun1(arg1,arg2)
      integer,intent(in), optional :: arg1
      integer,intent(in)          :: arg2
      integer                     :: fun1
      fun1 = arg2
   end function
end program


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

* [Bug fortran/53692] OPTIONAL: Scalarizing over the wrong array
  2012-06-15 20:47 [Bug fortran/53692] New: OPTIONAL: Scalarizing over the wrong array burnus at gcc dot gnu.org
@ 2012-06-18 18:32 ` burnus at gcc dot gnu.org
  2012-06-18 18:38 ` burnus at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-06-18 18:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-06-18 18:32:05 UTC ---
Author: burnus
Date: Mon Jun 18 18:31:54 2012
New Revision: 188749

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=188749
Log:
2012-06-18  Tobias Burnus  <burnus@net-b.de>

        PR fortran/53692
        * trans-array.c (set_loop_bounds): Don't scalarize via absent
        optional arrays.
        * resolve.c (resolve_elemental_actual): Don't stop resolving
        after printing a warning.

2012-06-18  Tobias Burnus  <burnus@net-b.de>

        PR fortran/53692
        * gfortran.dg/elemental_optional_args_6.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/elemental_optional_args_6.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug fortran/53692] OPTIONAL: Scalarizing over the wrong array
  2012-06-15 20:47 [Bug fortran/53692] New: OPTIONAL: Scalarizing over the wrong array burnus at gcc dot gnu.org
  2012-06-18 18:32 ` [Bug fortran/53692] " burnus at gcc dot gnu.org
@ 2012-06-18 18:38 ` burnus at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-06-18 18:38 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |burnus at gcc dot gnu.org
         Resolution|                            |FIXED

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-06-18 18:37:53 UTC ---
FIXED on the trunk (4.8).


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

end of thread, other threads:[~2012-06-18 18:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-15 20:47 [Bug fortran/53692] New: OPTIONAL: Scalarizing over the wrong array burnus at gcc dot gnu.org
2012-06-18 18:32 ` [Bug fortran/53692] " burnus at gcc dot gnu.org
2012-06-18 18:38 ` burnus at gcc dot gnu.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).