2010/3/9 Marcin Baczyński <marb...@gmail.com>:
> Hi,
> the following piece of code produces different output on svn trunk and
> gcc-4_4-branch:
>
> #include <stdio.h>
> int main()
> {
>        struct { unsigned bar:1; } foo;
>
>        foo.bar = 0x1;
>
>        printf("%08x\n", (unsigned char)(foo.bar * 0xfe));
>        printf("%08x\n", (unsigned char)(foo.bar * 0xff));
>
>        return 0;
> }
>
> monst...@yggdrasil /data/tmp $ gcc -v
> Using built-in specs.
> Target: x86_64-unknown-linux-gnu
> Configured with: ../gcc-svn/configure --enable-stage1-languages-c
> --enable-languages=c,c++
> Thread model: posix
> gcc version 4.4.4 20100309 (prerelease) (GCC)
> monst...@yggdrasil /data/tmp $ ./a.out
> 000000fe
> 00000001
>
> monst...@yggdrasil /data/tmp $ gcc -v
> Using built-in specs.
> COLLECT_GCC=gcc
> COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.5.0/lto-wrapper
> Target: x86_64-unknown-linux-gnu
> Configured with: ../gcc-svn/configure --enable-stage1-languages-c
> --enable-languages=c,c++
> Thread model: posix
> gcc version 4.5.0 20100309 (experimental) (GCC)
> monst...@yggdrasil /data/tmp $ ./a.out
> 000000fe
> 000000ff
>
> Is there something illegal in this code or is it a bug somewhere?

Probably something that was fixed for 4.5 but not backported to 4.4.
The 4.4 C frontend produces for the 2nd printf:

  printf ((const char * restrict) "%08x\n", (int) -foo.bar);

while 4.5 does

  printf ((const char * restrict) "%08x\n", (int) -(unsigned char) foo.bar);

I'm not sure where this difference comes from (and I can't convince
myself that this is a real fix).  Please file a bugreport.

Btw, 4.3 produced

  printf ((const char * restrict) (char *) "%08x\n", (int) (unsigned
char) ((int) foo.bar * 255));

and the same runtime result as 4.5.

Thanks,
Richard.

> Thanks,
> Marcin
>

Reply via email to