[PATCH] C11 _Bool bitfield diagnostic

Richard Smith richard at metafoo.co.uk
Mon Jun 1 21:05:46 PDT 2015


================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:4274-4279
@@ -4273,2 +4273,8 @@
   "number of elements must be either one or match the size of the vector">;
+def warn_bitfield_width_longer_than_necessary : Warning<
+  "size of bit-field %0 (%1 bits) exceeds the width needed to represent all "
+  "valid values of that bit-field type">, InGroup<BitFieldWidth>;
+def warn_anon_bitfield_width_longer_than_necessary : Warning<
+  "size of anonymous bit-field (%0 bits) exceeds the width needed to represent "
+  "all valid values of that bit-field type">, InGroup<BitFieldWidth>;
 
----------------
Since this is a constraint violation according to the C11 standard, this should be an `ExtWarn` or `Extension` rather than merely a `Warning`.

================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:4274-4279
@@ -4273,2 +4273,8 @@
   "number of elements must be either one or match the size of the vector">;
+def warn_bitfield_width_longer_than_necessary : Warning<
+  "size of bit-field %0 (%1 bits) exceeds the width needed to represent all "
+  "valid values of that bit-field type">, InGroup<BitFieldWidth>;
+def warn_anon_bitfield_width_longer_than_necessary : Warning<
+  "size of anonymous bit-field (%0 bits) exceeds the width needed to represent "
+  "all valid values of that bit-field type">, InGroup<BitFieldWidth>;
 
----------------
rsmith wrote:
> Since this is a constraint violation according to the C11 standard, this should be an `ExtWarn` or `Extension` rather than merely a `Warning`.
I think this diagnostic should be more specific. The diagnostic text should make it clear that: (1) the problem is that the field has a boolean type, and (2) why that might deserve a warning. Something like "ISO C11 forbids bit-field of type %0 of size greater than 1 (%1 specified)", maybe.

================
Comment at: lib/Sema/SemaDecl.cpp:12341
@@ +12340,3 @@
+    // different platforms
+    if (getLangOpts().C11 && 
+        FieldTy->isBooleanType() &&
----------------
It looks like this should apply in all modes that aren't C++: even in C99, we have a constraint in 6.7.2.1 that the specified bit-width cannot be greater than the width of the type, and width is defined in 6.2.6.2 as the number of precision + sign bits.

http://reviews.llvm.org/D10018

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list