[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 19 09:02:49 PDT 2023


erichkeane wrote:

>In my previous comments (https://github.com/llvm/llvm-project/pull/69104#issuecomment-1771167758, https://github.com/llvm/llvm-project/pull/69104#issuecomment-1771204043) I provided an example of StoredNameKind enum that has enumerators 0 through 8 (9 total, 4 bits to store), but we store it in a bit-fields of width 3, because the last enumerator is there to count other enumerators, and is used for offset purposes. If we apply -Wbitfield-enum-conversion to it as-is, we get a false-positive: https://godbolt.org/z/4xPs6qPTY.

I thought that was a contrived example, but I see where it is from now (note your example is the related but not-exactly-the-same `Wbitfield-constant-conversion`), which brings up an additional concern/thing to deal with for the `non_storable` attribute (that is, do we apply it to assignments? how about exact-assignments like you've done there?).

That is an odd/awkward pattern even so... I think there is still value to the warning as proposed, but I'm now not opposed to using `non_storable` as an escape hatch.




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


More information about the cfe-commits mailing list