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]

Re: noalias macro bug [was: Linux and aliasing?]


mark@codesourcery.com wrote:
>      The practice of reading from a different union member than the one
>      most recently written to (called "type-punning") is common.  Even
>      with `-fstrict-aliasing', type-punning is allowed, provided the
>      memory is accessed through the union type.  So, the code above
>      will work as expected.  However, this code might not:

> In other words, as in Linus' proposal, the "union trick" works only
> when accessing directly through the union.  You squirelled the pointer
> away, and then used it later, thereby losing the effects of the
> noalias macro.

Are you sure the macro works?

I don't think it's correct even in your short example.

The initialisation and reads of `a' are _not_ "from a different union
member" or any union member.  Therefore I don't think the uses of plain
`a' in the example are actually type-punning, and I wonder why the code
works.  Is it a GCC extension or luck?

For the same reason I don't think it's workable in the kernel.
I can see it would work by changing the data structures to contain
unions, and changing all the code that uses the structures to use the
union members.  But that's a lot of code.

Anonymous unions would reduce the amount of code needing to be changed
substantially.

We'd still need a warning to _find_ the dodgy casts though.

> Kernel people: is the use of the self-documenting noalias macro, as
> demonstrated here, really so hard?

Unless it does the right thing, I think it is.

-- Jamie


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