This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [GOMP4, OpenACC] Fixed-form Fortran code failing to parse


On 07/02/2014 12:02 PM, Tobias Burnus wrote:
> Thomas Schwinge wrote:
>> In -fopenmp mode as well as in combined -fopenacc -fopenmp mode as
>> well as in "regular" (no -fopen*) mode, it parses fine.
> 
> [Note I am testing with an outdated branch (20140404), but it still
> might be representative.]
> 
> I am not sure it parses fine in the combined more. If I use
> 
> *$ACC xPARALLEL
> 
> i.e. add a typo, it fails to diagnose it in the combined mode. It does
> diagnose it for -fopenacc:
> 
> *$ACC xPARALLEL COPYIN(ARGC)                                          
>       1
> Error: Unclassifiable OpenACC directive at (1)
> 
> And it does diagnose the problem for $OMP in only OpenMP and in combined
> mode.

Thanks for catching that.

>> I couldn't find anything obvious in gcc/fortran/parse.c; is someone
>> able to have a more in-depth look than I have?
> 
> First, some minor point, I think one should crosswise reset the
> {openmp,openacc}_flag, i.e.
> 
> --- a/gcc/fortran/scanner.c
> +++ b/gcc/fortran/scanner.c
> @@ -735,2 +735,3 @@ skip_oacc_attribute (locus start, locus old_loc,
> bool continue_flag)
>               openacc_flag = 1;
> +              openmp_flag = 0;
>               openacc_locus = old_loc;
> @@ -775,2 +776,3 @@ skip_omp_attribute (locus start, locus old_loc, bool
> continue_flag)
>               openmp_flag = 1;
> +             openacc_flag = 0;
>               openmp_locus = old_loc;
> @@ -826,3 +828,3 @@ skip_free_comments (void)
>           /* Keep the !GCC$ line.  */
> -                 if (at_bol && skip_gcc_attribute (start))
> +         if (at_bol && skip_gcc_attribute (start))
>             return false;

I think openmp and openacc should be able to coexist, so that should be
left in for now.

> Secondly, the following looks wrong (also scanner.c). I have the feeling
> that this could be behind the issue above. But in any case, it looks
> wrong to me.
> 
> 
> skip_fixed_comments (void)
> ...
>       start = gfc_current_locus;
>       c = next_char ();
>       if (c == '!' || c == 'c' || c == 'C' || c == '*')
>           if (gfc_option.gfc_flag_openmp)
>             {
>               if (next_char () == '$')
>                 {
>                   c = next_char ();
>                   if (c == 'o' || c == 'O')
>                     {
> ...
>               gfc_current_locus = start;
> ...
>             }
> 
>           if (gfc_option.gfc_flag_openacc)
>             {
>               if (next_char () == '$')
>                 {
> 
> Namely: If "omp" or the "!$" continuation lines hasn't been matched, one
> returns to "start". However, start is "!" or "*" in this case and not
> "$". In addition, also in this case, one might want to set the other
> flag to 0.
> 
> 
> My feeling is that the bug is also related to something in scanner.c.

The problem was inside skip_fixed_comments. The openacc_flag wasn't
being set to zero at the end of that function. That's bad, because acc
directive can't continue across multiple comments. E.g.

!$acc
! parallel

is invalid. This patch fixes that.

Thomas, is this patch ok for gomp-4_0-branch? If so, please check it in.

Thanks,
Cesar

> PS: I might try later to find out what goes wrong, but that requires in
> any case a binary which is not older than the source code.

2014-07-02  Cesar Philippidis  <cesar@codesourcery.com>

	gcc/fortran/
	* scanner.c (skip_fixed_comments): Reset openacc_flag
	if an openacc directive wasn't found.

	gcc/testsuite/
	* gfortran.dg/goacc/fixed-1.f: New test.
	* gfortran.dg/goacc/fixed-2.f: New test.


diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c
index 6936222..5869d7d 100644
--- a/gcc/fortran/scanner.c
+++ b/gcc/fortran/scanner.c
@@ -1170,6 +1170,7 @@ skip_fixed_comments (void)
     }
 
   openmp_flag = 0;
+  openacc_flag = 0;
   gcc_attribute_flag = 0;
   gfc_current_locus = start;
 }
diff --git a/gcc/testsuite/gfortran.dg/goacc/fixed-1.f b/gcc/testsuite/gfortran.dg/goacc/fixed-1.f
new file mode 100644
index 0000000..6a45419
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/fixed-1.f
@@ -0,0 +1,12 @@
+      INTEGER :: ARGC
+      ARGC = COMMAND_ARGUMENT_COUNT ()
+
+!$OMP PARALLEL
+!$ACC PARALLEL COPYIN(ARGC)
+      IF (ARGC .NE. 0) THEN
+         CALL ABORT
+      END IF
+!$ACC END PARALLEL
+!$OMP END PARALLEL
+
+      END
diff --git a/gcc/testsuite/gfortran.dg/goacc/fixed-2.f b/gcc/testsuite/gfortran.dg/goacc/fixed-2.f
new file mode 100644
index 0000000..2c2b0a3
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/fixed-2.f
@@ -0,0 +1,15 @@
+! { dg-do compile } 
+! { dg-additional-options "-fmax-errors=100" } 
+
+      INTEGER :: ARGC
+      ARGC = COMMAND_ARGUMENT_COUNT ()
+
+!$OMP xPARALLEL
+!$ACC xPARALLEL COPYIN(ARGC)	! { dg-error "Unclassifiable OpenACC directive" }
+      IF (ARGC .NE. 0) THEN
+         CALL ABORT
+      END IF
+!$ACC END PARALLEL 	! { dg-error "Unexpected" }
+!$OMP END PARALLEL
+
+      END

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]