aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Burnus <tobias@codesourcery.com>2020-11-03 09:55:58 +0100
committerTobias Burnus <tobias@codesourcery.com>2020-11-03 09:55:58 +0100
commit0caf400a865cb771f76bf1025cfc2a83e8ef00ed (patch)
tree259379fab27182a6be222d90c4f7ff3ca0778481
parent682ed7ad230f6177aadc060788e6f4a0780d8860 (diff)
downloadgcc-0caf400a865cb771f76bf1025cfc2a83e8ef00ed.zip
gcc-0caf400a865cb771f76bf1025cfc2a83e8ef00ed.tar.gz
gcc-0caf400a865cb771f76bf1025cfc2a83e8ef00ed.tar.bz2
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.
-rw-r--r--gcc/fortran/decl.c1
-rw-r--r--gcc/fortran/gfortran.h1
-rw-r--r--gcc/fortran/gfortran.texi3
-rw-r--r--gcc/fortran/resolve.c20
-rw-r--r--gcc/fortran/trans-decl.c2
-rw-r--r--gcc/testsuite/gfortran.dg/attr_deprecated.f9030
6 files changed, 56 insertions, 1 deletions
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 6df3206..93a155c 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 9500032..dfd7796 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 151e3d7..453b30f 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 45c14451..1641eb6 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 fca1622..cdef753 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 0000000..aa3f513
--- /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