This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] intrinsic rand with an optional argument


Paul Brook <paul@codesourcery.com>:

> On Monday 18 October 2004 10:17, Canqun Yang wrote:
> > The intrinsic rand should have an optional 
argument,
> > so both cases in following example are correct.
> >
> > program rand_ex
> >    write (*, *) rand ()
> >    write (*, *) rand (i)
> > end
> >
> > I attached a patch to fix gfortran for such issue.
> >
> > OK to commit?
> 
> Two problems:
> - The library function also needs changing to accept 
a null argument.
> - The same change should be made for the irand 
intrinsic.
> 

I found the problem just before I committing this 
patch, so I delayed my commitment.

> I'm modified your patch as follows.
> Tested on i686-linux.
> Applied to mainline.
> 

Thanks.

> Paul
> 
> 2004-10-30  Canqun Yang  <canqun@nudt.edu.cn>
> 
>  * check.c (gfc_check_rand): Allow missing optional 
argument. 
>  (gfc_check_irand): Ditto.
>  * intrinsic.c (add_functions): Set arg optional 
flag for {i,}rand.
> libgfortran/
>  * intrinsics/rand.c (irand): Handle NULL argument.
> 
> Index: gcc/fortran/check.c
> 
=======================================================
============
> RCS file: /var/cvsroot/gcc-
cvs/gcc/gcc/fortran/check.c,v
> retrieving revision 1.15
> diff -u -p -r1.15 check.c
> --- gcc/fortran/check.c 4 Oct 2004 21:30:26 -0000 
1.15
> +++ gcc/fortran/check.c 30 Oct 2004 14:08:39 -0000
> @@ -2001,6 +2001,9 @@ gfc_check_system_clock 
(gfc_expr * count
>  try
>  gfc_check_irand (gfc_expr * x)
>  {
> +  if (x == NULL)
> +    return SUCCESS;
> +
>    if (scalar_check (x, 0) == FAILURE)
>      return FAILURE;
>  
> @@ -2016,6 +2019,9 @@ gfc_check_irand (gfc_expr * x)
>  try
>  gfc_check_rand (gfc_expr * x)
>  {
> +  if (x == NULL)
> +    return SUCCESS;
> +
>    if (scalar_check (x, 0) == FAILURE)
>      return FAILURE;
>  
> Index: gcc/fortran/intrinsic.c
> 
=======================================================
============
> RCS file: /var/cvsroot/gcc-
cvs/gcc/gcc/fortran/intrinsic.c,v
> retrieving revision 1.25
> diff -u -p -r1.25 intrinsic.c
> --- gcc/fortran/intrinsic.c	4 Oct 2004 
21:30:26 -0000	1.25
> +++ gcc/fortran/intrinsic.c 30 Oct 2004 14:07:40 -
0000
> @@ -1307,7 +1307,7 @@ add_functions (void)
>    /* The following function is for G77 
compatibility.  */
>    add_sym_1 ("irand", 0, 1, BT_INTEGER, 4,
>               gfc_check_irand, NULL, NULL,
> -             i, BT_INTEGER, 4, 0);
> +             i, BT_INTEGER, 4, 1);
>  
>    make_generic ("irand", GFC_ISYM_IRAND);
>  
> @@ -1602,7 +1602,7 @@ add_functions (void)
>    /* The following function is for G77 
compatibility.  */
>    add_sym_1 ("rand", 0, 1, BT_REAL, 4,
>               gfc_check_rand, NULL, NULL,
> -             i, BT_INTEGER, 4, 0);
> +             i, BT_INTEGER, 4, 1);
>  
>    /* Compatibility with HP FORTRAN 77/iX 
Reference.  Note, rand() and 
>       ran() use slightly different shoddy 
multiplicative congruential 
> Index: libgfortran/intrinsics/rand.c
> 
=======================================================
============
> RCS file: /var/cvsroot/gcc-
cvs/gcc/libgfortran/intrinsics/rand.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 rand.c
> --- libgfortran/intrinsics/rand.c 30 Jun 2004 
08:21:54 -0000 1.4
> +++ libgfortran/intrinsics/rand.c 30 Oct 2004 
14:01:16 -0000
> @@ -51,7 +51,11 @@ GFC_INTEGER_4
>  prefix(irand) (GFC_INTEGER_4 *i)
>  {
>    
> -  GFC_INTEGER_4 j = *i;
> +  GFC_INTEGER_4 j;
> +  if (i)
> +    j = *i;
> +  else
> +    j = 0;
>  
>    switch (j)
>    {
> 



Canqun Yang
Creative Compiler Research Group.
National University of Defense Technology, China.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]