Strict aliasing in D

David Nadlinger code at klickverbot.at
Sat Jul 27 01:57:50 PDT 2013


On Saturday, 27 July 2013 at 06:58:04 UTC, Walter Bright wrote:
> Although it isn't in the spec, D should be "strict aliasing". 
> This is because:
>
> 1. it enables better code generation
>
> 2. there are ways, such as unions, to get the other aliasing 
> that doesn't break strict aliasing

We need to carefully formalize this then, and quickly. The 
problem GCC, Clang and others are facing is that (as you are 
probably aware) 2. isn't guaranteed to work for type-casting 
pointers either by the specs, but people want to be able to do 
this nonetheless.

Thus, they both accept pointer aliasing through union types, 
trying to optimize as much as possible while avoiding to break 
people's expectations and existing code. This is a very 
unfortunate situation for both compiler developers and users; 
just search for something like "gcc strict aliasing" on 
StackOverflow for examples.

There is already quite a lot of D code out there that violates 
the C-style strict aliasing rules.

David


More information about the Digitalmars-d mailing list