http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48784

           Summary: #pragma pack(1) + -fstrict-volatile-bitfields = bad
                    codegen
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: arthur.j.odw...@gmail.com


Created attachment 24109
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24109
Output of "ajo-gcc -fstrict-volatile-bitfields bug868575724-reduced.c -v"

#pragma pack(1) is incompatible with -fstrict-volatile-bitfields, causing
silently wrong codegen if you mix the two options. It feels like the compiler
really ought to warn the user that bad code will be generated, even if it *is*
ultimately the user's fault.  ...But is it even the user's fault, in this case?

cat >test.c <<EOF
#include <stdio.h>
#pragma pack(1)
volatile struct S0 {
   signed a : 7;
   unsigned b : 28;  /* b can't be fetched with an aligned 32-bit access, */
                     /* but it certainly can be fetched with an unaligned
access */
} g = {0,-1};
int main() {
    printf("%x\n", (unsigned int)g.b);
    return 0;
}
EOF
gcc test.c ; ./a.out  // prints "fffffff"
gcc -fstrict-volatile-bitfields test.c ; ./a.out  // prints "1ffffff"

Without -fstrict-volatile-bitfields, the correct 28-bit number "fffffff" is
printed. With -fstrict-volatile-bitfields, the incorrect 25-bit number
"1ffffff" is printed. 

Bug 43341 is a similar gray-area bug/not-a-bug involving #pragma pack.


This test case is reduced from the output of Csmith
(http://embed.cs.utah.edu/csmith/), using the following command line:
csmith --bitfields --packed-struct -s 868575724 > test868575724.c

Reply via email to