Patch: malloc function attribute

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Mon Nov 29 05:49:00 GMT 1999


 > From: Jeffrey A Law <law@cygnus.com>
 > 
 > I believe xrealloc is safe.  Consider the conditions under which is
 > can return the same pointer, I believe all are safe.

Okay, I'll tag xrealloc, but not spaces.

 >  
 >   > list.  (BTW, what the heck is spaces good for anyway?)
 > No idea.  Who added it?

Thu Oct 24 02:29:26 1991  Fred Fish  (fnf at cygnus.com)

        * [...] spaces.c: New files containing either portable C
	versions or emulations using native library calls.

Its been a few years. :-)  Does Fred still work for Cygnus?



 >   > gcc:
 >   > 	* calls.c (special_function_p): Add `strdup' to the list of
 >   > 	functions which have attribute malloc by default.
 >   > 
 >   > include:
 >   > 	* ansidecl.h (ATTRIBUTE_MALLOC): New macro.
 >   > 
 >   > 	* libiberty.h (buildargv, dupargv, concat, choose_temp_base,
 >   > 	make_temp_file, xmalloc, xcalloc, xstrdup, xmemdup): Add
 >   > 	ATTRIBUTE_MALLOC.
 >   > 	(xatexit): Remove __GNUC__ check, add ATTRIBUTE_NORETURN.
 > 
 > The only concern I have is people bootstrapping with older
 > snapshots may get errors because there was no malloc attribute
 > supported in older snapshots.
 > 
 > How do you propose to handle that?
 > jeff

IMHO, I don't think we need to handle it.  This case will only issue a
warning, not a hard error.  E.g. consider:

 > % cat foo.c
 > extern int main() __attribute__ ((__bogus__));
 > int main() { return 0; }
 > % gcc foo.c
 > gcc foo.c
 > foo.c:1: warning: `__bogus__' attribute directive ignored

The prior case where we had to bump the gcc version number for
attributes was because I modified the parser to handle attributes in
places where they weren't accepted before (namely on labels.)  Without
the bump, we got syntax errors.

Since functions already accept attributes, you'll only get a warning
in the case of new attributes gcc doesn't recognize.  The cases where
this extra warning will occur are limited, as you mentioned, to
bootstrapping with 2.96 snapshots prior to my patch.  Though you'd
probably get a lot of warnings, in no cases would we make any compile
actually fail.

Okay to proceed?

		--Kaveh
--
Kaveh R. Ghazi			Engagement Manager / Project Services
ghazi@caip.rutgers.edu		Qwest Internet Solutions


More information about the Gcc-patches mailing list