Bug 224207

Summary: Suppress -Warray-bounds warning spam in Bitmap.h
Product: WebKit Reporter: Michael Catanzaro <mcatanzaro>
Component: Web Template FrameworkAssignee: Michael Catanzaro <mcatanzaro>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, bugs-noreply, cdumez, cmarcelo, don.olmstead, ews-watchlist, mcatanzaro
Priority: P2 Keywords: DoNotImportToRadar
Version: WebKit Nightly Build   
Hardware: PC   
OS: Linux   
Attachments:
Description Flags
Patch
none
Patch for landing none

Description Michael Catanzaro 2021-04-05 14:44:05 PDT
With GCC 11, there is a huge warning spam coming from Bitmap.h:

In file included from ../../Tools/TestWebKitAPI/Tests/WTF/Bitmap.cpp:27:
DerivedSources/ForwardingHeaders/wtf/Bitmap.h: In function ‘void TestWebKitAPI::testBitmapIsFull() [with WordType = unsigned int]’:
DerivedSources/ForwardingHeaders/wtf/Bitmap.h:229:24: warning: array subscript ‘_Type {aka const unsigned int [4]}[0]’ is partly outside array bounds of ‘WTF::Bitmap<9, unsigned int> [1]’ [-Warray-bounds]
  229 |     bits[n / wordSize] &= ~(one << (n % wordSize));
      |     ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../Tools/TestWebKitAPI/Tests/WTF/Bitmap.cpp:104:33: note: while referencing ‘smallBitmap1’
  104 |     Bitmap<smallSize, WordType> smallBitmap1; /* Will hold values specified in expectedSmallBits1. */ \
      |                                 ^~~~~~~~~~~~
../../Tools/TestWebKitAPI/Tests/WTF/Bitmap.cpp:108:5: note: in expansion of macro ‘DECLARE_BITMAPS_FOR_TEST’
  108 |     DECLARE_BITMAPS_FOR_TEST() \
      |     ^~~~~~~~~~~~~~~~~~~~~~~~
../../Tools/TestWebKitAPI/Tests/WTF/Bitmap.cpp:441:5: note: in expansion of macro ‘DECLARE_AND_INIT_BITMAPS_FOR_TEST’
  441 |     DECLARE_AND_INIT_BITMAPS_FOR_TEST();
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It prints over 3000 lines of warnings for every translation unit that includes Bitmap.h.

After squinting at this for a while, I failed to understand why GCC thought there was a problem here, so instead I added a runtime assert to see if the array bounds are ever exceeded. They are not, at least not by TestWTF nor when smoketesting Epiphany.
Comment 1 Michael Catanzaro 2021-04-05 14:45:59 PDT
(Note the debug assert might be controversial because this function seems to be called very frequently. I don't mind taking that out if requested.)
Comment 2 Michael Catanzaro 2021-04-05 14:46:40 PDT
Created attachment 425209 [details]
Patch
Comment 3 Michael Catanzaro 2021-04-07 14:45:50 PDT
Let's land without the ASSERT. I don't think it matters very much either way.
Comment 4 Michael Catanzaro 2021-04-07 14:46:41 PDT
Created attachment 425442 [details]
Patch for landing
Comment 5 EWS 2021-04-07 16:49:45 PDT
Committed r275646: <https://commits.webkit.org/r275646>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 425442 [details].