Work around bogus GCC 9 warnings
authorDavid Emett <david.emett@broadcom.com>
Mon, 26 Jul 2021 16:33:03 +0000 (16:33 +0000)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Thu, 12 Aug 2021 07:01:10 +0000 (07:01 +0000)
commitb45d3fe50d6a462dfe20be5608b4d15f43c48145
tree7b17890ae8f20ee2bd76ac3a2d87e4116ee209b3
parent318de4b0c18f6ffa8a1df01187c5f601d2ed3e1f
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
modules/glshared/glsStateQueryUtil.hpp