From 0caf400a865cb771f76bf1025cfc2a83e8ef00ed Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Tue, 3 Nov 2020 09:55:58 +0100 Subject: [PATCH] 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(-) create mode 100644 gcc/testsuite/gfortran.dg/attr_deprecated.f90 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 -- 2.30.2