public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/77420 -- take two
@ 2016-09-14 22:11 Steve Kargl
  2016-09-15  4:04 ` Jerry DeLisle
  0 siblings, 1 reply; 2+ messages in thread
From: Steve Kargl @ 2016-09-14 22:11 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 833 bytes --]

The attached patch appears to fix PR fortran/77420 without
causing regressions.  The problem raised by Andrew Benson at
https://gcc.gnu.org/ml/fortran/2016-09/msg00039.html
contained in pr77420_3.f90 and pr77420_4.f90.  The original
testcase from the PR is in pr77420_1.f90 and a variation
on that testcase is in pr77420_2.f90.  Patch has been
regression tested on x86_64-*-freebsd.  OK to commit?

2016-09-14  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/77420
	* trans-common.c:  Handle array elements in equivalence when
	the lower and upper bounds of array spec are NULL.
 
2016-09-14  Steven G. Kargl  <kargl@gcc.gnu.org>

	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

[-- Attachment #2: pr77420.diff --]
[-- Type: text/x-diff, Size: 3110 bytes --]

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
+
+

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] PR fortran/77420 -- take two
  2016-09-14 22:11 [PATCH] PR fortran/77420 -- take two Steve Kargl
@ 2016-09-15  4:04 ` Jerry DeLisle
  0 siblings, 0 replies; 2+ messages in thread
From: Jerry DeLisle @ 2016-09-15  4:04 UTC (permalink / raw)
  To: kargl, fortran, gcc-patches

On 09/14/2016 02:49 PM, Steve Kargl wrote:
> The attached patch appears to fix PR fortran/77420 without
> causing regressions.  The problem raised by Andrew Benson at
> https://gcc.gnu.org/ml/fortran/2016-09/msg00039.html
> contained in pr77420_3.f90 and pr77420_4.f90.  The original
> testcase from the PR is in pr77420_1.f90 and a variation
> on that testcase is in pr77420_2.f90.  Patch has been
> regression tested on x86_64-*-freebsd.  OK to commit?

Yes OK,

Thanks  Steve

>
> 2016-09-14  Steven G. Kargl  <kargl@gcc.gnu.org>
>
> 	PR fortran/77420
> 	* trans-common.c:  Handle array elements in equivalence when
> 	the lower and upper bounds of array spec are NULL.
>
> 2016-09-14  Steven G. Kargl  <kargl@gcc.gnu.org>
>
> 	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.
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-15  3:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-14 22:11 [PATCH] PR fortran/77420 -- take two Steve Kargl
2016-09-15  4:04 ` Jerry DeLisle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).