[Committed] PR fortran/77420

2016-09-26 Thread Steve Kargl
This is a follow-up commit to really fix PR fortran/77420.
The code has been in my tree for 2 weeks and has passed
numerous regression tests.

2016-09-26  Steven G. Kargl  

PR fortran/77420
* trans-common.c:  Handle array elements in equivalence when
the lower and upper bounds of array spec are NULL.
 
2016-09-26  Steven G. Kargl  

PR fortran/77420
* gfortran.dg/pr77420_1.f90: New test.
* gfortran.dg/pr77420_2.f90: Ditto.
* gfortran.dg/pr77420_3.f90: New test. Requires ...
* gfortran.dg/pr77420_4.f90: this file.

-- 
Steve
Index: gcc/fortran/trans-common.c
===
--- gcc/fortran/trans-common.c	(revision 240140)
+++ gcc/fortran/trans-common.c	(working copy)
@@ -805,13 +805,21 @@ element_number (gfc_array_ref *ar)
   if (ar->dimen_type[i] != DIMEN_ELEMENT)
 gfc_internal_error ("element_number(): Bad dimension type");
 
-  mpz_sub (n, *get_mpz (ar->start[i]), *get_mpz (as->lower[i]));
+  if (as && as->lower[i])
+	mpz_sub (n, *get_mpz (ar->start[i]), *get_mpz (as->lower[i]));
+  else
+	mpz_sub_ui (n, *get_mpz (ar->start[i]), 1);
  
   mpz_mul (n, n, multiplier);
   mpz_add (offset, offset, n);
  
-  mpz_sub (extent, *get_mpz (as->upper[i]), *get_mpz (as->lower[i]));
-  mpz_add_ui (extent, extent, 1);
+  if (as && as->upper[i] && as->lower[i])
+	{
+	  mpz_sub (extent, *get_mpz (as->upper[i]), *get_mpz (as->lower[i]));
+	  mpz_add_ui (extent, extent, 1);
+	}
+  else
+	mpz_set_ui (extent, 0);
  
   if (mpz_sgn (extent) < 0)
 mpz_set_ui (extent, 0);
Index: gcc/testsuite/gfortran.dg/pr77420_1.f90
===
--- gcc/testsuite/gfortran.dg/pr77420_1.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr77420_1.f90	(working copy)
@@ -0,0 +1,15 @@
+! { dg-do compile }
+module test_equivalence
+  real, private :: array1(100)
+  real, private :: array2(100)
+  equivalence(array1(3),array2(3))
+end module test_equivalence
+
+module mymodule
+  use test_equivalence
+  real, dimension(:), allocatable :: array1
+end module mymodule
+
+program test
+  use mymodule
+end program test
Index: gcc/testsuite/gfortran.dg/pr77420_2.f90
===
--- gcc/testsuite/gfortran.dg/pr77420_2.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr77420_2.f90	(working copy)
@@ -0,0 +1,15 @@
+! { dg-do compile }
+module test_equivalence
+  real, private :: array1(100)
+  real, private :: array2(100)
+  equivalence(array1,array2)
+end module test_equivalence
+
+module mymodule
+  use test_equivalence
+  real, dimension(:), allocatable :: array1
+end module mymodule
+
+program test
+  use mymodule
+end program test
Index: gcc/testsuite/gfortran.dg/pr77420_3.f90
===
--- gcc/testsuite/gfortran.dg/pr77420_3.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr77420_3.f90	(working copy)
@@ -0,0 +1,9 @@
+! { dg-do link }
+! { dg-additional-sources pr77420_4.f90 }
+!
+module h5global
+  implicit none
+  integer :: h5p_default_f, h5p_flags
+  equivalence(h5p_flags, h5p_default_f)
+end module h5global
+! { dg-final { cleanup-modules "h5global" } }
Index: gcc/testsuite/gfortran.dg/pr77420_4.f90
===
--- gcc/testsuite/gfortran.dg/pr77420_4.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr77420_4.f90	(working copy)
@@ -0,0 +1,10 @@
+! { dg-do compile { target { ! *-*-* } } }
+!
+program bug
+  use H5GLOBAL
+  implicit none
+  integer :: i
+  i=H5P_DEFAULT_F
+end program bug
+
+


Re: [Committed] PR fortran/77420 -- revert previous commit

2016-09-13 Thread Jakub Jelinek
On Tue, Sep 13, 2016 at 10:05:56AM -0700, Steve Kargl wrote:
> --- gcc/fortran/module.c  (revision 240117)
> +++ gcc/fortran/module.c  (working copy)
> @@ -4647,7 +4647,7 @@ load_equiv (void)
>}
>  
>  /* Check for duplicate equivalences being loaded from different modules 
> */
> -duplicate = gfc_current_ns->equiv ? false:true;

Just a nit.  This would have been better written as !gfc_current_ns->equiv;
and if not, it is badly formatted (it should be ? false : true;).

