Fix -Wtype-limits warnings by removing redundant assertions#428
Fix -Wtype-limits warnings by removing redundant assertions#428csaavedra wants to merge 1 commit intozyantific:masterfrom
Conversation
This was uncovered in the context of WebKit. These assertions are always true as the bitfield variables in question are too small to hold the values that the assertions are comparing against: - ZydisSetAttributes: The arrays are defined to be larger than the bitfield holding cpu_state, fpu_state, and xmm_state, so the comparison is always true. - ZydisSetEffectiveOperandWidth: operand_size_map is a 3-bit bitfield, and the arrays have a size 8, thus the comparison is always true. - ZydisGetOperandDefinitions: operand_reference is a 15-bit bitfield, it can't hold 0xFFFF (which needs 16 bits), so the comparison is always true. See also https://bugs.webkit.org/show_bug.cgi?id=252309
|
Thanks for opening this! These asserts are mostly in place to guard against when the array sizes are changed at a later point, to remind us that the corresponding lookup table needs a fix-up. Arguably we should probably turn these into static asserts though (as mentioned in the WebKit thread). As for the assert in |
|
Interestingly enough, I wasn't actually able to reproduce the warning. I tried CFLAGS="-Werror=type-limits -Wall -Wpedantic" cmake -DZYAN_FORCE_ASSERTS=ON -DCMAKE_BUILD_TYPE=Debug ..with gcc 11.x, gcc 12.2.0, gcc 13.x, clang 11.x and clang 16.x but none of them bothered with printing a warning or error. |
|
Yeah, weirdly I only get this when I enable SCCACHE with WK. GCC alone is not enough. I am not sure what sorcery goes on in the build system when SCCACHE is enabled, but now that we disabled the warnings in WK I didn't run into this again. |
This was uncovered in the context of WebKit. These assertions are always true as the bitfield variables in question are too small to hold the values that the assertions are comparing against:
ZydisSetAttributes: The arrays are defined to be larger than the bitfield holding cpu_state, fpu_state, and xmm_state, so the comparison is always true.
ZydisSetEffectiveOperandWidth: operand_size_map is a 3-bit bitfield, and the arrays have a size 8, thus the comparison is always true.
ZydisGetOperandDefinitions: operand_reference is a 15-bit bitfield, it can't hold 0xFFFF (which needs 16 bits), so the comparison is always true.
See also https://bugs.webkit.org/show_bug.cgi?id=252309