void f (void)
{
  unsigned n = 0;
  T (__builtin_malloc (n));

  n = 1024;   /* 1 kibibyte (KB or KiB) */
  T (__builtin_malloc (n));

  n = 1025;
  T (__builtin_malloc (n));   /* { dg-warning "argument 1 value .1025. exceeds maximum object size 1024" } */
}
Exemple #2
0
int
main ()
{
  /* Heap allocated memory.  */
  char *p = (char *)__builtin_malloc (42);
  int r = foo (p);
  __builtin_free (p);

  p = (char *)__builtin_malloc (1024);
  bar (p, p + 1024);
  bar (p + 1024, p + 1023);
  bar (p + 1, p + 1023);
  __builtin_free (p);

  p = (char *)__builtin_malloc (4096);
  bar (p, p + 4096);
  bar (p + 10, p + 100);
  bar (p + 1024, p + 4096);
  bar (p + 4095, p + 4096);
  bar (p + 4095, p + 4094);
  bar (p + 100, p + 4096);
  bar (p + 100, p + 4094);
  __builtin_free (p);

  /* Global variable.  */
  bar (&global[0], &global[1]);
  bar (&global[1], &global[2]);
  bar (&global[2], &global[1]);
  bar (&global[0], &global[100]);
  bar (&global[1000], &global[7000]);
  bar (&global[500], &global[10]);
  p = &global[0];
  bar (p, p + 8192);
  p = &global[8000];
  bar (p, p + 192);

  p = &small_global[0];
  bar (p, p + 1);
  bar (p, p + 7);
  bar (p + 7, p + 1);
  bar (p + 6, p + 7);
  bar (p + 7, p + 7);

  /* Stack variable.  */
  char stack[10000];
  bar (&stack[0], &stack[100]);
  bar (&stack[1000], &stack[9000]);
  bar (&stack[500], &stack[10]);

  baz (0, &stack[10]);

  return 0;
}
Exemple #3
0
static void *
inl (const char *x, const char *y)
{
  T t = { &xa, &xb };
  int *f = (int *) __builtin_malloc (sizeof (int));
  const char *z;
  int o = 0;
  void *r = 0;

  for (z = y; *z; z++)
    {
      if (*z == 'r')
	o |= 1;
      if (*z == 'w')
	o |= 2;
    }
  if (o == 1)
    *f = baz (x, 0);
  if (o == 2)
    *f = baz (x, 1);
  if (o == 3)
    *f = baz (x, 2);

  if (o && *f > 0)
    r = bar (f, "w", t);
  return r;
}
Exemple #4
0
void test2(void)
{
  int *p = __builtin_malloc (sizeof (int) * 4);
  if (p == (void *)0)
    __builtin_abort ();
  __builtin_free (p);
}
Exemple #5
0
void test3(int b)
{
    int *p = __builtin_malloc (sizeof (int) * 4);
    if (b)
        __builtin_free (p);
    *p = 5;
}
Exemple #6
0
void foo(char *str)
{
  int len2 = strlen (str);
  char *a = (char *) __builtin_malloc (0);
  char *b = (char *) __builtin_malloc (len2*3);

  if ((int) (a-b) < (len2*3))
    {
#ifdef _WIN32
      abort ();
#endif
      free(a); free(b);
      return;
    }
    free(a); free(b);
}
void f (void)
{
  size_t n = 0;
  T (__builtin_malloc (n));

  n = __PTRDIFF_MAX__;
  T (__builtin_malloc (n));

  n += 1;
  T (__builtin_malloc (n));

  n = __SIZE_MAX__ - 1;
  T (__builtin_malloc (n));

  n = __SIZE_MAX__;
  T (__builtin_malloc (n));
}
void test (void *p, unsigned n)
{
  TEST (__builtin_aligned_alloc (n, 8));
  TEST (__builtin_alloca (n));
  TEST (__builtin_calloc (4, n));
  TEST (__builtin_malloc (n));
  TEST (__builtin_realloc (p, n + 1));
}
Exemple #9
0
void test1(void)
{
    int *p = __builtin_malloc (sizeof (int) * 4);
    int *q = p;
    *q++ = 4;
    *q++ = 4;
    __builtin_free (p);
}
void f(int n)
{
  char *p = __builtin_malloc (1);
  int i;
  do
    *p = 0;
  while (++i < n);
}
Exemple #11
0
int main()
{
 void *p = __builtin_malloc (sizeof (B));
 new (p) B;
 foo(p);
 reinterpret_cast<A *>(p)->~A();
 return 0;
}
Exemple #12
0
void f1 (const char *c)
{
  A *s = (A*) __builtin_malloc (sizeof (A));
  double *p = &s->d;
  s->i = 42;
  __builtin_memcpy (p, c, sizeof (double));
  int j = s->i;
  if (j != 42) __builtin_abort();
}
Exemple #13
0
int
main (void)
{
  volatile int a[5];
  a[4] = 1;
  a[2] = a[3];
  fn_p (a[4]);
  fn_a (a);

  int i = 4;
  a[i] = 1;
  a[2] = a[i];
  fn_p (a[i]);
  foo_i (i);

  const int n = 5;
  volatile int b[n];
  b[4] = 1;
  b[2] = b[3];
  fn_p (b[4]);
  fn_a (b);

  volatile int c[n][n][n];
  c[2][2][2] = 2;
  i = c[4][4][4];

  volatile struct S s;
  s.a[9] = 1;
  i = s.a[9];

  /* Don't instrument flexible array members.  */
  struct T *t = (struct T *) __builtin_malloc (sizeof (struct T) + 10);
  t->a[1] = 1;

  struct U *u = (struct U *) __builtin_malloc (sizeof (struct U) + 10);
  u->a[1] = 1;

  long int *d[10][5];
  d[9][0] = (long int *) 0;
  d[8][3] = d[9][0];

  return 0;
}
Exemple #14
0
void foo(int n)
{
  int * f = (int*) __builtin_malloc (n * sizeof (int));
  int * ff = (int*) __builtin_malloc (n * sizeof (int));
  int i;

  for (i = 0; i < n; ++i)
    {
      f[i] = 1;
      ff[i] = 2;
      if (f[i] != 1)
	link_error ();
      if (ff[i] != 2)
	link_error ();
    }

  __builtin_free (f);
  __builtin_free (ff);
}
static void *bar(__SIZE_TYPE__ n, int cond)
{
  void *p;
  if (cond)
    p = foo (n);
  else
    p = __builtin_malloc (n);

  return p;
}
Exemple #16
0
int main (void)
{
  unsigned long d = 0;
  while (1)
    {
      switch (b)
      case 'S':
	d = a;
      c = __builtin_malloc (d);
    }

  return 0;
}
Exemple #17
0
int main ()
{
  int i = 1;
  int **p;
  j = 0;
  p = __builtin_malloc (sizeof (int *));
  *p = &i;
  p = __builtin_realloc (p, 2 * sizeof (int *));
  **p = 0;
  if (i != 0)
    __builtin_abort ();
  return j;
}
Exemple #18
0
int
main ()
{
  struct S *p = __builtin_malloc (sizeof (struct S) + 16);
  if (p)
    {
      p->a = 1;
      __builtin_strcpy (p->b, "abcdefg");
      if (foo (p) != 7 || bar (p) != 7)
	__builtin_abort ();
      __builtin_free (p);
    }
  return 0;
}
Exemple #19
0
int
foobar (unsigned short length)
{
  char *pbuf;
  __SIZE_TYPE__ size = (__SIZE_TYPE__) length;

  if (size < 4032)
    pbuf = (char *) __builtin_alloca(size);
  else
    pbuf = (char *) __builtin_malloc (size);

  useit(pbuf);
  return 0;
}
Exemple #20
0
inline void* operator new(size_t sz)
{
  void *p;

  if (sz == 0)
    sz = 1;

  while ((p = __builtin_malloc (sz)) == 0)
    {
      handler_t handler = get_handle ();
      if (! handler)
        throw 42;
      handler ();
    }
  return p;
}
Exemple #21
0
void f(){
  char*p=__builtin_malloc(42);
  __builtin_memset(p,3,10);
  __builtin_memset(p,7,33);
}
Exemple #22
0
void h(){
  char*p=__builtin_malloc(42);
  g=__builtin_memset(p,3,10);
  __builtin_free(p);
}
Exemple #23
0
void test5(int b)
{
  int *p = __builtin_malloc (sizeof (int) * 4);
  if (p)
    __builtin_free (p);
}
Exemple #24
0
char*i(){
  char*p=__builtin_malloc(42);
  __builtin_memset(p,3,10);
  __builtin_memset(p,7,33);
  return p;
}
Exemple #25
0
void *
foo (void)
{
  return __builtin_malloc (5);
}
static void *foo (__SIZE_TYPE__ n)
{
  return __builtin_malloc (n * 10);
}
Exemple #27
0
void*f(){
    char*p=__builtin_malloc(42);
    __builtin_memset(p,0,42);
    __builtin_memset(p,0,42);
    return p;
};
Exemple #28
0
void *test1(size_t n)
{
  return __builtin_malloc(n);
}
Exemple #29
0
inline void* operator new(__SIZE_TYPE__ n){ return __builtin_malloc(n); }