Re: [PATCH 4/5] sim/erc32: avoid dereferencing type-punned pointer warnings

Pedro Alves
2022-10-13T10:50:01Z

Hi,

On 2022-10-13 11:35 a.m., Andrew Burgess wrote:
> Lancelot SIX <lsix@lancelotsix.com> writes:

>>
>> Another well defined (at least to my knowledge) solution to this problem
>> is memcpy. You could do something like:
>>
>> memcpy (&sregt->fs[rd], ddata, sizeof (float32));
>>
>> I tend to find this more straightforward than the type punning version,
>> but I would be happy with either.

Yes, memcpy is fine too.

> Pedro, Lancelot, thanks for taking the time to give really useful
> feedback.
>
> In the end I went with the memcpy approach. I ran a few tests with GCC,
> Clang, and ICC, and in each case the code generated at -O0 was either
> identical, or pretty much identical when using memcpy vs using a union.
> When switching to -O2 the code was identical in all cases I checked.
>
> Thoughts?

LGTM.

Pedro Alves