public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Should we create an attribute malloc for supposed alias  benefits?
@ 1999-09-08 13:27 Kaveh R. Ghazi
  1999-09-08 13:44 ` Mark Mitchell
  1999-09-30 18:02 ` Kaveh R. Ghazi
  0 siblings, 2 replies; 12+ messages in thread
From: Kaveh R. Ghazi @ 1999-09-08 13:27 UTC (permalink / raw)
  To: law, mark; +Cc: egcs, robertlipe

 > From: Mark Mitchell <mark@codesourcery.com>
 >  
 > >>>>> "Jeffrey" == Jeffrey A Law <law@cygnus.com> writes:
 >  
 >     Jeffrey> Mark as the resident expert, can "restrict" be used to
 >     Jeffrey> tell the aliasing code that the return value from certain
 >     Jeffrey> functions can never alias anything else in the program?
 >  
 > I think the answer is "no, but that's OK".  For example, the following
 > code is legal C9X:
 >  
 >   int *restrict rp1;
 >  
 >   int *restrict f () {
 >     return rp1;
 >   }
 >  
 >   void f()
 >   {
 >     int *restrict rp2 = f();
 >   }
 >  
 > If GCC can't tell `f' from `malloc', then it must worry that the
 > storage returned by `malloc' is actually the same memory pointed to by
 > `rp1'.  But, C9X forbids using `rp1' to access memory while `rp2' is
 > in (dynamic) scope.
 >  
 > Making sense?  C9X committee members?
 > --
 > Mark Mitchell                   mark@codesourcery.com



Sorry, does that mean an attribute malloc would be useful or not? :-)

Does gcc support c9x restrict today?  (Even if it does, would there be
a -c89 mode, like -traditional in which case `restrict' wouldn't work
and so we would want an attribute malloc anyway?)

I went ahead and wrote something which seems to work.  Should I bother
submitting it?

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

^ permalink raw reply	[flat|nested] 12+ messages in thread
* Should we create an attribute malloc for supposed alias benefits?
@ 1999-09-06 12:40 Kaveh R. Ghazi
  1999-09-06 14:36 ` Jeffrey A Law
  1999-09-30 18:02 ` Kaveh R. Ghazi
  0 siblings, 2 replies; 12+ messages in thread
From: Kaveh R. Ghazi @ 1999-09-06 12:40 UTC (permalink / raw)
  To: egcs

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~1999-09-30 18:02 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-08 13:27 Should we create an attribute malloc for supposed alias benefits? Kaveh R. Ghazi
1999-09-08 13:44 ` Mark Mitchell
1999-09-30 18:02   ` Mark Mitchell
1999-09-30 18:02 ` Kaveh R. Ghazi
  -- strict thread matches above, loose matches on Subject: below --
1999-09-06 12:40 Kaveh R. Ghazi
1999-09-06 14:36 ` Jeffrey A Law
1999-09-06 15:03   ` Robert Lipe
1999-09-07  0:22     ` Jeffrey A Law
1999-09-30 18:02       ` Jeffrey A Law
1999-09-30 18:02     ` Robert Lipe
1999-09-30 18:02   ` Jeffrey A Law
1999-09-30 18:02 ` Kaveh R. Ghazi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).