sim/erc32: avoid dereferencing type-punned pointer warnings
authorAndrew Burgess <aburgess@redhat.com>
Wed, 12 Oct 2022 10:45:53 +0000 (11:45 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Wed, 19 Oct 2022 13:32:22 +0000 (14:32 +0100)
commitd0a7ca87ab208d72b2c6a9d44e30fe20c3c0542e
tree046252c76230145d9c6afad2a6c975bfe6334c50
parente5961d2be503149aaa40927c0a9501c06ca980e5
sim/erc32: avoid dereferencing type-punned pointer warnings

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 makes use of memcpy when performing the type-punning,
which resolves the above warnings.

With this change, I now see no warnings when compiling exec.c, which
means that the line in Makefile.in that disables -Werror can be
removed.

There should be no change in behaviour after this commit.
sim/erc32/Makefile.in
sim/erc32/exec.c