This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch,Fortran,4.6] Coarray 7/n - add -fcoarray=<none|single>
- From: Tobias Burnus <burnus at net-b dot de>
- To: gcc patches <gcc-patches at gcc dot gnu dot org>, gfortran <fortran at gcc dot gnu dot org>
- Date: Wed, 31 Mar 2010 22:40:58 +0200
- Subject: [Patch,Fortran,4.6] Coarray 7/n - add -fcoarray=<none|single>
This patch is rather simple compared with the others and justs add a new
compiler flag: -fcoarray=... with the options "none" (which is default)
and "single".
With "none" - the default -, the compiler gives an error message when
encountering a coarray declaration or an image control statement. This
gives the user a hint that the program uses coarrays; this helps to
reduce the change of running into the following problems:
(a) using a single image for programs which expects, e.g., at least two
images (this is the usage case which Nick mentioned)
(b) compiling one file with single-image support and the other one with
full, library-based coarray support, which can easily happen but leads
obviously to wrong code.
(Additionally, the -fcoarray= argument would have been added anyway for
the real parallel version.)
Build and regtested on x86-64-linux.
OK for the 4.6 trunk?
Tobias
fortran/array.c | 6 ++++++
fortran/gfortran.h | 8 ++++++++
fortran/invoke.texi | 18 ++++++++++++++++--
fortran/lang.opt | 4 ++++
fortran/match.c | 12 ++++++++++++
fortran/options.c | 16 ++++++++++++++++
testsuite/gfortran.dg/coarray_2.f90 | 1 +
testsuite/gfortran.dg/coarray_3.f90 | 1 +
testsuite/gfortran.dg/coarray_4.f90 | 1 +
testsuite/gfortran.dg/coarray_6.f90 | 1 +
testsuite/gfortran.dg/coarray_7.f90 | 2 +-
testsuite/gfortran.dg/coarray_8.f90 | 2 +-
testsuite/gfortran.dg/coarray_9.f90 | 17 +++++++++++++++++
13 files changed, 85 insertions(+), 4 deletions(-)
2010-03-31 Tobias Burnus <burnus@net-b.de>
PR fortran/18918
* array.c (gfc_match_array_spec): Add error for -fcoarray=none.
* match.c (gfc_match_critical, sync_statement): Ditto.
* gfortran.h (gfc_fcoarray): New enum.
(gfc_option_t): Use it.
* lang.opt (fcoarray): Add new flag.
* invoke.texi (fcoarray): Document it.
* options.c (gfc_init_options,gfc_handle_option): Handle -fcoarray=.
(gfc_handle_coarray_option): New function.
2010-03-31 Tobias Burnus <burnus@net-b.de>
PR fortran/18918
* gfortran.dg/coarray_2.f90: Add dg-options -fcoarray=single.
* gfortran.dg/coarray_3.f90: Ditto.
* gfortran.dg/coarray_4.f90: Ditto.
* gfortran.dg/coarray_5.f90: Ditto.
* gfortran.dg/coarray_6.f90: Ditto.
* gfortran.dg/coarray_7.f90: Ditto.
* gfortran.dg/coarray_8.f90: Ditto.
* gfortran.dg/coarray_9.f90: New -fcoarray=none test.
diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c
index bc3148c..d9ca043 100644
--- a/gcc/fortran/array.c
+++ b/gcc/fortran/array.c
@@ -527,6 +527,12 @@ coarray:
== FAILURE)
goto cleanup;
+ if (gfc_option.coarray == GFC_FCOARRAY_NONE)
+ {
+ gfc_error ("Coarrays disabled at %C, use -fcoarray= to enable");
+ goto cleanup;
+ }
+
for (;;)
{
as->corank++;
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 2dd3715..8fb0090 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -562,6 +562,13 @@ typedef enum
}
init_local_integer;
+typedef enum
+{
+ GFC_FCOARRAY_NONE = 0,
+ GFC_FCOARRAY_SINGLE
+}
+gfc_fcoarray;
+
/************************* Structures *****************************/
/* Used for keeping things in balanced binary trees. */
@@ -2159,6 +2166,7 @@ typedef struct
int fpe;
int rtcheck;
+ gfc_fcoarray coarray;
int warn_std;
int allow_std;
diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi
index efcf5ef..963ff49 100644
--- a/gcc/fortran/invoke.texi
+++ b/gcc/fortran/invoke.texi
@@ -166,8 +166,8 @@ and warnings}.
@gccoptlist{-fno-automatic -ff2c -fno-underscoring @gol
-fwhole-file -fsecond-underscore @gol
-fbounds-check -fcheck-array-temporaries -fmax-array-constructor =@var{n} @gol
--fcheck=@var{<all|array-temps|bounds|do|mem|pointer|recursion>}
--fmax-stack-var-size=@var{n} @gol
+-fcheck=@var{<all|array-temps|bounds|do|mem|pointer|recursion>} @gol
+-fcoarray=@var{<none|single>} -fmax-stack-var-size=@var{n} @gol
-fpack-derived -frepack-arrays -fshort-enums -fexternal-blas @gol
-fblas-matmul-limit=@var{n} -frecursive -finit-local-zero @gol
-finit-integer=@var{n} -finit-real=@var{<zero|inf|-inf|nan|snan>} @gol
@@ -1212,6 +1212,20 @@ is implemented as a reference to the link-time external symbol
for compatibility with @command{g77} and @command{f2c}, and is implied
by use of the @option{-ff2c} option.
+@item -fcoarray=@var{<keyword>}
+@opindex @code{fcoarray}
+@cindex coarrays
+
+@table @asis
+@item @samp{none}
+Disable coarray support; using coarray declarations and image-control
+statements will produce a compile-time error. (Default)
+
+@item @samp{single}
+Single-image mode, i.e. @code{num_images()} is always one.
+@end table
+
+
@item -fcheck=@var{<keyword>}
@opindex @code{fcheck}
@cindex array, bounds checking
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
index 7ea06c2..8cf20d8 100644
--- a/gcc/fortran/lang.opt
+++ b/gcc/fortran/lang.opt
@@ -348,6 +348,10 @@ frepack-arrays
Fortran
Copy array sections into a contiguous block on procedure entry
+fcoarray=
+Fortran RejectNegative JoinedOrMissing
+-fcoarray=[...] Specify which coarray parallelization should be used
+
fcheck=
Fortran RejectNegative JoinedOrMissing
-fcheck=[...] Specify which runtime checks are to be performed
diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index 0d8518b..3341ef6 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -1750,6 +1750,12 @@ gfc_match_critical (void)
== FAILURE)
return MATCH_ERROR;
+ if (gfc_option.coarray == GFC_FCOARRAY_NONE)
+ {
+ gfc_error ("Coarrays disabled at %C, use -fcoarray= to enable");
+ return MATCH_ERROR;
+ }
+
if (gfc_find_state (COMP_CRITICAL) == SUCCESS)
{
gfc_error ("Nested CRITICAL block at %C");
@@ -2145,6 +2151,12 @@ sync_statement (gfc_statement st)
== FAILURE)
return MATCH_ERROR;
+ if (gfc_option.coarray == GFC_FCOARRAY_NONE)
+ {
+ gfc_error ("Coarrays disabled at %C, use -fcoarray= to enable");
+ return MATCH_ERROR;
+ }
+
if (gfc_find_state (COMP_CRITICAL) == SUCCESS)
{
gfc_error ("Image control statement SYNC at %C in CRITICAL block");
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
index bcde573..05da214 100644
--- a/gcc/fortran/options.c
+++ b/gcc/fortran/options.c
@@ -129,6 +129,7 @@ gfc_init_options (unsigned int argc, const char **argv)
gfc_option.fpe = 0;
gfc_option.rtcheck = 0;
+ gfc_option.coarray = GFC_FCOARRAY_NONE;
/* Argument pointers cannot point to anything but their argument. */
flag_argument_noalias = 3;
@@ -479,6 +480,18 @@ gfc_handle_fpe_trap_option (const char *arg)
static void
+gfc_handle_coarray_option (const char *arg)
+{
+ if (strcmp (arg, "none") == 0)
+ gfc_option.coarray = GFC_FCOARRAY_NONE;
+ else if (strcmp (arg, "single") == 0)
+ gfc_option.coarray = GFC_FCOARRAY_SINGLE;
+ else
+ gfc_fatal_error ("Argument to -fcoarray is not valid: %s", arg);
+}
+
+
+static void
gfc_handle_runtime_check_option (const char *arg)
{
int result, pos = 0, n;
@@ -930,6 +943,9 @@ gfc_handle_option (size_t scode, const char *arg, int value)
gfc_handle_runtime_check_option (arg);
break;
+ case OPT_fcoarray_:
+ gfc_handle_coarray_option (arg);
+ break;
}
return result;
diff --git a/gcc/testsuite/gfortran.dg/coarray_2.f90 b/gcc/testsuite/gfortran.dg/coarray_2.f90
index 1fcb9b8..902a0dd 100644
--- a/gcc/testsuite/gfortran.dg/coarray_2.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_2.f90
@@ -1,4 +1,5 @@
! { dg-do run }
+! { dg-options "-fcoarray=single" }
! { dg-shouldfail "error stop" }
!
! Coarray support
diff --git a/gcc/testsuite/gfortran.dg/coarray_3.f90 b/gcc/testsuite/gfortran.dg/coarray_3.f90
index 648f2fa..63c3bd3 100644
--- a/gcc/testsuite/gfortran.dg/coarray_3.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_3.f90
@@ -1,4 +1,5 @@
! { dg-do compile }
+! { dg-options "-fcoarray=single" }
!
! Coarray support
! PR fortran/18918
diff --git a/gcc/testsuite/gfortran.dg/coarray_4.f90 b/gcc/testsuite/gfortran.dg/coarray_4.f90
index cb693ea..5607ec9 100644
--- a/gcc/testsuite/gfortran.dg/coarray_4.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_4.f90
@@ -1,4 +1,5 @@
! { dg-do compile }
+! { dg-options "-fcoarray=single" }
!
! Coarray support -- corank declarations
! PR fortran/18918
diff --git a/gcc/testsuite/gfortran.dg/coarray_6.f90 b/gcc/testsuite/gfortran.dg/coarray_6.f90
index b6d8b49..d3c600b 100644
--- a/gcc/testsuite/gfortran.dg/coarray_6.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_6.f90
@@ -1,4 +1,5 @@
! { dg-do compile }
+! { dg-options "-fcoarray=single" }
!
! Coarray support -- corank declarations
! PR fortran/18918
diff --git a/gcc/testsuite/gfortran.dg/coarray_7.f90 b/gcc/testsuite/gfortran.dg/coarray_7.f90
index a32bf88..bb23c78 100644
--- a/gcc/testsuite/gfortran.dg/coarray_7.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_7.f90
@@ -1,5 +1,5 @@
! { dg-do compile }
-! { dg-options "-fmax-errors=1000" }
+! { dg-options "-fcoarray=single -fmax-errors=1000" }
!
! PR fortran/18918
!
diff --git a/gcc/testsuite/gfortran.dg/coarray_8.f90 b/gcc/testsuite/gfortran.dg/coarray_8.f90
index 0ab1190..6a385f8 100644
--- a/gcc/testsuite/gfortran.dg/coarray_8.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_8.f90
@@ -1,5 +1,5 @@
! { dg-do compile }
-! { dg-options "-fmax-errors=1000" }
+! { dg-options "-fcoarray=single -fmax-errors=1000" }
!
! PR fortran/18918
!
diff --git a/gcc/testsuite/gfortran.dg/coarray_9.f90 b/gcc/testsuite/gfortran.dg/coarray_9.f90
new file mode 100644
index 0000000..d44cdda
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray_9.f90
@@ -0,0 +1,17 @@
+! { dg-do compile }
+!
+! PR fortran/18918
+!
+! Check for error if no -fcoarray= option has been given
+!
+
+integer :: a
+integer :: b[*] ! { dg-error "Coarrays disabled" }
+
+error stop "Error"
+sync all ! { dg-error "Coarrays disabled" }
+
+critical ! { dg-error "Coarrays disabled" }
+end critical ! { dg-error "Expecting END PROGRAM statement" }
+
+end