Work around bogus GCC 9 warnings
Bogus warning can be seen with this example:
#include <stddef.h>
long broken()
{
struct
{
long a, b;
} value;
for (size_t i = 0; i < sizeof(long); ++i)
{
((char *)&value.a)[i] = (char)0xde;
((char *)&value.b)[i] = (char)0xde;
}
return value.b;
}
Compiled with -O3 -Warray-bounds GCC 9 warns:
In function 'long int broken()':
cc1plus: warning: 'void* __builtin_memset(void*, int, long unsigned int)' offset [9, 16] from the object at 'value' is out of the bounds of referenced subobject 'broken()::<unnamed struct>::a' with type 'long int' at offset 0 [-Warray-bounds]
It looks like GCC is recognising the loop as two memsets, merging them,
then forgetting that it has done this.
It seems this can be worked around by just using memset rather than
implementing it manually, which is also simpler and produces better
code.
The example compiles without warning on GCC 10+ (you can try on
https://godbolt.org/), so presumably this bug has been fixed in later
versions of gcc.
Change-Id: I09799d6dd833b1fba8608cddaa36a32e555cf861