Bug 44806 - 4.5.0 i686 code generation regression with -O2
Summary: 4.5.0 i686 code generation regression with -O2
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-03 16:35 UTC by jim
Modified: 2010-07-04 00:29 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jim 2010-07-03 16:35:12 UTC
This bug manifests on i686, and not on x86_64.
[FYI, pared down from a proposed patch for coreutils' du.c. ]

The following code, compiled with 4.5.0 and -O2 exits with status 1.
Compile with 4.4.4 and any optimization or 4.5.0 with -O1 and it exits with status 0.

$ cat k.c
#include <stdint.h>

#define N_DEV_BITS_4 5
#define N_INO_BITS_4 (32 - N_DEV_BITS_4 - 2 - 1)

#define N_DEV_BITS_8 8
#define N_INO_BITS_8 (64 - N_DEV_BITS_8 - 2 - 1)

struct dev_ino_4
{
  uint32_t mode:2;
  uint32_t short_ino:N_INO_BITS_4;
  uint32_t mapped_dev:N_DEV_BITS_4;
  uint32_t always_set:1;
};

struct dev_ino_8
{
  uint32_t mode:2;
  uint64_t short_ino:N_INO_BITS_8;
  uint32_t mapped_dev:N_DEV_BITS_8;
  uint32_t always_set:1;
};

struct dev_ino_full
{
  uint32_t mode:2;
  uint32_t dev;
  uint32_t ino;
};

enum di_mode
{
  DI_MODE_4 = 1,
  DI_MODE_8 = 2,
  DI_MODE_FULL = 3
};

struct di_ent
{
  union
  {
    struct dev_ino_4 di4;
    struct dev_ino_8 di8;
    struct dev_ino_full full;
    uint32_t u32;
    uint64_t u64;
    void *ptr;
  } u;
};

static struct di_ent
decode_ptr (struct di_ent const *v)
{
  struct di_ent di;
  di.u.ptr = (void *) v;
  return di;
}

static int
di_ent_equal (void const *x, void const *y)
{
  struct di_ent a = decode_ptr (x);
  struct di_ent b = decode_ptr (y);
  if (a.u.di4.mode != b.u.di4.mode)
    return 0;

  if (a.u.di4.mode == DI_MODE_4)
    return (a.u.di4.short_ino == b.u.di4.short_ino
            && a.u.di4.mapped_dev == b.u.di4.mapped_dev);

  if (a.u.di8.mode == DI_MODE_8)
    return (a.u.di8.short_ino == b.u.di8.short_ino
            && a.u.di8.mapped_dev == b.u.di8.mapped_dev);

  return (a.u.full.ino == b.u.full.ino
          && a.u.full.dev == b.u.full.dev);
}

int
main ()
{
  return di_ent_equal ((void *) 0x80143c4d, (void *) 0x80173851);
}
$ /p/p/gcc-4.5.0/bin/gcc -Wall -O2 k.c && ./a.out
[Exit 1]
$ /p/p/gcc-4.5.0/bin/gcc -Wall -O1 k.c && ./a.out; echo $?
0
$ gcc -v 2>&1|tail -1
gcc version 4.4.4 20100503 (Red Hat 4.4.4-2) (GCC) 
$ gcc -Wall -O2 k.c && ./a.out; echo $?
0

configured with: ../configure --disable-nls --enable-languages=c --prefix=/p/p/gcc-4.5.0
Comment 1 Mikael Pettersson 2010-07-03 20:44:02 UTC
This test case works for me on i686-linux with gcc-4.5-20100701, but fails with gcc-4.5.0.  So it should be fixed in 4.5.1.
Comment 2 Richard Biener 2010-07-03 21:21:58 UTC
Fixed.
Comment 3 hjl@gcc.gnu.org 2010-07-03 22:44:45 UTC
Subject: Bug 44806

Author: hjl
Date: Sat Jul  3 22:44:32 2010
New Revision: 161787

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161787
Log:
Add a testcase for PR 44806.

2010-07-03  H.J. Lu  <hongjiu.lu@intel.com>

	PR c/44806
	* gcc.dg/torture/pr44806.c: New.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr44806.c
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 4 hjl@gcc.gnu.org 2010-07-03 22:47:56 UTC
Subject: Bug 44806

Author: hjl
Date: Sat Jul  3 22:47:43 2010
New Revision: 161789

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161789
Log:
Add a testcase for PR 44806.

2010-07-03  H.J. Lu  <hongjiu.lu@intel.com>

	Backport from mainline
	2010-07-03  H.J. Lu  <hongjiu.lu@intel.com>

	PR c/44806
	* gcc.dg/torture/pr44806.c: New.

Added:
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/torture/pr44806.c
Modified:
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog

Comment 5 H.J. Lu 2010-07-04 00:29:57 UTC
It is fixed by revision 158826:

http://gcc.gnu.org/ml/gcc-cvs/2010-04/msg00933.html