This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

More info on alpha bug


As I reported earlier, this code fails to run on alpha/linux:

# gcc -O inline.cc
# a.out
Aborted (core dumped)

The problem is the way how gcc works on alpha. Although alpha is
64 bit, gcc still uses 32 bit operations on many 64 bit integers.
It converts them back and forth between 32 bit/64 bit. As the
result, the return value of slen () is computed as 32 bit and sign
extened to 64 bit upon return. But between inlining and 32 bit/64 bit
coverting, srclen is stored as 32 bit integer on stack. Since
the original value is -1 and the computed value is 5, we get
0xffffffff00000005 instead of 0x0000000000000005. I hope it
will be fixed in the first release.


-- 
H.J. Lu (hjl@gnu.ai.mit.edu)
---
#include <new.h>

typedef struct
{
  unsigned short    len;
  unsigned short    sz;
  char s[1];
} Rep;

inline static void ncopy0(const char* from, char* to, int n)
{
  if (from != to)
  {
    while (--n >= 0) *to++ = *from++;
    *to = 0;
  }
  else
    to[n] = 0;
}

inline static int slen(const char* t) // inline  strlen               
{
  if (t == 0)                                                      
    return 0;                                                       
  else        
  {
    const char* a = t; 
    while (*a++ != 0);       
    return a - 1 - t;
  }
}

inline static Rep* Snew(int newsiz)
{
  if (newsiz == -1)
    abort ();

  Rep* rep = new (operator new (sizeof(Rep) + newsiz)) Rep;
  rep->sz = newsiz;
  return rep;
}

Rep *
copy (Rep *old, const char *src, int srclen, int newlen)
{
  if (srclen < 0) srclen = slen (src);
  if (newlen < srclen) newlen = srclen;
  Rep* rep;
  if (old == 0 || newlen > old->sz)  
  {
    rep = Snew (newlen);
  }
  else
    rep = old;

  rep->len = newlen;
  ncopy0(src, rep->s, srclen);

  return rep;
}

main ()
{
  Rep *rep = copy (0, "Hello", -1, -1);

  exit (0);
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]