User account creation filtered due to spam.

Bug 33317 - CSHIFT/EOSHIFT: Rejects optional dummy for DIM=
Summary: CSHIFT/EOSHIFT: Rejects optional dummy for DIM=
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Jerry DeLisle
URL:
Keywords: rejects-valid
Depends on:
Blocks: 32834 34540
  Show dependency treegraph
 
Reported: 2007-09-05 20:59 UTC by Tobias Burnus
Modified: 2007-12-23 16:43 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-11-14 05:20:33


Attachments
New patch for testing on Darwin and ppc (1.23 KB, patch)
2007-11-20 04:46 UTC, Jerry DeLisle
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-09-05 20:59:44 UTC
The following program should print twice "T T T T" as if DIM is not present, 1 is assumed.

The standard does not forbid to pass a variable which has the OPTIONAL attribute to CSHIFT. NAG f95 and ifort print as expected twice "T T T T".

gfortran simply crashes.

program test
 implicit none
 call sub(1)
 call sub()
contains
 subroutine sub(d)
   integer, optional :: d
   print *, cshift([.true.,.true.,.true.,.true.],1,d)
 end subroutine
end program test
Comment 1 Tobias Burnus 2007-09-05 21:04:25 UTC
Same for EOSHIFT, example (replace in above's program)

   print *, eoshift([.true.,.true.,.true.,.true.],1,dim=d)

ifort and NAG f95 print twice "T T T F".
Comment 2 Tobias Burnus 2007-09-05 21:20:06 UTC
Correction: gfortran rejects this currently and does not accept it and crash; better than crashing but still wrong.
(I modified check.c's dim_check and enabled it accidentally.)
Comment 3 Dominique d'Humieres 2007-10-25 09:39:46 UTC
On Darwin with revision 129623, the orginal code gives:

pr33317.f90:8.51:

   print *, cshift([.true.,.true.,.true.,.true.],1,d)
                                                  1
Error: 'dim' argument of 'cshift' intrinsic at (1) must not be OPTIONAL

while

program test
 implicit none
 call sub(1)
 call sub()
contains
 subroutine sub(d)
   integer, optional :: d
   if (present(d)) then
      print *, eoshift((/.true.,.true.,.true.,.true./),1,d)
   else
      print *, eoshift((/.true.,.true.,.true.,.true./),1)
   end if
 end subroutine
end program test

ICE with:

pr33317_db_1.f90:9.61:

      print *, eoshift((/.true.,.true.,.true.,.true./),1,dim=d)
                                                            1
pr33317_db_1.f90:0: internal compiler error: Bus error
Comment 4 Jerry DeLisle 2007-11-16 06:23:34 UTC
program test
 implicit none
 call sub(1)
 call sub()
contains
 subroutine sub(dimmy)
   integer, optional :: dimmy
   logical :: lotto(4)
   lotto = .false.
   lotto = cshift((/.true.,.true.,.true.,.true./),1,dimmy)
   print *, lotto
 end subroutine
end program test

After enabling the optional argument with -m32 -fdump-tree-original we get:

sub (dimmy)
{
  logical4 lotto[4];

  (void) __builtin_memset ((void *) &lotto, 0, 16);
  {
    int4 * D.515;
    static int4 C.514 = 1;
    struct array1_logical4 parm.2;
    static logical4 A.1[4] = {1, 1, 1, 1};
    struct array1_logical4 parm.0;

    parm.0.dtype = 273;
    parm.0.dim[0].lbound = 1;
    parm.0.dim[0].ubound = 4;
    parm.0.dim[0].stride = 1;
    parm.0.data = (void *) &lotto[0];
    parm.0.offset = -1;
    parm.2.dtype = 273;
    parm.2.dim[0].lbound = 1;
    parm.2.dim[0].ubound = 4;
    parm.2.dim[0].stride = 1;
    parm.2.data = (void *) &A.1[0];
    parm.2.offset = 0;
    D.515 = dimmy != 0B ? dimmy : 0B;
    _gfortran_cshift0_4 (&parm.0, &parm.2, &C.514, D.515);
  }
 and it works as expected.

With -m64 it obviously fails with the following:

sub (dimmy)
{
  logical4 lotto[4];

  (void) __builtin_memset ((void *) &lotto, 0, 16);
  {
    int4 D.874;
    static int4 C.873 = 1;
    struct array1_logical4 parm.2;
    static logical4 A.1[4] = {1, 1, 1, 1};
    struct array1_logical4 parm.0;

    parm.0.dtype = 273;
    parm.0.dim[0].lbound = 1;
    parm.0.dim[0].ubound = 4;
    parm.0.dim[0].stride = 1;
    parm.0.data = (void *) &lotto[0];
    parm.0.offset = -1;
    parm.2.dtype = 273;
    parm.2.dim[0].lbound = 1;
    parm.2.dim[0].ubound = 4;
    parm.2.dim[0].stride = 1;
    parm.2.data = (void *) &A.1[0];
    parm.2.offset = 0;
    D.874 = *dimmy;
    _gfortran_cshift0_4 (&parm.0, &parm.2, &C.873, &D.874);
  }
Comment 5 Jerry DeLisle 2007-11-17 18:22:38 UTC
The problem here is that when we resolve cshift and eoshift we convert dim from a EXPR_VARIABLE to a EXPR_FUNCTION that converts the type to match up with the runtime function.

Later in trans-expr.c, code is not built to test for NULL and set dim to the default of 1 since dim is no longer a variable and there is nothing in gfc_conv_function_call to handle it.  It is normally handled by gfc_conv_missing_dummy.

Further complicating this, the conversion of type function, such as convert_i8_i4 which gets simplified to a cast segfaults when dim is NULL.

I think the solution is to build the type conversion later in gfc_conv_missing_dummy after building the test for NULL.
Comment 6 Jerry DeLisle 2007-11-18 20:59:53 UTC
Subject: Bug 33317

Author: jvdelisle
Date: Sun Nov 18 20:59:41 2007
New Revision: 130277

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130277
Log:
2007-11-18  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/33317
	* gfortran.dg/optional_dim_2.f90: New test.
	
	PR fortran/34139
	* gfortran.dg/subref_array_pointer_2.f90: Update test condition.

Added:
    trunk/gcc/testsuite/gfortran.dg/optional_dim_2.f90
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/subref_array_pointer_2.f90

Comment 7 Jerry DeLisle 2007-11-18 21:15:09 UTC
Fixed on trunk. Rev 130276

http://gcc.gnu.org/viewcvs/trunk/gcc/fortran/check.c?view=log&pathrev=130276
Comment 8 Dominique d'Humieres 2007-11-18 22:46:15 UTC
Sorry to reopen the bug, but I have a lot of failures in my tests. A reduced case is:

integer(8) :: i
i = 1_8  
print *, cshift((/.true.,.false.,.true.,.false./),1,dim=i)
end

which fails at runtime with:

Fortran runtime error: Argument 'DIM' is out of range in call to 'CSHIFT'

As this is on PPC Darwin8, while this works on Intel Darwin9, could the problem be related to some endian issue?

Comment 9 Jerry DeLisle 2007-11-18 23:45:05 UTC
No sorry necessary.  Could you post the -fdump-tree-original for your test case?

In the mean time I will get logged on to a linux PPC machine and see if I see it there.

Comment 10 Jerry DeLisle 2007-11-19 01:22:53 UTC
I found the problem.  We key off of the kind of shift to determine which version of the runtime to resolve to.  In your test case, shift is kind=4 so we load in the cshift0_4 instead of the cshift0_8 version of cshift.  It shows up because of endianess on PPC.

I was able to reproduce this on ppc linux.

Regardless, I will work up a patch.
Comment 11 Jerry DeLisle 2007-11-19 06:05:36 UTC
Regressed on PPC.  I am working on a fix.  If I can not fix by end of tomorrow, I will revert the previous patch
Comment 12 Dominique d'Humieres 2007-11-19 08:07:55 UTC
Additional problem: gfortran.dg/optional_dim_2.f90 segfaults with -m64 on Intel Darwin9.

Comment 13 Jerry DeLisle 2007-11-20 01:37:56 UTC
Subject: Bug 33317

Author: jvdelisle
Date: Tue Nov 20 01:37:43 2007
New Revision: 130304

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130304
Log:
2007-11-19  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/33317
	* trans-expr.c (gfc_conv_missing_dummy): Revert.
	* iresolve.c (gfc_resolve_cshift): Revert.
	(gfc_resolve_eoshift): Likewise.
	* check.c (gfc_check_cshift): Revert.
	(gfc_check_eoshift): Likewise.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/check.c
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/fortran/trans-expr.c

Comment 14 Jerry DeLisle 2007-11-20 01:51:15 UTC
Subject: Bug 33317

Author: jvdelisle
Date: Tue Nov 20 01:51:04 2007
New Revision: 130305

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130305
Log:
2007-11-19  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/33317
	* gfortran.dg/optional_dim_2.f90: Remove test.

Removed:
    trunk/gcc/testsuite/gfortran.dg/optional_dim_2.f90
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 15 Jerry DeLisle 2007-11-20 04:46:50 UTC
Created attachment 14583 [details]
New patch for testing on Darwin and ppc

This patch regrssion tests OK on powerpc-linux-gnu.  Please test on the Darwin Intel and ppc if you can.  The patch is against current trunk.
Comment 16 patchapp@dberlin.org 2007-11-20 05:04:24 UTC
Subject: Bug number PR33317

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-11/msg00962.html
Comment 17 patchapp@dberlin.org 2007-11-23 15:15:35 UTC
Subject: Bug number PR33317

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-11/msg01228.html
Comment 18 Jerry DeLisle 2007-11-24 00:25:13 UTC
Subject: Bug 33317

Author: jvdelisle
Date: Sat Nov 24 00:25:01 2007
New Revision: 130391

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130391
Log:
2007-11-23  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/34209
	* iresolve.c (gfc_resolve_nearest): If sign variable kind does not match
	kind of input variable, convert it to match.

	PR fortran/33317
	* trans.h: Modify prototype for gfc_conv_missing_dummy.
	* trans-expr.c (gfc_conv_missing_dummy): Modify to pass an integer kind
	parameter in.  Set the type of the dummy to the kind given.
	(gfc_conv_function_call): Pass representation.length to
	gfc_conv_missing_dummy.
	* iresolve.c (gfc_resolve_cshift): Determine the correct kind to use and
	if appropriate set representation.length to this kind value.
	(gfc_resolve_eoshift): Likewise.
	* check.c (gfc_check_cshift): Enable dim_check to allow DIM as an
	optional argument. (gfc_check_eoshift): Likewise.
	* trans_intrinsic.c (gfc_conv_intrinsic_function_args): Update call to
	gfc_conv_missing_dummy.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/check.c
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/fortran/trans.h

Comment 19 Jerry DeLisle 2007-11-24 00:29:24 UTC
Subject: Bug 33317

Author: jvdelisle
Date: Sat Nov 24 00:29:14 2007
New Revision: 130392

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130392
Log:
2007-11-23  Tobias Burnus  <burnus@net-b.de>

	PR fortran/34209
	* gfortran.dg/nearest_3.f90: New test.

2007-11-23  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/33317
	* gfortran.dg/optional_dim_2.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/nearest_3.f90
    trunk/gcc/testsuite/gfortran.dg/optional_dim_2.f90
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 20 Jerry DeLisle 2007-11-24 00:36:42 UTC
Fixed on trunk.