This is the mail archive of the gcc@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]

Should we create an attribute malloc for supposed alias benefits?


I noticed the following in calls.c:

 >       /* XXX should have "malloc" attribute on functions instead
 >          of recognizing them by name.  */
 >       else if (! strcmp (tname, "malloc")
 >                || ! strcmp (tname, "calloc")
 >                || ! strcmp (tname, "realloc")
 >                /* Note use of NAME rather than TNAME here.  These functions
 >                   are only reserved when preceded with __.  */
 >                || ! strcmp (name, "__vn")       /* mangled __builtin_vec_new */
 >                || ! strcmp (name, "__nw")       /* mangled __builtin_new */
 >                || ! strcmp (name, "__builtin_new")
 >                || ! strcmp (name, "__builtin_vec_new"))
 >         *is_malloc = 1;


	It looks like `is_malloc' is used later to decide that the
return value of a malloc-like function will never alias anything else.

Would it be useful to follow the comments and create an attribute
malloc?  Then we could declare things like xmalloc/xrealloc/xcalloc
with that attribute.  (We should probably add strdup/xstrdup to that
list.)  I don't know if the alias benefits would be worth it though.

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


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