Bug#491653: gcc-4.3: misoptimization of 64-bit bitfield when not byte aligned
Package: gcc-4.3
Version: 4.3.1-6
Severity: normal
This testcase produces different output depending on whether -O1 or -O2 is
specified. Correct:
# gcc PR1386.c -o pr1386 -O1
PR1386.c: In function ‘main’:
PR1386.c:15: warning: large integer implicitly truncated to unsigned type
PR1386.c:17: warning: large integer implicitly truncated to unsigned type
# ./pr1386
bad bits: 0
Wrong:
# gcc PR1386.c -o pr1386 -O2
PR1386.c: In function ‘main’:
PR1386.c:15: warning: large integer implicitly truncated to unsigned type
PR1386.c:17: warning: large integer implicitly truncated to unsigned type
# ./pr1386
bad bits: 268237f7fb6a30
Testcase taken from llvm.org/PR1386 (it shows up as a flaw in llvm testing,
but it's actually gcc getting it wrong. Doh!)
-- System Information:
Debian Release: lenny/sid
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: i386 (x86_64)
Kernel: Linux 2.6.25.9 (PREEMPT)
Locale: LANG=en_CA.UTF-8, LC_CTYPE=en_CA.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages gcc-4.3 depends on:
hi binutils 2.18.50.20080507-1 The GNU assembler, linker and bina
ii cpp-4.3 4.3.1-6 The GNU C preprocessor
ii gcc-4.3-base 4.3.1-6 The GNU Compiler Collection (base
ii libc6 2.7-12 GNU C Library: Shared libraries
ii libgcc1 1:4.3.1-6 GCC support library
ii libgomp1 4.3.1-6 GCC OpenMP (GOMP) support library
Versions of packages gcc-4.3 recommends:
ii libc6-dev 2.7-12 GNU C Library: Development Librari
Versions of packages gcc-4.3 suggests:
pn gcc-4.3-doc <none> (no description available)
pn gcc-4.3-locales <none> (no description available)
pn gcc-4.3-multilib <none> (no description available)
ii libgcc1-dbg 1:4.3.1-6 GCC support library (debug symbols
pn libgomp1-dbg <none> (no description available)
pn libmudflap0-4.3-dev <none> (no description available)
pn libmudflap0-dbg <none> (no description available)
-- no debconf information
#include <stdio.h>
#include <stdint.h>
struct X {
unsigned char pad : 4;
uint64_t a : 64;
uint64_t b : 60;
} __attribute__((packed));
int main (void)
{
struct X x;
uint64_t bad_bits;
x.pad = 255;
x.a = -1ULL;
x.b = -1ULL;
bad_bits = ((uint64_t)-1ULL) ^ *(1+(uint64_t *) &x);
printf("bad bits: %llx\n", bad_bits);
return bad_bits != 0;
}
Reply to: