public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch] Fortran: Add !GCC$ attributes DEPRECATED
@ 2020-11-02 19:08 Tobias Burnus
  2020-11-03  8:48 ` Paul Richard Thomas
  0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2020-11-02 19:08 UTC (permalink / raw)
  To: gcc-patches, fortran

[-- Attachment #1: Type: text/plain, Size: 694 bytes --]

This adds the Fortran equivalent to __attribute__((deprecated)),
except that "deprecated(message)" is not supported and that only
procedures + variables (and parameters) are supported and not
types.

The issue came up with OpenMP,
cf. https://gcc.gnu.org/pipermail/gcc-patches/2020-October/557359.html

OK?

Tobias

PS: The location for parameter is not ideal as they are resolved
too early; it can be improved, e.g., by moving to match_variable;
but I am not sure it is worth doing so.

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter

[-- Attachment #2: fort-depr.diff --]
[-- Type: text/x-patch, Size: 5886 bytes --]

Fortran: Add !GCC$ attributes DEPRECATED

gcc/fortran/ChangeLog:

	* decl.c (ext_attr_list): Add EXT_ATTR_DEPRECATED.
	* gfortran.h (ext_attr_id_t): Ditto.
	* gfortran.texi (GCC$ ATTRIBUTES): Document it.
	* resolve.c (resolve_variable, resolve_function,
	resolve_call, resolve_values): Show -Wdeprecated-declarations warning.
	* trans-decl.c (add_attributes_to_decl): Skip those
	with no middle_end_name.

gcc/testsuite/ChangeLog:

	* gfortran.dg/attr_deprecated.f90: New test.

 gcc/fortran/decl.c                            |  1 +
 gcc/fortran/gfortran.h                        |  1 +
 gcc/fortran/gfortran.texi                     |  3 +++
 gcc/fortran/resolve.c                         | 20 ++++++++++++++++++
 gcc/fortran/trans-decl.c                      |  2 +-
 gcc/testsuite/gfortran.dg/attr_deprecated.f90 | 30 +++++++++++++++++++++++++++
 6 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 6df32068777..93a155c5f75 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -11585,6 +11585,7 @@ const ext_attr_t ext_attr_list[] = {
   { "stdcall",      EXT_ATTR_STDCALL,      "stdcall"   },
   { "fastcall",     EXT_ATTR_FASTCALL,     "fastcall"  },
   { "no_arg_check", EXT_ATTR_NO_ARG_CHECK, NULL        },
+  { "deprecated",   EXT_ATTR_DEPRECATED,   NULL	       },
   { NULL,           EXT_ATTR_LAST,         NULL        }
 };
 
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 9500032f0e3..dfd7796cce0 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -770,6 +770,7 @@ typedef enum
   EXT_ATTR_CDECL,
   EXT_ATTR_FASTCALL,
   EXT_ATTR_NO_ARG_CHECK,
+  EXT_ATTR_DEPRECATED,
   EXT_ATTR_LAST, EXT_ATTR_NUM = EXT_ATTR_LAST
 }
 ext_attr_id_t;
diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index 151e3d764e7..453b30f7c61 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -3639,6 +3639,9 @@ requires an explicit interface.
 
 @itemize
 @item @code{NO_ARG_CHECK} -- disable the type, kind and rank checking
+@item @code{DEPRECATED} -- print a warning when using a such-tagged
+deprecated procedure, variable or parameter; the warning can be suppressed
+with @option{-Wno-deprecated-declarations}.
 @end itemize
 
 
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 45c144517f2..1641eb6ca10 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -3404,6 +3404,11 @@ resolve_function (gfc_expr *expr)
     /* typebound procedure: Assume the worst.  */
     gfc_current_ns->proc_name->attr.array_outer_dependency = 1;
 
+  if (expr->value.function.esym
+      && expr->value.function.esym->attr.ext_attr & (1 << EXT_ATTR_DEPRECATED))
+    gfc_warning (OPT_Wdeprecated_declarations,
+		 "Using function %qs at %L is deprecated",
+		 sym->name, &expr->where);
   return t;
 }
 
@@ -3747,6 +3752,12 @@ resolve_call (gfc_code *c)
     /* Typebound procedure: Assume the worst.  */
     gfc_current_ns->proc_name->attr.array_outer_dependency = 1;
 
+  if (c->resolved_sym
+      && c->resolved_sym->attr.ext_attr & (1 << EXT_ATTR_DEPRECATED))
+    gfc_warning (OPT_Wdeprecated_declarations,
+		 "Using subroutine %qs at %L is deprecated",
+		 c->resolved_sym->name, &c->loc);
+
   return t;
 }
 
@@ -5917,6 +5928,10 @@ resolve_procedure:
   if (t && flag_coarray == GFC_FCOARRAY_LIB && gfc_is_coindexed (e))
     add_caf_get_intrinsic (e);
 
+  if (sym->attr.ext_attr & (1 << EXT_ATTR_DEPRECATED) && sym != sym->result)
+    gfc_warning (OPT_Wdeprecated_declarations,
+		 "Using variable %qs at %L is deprecated",
+		 sym->name, &e->where);
   /* Simplify cases where access to a parameter array results in a
      single constant.  Suppress errors since those will have been
      issued before, as warnings.  */
@@ -12232,6 +12247,11 @@ resolve_values (gfc_symbol *sym)
   if (sym->value == NULL)
     return;
 
+  if (sym->attr.ext_attr & (1 << EXT_ATTR_DEPRECATED))
+    gfc_warning (OPT_Wdeprecated_declarations,
+		 "Using parameter %qs declared at %L is deprecated",
+		 sym->name, &sym->declared_at);
+
   if (sym->value->expr_type == EXPR_STRUCTURE)
     t= resolve_structure_cons (sym->value, 1);
   else
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index fca1622edd1..cdef753ea8d 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -1427,7 +1427,7 @@ add_attributes_to_decl (symbol_attribute sym_attr, tree list)
   tree attr;
 
   for (id = 0; id < EXT_ATTR_NUM; id++)
-    if (sym_attr.ext_attr & (1 << id))
+    if (sym_attr.ext_attr & (1 << id) && ext_attr_list[id].middle_end_name)
       {
 	attr = build_tree_list (
 		 get_identifier (ext_attr_list[id].middle_end_name),
diff --git a/gcc/testsuite/gfortran.dg/attr_deprecated.f90 b/gcc/testsuite/gfortran.dg/attr_deprecated.f90
new file mode 100644
index 00000000000..aa3f5138a6c
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/attr_deprecated.f90
@@ -0,0 +1,30 @@
+! { dg-do compile }
+
+module m
+  implicit none
+  integer :: A
+  integer, parameter :: PARM = 5  ! { dg-warning "Using parameter 'parm' declared at .1. is deprecated" }
+!GCC$ ATTRIBUTES  DEPRECATED :: A, foo, func, parm
+contains
+subroutine foo
+end
+integer function func()
+  func = 42
+end
+subroutine bar
+  integer :: i
+  call foo    ! { dg-warning "Using subroutine 'foo' at .1. is deprecated" }
+  print *, A  ! { dg-warning "Using variable 'a' at .1. is deprecated" }
+  i = func()  ! { dg-warning "Using function 'func' at .1. is deprecated" }
+  print *, PARM
+end
+  
+end module m
+
+use m  ! { dg-warning "Using parameter 'parm' declared at .1. is deprecated" }
+  integer :: i
+  call foo  ! { dg-warning "Using subroutine 'foo' at .1. is deprecated" }
+  print *, A  ! { dg-warning "Using variable 'a' at .1. is deprecated" }
+  i = func()  ! { dg-warning "Using function 'func' at .1. is deprecated" }
+  print *, PARM
+end

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Patch] Fortran: Add !GCC$ attributes DEPRECATED
  2020-11-02 19:08 [Patch] Fortran: Add !GCC$ attributes DEPRECATED Tobias Burnus
@ 2020-11-03  8:48 ` Paul Richard Thomas
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Richard Thomas @ 2020-11-03  8:48 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc-patches, fortran

Hi Tobias,

That looks to be the best that can be done with a sensible amount of
effort. OK by me.

Regards

Paul


On Mon, 2 Nov 2020 at 19:09, Tobias Burnus <tobias@codesourcery.com> wrote:

> This adds the Fortran equivalent to __attribute__((deprecated)),
> except that "deprecated(message)" is not supported and that only
> procedures + variables (and parameters) are supported and not
> types.
>
> The issue came up with OpenMP,
> cf. https://gcc.gnu.org/pipermail/gcc-patches/2020-October/557359.html
>
> OK?
>
> Tobias
>
> PS: The location for parameter is not ideal as they are resolved
> too early; it can be improved, e.g., by moving to match_variable;
> but I am not sure it is worth doing so.
>
> -----------------
> Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München /
> Germany
> Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung,
> Alexander Walter
>


-- 
"If you can't explain it simply, you don't understand it well enough" -
Albert Einstein

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-03  8:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-02 19:08 [Patch] Fortran: Add !GCC$ attributes DEPRECATED Tobias Burnus
2020-11-03  8:48 ` Paul Richard Thomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).