public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/30964]  New: optional arguments to random_seed
@ 2007-02-25 21:16 tkoenig at gcc dot gnu dot org
  2007-02-26  0:14 ` [Bug fortran/30964] " kargl at gcc dot gnu dot org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-02-25 21:16 UTC (permalink / raw)
  To: gcc-bugs

This is similar to PR 30865.  Any of the
arguments to random_seed may be specified if they
are optional arguments to the subroutine that is called.
The following is legal:

program trs
  implicit none
  integer :: size, ierr
  integer, allocatable, dimension(:) :: seed
  call test_random_seed(size)
  allocate(seed(size), stat=ierr)
  if (ierr /= 0) stop
  call test_random_seed(get=seed)
  call test_random_seed(put=seed)
contains
  subroutine test_random_seed(size, put, get)
    integer, optional :: size
    integer, dimension(:), optional :: put
    integer, dimension(:), optional :: get
    call random_seed(size, put, get)
  end subroutine test_random_seed
end program trs


-- 
           Summary: optional arguments to random_seed
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tkoenig at gcc dot gnu dot org


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


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

* [Bug fortran/30964] optional arguments to random_seed
  2007-02-25 21:16 [Bug fortran/30964] New: optional arguments to random_seed tkoenig at gcc dot gnu dot org
@ 2007-02-26  0:14 ` kargl at gcc dot gnu dot org
  2007-02-26 19:53 ` tkoenig at gcc dot gnu dot org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: kargl at gcc dot gnu dot org @ 2007-02-26  0:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from kargl at gcc dot gnu dot org  2007-02-26 00:14 -------
I have a patch to permit gfc_check_random_seed to deal with arguments
with the optional attribute set.  I was waiting on pault's size0/size1
patch to hit the tree to see if it does the right thing.


-- 


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


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

* [Bug fortran/30964] optional arguments to random_seed
  2007-02-25 21:16 [Bug fortran/30964] New: optional arguments to random_seed tkoenig at gcc dot gnu dot org
  2007-02-26  0:14 ` [Bug fortran/30964] " kargl at gcc dot gnu dot org
@ 2007-02-26 19:53 ` tkoenig at gcc dot gnu dot org
  2007-03-03 10:36 ` fxcoudert at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-02-26 19:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from tkoenig at gcc dot gnu dot org  2007-02-26 19:53 -------
(In reply to comment #1)
> I have a patch to permit gfc_check_random_seed to deal with arguments
> with the optional attribute set.  I was waiting on pault's size0/size1
> patch to hit the tree to see if it does the right thing.

In case you missed it, I submitted pault's patch (without changes),
to http://gcc.gnu.org/ml/gcc-patches/2007-02/msg01956.html .  You could
also attach your patch to this PR, I'll have a look at it then.


-- 


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


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

* [Bug fortran/30964] optional arguments to random_seed
  2007-02-25 21:16 [Bug fortran/30964] New: optional arguments to random_seed tkoenig at gcc dot gnu dot org
  2007-02-26  0:14 ` [Bug fortran/30964] " kargl at gcc dot gnu dot org
  2007-02-26 19:53 ` tkoenig at gcc dot gnu dot org
@ 2007-03-03 10:36 ` fxcoudert at gcc dot gnu dot org
  2007-03-15 12:59 ` fxcoudert at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-03 10:36 UTC (permalink / raw)
  To: gcc-bugs



-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-03-03 10:36:07
               date|                            |


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


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

* [Bug fortran/30964] optional arguments to random_seed
  2007-02-25 21:16 [Bug fortran/30964] New: optional arguments to random_seed tkoenig at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2007-03-03 10:36 ` fxcoudert at gcc dot gnu dot org
@ 2007-03-15 12:59 ` fxcoudert at gcc dot gnu dot org
  2007-05-21 14:21 ` fxcoudert at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-15 12:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from fxcoudert at gcc dot gnu dot org  2007-03-15 12:59 -------
(In reply to comment #1)
> I have a patch to permit gfc_check_random_seed to deal with arguments
> with the optional attribute set.  I was waiting on pault's size0/size1
> patch to hit the tree to see if it does the right thing.

I think it was commited.


-- 


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


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

* [Bug fortran/30964] optional arguments to random_seed
  2007-02-25 21:16 [Bug fortran/30964] New: optional arguments to random_seed tkoenig at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2007-03-15 12:59 ` fxcoudert at gcc dot gnu dot org
@ 2007-05-21 14:21 ` fxcoudert at gcc dot gnu dot org
  2007-05-22  8:24 ` fxcoudert at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-05-21 14:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from fxcoudert at gcc dot gnu dot org  2007-05-21 15:21 -------
Created an attachment (id=13595)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13595&action=view)
Patch for that issue; not tested yet


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |fxcoudert at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED


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


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

