This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Patch: malloc function attribute



  In message <199911280352.TAA09097@fencer.cygnus.com>you write:
  > 
  > The java runtime library has many functions for allocating memory in
  > different ways.  They all behave like `malloc' in that they always
  > return pointers that cannot alias anything.  The compiler should be
  > taking advantage of this information.  It already tries to identify
  > malloc-like functions by looking for special function names (see
  > special_function_p in calls.c).  Rather than add more magic function
  > names, I've added a `malloc' function attribute for annotating source
  > - as is suggested by this comment in special_function_p:
  > 
  >       /* XXX should have "malloc" attribute on functions instead
  > 	 of recognizing them by name.  */
  > 
  > I have correspoding patches to annotate jc1's builtin decls, and the
  > libgcj header files.  It definitely results in better code.
  > 
  > 1999-11-27  Anthony Green  <green@cygnus.com>
  > 
  > 	* tree.h (struct tree_decl): Add malloc_flag.
  > 	(DECL_IS_MALLOC): Define.
  > 	* c-common.c (attrs): Add A_MALLOC attribute.
  > 	(init_attributes): Add this attribute to the table.
  > 	(decl_attributes): Handle malloc attribute.
  > 	* calls.c (special_function_p): Check for the malloc attribute.
  > 	* extend.texi (Function Attributes): Document malloc attribute.
  > 
  > @@ -1347,6 +1352,7 @@
  >    unsigned virtual_flag : 1;
  >    unsigned ignored_flag : 1;
  >    unsigned abstract_flag : 1;
  > +  unsigned malloc_flag : 1;
You should probably add this after "comdat_flag" -- the flags come in
blocks of 8 flags, you put malloc_flag into a block of 8 that was already
full.

You should probably remove the XXX comment, or at least change it to 
say "do not add more malloc-like functions, instead mark them as
malloc functions using the malloc attribute" or something of that
nature.

Otherwise it looks great.  Please install it.

jeff


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]