This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[patch] Add a few simple attributes to some of the library functions
- From: Steven Bosscher <stevenb at suse dot de>
- To: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Sun, 31 Jul 2005 23:41:03 +0200
- Subject: [patch] Add a few simple attributes to some of the library functions
- Organization: SUSE Labs
Hi,
I noticed that the runtime_error function was not marked as a noreturn
function. This makes GCC think that runtime_error returns, clobbering
a few things along the way. With the noreturn attribute, GCC knows that
whatever the function does (in this case, end the program), it cannot
modify anything that can be call clobbered.
I think we should also handle the internal malloc functions as malloc,
i.e. their result does not alias with anything.
There are other functions that we could annotate with pure and const
attributes, but it is a bit difficult to figure out which functions may
read from e.g. array descriptors (such functions cannot be pure) and so
on, so that is for another time.
Bootstrapped and tested on x86_64-pc-linux-gnu.
Gr.
Steven
* trans-decl.c (gfc_build_builtin_function_decls): Give the internal
malloc functions the 'malloc' attribute. Give runtime_error the
'noreturn' attribute.
Index: trans-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-decl.c,v
retrieving revision 1.63
diff -u -3 -p -r1.63 trans-decl.c
--- trans-decl.c 8 Jul 2005 23:37:05 -0000 1.63
+++ trans-decl.c 31 Jul 2005 21:36:08 -0000
@@ -1874,14 +1874,17 @@ gfc_build_builtin_function_decls (void)
tree gfc_logical4_type_node = gfc_get_logical_type (4);
tree gfc_pint4_type_node = build_pointer_type (gfc_int4_type_node);
+ /* Treat these two internal malloc wrappers as malloc. */
gfor_fndecl_internal_malloc =
gfc_build_library_function_decl (get_identifier (PREFIX("internal_malloc")),
pvoid_type_node, 1, gfc_int4_type_node);
+ DECL_IS_MALLOC (gfor_fndecl_internal_malloc) = 1;
gfor_fndecl_internal_malloc64 =
gfc_build_library_function_decl (get_identifier
(PREFIX("internal_malloc64")),
pvoid_type_node, 1, gfc_int8_type_node);
+ DECL_IS_MALLOC (gfor_fndecl_internal_malloc64) = 1;
gfor_fndecl_internal_free =
gfc_build_library_function_decl (get_identifier (PREFIX("internal_free")),
@@ -1930,6 +1933,8 @@ gfc_build_builtin_function_decls (void)
3,
pchar_type_node, pchar_type_node,
gfc_int4_type_node);
+ /* The runtime_error function does not return. */
+ TREE_THIS_VOLATILE (gfor_fndecl_runtime_error) = 1;
gfor_fndecl_in_pack = gfc_build_library_function_decl (
get_identifier (PREFIX("internal_pack")),