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

John McCall via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 15:51:47 PST 2024


================
@@ -122,6 +122,26 @@ Non-comprehensive list of changes in this release
 
 New Compiler Flags
 ------------------
+- ``-fsanitize=implicit-unsigned-bitfield-truncation`` catches implicit
+  unsigned conversions involving bitfields.
+- ``-fsanitize=implicit-signed-bitfield-truncation`` catches implicit
+  signed conversions involving bitfields.
+- ``-fsanitize=implicit-bitfield-sign-change`` catches implicit
+  conversions involving bitfields that result in a sign change.
+- ``-fsanitize=implicit-bitfield-truncation`` a group to include both
+  ``-fsanitize=implicit-unsigned-bitfield-truncation`` and
+  ``-fsanitize=implicit-signed-bitfield-truncation``.
+- ``-fsanitize=implicit-bitfield-arithmetic-value-change`` a group to
+  include both ``implicit-signed-bitfield-truncation`` and
+  ``implicit-bitfield-sign-change``.
+- ``-fsanitize=implicit-bitfield-conversion`` a group to include
+  ``-fsanitize=implicit-unsigned-bitfield-truncation``,
+  ``-fsanitize=implicit-signed-bitfield-truncation`` and
+  ``implicit-bitfield-sign-change``.
+- ``-fsanitize=implicit-integer-conversion`` a group to include
+  ``-fsanitize=implicit-unsigned-integer-truncation``,
+  ``-fsanitize=implicit-signed-integer-truncation`` and
+  ``implicit-integer-sign-change``.
----------------
rjmccall wrote:

Do we really need a million different flags here?  The reason we have different checks for different signednesses with the normal conversion checks, I think, is because the standard actually treats them differently: some of those checks are actually checking for UB.  Since there's no UB here in any case, I think you may be overthinking this.  Consider just having `-fsanitize=implicit-bitfield-conversion`, which covers every case in which the value we'd read out the bitfield is not the value that we assigned into it.

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


More information about the llvm-commits mailing list