This is the mail archive of the gcc-patches@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]

structure return test case


The original form of this test only verified the the contents of the
copied structure were correct after the copy.  Thus the test would
only fail if the target's memcpy is unrolled just enough to see the
overlap, but not enough to perform the entire copy in one go.

But this form of the test fails on alpha (and likely elsewhere) as
well, since *any* overlap in the arguments to memcpy is illegal.

I'm not sure how best to solve this.  Ideally we'd invoke memmove
instead of memcpy when we are not sure that there's no overlap.  How
to identify that condition without genericly replacing memcpy with
memmove in the expansion of a MODIFY_EXPR is an open question.

Wasn't there some discussion at one point about Fortran needing a
form of MODIFY_EXPR that might overlap?  I don't see that we ever
added such a thing...

This is a regression from egcs-1.1, so I've left it without xfails.


r~
/* Verify that structure return doesn't invoke memcpy on 
   overlapping objects.  */

extern void abort (void);
typedef __SIZE_TYPE__ size_t;

struct S {
  char stuff[1024];
};

union U {
  struct {
    int space;
    struct S s;
  } a;
  struct {
    struct S s;
    int space;
  } b;
};

static struct S f(struct S *);
static void g(union U *);

int main()
{
  union U u;
  u.b.s = f(&u.a.s);
  u.a.s = f(&u.b.s);
  g(&u);
  return 0;
}
  
static struct S f(struct S *p)
{
  return *p;
}

static void g(union U *p)
{
}

static void *memcpy(void *a, const void *b, size_t len)
{
  if (a < b && a+len > b)
    abort ();
  if (b < a && b+len > a)
    abort ();
  return a;
}

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