Patchwork [Fortran] PR39505 - add support for !GCC$ attributes NO_ARG_CHECK

login
register
mail settings
Submitter Tobias Burnus
Date April 15, 2013, 10:30 p.m.
Message ID <516C7F83.4010509@net-b.de>
Download mbox | patch
Permalink /patch/236757/
State New
Headers show

Comments

Tobias Burnus - April 15, 2013, 10:30 p.m.
Tobias Burnus wrote:
> Am 15.04.2013 23:03, schrieb Thomas Koenig:
>> I see that it can be useful, but I really dislike disabling the TKR
>> checks.

Side remark: TS29113 already allows to disable TK checks via TYPE(*). 
And I find disabling TRK checks very useful for certain applications - 
and MPI buffers is one. On has just to make sure that it is difficult to 
abuse it. The J3 team spend some time on it to ensure this for TYPE(*) - 
and the NO_ARG_CHECK makes use of that feature.

>> Can you put this behind an option so the user has to specify that
>> he really means it?
>
> Well, it is difficult to write accidentally
>   !GCC$ attributes NO_ARG_CHECKS :: args
>
> Additionally, for the purpose of libraries - such as MPI, it makes 
> sense to disable the TKR check without requiring the users to always 
> compile their programs with special options.
>
> Regarding an option: Would be -f(no-)directives (with default = on) a 
> suitable option, which also affects the other !GCC$ attributes, such 
> as dllexport etc.?

Namely, the attached patch?

Tobias
Tobias Burnus - April 16, 2013, 8:57 p.m.
Tobias Burnus wrote:
>>> Can you put this behind an option so the user has to specify that
>>> he really means it?
>>
>> Regarding an option: Would be -f(no-)directives (with default = on) a 
>> suitable option, which also affects the other !GCC$ attributes, such 
>> as dllexport etc.?
> Namely, the attached patch?

I have now committed the original patch (Rev. 198011). The option thing 
can be done as follow up. Is my -f(no-)directives patch okay? Or do you 
envision something else?

Tobias
Thomas Koenig - April 17, 2013, 9:20 p.m.
Hi Tobias,

> Is my -f(no-)directives patch okay? Or do you envision something else?

In principle, it is OK; the only question is what the default should be :-)

For OpenMP, we require an option to change the semantics of a program
based on special comments.  Currently, we do not do so for directives
which do the same thing.  So, what should we do?

Does anybody else have an opinion here?  I'm willing to go with the
majority here.

	Thomas
Tobias Burnus - April 17, 2013, 9:34 p.m.
Thomas Koenig wrote:
>> Is my -f(no-)directives patch okay? Or do you envision something else?
>
> In principle, it is OK; the only question is what the default should 
> be :-)

I am in favor of "on".

> For OpenMP, we require an option to change the semantics of a program
> based on special comments.  Currently, we do not do so for directives
> which do the same thing.

Well, I see a difference here: (Nearly) all program using OpenMP work 
also as serial program (-fno-openmp). On the other hand, without "!GCC$ 
attributes" directives (or the C equivalent: "__attribute__((...))"), 
the program does not work properly. The attributes are used to be able 
to express some feature which is not available in the standard but still 
in some way required: stdcall, fastcall, dllimport, dllexport. "unused" 
arguments, weak bindings (not yet for Fortran), disabling argument 
checking (only Fortran), etc.

Tobias

Patch

2013-04-16  Tobias Burnus  <burnus@net-b.de>

	PR fortran/39505
	* gfortran.h (gfc_option_t): Add flag_directives.
        * gfortran.texi (GCC Fortran directives): Mention
	-fno-directives.
	* invoke.texi (-fno-directives): Add.
	* lang.opt (fdirectives): Add.
	* options.c (gfc_init_options, gfc_handle_option): Handle it.
	* scanner.c (skip_gcc_attribute): Ditto.

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index a69cea2..bb4ec1b 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -2300,6 +2300,7 @@  typedef struct
   int flag_realloc_lhs;
   int flag_aggressive_function_elimination;
   int flag_frontend_optimize;
+  int flag_directives;
 
   int fpe;
   int rtcheck;
diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index 61cb3bb..c2bb0d5 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -2663,6 +2663,9 @@  on the processor; see
 @ref{Top,,C Extensions,gcc,Using the GNU Compiler Collection (GCC)}
 for details.
 
+Note that the parsing of the directives can be disabled via the
+@option{-fno-directives} option.
+
 For procedures and procedure pointers, the following attributes can
 be used to change the calling convention:
 
diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi
index 12c200e..9f250ad 100644
--- a/gcc/fortran/invoke.texi
+++ b/gcc/fortran/invoke.texi
@@ -116,7 +116,7 @@  by type.  Explanations are in the following sections.
 @xref{Fortran Dialect Options,,Options controlling Fortran dialect}.
 @gccoptlist{-fall-intrinsics -fbackslash -fcray-pointer -fd-lines-as-code @gol
 -fd-lines-as-comments -fdefault-double-8 -fdefault-integer-8 @gol
--fdefault-real-8 -fdollar-ok -ffixed-line-length-@var{n} @gol
+-fdefault-real-8 -fdirectives -fdollar-ok -ffixed-line-length-@var{n} @gol
 -ffixed-line-length-none -ffree-form -ffree-line-length-@var{n} @gol
 -ffree-line-length-none -fimplicit-none -finteger-4-integer-8 @gol
 -fmax-identifier-length -fmodule-private -fno-fixed-form -fno-range-check @gol
@@ -250,6 +250,11 @@  the kind of non-double real constants like @code{1.0}, and does promote
 the default width of @code{DOUBLE PRECISION} to 16 bytes if possible, unless
 @code{-fdefault-double-8} is given, too.
 
+@item -fno-directives
+@opindex @code{fdirectives}
+@opindex @code{fno-directives}
+Disable the GNU Fortran Compiler Directives (@code{!GCC$}) directives.
+
 @item -fdollar-ok
 @opindex @code{fdollar-ok}
 @cindex @code{$}
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
index dbc3f6b..5fb1a13 100644
--- a/gcc/fortran/lang.opt
+++ b/gcc/fortran/lang.opt
@@ -389,6 +389,10 @@  fdollar-ok
 Fortran
 Allow dollar signs in entity names
 
+fdirectives
+Fortran
+Enable !GCC$ directives
+
 fdump-core
 Fortran Ignore
 Does nothing. Preserved for backward compatibility.
diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
index 3f5de03..00e6a50 100644
--- a/gcc/fortran/options.c
+++ b/gcc/fortran/options.c
@@ -122,6 +122,7 @@  gfc_init_options (unsigned int decoded_options_count,
   gfc_option.flag_integer4_kind = 0;
   gfc_option.flag_real4_kind = 0;
   gfc_option.flag_real8_kind = 0;
+  gfc_option.flag_directives = 1;
   gfc_option.flag_dollar_ok = 0;
   gfc_option.flag_underscoring = 1;
   gfc_option.flag_f2c = 0;
@@ -766,6 +767,10 @@  gfc_handle_option (size_t scode, const char *arg, int value,
       gfc_option.flag_d_lines = 0;
       break;
 
+    case OPT_fdirectives:
+      gfc_option.flag_directives = value;
+      break;
+
     case OPT_fdump_fortran_original:
     case OPT_fdump_parse_tree:
       gfc_option.dump_fortran_original = value;
diff --git a/gcc/fortran/scanner.c b/gcc/fortran/scanner.c
index fd8f284..8c95f90 100644
--- a/gcc/fortran/scanner.c
+++ b/gcc/fortran/scanner.c
@@ -718,6 +718,9 @@  skip_gcc_attribute (locus start)
   char c;
   locus old_loc = gfc_current_locus;
 
+  if (!gfc_option.flag_directives)
+    return false;
+
   if ((c = next_char ()) == 'g' || c == 'G')
     if ((c = next_char ()) == 'c' || c == 'C')
       if ((c = next_char ()) == 'c' || c == 'C')
@@ -770,7 +773,7 @@  skip_free_comments (void)
       if (c == '!')
 	{
 	  /* Keep the !GCC$ line.  */
-		  if (at_bol && skip_gcc_attribute (start))
+	  if (at_bol && skip_gcc_attribute (start))
 	    return false;
 
 	  /* If -fopenmp, we need to handle here 2 things: