public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/48784] New: #pragma pack(1) + -fstrict-volatile-bitfields = bad codegen
@ 2011-04-27  1:19 arthur.j.odwyer at gmail dot com
  2012-08-18  1:11 ` [Bug middle-end/48784] " sandra at codesourcery dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2011-04-27  1:19 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: arthur.j.odwyer@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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-09-28  1:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-27  1:19 [Bug tree-optimization/48784] New: #pragma pack(1) + -fstrict-volatile-bitfields = bad codegen arthur.j.odwyer at gmail dot com
2012-08-18  1:11 ` [Bug middle-end/48784] " sandra at codesourcery dot com
2013-06-08 19:55 ` sandra at codesourcery dot com
2013-06-14  2:59 ` sandra at codesourcery dot com
2013-10-07 15:40 ` sandra at codesourcery dot com
2013-12-11 16:50 ` edlinger at gcc dot gnu.org
2013-12-11 16:59 ` edlinger at gcc dot gnu.org
2014-02-27  7:28 ` jye2 at gcc dot gnu.org
2021-09-28  1:37 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).