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]
Other format: [Raw text]

Re: 'malloc' attribute?


On Wed, 26 Feb 2003, Zack Weinberg wrote:
> Chris Lattner <sabre at nondot dot org> writes:
> > Apparently C99 doesn't allow declaring a function to return a 'restrict'
> > pointer (GCC rejects it at least), but GCC does allow you to attach the
> > malloc attribute to a function.  It seems to me that this is the exact
> > same information, ie, the following two function prototypes should be
> > equivalent:
> > restrict int* foo();            // Currently rejected with -std=c99
> You've got the 'restrict' in the wrong place: try
> int * restrict foo();
> which attaches the qualifier to the pointer, not the thing it points
> to.

Yup, sorry for the noise, I figured that out right after I sent out the
message. :(

I've been digging into an older version of GCC, and the differences
between the two seem to be that attribute(malloc) is processed (A_MALLOC
-> DECL_IS_MALLOC -> ECF_MALLOC) to end up adding an RTL annotation to the
pointer, indicating that it cannot alias anything:

          /* The return value from a malloc-like function can not alias
             anything else.  */
          last = get_last_insn ();
          REG_NOTES (last) =
            gen_rtx_EXPR_LIST (REG_NOALIAS, temp, REG_NOTES (last));

In contrast, the restrict annotation interacts with the TBAA code (ie,
only enabled with -fstrict-aliasing) indicating that:

          /* No two restricted pointers can point at the same thing.
             However, a restricted pointer can point at the same thing
             as an unrestricted pointer, if that unrestricted pointer
             is based on the restricted pointer.  So, we make the
             alias set for the restricted pointer a subset of the
             alias set for the type pointed to by the type of the
             decl.  */

It seems that the two annotations cause very different actions at
different levels, so, again, should they be unified?

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/



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