Re: set_bit() is broken on i386?

From: Valdis . Kletnieks
Date: Fri Jan 20 2006 - 20:31:44 EST


On Fri, 20 Jan 2006 19:53:14 EST, Chuck Ebbert said:
> /*
> * setbit.c -- test the Linux set_bit() function
> *
> * Compare the output of this program with and without the
> * -finline-functions option to GCC.
> *
> * If they are not the same, set_bit is broken.
> *
> * Result on i386 with gcc 3.3.2 (Fedora Core 2):
> *
> * [me@d2 t]$ gcc -O2 -o setbit.ex setbit.c ; ./setbit.ex
> * 00010001
> * [me@d2 t]$ gcc -O2 -o setbit.ex -finline-functions setbit.c ; ./setbit.ex
> * 00000001

It certainly seems to be gcc version dependent (and I'd not be surprised if the
exact combo of -O2, -Os, and -mfoo and -fwhatever flags as well). Trond is
probably right that a memory clobber will force gcc to DTIT (Do The Intended
Thing, which may be different from a DTRT) regardless of what gcc's code generator
decides to do....

% gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.0 20060117 (Red Hat 4.1.0-0.15)
% gcc -O2 -o setbit.ex setbit.c ; ./setbit.ex
00000001
% gcc -O2 -o setbit.ex -finline-functions setbit.c ; ./setbit.ex
00000001

Fedora Core -devel tree as of this morning (so sort-of FC5 test2).

Attachment: pgp00000.pgp
Description: PGP signature