Gennady Agranov wrote 11 lines
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