aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran
diff options
context:
space:
mode:
authorRimvydas Jasinskas <rimvydas.jas@gmail.com>2023-02-12 06:16:51 +0000
committerHarald Anlauf <anlauf@gmx.de>2023-02-13 18:35:26 +0100
commit086a1df4374962787db37c1f0d1bd9beb828f9e3 (patch)
treea94688f95cc312c3dece0c6cfee62c78d83856db /gcc/fortran
parent72ae1e5635648bd3f6a5760ca46d531ad1f2c6b1 (diff)
downloadgcc-086a1df4374962787db37c1f0d1bd9beb828f9e3.zip
gcc-086a1df4374962787db37c1f0d1bd9beb828f9e3.tar.gz
gcc-086a1df4374962787db37c1f0d1bd9beb828f9e3.tar.bz2
Fortran: Add !GCC$ attributes NOINLINE,NORETURN,WEAK
gcc/fortran/ChangeLog: * decl.cc: Add EXT_ATTR_NOINLINE, EXT_ATTR_NORETURN, EXT_ATTR_WEAK. * gfortran.h (ext_attr_id_t): Ditto. * gfortran.texi (GCC$ ATTRIBUTES): Document them. * trans-decl.cc (build_function_decl): Apply them. gcc/testsuite/ChangeLog: * gfortran.dg/noinline.f90: New test. * gfortran.dg/noreturn-1.f90: New test. * gfortran.dg/noreturn-2.f90: New test. * gfortran.dg/noreturn-3.f90: New test. * gfortran.dg/noreturn-4.f90: New test. * gfortran.dg/noreturn-5.f90: New test. * gfortran.dg/weak-1.f90: New test. Signed-off-by: Rimvydas Jasinskas <rimvydas.jas@gmail.com>
Diffstat (limited to 'gcc/fortran')
-rw-r--r--gcc/fortran/decl.cc3
-rw-r--r--gcc/fortran/gfortran.h3
-rw-r--r--gcc/fortran/gfortran.texi7
-rw-r--r--gcc/fortran/trans-decl.cc13
4 files changed, 25 insertions, 1 deletions
diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 27b728f..eec0314 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -11732,6 +11732,9 @@ const ext_attr_t ext_attr_list[] = {
{ "fastcall", EXT_ATTR_FASTCALL, "fastcall" },
{ "no_arg_check", EXT_ATTR_NO_ARG_CHECK, NULL },
{ "deprecated", EXT_ATTR_DEPRECATED, NULL },
+ { "noinline", EXT_ATTR_NOINLINE, NULL },
+ { "noreturn", EXT_ATTR_NORETURN, NULL },
+ { "weak", EXT_ATTR_WEAK, NULL },
{ NULL, EXT_ATTR_LAST, NULL }
};
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 9884a55..a893ee0 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -838,6 +838,9 @@ typedef enum
EXT_ATTR_FASTCALL,
EXT_ATTR_NO_ARG_CHECK,
EXT_ATTR_DEPRECATED,
+ EXT_ATTR_NOINLINE,
+ EXT_ATTR_NORETURN,
+ EXT_ATTR_WEAK,
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 c3813d0..c483e13 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -3246,6 +3246,13 @@ requires an explicit interface.
@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}.
+@item @code{NOINLINE} -- prevent inlining given function.
+@item @code{NORETURN} -- add a hint that a given function cannot return.
+@item @code{WEAK} -- emit the declaration of an external symbol as a weak
+symbol rather than a global. This is primarily useful in defining library
+functions that can be overridden in user code, though it can also be used with
+non-function declarations. The overriding symbol must have the same type as
+the weak symbol.
@end itemize
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index f7a7ff6..ff64588 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -2338,7 +2338,7 @@ module_sym:
}
/* Mark non-returning functions. */
- if (sym->attr.noreturn)
+ if (sym->attr.noreturn || sym->attr.ext_attr & (1 << EXT_ATTR_NORETURN))
TREE_THIS_VOLATILE(fndecl) = 1;
sym->backend_decl = fndecl;
@@ -2482,6 +2482,17 @@ build_function_decl (gfc_symbol * sym, bool global)
TREE_SIDE_EFFECTS (fndecl) = 0;
}
+ /* Mark noinline functions. */
+ if (attr.ext_attr & (1 << EXT_ATTR_NOINLINE))
+ DECL_UNINLINABLE (fndecl) = 1;
+
+ /* Mark noreturn functions. */
+ if (attr.ext_attr & (1 << EXT_ATTR_NORETURN))
+ TREE_THIS_VOLATILE (fndecl) = 1;
+
+ /* Mark weak functions. */
+ if (attr.ext_attr & (1 << EXT_ATTR_WEAK))
+ declare_weak (fndecl);
/* Layout the function declaration and put it in the binding level
of the current function. */