Closed Bug 1508927 (Wbitfield-enum-conversion) Opened 10 months ago Closed 10 months ago

Enable clang's -Wbitfield-enum-conversion warnings

Categories

(Firefox Build System :: Source Code Analysis, enhancement, P3)

65 Branch
enhancement

Tracking

(firefox64 wontfix, firefox65 fixed)

RESOLVED FIXED
mozilla65
Tracking Status
firefox64 --- wontfix
firefox65 --- fixed

People

(Reporter: cpeterson, Assigned: cpeterson)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

clang's -Wbitfield-enum-conversion warning reports when an enum value is assigned to a bit field that is not wide enough to store all the enum values:

https://clang.llvm.org/docs/DiagnosticsReference.html#wbitfield-enum-conversion

This warning found some real layout style bugs where a 4-bit enum was implicitly truncated to a 3-bit bit field:

layout/tables/nsTableFrame.cpp:5318:14 [-Wbitfield-enum-conversion] bit-field 'ownerElem' is not wide enough to store all enumerators of 'BCBorderOwner'
layout/tables/nsTableFrame.cpp:5358:16 [-Wbitfield-enum-conversion] bit-field 'ownerElem' is not wide enough to store all enumerators of 'BCBorderOwner'
layout/tables/nsTableFrame.cpp:5374:18 [-Wbitfield-enum-conversion] bit-field 'subElem' is not wide enough to store all enumerators of 'BCBorderOwner'
layout/tables/nsTableFrame.cpp:5385:18 [-Wbitfield-enum-conversion] bit-field 'subElem' is not wide enough to store all enumerators of 'BCBorderOwner'

I fixed the bit fields (bug 1485179), which unfortunately revealed some underlying layout bugs (bug 1508921) that depended on the buggy behavior.
https://clang.llvm.org/docs/DiagnosticsReference.html#wbitfield-enum-conversion

This clang warning caught a real layout bug related to implicitly truncated enums in the table border style code (bug 1485179):

layout/tables/nsTableFrame.cpp:5318:14 [-Wbitfield-enum-conversion] bit-field 'ownerElem' is not wide enough to store all enumerators of 'BCBorderOwner'
layout/tables/nsTableFrame.cpp:5358:16 [-Wbitfield-enum-conversion] bit-field 'ownerElem' is not wide enough to store all enumerators of 'BCBorderOwner'
layout/tables/nsTableFrame.cpp:5374:18 [-Wbitfield-enum-conversion] bit-field 'subElem' is not wide enough to store all enumerators of 'BCBorderOwner'
layout/tables/nsTableFrame.cpp:5385:18 [-Wbitfield-enum-conversion] bit-field 'subElem' is not wide enough to store all enumerators of 'BCBorderOwner'

Also update the comment linking to clang and gcc's warning documentation.
Severity: normal → enhancement
Pushed by cpeterson@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/6feb94524b7e
Enable clang's -Wbitfield-enum-conversion warnings. r=glandium
https://hg.mozilla.org/mozilla-central/rev/6feb94524b7e
Status: NEW → RESOLVED
Closed: 10 months ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 65
Target Milestone: Firefox 65 → mozilla65
You need to log in before you can comment on or make changes to this bug.