[PATCH] D71142: [Sema] Validate large bitfields

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 7 06:35:03 PST 2019


aaron.ballman added a comment.

In D71142#1773933 <https://reviews.llvm.org/D71142#1773933>, @Mordante wrote:

> I'll have a look whether I can find a sane maximum width for a bit-field.


The limits according to C are the size of the field's declared type (C17 6.7.2.1p4), but it seems that C++ decided it would make sense to turn the bits into padding bits (http://eel.is/c++draft/class.bit#1.sentence-6), so I guess a reasonable implementation limit would be `SIZE_MAX` for the target architecture (aka, `sizeof(size_t) * CHAR_BIT` bits).



================
Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:5186-5189
+def warn_bitfield_width_exceeds_maximum_width: Error<
+  "width of bit-field %0 doesn't fit in a 64 bit unsigned integer">;
+def warn_anon_bitfield_width_exceeds_maximum_width : Error<
+  "width of anonymous bit-field doesn't fit in a 64 bit unsigned integer">;
----------------
rsmith wrote:
> aaron.ballman wrote:
> > I feel like this situation should be an error rather than a warning -- what could the code possibly have meant?
> The name of the diagnostic and the kind of diagnostic should agree. Currently we have `warn_` vs `Error<`.
Ooof, good catch! These diagnostics should be renamed to start with `err_` instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71142





More information about the cfe-commits mailing list