[clang] Add an off-by-default warning to complain about MSVC bitfield padding (PR #117428)

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 2 15:22:56 PST 2024


================
@@ -631,6 +631,9 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses dangling references for C++20's parenthesized aggregate initialization (#101957).
 
+- A new off-by-default warning ``-Wms-bitfield-compatibility`` has been added to alert to cases where bit-field
----------------
rnk wrote:

I wanted to bikeshed the name. Is this really a compatibility warning? It's a compatibility issue for someone trying to use C structs to do memory-mapped I/O or something, but for LLVM's application, it's supposed to be a warning about extra bitfield padding, suggesting a name like `-Wms-bitfield-padding` or `-Wms-bitfield-packing`.

It also doesn't catch all bitfield layout differences. There are cases like [this](https://godbolt.org/z/hvd8aY8ba). Do we care about that, or is it better to leave that to `-Wpadding`?
```
struct Foo {
  char a;
  int x : 7; // msvc aligns to 4, gcc doesn't
  int y : 9;
};
```

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


More information about the cfe-commits mailing list