aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land.
In D158145#4594569 <https://reviews.llvm.org/D158145#4594569>, @cor3ntin wrote: > In D158145#4594549 <https://reviews.llvm.org/D158145#4594549>, @danix800 > wrote: > >> I also investigated whether we could count those bits at compile time and >> statically assert on them, >> because a small typo or missed update could spend us a lot of time to dig >> for the cause. >> >> My first step is trying to count number of bits for a single bitfield, this >> is promising based on this >> <https://gist.github.com/RMDarth/6357ddd6e09b4117efe84fc3347a732a> but >> with a restriction, it only works on `struct` (default public fields), not >> `class` (default to private fields). >> >> If we can implement this `bitsizeof` then we could have: >> >> enum { NumFunctionDeclBits = offsetof(FunctionDeclBitfields, SClass) >> + offsetof(FunctionDeclBitfields, IsInline) >> + ... }; >> >> This can automatically update total number of bits if any of the existing >> one is updated. >> >> The second step is trying to enumerate all bit fields at compile time so >> that we can totally fix this kind >> of issue, but it seems not possible. >> >> Any suggestions or advices? Is it even worth it to do it like this? > > It would be great to be able to stattic_assert these sort of bugs. I think > @aaron did some research in this area, it might be worth asking him how far > he got! I was never able to find a conforming way to do it without implementing something like a "bitwidth of" operator, which is something I was planning to propose to WG14 anyway for use with `_BitInt`. I've not implemented the extension yet though, and even if I did, it wouldn't help us with non-Clang host compilers, so I eventually gave up trying to automatically calculate the values. Changes LGTM! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D158145/new/ https://reviews.llvm.org/D158145 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits