https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100058

            Bug ID: 100058
           Summary: -Wpadded is inconsistent using -mms-bitfields
           Product: gcc
           Version: 10.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: the4naves at gmail dot com
  Target Milestone: ---

// -----------
#include <stdint.h>
#include <stdio.h>

struct {
    uint16_t a;
    uint8_t b;
} test1;

struct {
    uint8_t b;
    uint16_t a;
} test2;

int main() {
    printf("Size 1: %d\n", sizeof(test1));
    printf("Size 2: %d", sizeof(test2));

    return 0;
}
// -----------

Compiling this code using `gcc test.cpp -Wpadded -mms-bitfields` only gives a
padding warning for the test1 struct. The printed sizes are both 4. Replacing
`-mms-bitfields` with `-mno-ms-bitfields` gives the expected warnings for
(test1) and (test2.a). The marked gcc version is 10.3, but I was able to
replicate this in every version back to 4.4. 4.1 does seem to work correctly.

Exact version is 10.3.0 under x86_64-linux-gnu. Other than the padding warnings
(1 for ms-bitfields, 2 for no-ms-bitfields), no warnings are printed.

`gcc -v` gives:
Configured with: ../gcc-10.3.0/configure
--prefix=/opt/compiler-explorer/gcc-build/staging --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu --disable-bootstrap
--enable-multiarch --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --enable-clocale=gnu
--enable-languages=c,c++,fortran,ada,go,d --enable-ld=yes --enable-gold=yes
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-linker-build-id
--enable-lto --enable-plugins --enable-threads=posix
--with-pkgversion=Compiler-Explorer-Build

Someone else suggested that the line `!targetm.ms_bitfield_layout_p (rli->t)`
in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52238 could be the issue, which
to me seems likely from a brief look.

Reply via email to