[fpc-devel] Can FPC at least give a hint/warning?

Jonas Maebe jonas.maebe at elis.ugent.be
Thu Nov 10 08:32:19 CET 2016


Gennady Agranov wrote:
> Hi,
> 
>>>> Or what are the conditions when you want to emit the hint?
> 
> I thought that hint could come from some layer that actually allocates
> the record - on the stack or on the heap - this layer may actually know
> the "effective" alignment
> 
> Heap allocation should be aligned to the largest required alignment (is
> it 8?) - i.e. it should relatively simple to validate that offset of
> some "double" field is properly aligned

The compiler does not know where a pointer comes from when it is used.
It may be the result of a getmem call, of getting the address of an
unaligned field, or of manual pointer arithmetic. Additionally, the
memory manager may have been overridden and may return anything it wants.

> I actually do not know how stack allocation works - i.e. when and how
> compiler aligns double, extended or record values (packed or unpacked)

The guaranteed alignment of the start of a record declared with
{$packrecords X} is at most a multiple of X, regardless of the type of
its fields. The reasoning is that aligning a record when you don't
guarantee the same alignment in the record itself, is kind of misleading
(even if it helps initially to get some field aligned, any change to the
record could break this) and probably wasteful.

> So if in your opinion this hint would report too many false positives -
> case is closed :)

It's not only about false positives, but also about the fact that it
would be impossible to get rid of this hint/warning when you have
determined that the caller can deal with the unaligned data.


Jonas



More information about the fpc-devel mailing list