On Tue, Jan 17, 2012 at 14:29, Paul Richard Thomas <paul.richard.tho...@gmail.com> wrote: > Dear Tobias and Janne, > > I had preparedand was about to submit the identical patch :-) > > On Tue, Jan 17, 2012 at 12:45 PM, Janne Blomqvist > <blomqvist.ja...@gmail.com> wrote: >> On Tue, Jan 17, 2012 at 13:24, Tobias Burnus <bur...@net-b.de> wrote: >>> This patch nullifies (scalar) allocatables after malloc, if (and only if) >>> they contain allocatable components to make sure that no uninitialized >>> memory is accessed. >>> >>> Build and regtested on x86-64-linux. >>> OK for the trunk? >> >> calloc potentially has better performance than malloc+memset, and has >> smaller generated code size too. > > On a previous occasion (for class array allocation), I looked for and > was unable to find a __BUILTIN_CALLOC. If it exists, use that.
It exists in the middle end, but doesn't seem to be wired up in the Fortran frontend yet. A simple --- f95-lang.c.orig 2012-01-17 14:32:10.000000000 +0200 +++ f95-lang.c 2012-01-17 14:35:13.000000000 +0200 @@ -1007,6 +1007,12 @@ gfc_init_builtin_functions (void) "malloc", ATTR_NOTHROW_LEAF_LIST); DECL_IS_MALLOC (builtin_decl_explicit (BUILT_IN_MALLOC)) = 1; + ftype = build_function_type_list (pvoid_type_node, size_type_node, + size_type_node, NULL_TREE); + gfc_define_builtin ("__builtin_calloc", ftype, BUILT_IN_CALLOC, + "calloc", ATTR_NOTHROW_LEAF_LIST); + DECL_IS_MALLOC (builtin_decl_explicit (BUILT_IN_MALLOC)) = 1; + ftype = build_function_type_list (pvoid_type_node, size_type_node, pvoid_type_node, NULL_TREE); ought to do it (untested). -- Janne Blomqvist