Jakub


[Committed] PR fortran/77420 -- revert previous commit

2016-09-13 Thread Steve Kargl
I've reverted my previous fix for PR fortran/77420.
It was causing a regression that could, in principle,
effect a significant nubmer of gfortran users. 

2016-09-13  Steven G. Kargl  

PR fortran/77420
* module.c (load_equiv):  Revert revision 240063.

2016-09-13  Steven G. Kargl  

PR fortran/77420
* gfortran.dg/pr77420.f90: Revert revision 240063 by removing test.

Index: gcc/fortran/module.c
===
--- gcc/fortran/module.c(revision 240117)
+++ gcc/fortran/module.c(working copy)
@@ -4647,7 +4647,7 @@ load_equiv (void)
   }
 
 /* Check for duplicate equivalences being loaded from different modules */
-duplicate = gfc_current_ns->equiv ? false:true;
+duplicate = false;
 for (equiv = gfc_current_ns->equiv; equiv; equiv = equiv->next)
   {
if (equiv->module && head->module
Index: gcc/testsuite/ChangeLog
===
--- gcc/testsuite/ChangeLog (revision 240117)
+++ gcc/testsuite/ChangeLog (working copy)
@@ -84,13 +84,6 @@
PR rtl-optimization/77289
* gcc.target/powerpc/pr77289.c: New test.
 
-2016-09-09  Steven G. Kargl  
-
-   PR fortran/77420
-   * module.c (load_equiv): If the current namespace has a list of
-   equivalence statements, initialize duplicate to false and then
-   look for duplicates; otherwise, initialize it to true.
-
 2016-09-09  Martin Sebor  
 
PR c/77520
@@ -100,11 +93,6 @@
 
 2016-09-09  Steven G. Kargl  
 
-   PR fortran/77420
-   * gfortran.dg/pr77420.f90: New test.
-
-2016-09-09  Steven G. Kargl  
-
PR fortran/77506
* gfortran.dg/pr77506.f90: New test.
 
Index: gcc/testsuite/gfortran.dg/pr77420.f90
===
--- gcc/testsuite/gfortran.dg/pr77420.f90   (revision 240117)
+++ gcc/testsuite/gfortran.dg/pr77420.f90   (nonexistent)
@@ -1,18 +0,0 @@
-! { dg-do compile }
-MODULE test_equivalence
-  REAL, PRIVATE, DIMENSION(100) :: array1
-  REAL, PRIVATE, DIMENSION(100) :: array2
-  EQUIVALENCE(array1(1),array2(1))
-END MODULE test_equivalence
-
-MODULE mymodule
-  USE test_equivalence
-  ! declare a local variable with the same name as the (private!)
-  ! variable in module test_equivalence:
-  REAL, DIMENSION(:), ALLOCATABLE :: array1
-END MODULE mymodule
-
-PROGRAM test
-  USE mymodule
-END PROGRAM test
-

-- 
Steve


[Committed] PR fortran/77420

2016-09-09 Thread Steve Kargl
I've committed the following patch.  It restores gfortran's
behavior prior to my commit r224159 if the current namespace
has an empty equivalent list.

2016-09-09  Steven G. Kargl  

PR fortran/77420
* module.c (load_equiv): If the current namespace has a list of
equivalence statements, initialize duplicate to false and then
look for duplicates; otherwise, initialize it to true.
 
2016-09-09  Steven G. Kargl  

PR fortran/77420
* gfortran.dg/pr77420.f90: New test.


Index: gcc/fortran/module.c
===
--- gcc/fortran/module.c(revision 240057)
+++ gcc/fortran/module.c(working copy)
@@ -4647,7 +4647,7 @@ load_equiv (void)
   }
 
 /* Check for duplicate equivalences being loaded from different modules */
-duplicate = false;
+duplicate = gfc_current_ns->equiv ? false:true;
 for (equiv = gfc_current_ns->equiv; equiv; equiv = equiv->next)
   {
if (equiv->module && head->module
Index: gcc/testsuite/gfortran.dg/pr77420.f90
===
--- gcc/testsuite/gfortran.dg/pr77420.f90   (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr77420.f90   (working copy)
@@ -0,0 +1,18 @@
+! { dg-do compile }
+MODULE test_equivalence
+  REAL, PRIVATE, DIMENSION(100) :: array1
+  REAL, PRIVATE, DIMENSION(100) :: array2
+  EQUIVALENCE(array1(1),array2(1))
+END MODULE test_equivalence
+
+MODULE mymodule
+  USE test_equivalence
+  ! declare a local variable with the same name as the (private!)
+  ! variable in module test_equivalence:
+  REAL, DIMENSION(:), ALLOCATABLE :: array1
+END MODULE mymodule
+
+PROGRAM test
+  USE mymodule
+END PROGRAM test
+
-- 
Steve