[Bug middle-end/18089] [4.0 regression] Valgrind errors in real.c

jakub at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Fri Jan 14 20:36:00 GMT 2005


------- Additional Comments From jakub at gcc dot gnu dot org  2005-01-14 20:36 -------
To prove this is a valgrind bug and not GCC bug, I wrote a small self-contained
testcase on which valgrind complains:
#define EXP_BITS (32 - 5)
struct real_value
{
  unsigned int cl : 2;
  unsigned int sign : 1;
  unsigned int signalling : 1;
  unsigned int canonical : 1;
  unsigned int uexp : EXP_BITS;
  unsigned long sig[4];
};

#if defined __i386__ && defined USE_ASM
#define REAL_EXP(REAL) \
  ({ int ret; \
     __asm ("movl (%%eax),%%eax; subl $0x80000000,%%eax; shrl $5, %%eax; subl
$0x4000000,%%eax" \
            : "=a" (ret) : "a" (REAL), "m" (*(REAL))); \
     ret; })
#else
#define REAL_EXP(REAL) \
  ((int)((REAL)->uexp ^ (unsigned int)(1 << (EXP_BITS - 1))) \
   - (1 << (EXP_BITS - 1)))
#endif

#if __GNUC__ >= 3
#define __noinline __attribute ((noinline))
#else
#define __noinline
#endif

int dummy;

void __noinline
bar (void)
{
  ++dummy;
}

void __noinline
foo (struct real_value *r)
{
  if (REAL_EXP (r) <= 5)
    bar ();
}

int
main (void)
{
  struct real_value r;
  r.uexp = 0x21;
  foo (&r);
  return 0;
}

Both with -DUSE_ASM and without CVS GCC generates the same assembly and in both
cases valgrind --tool=memcheck /tmp/test fails with:
==31022== Conditional jump or move depends on uninitialised value(s)
==31022==    at 0x8048368: foo (test.c:41)
==31022==    by 0x80483A4: main (test.c:50)


-- 


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



More information about the Gcc-bugs mailing list