Bug 33636 - Rejects valid use of vector subscript in derived type parameter
Summary: Rejects valid use of vector subscript in derived type parameter
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Francois-Xavier Coudert
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: patch, rejects-valid
Depends on:
Blocks: 32834
  Show dependency treegraph
Reported: 2007-10-03 12:27 UTC by Francois-Xavier Coudert
Modified: 2007-10-10 13:41 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2007-10-10 11:23:10


Note You need to log in before you can comment on or make changes to this bug.
Description Francois-Xavier Coudert 2007-10-03 12:27:09 UTC
This was seen on ppc-darwin and x86_64-linux with -m32:

$ cat x.f90
  implicit none
  type vec3
    integer, dimension(1) :: coords
  end type vec3
  type(vec3), parameter :: v1 = vec3((/ 0 /))
  integer :: i

  i = 1
  print *, v1%coords ((/i/))
$ gfortran -m32 x.f90

  print *, v1%coords ((/i/))
Error: index in dimension 1 is out of bounds at (1)
Comment 1 Dominique d'Humieres 2007-10-03 13:03:49 UTC
On PPC Darwin, I get:

[karma] f90/bug% gfc pr33636.f90
[karma] f90/bug% a.out
[karma] f90/bug% gfc -m64 pr33636.f90
[karma] f90/bug% a.out
[karma] f90/bug% gfc /opt/gcc/_gcc-clean/gcc/testsuite/gfortran.dg/derived_comp_array_ref_5.f90

      v2 = vec3 (v1%coords ((/i+1, i, i-1/))) ! also broken
Error: index in dimension 1 is out of bounds at (1)
[karma] f90/bug% gfc -m64 /opt/gcc/_gcc-clean/gcc/testsuite/gfortran.dg/derived_comp_array_ref_5.f90
[karma] f90/bug% a.out 
[karma] f90/bug% 

i.e., the test case of this PR compiles for both 32 and 64 bit modes for gcc version 4.3.0 20071002, while derived_comp_array_ref_5.f90 compiles only in 64 bit mode (wrong cast somewhere?-)
Comment 2 Paul Thomas 2007-10-06 17:17:20 UTC
(In reply to comment #1)

Needless to say, it was developed on a 64bit machine.

Thanks, Dominique

Comment 3 Francois-Xavier Coudert 2007-10-10 11:23:10 UTC
The problem is that we try simplification in find_array_section() because the vector subscript is EXPR_ARRAY, which is not necessarily constant (in this case, the values in the constructor depend on variable i). So, the check for constantness needs to call gfc_is_constant_expr(), as in the patch below.

(This was hidden on 64-bit machines because there, expressions "i", "i+1" and "i-1" have to be converted to integer(8), which means the vector subscript isn't an EXPR_ARRAY but and EXPR_FUNCTION. Thus, we bailed out of the simplification business.)

Index: expr.c
--- expr.c      (revision 129054)
+++ expr.c      (working copy)
@@ -1165,7 +1165,7 @@ find_array_section (gfc_expr *expr, gfc_
          gcc_assert (begin);

-         if (begin->expr_type != EXPR_ARRAY)
+         if (begin->expr_type != EXPR_ARRAY || !gfc_is_constant_expr (begin))
              t = FAILURE;
              goto cleanup;
Comment 4 Francois-Xavier Coudert 2007-10-10 13:38:53 UTC
Subject: Bug 33636

Author: fxcoudert
Date: Wed Oct 10 13:38:38 2007
New Revision: 129208

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129208
	PR fortran/33636
	* expr.c (find_array_section): Check for constructor constantness.


Comment 5 Francois-Xavier Coudert 2007-10-10 13:41:11 UTC