* [Bug fortran/30964] optional arguments to random_seed
  2007-02-25 21:16 [Bug fortran/30964] New: optional arguments to random_seed tkoenig at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2007-05-21 14:21 ` fxcoudert at gcc dot gnu dot org
@ 2007-05-22  8:24 ` fxcoudert at gcc dot gnu dot org
  2007-05-28 20:48 ` fxcoudert at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-05-22  8:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from fxcoudert at gcc dot gnu dot org  2007-05-22 09:23 -------
There's more to it. When generate wrong-code for optional arguments, as shown
by the following code:

$ cat b.f90 
program trs
  implicit none
  integer :: size, ierr
  integer, allocatable, dimension(:) :: seed
  call random_seed(size)
  allocate(seed(size), stat=ierr)
  if (ierr /= 0) stop
  call test_random_seed()
contains
  subroutine test_random_seed(get)
    integer, dimension(:), optional :: get
    call random_seed(get=get)
  end subroutine test_random_seed
end program trs
$ gfortran b.f90 && ./a.out
Segmentation fault


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |major
           Keywords|                            |wrong-code


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


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

* [Bug fortran/30964] optional arguments to random_seed
  2007-02-25 21:16 [Bug fortran/30964] New: optional arguments to random_seed tkoenig at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2007-05-22  8:24 ` fxcoudert at gcc dot gnu dot org
@ 2007-05-28 20:48 ` fxcoudert at gcc dot gnu dot org
  2007-08-11 23:22 ` fxcoudert at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-05-28 20:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from fxcoudert at gcc dot gnu dot org  2007-05-28 20:48 -------
The following two codes are handled differently:

$ cat u.f90
  call foo()
contains
  subroutine foo(x)
    integer, dimension(:), optional :: x
    interface
      subroutine bar(x)
        integer, dimension(:), optional :: x
      end subroutine bar
    end interface

    call bar(x)
  end subroutine foo
end
$ cat v.f90
  call foo()
contains
  subroutine foo(x)
    integer, dimension(:), optional :: x

    call random_seed(get=x)
  end subroutine foo
end


For the first one, gfc_conv_missing_dummy() is called, which leads to correct
code. For the second one, gfc_conv_missing_dummy() is not called, leading to
wrong-code.


-- 


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


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

* [Bug fortran/30964] optional arguments to random_seed
  2007-02-25 21:16 [Bug fortran/30964] New: optional arguments to random_seed tkoenig at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2007-05-28 20:48 ` fxcoudert at gcc dot gnu dot org
@ 2007-08-11 23:22 ` fxcoudert at gcc dot gnu dot org
  2007-08-11 23:33 ` fxcoudert at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-08-11 23:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from fxcoudert at gcc dot gnu dot org  2007-08-11 23:22 -------
(In reply to comment #6)
> For the first one, gfc_conv_missing_dummy() is called, which leads to correct
> code. For the second one, gfc_conv_missing_dummy() is not called, leading to
> wrong-code.

The reason for that is in gfc_trans_call, around line 2316 (the call to
gfc_conv_missing_dummy): when we come here, we check both the list of actual
args and the list of formal args for optional args. This is need, because we
need the type of the formal arg. Problem is that apparently intrinsic
subroutines don't have a list of formal args when we come up here.


-- 


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


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

* [Bug fortran/30964] optional arguments to random_seed
  2007-02-25 21:16 [Bug fortran/30964] New: optional arguments to random_seed tkoenig at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2007-08-11 23:22 ` fxcoudert at gcc dot gnu dot org
@ 2007-08-11 23:33 ` fxcoudert at gcc dot gnu dot org
  2007-08-12  0:16 ` fxcoudert at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-08-11 23:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from fxcoudert at gcc dot gnu dot org  2007-08-11 23:33 -------
