Bug 224207 - Suppress -Warray-bounds warning spam in Bitmap.h
Summary: Suppress -Warray-bounds warning spam in Bitmap.h
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Nightly Build
Hardware: PC Linux
: P2 Normal
Assignee: Michael Catanzaro
Keywords: DoNotImportToRadar
Depends on:
Reported: 2021-04-05 14:44 PDT by Michael Catanzaro
Modified: 2021-04-07 16:49 PDT (History)
7 users (show)

See Also:

Patch (1.37 KB, patch)
2021-04-05 14:46 PDT, Michael Catanzaro
no flags Details | Formatted Diff | Diff
Patch for landing (1.23 KB, patch)
2021-04-07 14:46 PDT, Michael Catanzaro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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’
      |     ^~~~~~~~~~~~~~~~~~~~~~~~
../../Tools/TestWebKitAPI/Tests/WTF/Bitmap.cpp:441:5: note: in expansion of macro ‘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]
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].