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: varargs, 64-bit targets, and strict-aliasing warnings


Roland Dreier <roland@topspin.com> writes:

> Thanks for the explanation.  However I'm still a little hazy on what's
> being done that's forbidden by the strict-aliasing rules.  For one
> thing, the warning produced by gcc is at least a little misleading: 
> casting a uint64_t * to another pointer type is (as far as I know)
> perfectly legal

But it is producing undefined behaviour when dereferenced.

> and there is no type-punned pointer anywhere to be found.

The cast itself is creating the type-punned pointer.

> And of course no pointer is being dereferenced at the line gcc warns
> about.

The place of the cast is the only place where the compiler can know that
there is a potential for undefined behaviour.  Without such a cast there
cannot be an aliasing violation.

> Also, hiding the cast from gcc by first casting to void * and then
> going through an inline function shuts gcc up (as shown below), which
> seems odd.  Does this void * cast make gcc relax its aliasing rules?

Pointers to void and char can alias everything, forcing the compiler to
drop some optimisations.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


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