Skip to content

[clang] -Wpadded-bitfield warns a wrong number of padded bytes with ms_struct #131647

Closed
@theomagellan

Description

@theomagellan

For the following struct:

struct __attribute__((ms_struct)) Foo {
  long long x;
  char a : 1;
  long long b : 1;
};

We should have a padding of 63 bits between a and b as the compiler aims for an 8 byte alignment, with a taking 1 bit and b having a different underlying type.

The following command clang -Wpaded foo.cc gives out the following warning:

test.cc:4:13: warning: padding struct 'Foo' with 7 bytes to align 'yy' [-Wpadded-bitfield]
    4 |   long long yy : 1;
      |             ^
test.cc:1:35: warning: padding size of 'Foo' with 63 bits to alignment boundary [-Wpadded]
    1 | struct __attribute__((ms_struct)) Foo {
      |                                   ^

From my understanding, something is wrong with the way the alignment warning for -Wpadded-bitfield is computed. Can somebody confirm this?

If confirmed, I would like to work on this issue.

Metadata

Metadata

Assignees

Labels

clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions