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

            Bug ID: 59138
           Summary: possible packed struct miscompile
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: regehr at cs dot utah.edu

[regehr@imp test1]$ clang -O -Wall ./work17/reduce_D0DDXs/small.c ; ./a.out 
0
[regehr@imp test1]$ gcc -O2 -Wall ./work17/reduce_D0DDXs/small.c ; ./a.out
0
[regehr@imp test1]$ gcc -Os -Wall ./work17/reduce_D0DDXs/small.c ; ./a.out
1
[regehr@imp test1]$ cat ./work17/reduce_D0DDXs/small.c
int printf(const char *, ...);
#pragma pack(1)
struct S0 {
  int f0;
  int f1;
  int f2;
  short f3;
};
short a = 1;
struct S0 b = { 1 }, c, d, e;

struct S0 fn1() { return c; }

void fn2() {
  b = fn1();
  a = 0;
  d = e;
}

int main() {
  fn2();
  printf("%d\n", a);
  return 0;
}
[regehr@imp test1]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/mnt/local/randomtest/compiler-install/gcc-r204770-install/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /users/regehr/z/compiler-source/gcc/configure
--prefix=/users/regehr/z/compiler-install/gcc-r204770-install
--enable-languages=c,c++ --enable-multilib
Thread model: posix
gcc version 4.9.0 20131114 (experimental) (GCC)

Reply via email to