[Bug c/46452] New: Apparently invalid optimization of bitfield access (4.5 regression?)

mbooth at redhat dot com gcc-bugzilla@gcc.gnu.org
Fri Nov 12 14:29:00 GMT 2010


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

           Summary: Apparently invalid optimization of bitfield access
                    (4.5 regression?)
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mbooth@redhat.com


Details here:

http://www.redhat.com/archives/augeas-devel/2010-November/msg00037.html

In summary, it appears that gcc is invalidly optimizing access to a bitfield in
the following struct:

struct dict {
    struct dict_node **nodes;
    uint32_t          size : 24;
    uint32_t          used : 24;
    uint32_t          marked : 1;
};

'used' is accessed from a static function, which appears to have been inlined.
A printf immediately before the function call gives used a value of 30, whereas
a printf immediately after the function call gives it a value of 2^24+30, which
should not be possible. Note that this only happens on i686, and did not happen
on 4.4.

I have attempted to reproduce this error in a smaller test case, but haven't
managed it. It is fortunately relatively simple to reproduce this error,
though:

* Grab augeas 0.7.3 from here: http://augeas.net/download/augeas-0.7.3.tar.gz
* Compile it with CFLAGS="-m32 -O2 -g"
* Ensure /etc/php.ini exists on your system (php-common rpm on F14)
* Run the following as root from the source directory:
    echo -e 'set /files/etc/php.ini/Date/date.timezone
"America/Los_Angeles"\nsave' | LD_LIBRARY_PATH=./src/.libs
AUGEAS_LENS_LIB=./lenses ./src/.libs/augtool

This will crash. At the point of the crash, dist->used = 2^24 + 30, according
to printf("%i", dist->used).

CFLAGS="-m32 -O2 -g"
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.5.1/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-gnu-unique-object
--enable-linker-build-id
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada,lto --enable-plugin
--enable-java-awt=gtk --disable-dssi
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
--with-ppl --with-cloog --with-tune=generic --with-arch_32=i686
--build=x86_64-redhat-linux
Thread model: posix
gcc version 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC)



More information about the Gcc-bugs mailing list