CTSRD-CHERI / clang

DO NOT USE. Use llvm-project instead
Other
9 stars 8 forks source link

-Wcheri-bitwise-operations should ignore small constant operands #192

Closed brooksdavis closed 6 years ago

brooksdavis commented 6 years ago

The most common valid and correct use that -Wcheri-bitwise-operations fires on is using the bottom one or two bits of a pointer as storage. These cases are going be fine and should not trigger the warning. The inverse of small constants would also have to be ignored. I think it would always be safe to ignore values <= 0x3 and it might be ok to ignore <= 0x7 in 64-bit platforms.

arichardson commented 6 years ago

The problem is that getting there value of the low bits is quite confusing:

if (p & 1) works but if ((p & 1) == 1) is always false. This is what caused QMutexLocker::unlock to always assume the lock was already unlocked. In the first case we are checking if pointer with offset set tooffset & 1 is not equal to null (so this might even be always true, will need to check) and in the latter case pointer with offset == null with offset 1 so always false.

I could probably ignore values that are < 7 negated since clearing the bits works as expected but checking if they are set is confusing.

brooksdavis commented 6 years ago

ah, that makes sense.