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: strict-aliasing and typedefs


Joe Buck <jbuck@synopsys.com> writes:

| Joe Buck <jbuck@synopsys.com> writes:
| > | How about one-element structs (with same layout but distinct names)?  Those
| > | can't alias.
|  
| On Wed, May 14, 2003 at 11:30:15PM +0200, Gabriel Dos Reis wrote:
| > Yes, that will work but then, as Fergus pointed out, GCC seems to very
| > fragile when it comes to optimize "simple" structures.  
| 
| GCC does a decent job with one-element structs; its performance
| quickly drops like a rock as soon as there are two elements.  Still,
| there may well be some loss from using it.
|  
| > I would use "restrict" here.
| 
| "restrict" says that nothing at all aliases with some object.  What

No, that is not exact.  Here is an example from C standard:

       [#7] EXAMPLE 1 The file scope declarations

               int * restrict a;
               int * restrict b;
               extern int c[];

       assert  that  if an object is accessed using one of a, b, or
       c, and that object is modified anywhere in the program, then
       it is never accessed using either of the other two.

both a, b, c may alias the same object, but they cannot be used
simultaneously to modify the object. 

| if you have two pointers to Fred and two pointers to Barney?
| "restrict" cannot express the aliasing relationship.

His example is:

   stackslot *sp;
   heapslot *hp;

 rewrite it as

   stackslot *restrict sp = some_stack_pointer;
   heapslot *restrict hp = some_heap_pointer;

to meet the example from the C standard.

-- Gaby


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