[clang] [clang][NFC] Annotate `Type` bit-fields with `clang::preferred_type` (PR #70349)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 27 00:17:22 PDT 2023


================
@@ -49,7 +49,7 @@ struct ExprDependenceScope {
 using ExprDependence = ExprDependenceScope::ExprDependence;
 
 struct TypeDependenceScope {
-  enum TypeDependence : uint8_t {
+  enum TypeDependence : unsigned {
----------------
cor3ntin wrote:

I had a chat with @Endilll offline.
The reason for this change is that `preferred_type` (#69104) warns when the enumerator has a different underlying type as the bit field. https://godbolt.org/z/zz99s6M3j

This warning does seem a bit off to me - but I really like its intent.
The warning only triggers on enumerators (which probably make sense as a general warning may have too many false positives), but I think the warning is too restrictive.
If the underlying type has the same signedness and has a size equal to **or smaller**  than the the size of the type of the bitfield, I don't think a warning should be produced.

I have convinced myself that the changes here are most likely fine (`TypeDependence` is (afaict) only stored in TypeBitfields, as far as i can tell, and this uses the number of bits of the greatest enumerator, which i did not initially realize).

Yet I do not like the idea that we would change the underlying type of all enums used in bitfields for the sake of that warning.

My preferred solution would be to make `-Wbitfield-type` less aggressive and not change the underlying types of enums is this patch.





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


More information about the cfe-commits mailing list