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

Mike Frysinger via Gdb-patches
2022-10-23T13:49:11Z

[-- Attachment #1: Type: text/plain, Size: 802 bytes --]

On 12 Oct 2022 13:38, Andrew Burgess via Gdb-patches wrote:
> When building the erc32 simulator I get a few warnings like this:
>
> /tmp/build/sim/../../src/sim/erc32/exec.c:1377:21: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
> 1377 | sregs->fs[rd] = *((float32 *) & ddata[0]);
> | ~^~~~~~~~~~~~~~~~~~~~~~~
>
> The type of '& ddata[0]' will be 'uint32_t *', which is what triggers
> the warning.
>
> This commit uses an intermediate pointer of type 'char *' when
> performing the type-punning, which is well-defined behaviour, and will
> silence the above warning.

this is kind of a poor fix. if we can't arrange for the pointers to be
the right type, at least a memcpy would be better.
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]