OSDN Git Service

2007-09-22 Paul Thomas <pault@gcc.gnu.org>
authorpault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 22 Sep 2007 15:46:41 +0000 (15:46 +0000)
committerpault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 22 Sep 2007 15:46:41 +0000 (15:46 +0000)
PR fortran/33337
PR fortran/33376
* trans-decl.c (gfc_create_module_variable): Output
derived type parameters.
* arith.c (gfc_parentheses): Return the argument if
it is a constant expression.
* primary.c (gfc_match_rvalue): Remove the clearing of
the module name and the use_assoc attribute for derived
type parameter expressions.

2007-09-22  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/33337
* gfortran.dg/derived_comp_array_ref_3.f90: New test.

PR fortran/33376
* gfortran.dg/derived_comp_array_ref_4.f90: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@128672 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/arith.c
gcc/fortran/primary.c
gcc/fortran/trans-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/derived_comp_array_ref_3.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/derived_comp_array_ref_4.f90 [new file with mode: 0644]

index 36904b2..cb8f7cc 100644 (file)
@@ -1,3 +1,15 @@
+2007-09-22  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/33337
+       PR fortran/33376
+       * trans-decl.c (gfc_create_module_variable): Output
+       derived type parameters.
+       * arith.c (gfc_parentheses): Return the argument if
+       it is a constant expression.
+       * primary.c (gfc_match_rvalue): Remove the clearing of
+       the module name and the use_assoc attribute for derived
+       type parameter expressions.
+
 2007-09-22  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        PR fortran/33502
index 149f93f..7e3d0a4 100644 (file)
@@ -1793,6 +1793,9 @@ eval_intrinsic_f3 (gfc_intrinsic_op operator,
 gfc_expr *
 gfc_parentheses (gfc_expr *op)
 {
+  if (gfc_is_constant_expr (op))
+    return op;
+
   return eval_intrinsic_f2 (INTRINSIC_PARENTHESES, gfc_arith_identity,
                            op, NULL);
 }
index f622996..575a4c7 100644 (file)
@@ -2148,11 +2148,12 @@ gfc_match_rvalue (gfc_expr **result)
       if (sym->ts.is_c_interop || sym->ts.is_iso_c)
        break;
 
-      /* Variable array references to derived type parameters cause
-        all sorts of headaches in simplification.  Make them variable
-        and scrub any module identity because they do not appear to
-        be referencable from the module.  */  
-      if (sym->value && sym->ts.type == BT_DERIVED && e->ref)
+      /* Variable array references to use associated derived type
+        parameters cause all sorts of headaches in simplification.
+        For this reason, we write the parameter to the module and
+        treat them as variable references.  */  
+      if (sym->value && sym->ts.type == BT_DERIVED
+           && sym->attr.use_assoc && e->ref)
        {
          for (ref = e->ref; ref; ref = ref->next)
            if (ref->type == REF_ARRAY)
@@ -2168,8 +2169,6 @@ gfc_match_rvalue (gfc_expr **result)
          e->expr_type = EXPR_VARIABLE;
          e->symtree = symtree;
          e->ref = ref;
-         sym->attr.use_assoc = 0;
-         sym->module = NULL;
        }
 
       break;
index 854ca54..e27a04b 100644 (file)
@@ -2764,9 +2764,11 @@ gfc_create_module_variable (gfc_symbol * sym)
       && sym->ts.type == BT_DERIVED)
     sym->backend_decl = gfc_typenode_for_spec (&(sym->ts));
 
-  /* Only output variables and array valued parameters.  */
+  /* Only output variables and array valued, or derived type,
+     parameters.  */
   if (sym->attr.flavor != FL_VARIABLE
-      && (sym->attr.flavor != FL_PARAMETER || sym->attr.dimension == 0))
+       && !(sym->attr.flavor == FL_PARAMETER
+              && (sym->attr.dimension || sym->ts.type == BT_DERIVED)))
     return;
 
   /* Don't generate variables from other modules. Variables from
index 96387b2..bad8331 100644 (file)
@@ -1,3 +1,11 @@
+2007-09-22  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/33337
+       * gfortran.dg/derived_comp_array_ref_3.f90: New test.
+
+       PR fortran/33376
+       * gfortran.dg/derived_comp_array_ref_4.f90: New test.
+
 2007-09-22  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/33445
diff --git a/gcc/testsuite/gfortran.dg/derived_comp_array_ref_3.f90 b/gcc/testsuite/gfortran.dg/derived_comp_array_ref_3.f90
new file mode 100644 (file)
index 0000000..53d73e7
--- /dev/null
@@ -0,0 +1,29 @@
+! { dg-do run }
+! Tests the fix for PR33337, which was partly associated with
+! the problem in PR31564 and, in addition, the parentheses in
+! the initialization expression for the_chi_square.
+!
+! Contributed by Michael Richmond <michael.a.richmond@nasa.gov>
+!
+MODULE cdf_nc_chisq_mod
+  PUBLIC
+  TYPE :: one_parameter
+    INTEGER :: high_bound
+  END TYPE one_parameter
+  TYPE :: the_distribution
+    TYPE (one_parameter) :: parameters(1)
+  END TYPE the_distribution
+  TYPE (the_distribution), PARAMETER :: the_chi_square = &
+    the_distribution((/(one_parameter(99))/))
+CONTAINS
+  SUBROUTINE local_cum_nc_chisq()
+    integer :: df0
+    df0 = the_chi_square%parameters(1)%high_bound
+    print *, df0
+  END SUBROUTINE local_cum_nc_chisq
+END MODULE cdf_nc_chisq_mod
+
+  use cdf_nc_chisq_mod
+  call local_cum_nc_chisq
+end
+! { dg-final { cleanup-modules "cdf_aux_mod cdf_beta_mod" } }
diff --git a/gcc/testsuite/gfortran.dg/derived_comp_array_ref_4.f90 b/gcc/testsuite/gfortran.dg/derived_comp_array_ref_4.f90
new file mode 100644 (file)
index 0000000..0c78539
--- /dev/null
@@ -0,0 +1,38 @@
+! { dg-do run }
+! Tests the fix for PR33376, which was a regression caused by the
+! fix for PR31564.
+!
+! Contributed by Harald Anlauf <anlauf@gmx.de>
+!
+module foo
+  implicit none
+  public chk
+
+  type mytype
+    character(len=4) :: str
+  end type mytype
+  type (mytype) ,parameter :: chk (2) &
+                      = (/ mytype ("abcd") , mytype ("efgh") /)
+end module foo
+
+module gfcbug70
+  use foo, only: chk_ => chk
+  implicit none
+contains
+
+  subroutine chk (i)
+    integer, intent(in) :: i
+    if (i .eq. 1) then
+      if (chk_(i)% str .ne. "abcd") call abort ()
+    else
+      if (chk_(i)% str .ne. "efgh") call abort ()
+    end if
+
+  end subroutine chk
+end module gfcbug70
+
+  use gfcbug70
+  call chk (2)
+  call chk (1)
+end
+! { dg-final { cleanup-modules "foo gfcbug70" } }