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]

[Fortran, Patch, OpenMP] PR33445 - Warn if (free format) !$OMP& is used as no continuation line


:ADDPATCH fortran:

In fixed-format, the following two lines form one directive:

!$OMP some-Directive
!$OMP& default(shared)

In free-format Fortran, the latter is no continuation line and thus
treated as comment. As there is no error/warning, one can easily forget
to put the ampersand at the preceding line, when converting
fixed-formatted into free-formatted code. (This can lead to code which
gives wrong results, see example in the PR.)


Other compilers give an error (ifort, sunf95) in this case. As it is
valid ("!$OMP& ..." is a comment line), FX (and Jakub) convinced me that
one should only print a warning and not an error.


The attached patch prints such a warning if it encounters in
free-formatted code  !$OMP&  unless that line is a continuation line:

Warning: Found $!OMP& at (1) but no preceeding directive with a tailing &


Build and regression tested (check-gfortran  + libgomp) on x86-64/Linux.

OK for the trunk?


Tobias
2007-09-21  Tobias Burnus  <burnus@net-b.de>

	PR fortran/33445
	* scanner.c (skip_free_comments): Warn if !$OMP& is used
	if no OpenMP directive is to be continued.

2007-09-21  Tobias Burnus  <burnus@net-b.de>

	PR fortran/33445
	* gfortran.dg/gomp/free-2.f90: New.
	* gfortran.dg/gomp/appendix-a/a.31.1.f90: Add missing &.

Index: gcc/fortran/scanner.c
===================================================================
--- gcc/fortran/scanner.c	(Revision 128649)
+++ gcc/fortran/scanner.c	(Arbeitskopie)
@@ -417,18 +417,25 @@ skip_free_comments (void)
 		  if (c == 'o' || c == 'O')
 		    {
 		      if (((c = next_char ()) == 'm' || c == 'M')
-			  && ((c = next_char ()) == 'p' || c == 'P')
-			  && ((c = next_char ()) == ' ' || continue_flag))
+			  && ((c = next_char ()) == 'p' || c == 'P'))
 			{
-			  while (gfc_is_whitespace (c))
-			    c = next_char ();
-			  if (c != '\n' && c != '!')
+			  char c2 = next_char ();
+			  if (c2 == ' ' || continue_flag)
 			    {
-			      openmp_flag = 1;
-			      openmp_locus = old_loc;
-			      gfc_current_locus = start;
-			      return false;
+			      while (gfc_is_whitespace (c))
+				c = next_char ();
+			      if (c != '\n' && c != '!')
+				{
+				  openmp_flag = 1;
+				  openmp_locus = old_loc;
+				  gfc_current_locus = start;
+				  return false;
+				}
 			    }
+			  else if (c2 == '&')
+			    gfc_warning_now ("Found $!OMP& at %C but no "
+					     "preceeding directive with "
+					     "a tailing &");
 			}
 		      gfc_current_locus = old_loc;
 		      next_char ();
Index: gcc/testsuite/gfortran.dg/gomp/free-2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/gomp/free-2.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/gomp/free-2.f90	(Revision 0)
@@ -0,0 +1,9 @@
+! { dg-do compile }
+!
+! PR fortran/33445
+!
+!$OMP&foo ! { dg-warning "no preceeding directive" }
+!$OMP parallel 
+!$OMP& default(shared) ! { dg-warning "no preceeding directive" }
+!$OMP end parallel
+       end
Index: gcc/testsuite/gfortran.dg/gomp/appendix-a/a.31.1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/gomp/appendix-a/a.31.1.f90	(Revision 128649)
+++ gcc/testsuite/gfortran.dg/gomp/appendix-a/a.31.1.f90	(Arbeitskopie)
@@ -3,7 +3,7 @@
       SUBROUTINE A31_1(A, B, X, Y, N)
         INTEGER N
         REAL X(*), Y(*), A, B
-!$OMP PARALLEL DO PRIVATE(I) SHARED(X, N) REDUCTION(+:A)
+!$OMP PARALLEL DO PRIVATE(I) SHARED(X, N) REDUCTION(+:A) &
 !$OMP& REDUCTION(MIN:B)
         DO I=1,N
            A = A + X(I)

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