Bug 211044

Summary: [WTF] Workaround gcc bug for unsigned bitfield related usual arithmetic conversions
Product: WebKit Reporter: Joonghun Park <jh718.park>
Component: Web Template FrameworkAssignee: Joonghun Park <jh718.park>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, cdumez, cmarcelo, darin, ews-watchlist, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

Description Joonghun Park 2020-04-26 02:12:11 PDT
(unsigned + signed) should return unsigned int type as a common type defined by usual arithmetic conversions.

But gcc 9.3.0 returns signed int type for this case.

I filed a bug for this issue on gcc bugzilla,
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94767.

To workaround this, I originally submitted the patch, http://svn.webkit.org/repository/webkit/trunk@260715,
but according to Darin's comment, use unsigned integer suffix instead of static_cast<unsigned>.
Comment 1 Joonghun Park 2020-04-26 02:15:01 PDT
Created attachment 397614 [details]
Patch
Comment 2 EWS 2020-04-26 11:55:25 PDT
Committed r260727: <https://trac.webkit.org/changeset/260727>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 397614 [details].
Comment 3 Radar WebKit Bug Importer 2020-04-26 11:56:17 PDT
<rdar://problem/62403735>
Comment 4 Joonghun Park 2020-04-27 03:09:23 PDT
FYI, in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94767,
Jonathan Wakely left a comment for a c++ standard entry for this issue.

http://eel.is/c++draft/conv.prom#5,

and the statement of this link is as below.

"A prvalue for an integral bit-field ([class.bit]) can be converted to a prvalue of type int if int can represent all the values of the bit-field; otherwise, it can be converted to unsigned int if unsigned int can represent all the values of the bit-field. If the bit-field is larger yet, no integral promotion applies to it. If the bit-field has an enumerated type, it is treated as any other value of that type for promotion purposes."

So I think gcc's build warning,

warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]

was valid one and this patch could be a proper fix, not just a workaround.