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]

A strang alpha bug


On alpha, I got

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

It seems that the exception handling is messing up something.


-- 
H.J. Lu (hjl@gnu.ai.mit.edu)
---inline.cc--
#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]