D defined behavior
Luís Marques
luis at luismarques.eu
Mon Apr 27 15:12:51 UTC 2020
On Monday, 27 April 2020 at 14:57:09 UTC, Johan wrote:
> I think you mean to ask whether D defines writing to partially
> overlapping objects. Or if it is defined to write a type `int`
> to memory locations that were typed as `char`.
I left it purposefully vague because it wasn't clear what
question should be asked at that level (and because I'm *really*
short for time at the moment, sorry). For instance, another
possibly question is if it's valid for safe code to create
pointers to unaligned values. Avoiding that could potentially
provide another avenue for addressing issues like this, I guess.
> LDC assumes `a` and `b` may alias partially, and therefore `a`
> must be reloaded in the return statement. LDC does not pass
> type-based alias information to the optimizer (TBAA if you are
> interested), which Clang _would_ do; it be nice if someone
> could check me on this:
> https://llvm.org/docs/LangRef.html#pointer-aliasing-rules
> Still, Clang does not optimize the code as it probably could,
> same as GCC does. My guess is that GDC inherits the C or C++
> type-based aliasing rules here.
Thanks for the details.
More information about the Digitalmars-d
mailing list