On 10/19/26 15:31, Igor Shevlyakov wrote:
get_fpu_state and set_fpu_state take a GFC_FPE_STATE_BUFFER_SIZE buffer
that is a character array: either the front end's fpstate temporary
created by gfc_save_fp_state, or the hidden component of IEEE_STATUS_TYPE
passed by IEEE_GET_STATUS / IEEE_SET_STATUS.  Neither has more than byte
alignment, but every fpu-*.h implementation used the buffer directly as
the target's fenv_t (or its own state struct).  On strict-alignment
targets that is a misaligned access and faults, e.g. the SIGBUS in
__fegetenv for ieee_6.f90 at -O0 on SPARC.

Giving the buffer a stricter type instead (an integer array rather than
a character array) would change the alignment, and so the layout, of
any user derived type that contains an IEEE_STATUS_TYPE.

So build the state in a properly aligned local and memcpy it to or from
the caller's buffer, in all six implementations (glibc, aix, macppc, 387,
aarch64, sysv).  This covers both callers on every target and leaves the
buffer layout unchanged.

The new test places two IEEE_STATUS_TYPE components at offsets 1 and 34
of a derived type, so at least one of them is misaligned for any state
type that needs more than byte alignment.

Can you attach the diff?

% patch -p1 < ../fpu.eml
% find . -name \*.rej
./libgfortran/config/fpu-387.h.rej
./libgfortran/config/fpu-aarch64.h.rej
./libgfortran/config/fpu-aix.h.rej
./libgfortran/config/fpu-glibc.h.rej
./libgfortran/config/fpu-macppc.h.rej
./libgfortran/config/fpu-sysv.h.rej

--
steve

Reply via email to