This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

bad user, or optimization bug with worked-around lvalue casts ?


Hi,

after switching to gcc-4.1.1 from gcc-3.4.5, I'm facing a problem with
this code searching for non-blank in a string (extracted test-case):

#include <stdio.h>
int check(const void *pvBuf)
{
    for(; *((char*)pvBuf) == ' '; ++ *((char**)&pvBuf));
    return *((char*)pvBuf);
}
int main(void)
{
        printf("%d\n", check(" x"));
        return 0;
}

When building without optimization, it works as expected.
When building with -O2 or higher, the loop hangs.
This seems to be platform independant, as it occurs on x86-linux as well
as powerpc-aix, hppa-hpux, ia64-hpux, x86-solaris and sparc-solaris.

Now the question is:
Is this a user-bug only, not looking at the output of "-Wall" (because
this code builds and works successfully for 5 years now),
or is it a gcc-bug too, producing working code without optimization
and non-working code with optimization level >= 2 ?

And: can this code be changed without using an intermediate variable ?

Thanks,
  haubi


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]