Bug 87344

Summary: archival/libarchive/decompress_gunzip.c:1139:2: error: size of unnamed array is negative, -mms-bitfields influences non-bitfield struct layout
Product: gcc Reporter: Wen Yang <yellowriver2010>
Component: targetAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal Keywords: ABI
Priority: P3    
Version: 6.2.0   
Target Milestone: ---   
Host: Target: x86_64-*-*, i?86-*-*
Build: Known to work:
Known to fail: 6.2.0, 6.4.0, 7.2.0 Last reconfirmed: 2018-09-18 00:00:00
Attachments: compile.sh
decompress_gunzip.i
decompress_gunzip.i

Description Wen Yang 2018-09-18 06:47:27 UTC
Created attachment 44710 [details]
compile.sh

# ./compile.sh
archival/libarchive/decompress_gunzip.c:1:0: warning: this target machine does not have delayed branches [enabled by default]
archival/libarchive/decompress_gunzip.c:1:0: warning: -fassociative-math disabled; other options take precedence [enabled by default]
archival/libarchive/decompress_gunzip.c: In function ‘check_header_gzip’:
archival/libarchive/decompress_gunzip.c:1139:2: error: size of unnamed array is negative





The orignal code is:
1126 static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
1127 {
1128     union {
1129         unsigned char raw[8];
1130         struct {
1131             uint8_t gz_method;
1132             uint8_t flags;
1133             uint32_t mtime;
1134             uint8_t xtra_flags_UNUSED;
1135             uint8_t os_flags_UNUSED;
1136         } PACKED formatted;
1137     } header;
1138
1139     BUILD_BUG_ON(sizeof(header) != 8);


The preprocessed code is:
11347 static int check_header_gzip(state_t *state, transformer_state_t *xstate)
11348 {
11349  union {
11350   unsigned char raw[8];
11351   struct {
11352    uint8_t gz_method;
11353    uint8_t flags;
11354    uint32_t mtime;
11355    uint8_t xtra_flags_UNUSED;
11356    uint8_t os_flags_UNUSED;
11357   } __attribute__ ((__packed__)) formatted;
11358  } header;
11359
11360  ((void)sizeof(char[1 - 2*!!(sizeof(header) != 8)]));
Comment 1 Wen Yang 2018-09-18 06:48:35 UTC
Created attachment 44711 [details]
decompress_gunzip.i
Comment 2 Wen Yang 2018-09-18 06:51:06 UTC
Created attachment 44712 [details]
decompress_gunzip.i
Comment 3 Richard Biener 2018-09-18 07:39:08 UTC
Confirmed with your gazillion command line flags, works fine with plain -Os.

Maybe you can remove the ones not necessary, it's hard to see if there's a stupid user error.
Comment 4 Richard Biener 2018-09-18 07:46:34 UTC
It's -mms-bitfields which appearantly influences layout of the following struct:

 union {
  unsigned char raw[8];
  struct {
   uint8_t gz_method;
   uint8_t flags;
   uint32_t mtime;
   uint8_t xtra_flags_UNUSED;
   uint8_t os_flags_UNUSED;
  } __attribute__ ((__packed__)) formatted;
 } header;

 ((void)sizeof(char[1 - 2*!!(sizeof(header) != 8)]));

Not sure if the difference is intended.
Comment 5 Martin Liška 2018-09-18 08:04:53 UTC
Fixed in r258075, thus dup.

*** This bug has been marked as a duplicate of bug 52991 ***