Please find attached a patch to replace the test cases for "Automatic in
equivalence".
ChangeLog:
Mark Eggleston <mark.eggles...@codethink.com>
* gfortran.dg/auto_in_equiv_1.f90: Deleted.
* gfortran.dg/auto_in_equiv_2.f90: Deleted.
* gfortran.dg/auto_in_equiv_3.f90: Deleted.
* gfortran.dg/automatics_in_equivalence_1.f90: New test.
* gfortran.dg/automatics_in_equivalence_2.f90: New test.
OK to commit?
regards,
Mark
On 30/09/2019 13:18, Mark Eggleston wrote:
On 30/09/2019 10:06, Mark Eggleston wrote:
Thanks to Tobias Burnius for fixing the dg directives in test cases.
Now that the test cases for "Automatics in equivalence" (svn revision
274565) are actually being run, test failures are occurring.
I've investigated the test failures for auto-in-equiv_3.f90:
- -O1, -O2, -O3 and -Os fail
- -O1 fails because the check of address fails due to a 40 byte
difference in location of the stack
- -O2, -O3 and -Os fail due the evaluation of an .and. operation
returning .false. when both operands are .true..
The test case could be better and should probably be replaced with a
better one.
I've discovered that -finit-local-zero doesn't work if the local
variable is in an equivalence statement where at least one the
variables has an AUTOMATIC attribute.
On further investigation I find that local variables are not
initialised if the EQUIVALENCE attribute is set
(build_default_init_expr). So this is expected behaviour. So back to
the drawing board for a suitable test case.
What is the best way of dealing with this? Reverting the commit and
resubmitting a corrected patch when it's been fixed?
regards,
Mark
--
https://www.codethink.co.uk/privacy.html
>From e461900f602b48e8d13402fca46d34506308785f Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggles...@codethink.com>
Date: Wed, 2 Oct 2019 10:23:49 +0100
Subject: [PATCH] Replace test cases for Automatics in equivalence
---
gcc/testsuite/gfortran.dg/auto_in_equiv_1.f90 | 36 -------------
gcc/testsuite/gfortran.dg/auto_in_equiv_2.f90 | 38 -------------
gcc/testsuite/gfortran.dg/auto_in_equiv_3.f90 | 63 ----------------------
.../gfortran.dg/automatics_in_equivalence_1.f90 | 35 ++++++++++++
.../gfortran.dg/automatics_in_equivalence_2.f90 | 37 +++++++++++++
5 files changed, 72 insertions(+), 137 deletions(-)
delete mode 100644 gcc/testsuite/gfortran.dg/auto_in_equiv_1.f90
delete mode 100644 gcc/testsuite/gfortran.dg/auto_in_equiv_2.f90
delete mode 100644 gcc/testsuite/gfortran.dg/auto_in_equiv_3.f90
create mode 100644 gcc/testsuite/gfortran.dg/automatics_in_equivalence_1.f90
create mode 100644 gcc/testsuite/gfortran.dg/automatics_in_equivalence_2.f90
diff --git a/gcc/testsuite/gfortran.dg/auto_in_equiv_1.f90 b/gcc/testsuite/gfortran.dg/auto_in_equiv_1.f90
deleted file mode 100644
index bf6e0c68a57..00000000000
--- a/gcc/testsuite/gfortran.dg/auto_in_equiv_1.f90
+++ /dev/null
@@ -1,36 +0,0 @@
-! { dg-do compile }
-
-! Contributed by Mark Eggleston <mark.eggles...@codethink.com>
-program test
- call suba(0)
- call subb(0)
- call suba(1)
-
-contains
- subroutine suba(option)
- integer, intent(in) :: option
- integer, automatic :: a ! { dg-error "AUTOMATIC at \\(1\\) is a DEC extension" }
- integer :: b
- integer :: c
- equivalence (a, b)
- if (option.eq.0) then
- ! initialise a and c
- a = 9
- c = 99
- if (a.ne.b) stop 1
- if (loc(a).ne.loc(b)) stop 2
- else
- ! a should've been overwritten
- if (a.eq.9) stop 3
- end if
- end subroutine suba
-
- subroutine subb(dummy)
- integer, intent(in) :: dummy
- integer, automatic :: x ! { dg-error "AUTOMATIC at \\(1\\) is a DEC extension" }
- integer :: y
- x = 77
- y = 7
- end subroutine subb
-
-end program test
diff --git a/gcc/testsuite/gfortran.dg/auto_in_equiv_2.f90 b/gcc/testsuite/gfortran.dg/auto_in_equiv_2.f90
deleted file mode 100644
index e40c0f15f3e..00000000000
--- a/gcc/testsuite/gfortran.dg/auto_in_equiv_2.f90
+++ /dev/null
@@ -1,38 +0,0 @@
-! { dg-do run }
-! { dg-options "-fdec-static" }
-
-! Contributed by Mark Eggleston <mark.eggles...@codethink.com>
-
-program test
- call suba(0)
- call subb(0)
- call suba(1)
-
-contains
- subroutine suba(option)
- integer, intent(in) :: option
- integer, automatic :: a
- integer :: b
- integer :: c
- equivalence (a, b)
- if (option.eq.0) then
- ! initialise a and c
- a = 9
- c = 99
- if (a.ne.b) stop 1
- if (loc(a).ne.loc(b)) stop 2
- else
- ! a should've been overwritten
- if (a.eq.9) stop 3
- end if
- end subroutine suba
-
- subroutine subb(dummy)
- integer, intent(in) :: dummy
- integer, automatic :: x
- integer :: y
- x = 77
- y = 7
- end subroutine subb
-
-end program test
diff --git a/gcc/testsuite/gfortran.dg/auto_in_equiv_3.f90 b/gcc/testsuite/gfortran.dg/auto_in_equiv_3.f90
deleted file mode 100644
index 57c384d1772..00000000000
--- a/gcc/testsuite/gfortran.dg/auto_in_equiv_3.f90
+++ /dev/null
@@ -1,63 +0,0 @@
-! { dg-do run }
-! { dg-options "-fdec-static -fno-automatic" }
-
-! Contributed by Mark Eggleston <mark.eggles...@codethink.com>
-
-! Storage is NOT on the static unless explicitly specified using the
-! DEC extension "automatic". The address of the first local variable
-! is used to determine that storage for the automatic local variable
-! is different to that of a local variable with no attributes. The
-! contents of the local variable in suba should be overwritten by the
-! call to subb.
-!
-program test
- integer :: dummy
- integer, parameter :: address = kind(loc(dummy))
- integer(address) :: ad1
- integer(address) :: ad2
- integer(address) :: ad3
- logical :: ok
-
- call suba(0, ad1)
- call subb(0, ad2)
- call suba(1, ad1)
- call subc(0, ad3)
- ok = (ad1.eq.ad3).and.(ad1.ne.ad2)
- if (.not.ok) stop 4
-
-contains
- subroutine suba(option, addr)
- integer, intent(in) :: option
- integer(address), intent(out) :: addr
- integer, automatic :: a
- integer :: b
- equivalence (a, b)
- addr = loc(a)
- if (option.eq.0) then
- ! initialise a and c
- a = 9
- if (a.ne.b) stop 1
- if (loc(a).ne.loc(b)) stop 2
- else
- ! a should've been overwritten
- if (a.eq.9) stop 3
- end if
- end subroutine suba
-
- subroutine subb(dummy, addr)
- integer, intent(in) :: dummy
- integer(address), intent(out) :: addr
- integer :: x
- addr = loc(x)
- x = 77
- end subroutine subb
-
- subroutine subc(dummy, addr)
- integer, intent(in) :: dummy
- integer(address), intent(out) :: addr
- integer, automatic :: y
- addr = loc(y)
- y = 77
- end subroutine subc
-
-end program test
diff --git a/gcc/testsuite/gfortran.dg/automatics_in_equivalence_1.f90 b/gcc/testsuite/gfortran.dg/automatics_in_equivalence_1.f90
new file mode 100644
index 00000000000..2791675af1b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/automatics_in_equivalence_1.f90
@@ -0,0 +1,35 @@
+! { dg-do run }
+! { dg-options "-fdec-static -frecursive" }
+
+! Contributed by Mark Eggleston <mark.eggles...@codethink.com>
+!
+! Check automatic variables can be used in equivalence statements.
+! Any other variables that do not explicitly have the automatic
+! attribute will be given the automatic attribute.
+!
+! Check that variables are on the stack by incorporating the
+! equivalence in a recursive function.
+!
+program test
+ integer :: f
+
+ f = factorial(5)
+ if (f.ne.120) stop 2
+
+contains
+ function factorial(n) result(f)
+ integer :: f
+ integer, intent(in) :: n
+ integer, automatic :: a
+ integer :: b
+ equivalence (a,b)
+
+ if (loc(a).ne.loc(b)) stop 1
+ b = n
+ if (a.eq.1) then
+ f = 1
+ else
+ f = a * factorial(b-1)
+ end if
+ end function
+end program test
diff --git a/gcc/testsuite/gfortran.dg/automatics_in_equivalence_2.f90 b/gcc/testsuite/gfortran.dg/automatics_in_equivalence_2.f90
new file mode 100644
index 00000000000..626db5835b8
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/automatics_in_equivalence_2.f90
@@ -0,0 +1,37 @@
+! { dg-do run }
+! { dg-options "-fdec-static -frecursive -fno-automatic" }
+
+! Contributed by Mark Eggleston <mark.eggles...@codethink.com>
+!
+! Check automatic variables can be used in equivalence statements.
+! Any other variables that do not explicitly have the automatic
+! attribute will be given the automatic attribute.
+!
+! Check that variables are on the stack by incorporating the
+! equivalence in a recursive function.
+!
+program test
+ integer :: f
+
+ f = factorial(5)
+ if (f.ne.120) stop 2
+
+contains
+ function factorial(n) result(f)
+ integer :: f
+ integer, intent(in) :: n
+ integer, automatic :: a
+ integer :: b
+ equivalence (a,b)
+
+ if (loc(a).ne.loc(b)) stop 1
+ b = n
+ if (a.eq.1) then
+ f = 1
+ else
+ f = a * factorial(b-1)
+ end if
+ end function
+end program test
+
+! { dg-warning "Flag '-fno-automatic' overwrites '-frecursive'" "warning" { target *-*-* } 0 }
--
2.11.0