(In reply to comment #7)
> The reason for that is in gfc_trans_call

This should be: gfc_conv_function_call


-- 


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


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

* [Bug fortran/30964] optional arguments to random_seed
  2007-02-25 21:16 [Bug fortran/30964] New: optional arguments to random_seed tkoenig at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2007-08-11 23:33 ` fxcoudert at gcc dot gnu dot org
@ 2007-08-12  0:16 ` fxcoudert at gcc dot gnu dot org
  2007-08-12 16:41 ` fxcoudert at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-08-12  0:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from fxcoudert at gcc dot gnu dot org  2007-08-12 00:16 -------
Haven't yet had time to regtest this patch, but it should fix the bug:

Index: trans-expr.c
===================================================================
--- trans-expr.c        (revision 127363)
+++ trans-expr.c        (working copy)
@@ -2303,36 +2303,38 @@ gfc_conv_function_call (gfc_se * se, gfc
            } 
        }

-      if (fsym)
-       {
-         if (e)
+      /* The case with fsym->attr.optional is that of a user subroutine
+        with an interface indicating an optional argument.  When we call
+        an intrinsic subroutine, however, fsym is NULL, but we might still
+        have an optional argument, so we proceed to the substitution
+        just in case.  */
+      if (e && (fsym == NULL || fsym->attr.optional))
+       {
+         /* If an optional argument is itself an optional dummy argument,
+            check its presence and substitute a null if absent.  */
+         if (e->expr_type == EXPR_VARIABLE
+             && e->symtree->n.sym->attr.optional)
+           gfc_conv_missing_dummy (&parmse, e, fsym ? fsym->ts : e->ts);
+       }
+
+      if (fsym && e)
+       {
+         /* Obtain the character length of an assumed character length
+            length procedure from the typespec.  */
+         if (fsym->ts.type == BT_CHARACTER
+             && parmse.string_length == NULL_TREE
+             && e->ts.type == BT_PROCEDURE
+             && e->symtree->n.sym->ts.type == BT_CHARACTER
+             && e->symtree->n.sym->ts.cl->length != NULL)
            {
-             /* If an optional argument is itself an optional dummy
-                argument, check its presence and substitute a null
-                if absent.  */
-             if (e->expr_type == EXPR_VARIABLE
-                   && e->symtree->n.sym->attr.optional
-                   && fsym->attr.optional)
-               gfc_conv_missing_dummy (&parmse, e, fsym->ts);
-
-             /* Obtain the character length of an assumed character
-                length procedure from the typespec.  */
-             if (fsym->ts.type == BT_CHARACTER
-                   && parmse.string_length == NULL_TREE
-                   && e->ts.type == BT_PROCEDURE
-                   && e->symtree->n.sym->ts.type == BT_CHARACTER
-                   && e->symtree->n.sym->ts.cl->length != NULL)
-               {
-                 gfc_conv_const_charlen (e->symtree->n.sym->ts.cl);
-                 parmse.string_length
-                       = e->symtree->n.sym->ts.cl->backend_decl;
-               }
+             gfc_conv_const_charlen (e->symtree->n.sym->ts.cl);
+             parmse.string_length = e->symtree->n.sym->ts.cl->backend_decl;
            }
-
-         if (need_interface_mapping)
-           gfc_add_interface_mapping (&mapping, fsym, &parmse);
        }

+      if (fsym && need_interface_mapping)
+       gfc_add_interface_mapping (&mapping, fsym, &parmse);
+
       gfc_add_block_to_block (&se->pre, &parmse.pre);
       gfc_add_block_to_block (&post, &parmse.post);



-- 


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


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

* [Bug fortran/30964] optional arguments to random_seed
  2007-02-25 21:16 [Bug fortran/30964] New: optional arguments to random_seed tkoenig at gcc dot gnu dot org
                   ` (9 preceding siblings ...)
  2007-08-12  0:16 ` fxcoudert at gcc dot gnu dot org
@ 2007-08-12 16:41 ` fxcoudert at gcc dot gnu dot org
  2007-08-12 20:45 ` fxcoudert at gcc dot gnu dot org
  2007-08-12 20:46 ` fxcoudert at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-08-12 16:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from fxcoudert at gcc dot gnu dot org  2007-08-12 16:41 -------
Complete patch submitted:
http://gcc.gnu.org/ml/gcc-patches/2007-08/msg00782.html


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |http://gcc.gnu.org/ml/gcc-
                   |                            |patches/2007-
                   |                            |08/msg00782.html
           Keywords|                            |patch


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


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

* [Bug fortran/30964] optional arguments to random_seed
  2007-02-25 21:16 [Bug fortran/30964] New: optional arguments to random_seed tkoenig at gcc dot gnu dot org
                   ` (10 preceding siblings ...)
  2007-08-12 16:41 ` fxcoudert at gcc dot gnu dot org
@ 2007-08-12 20:45 ` fxcoudert at gcc dot gnu dot org
  2007-08-12 20:46 ` fxcoudert at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-08-12 20:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from fxcoudert at gcc dot gnu dot org  2007-08-12 20:45 -------
Subject: Bug 30964

Author: fxcoudert
Date: Sun Aug 12 20:45:29 2007
New Revision: 127383

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=127383
Log:
        PR fortran/30964
        PR fortran/33054

        * trans-expr.c (gfc_conv_function_call): When no formal argument
        list is available, we still substitute missing optional arguments.
        * check.c (gfc_check_random_seed): Correct the check on the
        number of arguments to RANDOM_SEED.
        * intrinsic.c (add_subroutines): Add a resolution function to
        RANDOM_SEED.
        * iresolve.c (gfc_resolve_random_seed): New function.
        * intrinsic.h (gfc_resolve_random_seed): New prototype.

        * intrinsics/random.c (random_seed): Rename into random_seed_i4.
        (random_seed_i8): New function.
        * gfortran.map (GFORTRAN_1.0): Remove _gfortran_random_seed,
        add _gfortran_random_seed_i4 and _gfortran_random_seed_i8.
        * libgfortran.h (iexport_proto): Replace random_seed by
        random_seed_i4 and random_seed_i8.
        * runtime/main.c (init): Call the new random_seed_i4.

        * gfortran.dg/random_4.f90: New test.
        * gfortran.dg/random_5.f90: New test.
        * gfortran.dg/random_6.f90: New test.
        * gfortran.dg/random_7.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/random_4.f90
    trunk/gcc/testsuite/gfortran.dg/random_5.f90
    trunk/gcc/testsuite/gfortran.dg/random_6.f90
    trunk/gcc/testsuite/gfortran.dg/random_7.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/check.c
    trunk/gcc/fortran/intrinsic.c
    trunk/gcc/fortran/intrinsic.h
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/gfortran.map
    trunk/libgfortran/intrinsics/random.c
    trunk/libgfortran/libgfortran.h
    trunk/libgfortran/runtime/main.c


-- 


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


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

* [Bug fortran/30964] optional arguments to random_seed
  2007-02-25 21:16 [Bug fortran/30964] New: optional arguments to random_seed tkoenig at gcc dot gnu dot org
                   ` (11 preceding siblings ...)
  2007-08-12 20:45 ` fxcoudert at gcc dot gnu dot org
@ 2007-08-12 20:46 ` fxcoudert at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-08-12 20:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from fxcoudert at gcc dot gnu dot org  2007-08-12 20:46 -------
Fixed.


-- 

fxcoudert at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2007-08-12 20:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-25 21:16 [Bug fortran/30964] New: optional arguments to random_seed tkoenig at gcc dot gnu dot org
2007-02-26  0:14 ` [Bug fortran/30964] " kargl at gcc dot gnu dot org
2007-02-26 19:53 ` tkoenig at gcc dot gnu dot org
2007-03-03 10:36 ` fxcoudert at gcc dot gnu dot org
2007-03-15 12:59 ` fxcoudert at gcc dot gnu dot org
2007-05-21 14:21 ` fxcoudert at gcc dot gnu dot org
2007-05-22  8:24 ` fxcoudert at gcc dot gnu dot org
2007-05-28 20:48 ` fxcoudert at gcc dot gnu dot org
2007-08-11 23:22 ` fxcoudert at gcc dot gnu dot org
2007-08-11 23:33 ` fxcoudert at gcc dot gnu dot org
2007-08-12  0:16 ` fxcoudert at gcc dot gnu dot org
2007-08-12 16:41 ` fxcoudert at gcc dot gnu dot org
2007-08-12 20:45 ` fxcoudert at gcc dot gnu dot org
2007-08-12 20:46 ` fxcoudert 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).