[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 11 11:44:00 PDT 2023
================
@@ -6171,6 +6171,11 @@ def warn_signed_bitfield_enum_conversion : Warning<
"signed bit-field %0 needs an extra bit to represent the largest positive "
"enumerators of %1">,
InGroup<BitFieldEnumConversion>, DefaultIgnore;
+def warn_bitfield_too_small_for_integral_type : Warning<
+ "conversion from %2 (%3 bits) to bit-field %0 (%1 bits) may change value">,
+ InGroup<BitFieldConversion>, DefaultIgnore;
+def note_bitfield_assign : Note<
+ "Bit-field %0 (%1 bits) is too narrow to store assigned value %2 (%3 bits)">;
----------------
AaronBallman wrote:
```suggestion
"bit-field %0 (%1 bits) is too narrow to store assigned value %2 (%3 bits)">;
```
Actually, I don't think we need this note, but we could instead use the generic "declared here" diagnostic (`diag::note_declared_at`). The current note duplicates a lot of information already present in the warning or the source being noted, but once we remove the duplicate information, we're pretty much left with "bit-field declared here".
https://github.com/llvm/llvm-project/pull/68276
More information about the cfe-commits
mailing list