[clang] [compiler-rt] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

Axel Lundberg via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 7 06:55:15 PST 2024


Zonotora wrote:

Hi again, I have now finally gotten time and updated the patch so that the unnecessary emits I mentioned in the initial commit are avoided. The current patch introduces a number of new fsanitizer flags to separate integer conversions from bitfield conversions. E.g., 

- ``-fsanitize=implicit-unsigned-bitfield-truncation``
- ``-fsanitize=implicit-signed-bitfield-truncation``
- ``-fsanitize=implicit-bitfield-sign-change``
- ``-fsanitize=implicit-bitfield-truncation``
- ``-fsanitize=implicit-bitfield-arithmetic-value-change``
- ``-fsanitize=implicit-bitfield-conversion``
- ``-fsanitize=implicit-integer-conversion`` <---- This used to be ``-fsanitize=implicit-conversion``

``-fsanitize=implicit-conversion`` will now represent ``-fsanitize=implicit-integer-conversion`` and ``-fsanitize=implicit-bitfield-conversion``.

Previously the following:
```c
typedef struct {
    unsigned char a:4;
} X;

int main(void) {
    X x;
    unsigned int a = 272;
    x.a = a;
    return 0;
}
```
emitted a implict integer conversion error in the assignment of `x.a = a` with the ``-fsanitize=implicit-integer-conversion``. This is no longer the case as the assignment involves bitfields. To get the emission error, one would have to include the ``-fsanitize=implicit-bitfield-conversion`` flag instead.

I have compiled clang with the -fsanitizer flag ``-fsanitize=implicit-bitfield-conversion`` without any problems. What are your thoughts on this new change? @vitalybuka @AaronBallman @LebedevRI @efriedma-quic

https://github.com/llvm/llvm-project/pull/75481


More information about the cfe-commits mailing list