[PATCH] D131255: Fix Wbitfield-constant-conversion on 1-bit signed bitfield

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 17 10:23:20 PDT 2022


aaron.ballman added a comment.

After some more thought and some offline discussions, I think I have a reasonable way forward: let's add `-Wsingle-bit-bitfield-constant-conversion` as a new warning group under `-Wbitfield-constant-conversion` that controls the diagnostic for one-bit bitfields. The diagnostic behavior here is pedantically correct and will help catch some bugs for folks, but there's enough existing code using `1` and not misbehaving (probably because they're not inspecting the value except in a boolean context) that having separate control seems useful.

What do others think?

In D131255#3725818 <https://reviews.llvm.org/D131255#3725818>, @bjope wrote:

> A similar warning (when assigning -1 to an unsigned bitfield) can be given by both gcc and clang by using ` -Wsign-conversion` but that is not part of `-Wall` either. But maybe that is a totally different thing.

It's a different thing.  When the bit-field is unsigned, the conversion from signed is well-defined and so we only issue a `-Wconversion` warning, but it doesn't technically truncate the bit-field. That's also why we don't diagnose: https://godbolt.org/z/WW9477jfG


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131255/new/

https://reviews.llvm.org/D131255



More information about the cfe-commits mailing list